*: drop miner transaction
1. Completely remove miner transaction 2. Change validation rule for block: block without transactions is valid.
This commit is contained in:
parent
55fd9f8d24
commit
29d321b5e1
24 changed files with 128 additions and 314 deletions
|
@ -83,17 +83,7 @@ func (bc *Blockchain) genBlocks(n int) ([]*block.Block, error) {
|
|||
lastHash := bc.topBlock.Load().(*block.Block).Hash()
|
||||
lastIndex := bc.topBlock.Load().(*block.Block).Index
|
||||
for i := 0; i < n; i++ {
|
||||
minerTx := transaction.NewMinerTXWithNonce(uint32(1234 + i))
|
||||
minerTx.ValidUntilBlock = lastIndex + uint32(i) + 1
|
||||
err := addSender(minerTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = signTx(bc, minerTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blocks[i] = newBlock(bc.config, uint32(i)+lastIndex+1, lastHash, minerTx)
|
||||
blocks[i] = newBlock(bc.config, uint32(i)+lastIndex+1, lastHash)
|
||||
if err := bc.AddBlock(blocks[i]); err != nil {
|
||||
return blocks, err
|
||||
}
|
||||
|
@ -146,7 +136,6 @@ func newDumbBlock() *block.Block {
|
|||
Nonce: 1111,
|
||||
},
|
||||
Transactions: []*transaction.Transaction{
|
||||
{Type: transaction.MinerType},
|
||||
{Type: transaction.IssueType},
|
||||
},
|
||||
}
|
||||
|
@ -181,13 +170,6 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
return testNonce
|
||||
}
|
||||
|
||||
// Creates new miner tx with specified validUntilBlock field
|
||||
nextMinerTx := func(validUntilBlock uint32) *transaction.Transaction {
|
||||
minerTx := transaction.NewMinerTXWithNonce(getNextNonce())
|
||||
minerTx.ValidUntilBlock = validUntilBlock
|
||||
return minerTx
|
||||
}
|
||||
|
||||
var neoAmount = util.Fixed8FromInt64(99999000)
|
||||
var neoRemainder = util.Fixed8FromInt64(100000000) - neoAmount
|
||||
bc := newTestChain(t)
|
||||
|
@ -201,8 +183,8 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
// use output of issue tx from genesis block as an input
|
||||
genesisBlock, err := bc.GetBlock(bc.GetHeaderHash(0))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 5, len(genesisBlock.Transactions))
|
||||
h := genesisBlock.Transactions[3].Hash()
|
||||
require.Equal(t, 4, len(genesisBlock.Transactions))
|
||||
h := genesisBlock.Transactions[2].Hash()
|
||||
txMoveNeo.AddInput(&transaction.Input{
|
||||
PrevHash: h,
|
||||
PrevIndex: 0,
|
||||
|
@ -225,12 +207,8 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
Position: 1,
|
||||
})
|
||||
txMoveNeo.Data = new(transaction.ContractTX)
|
||||
|
||||
minerTx := nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = neoOwner
|
||||
|
||||
require.NoError(t, signTx(bc, minerTx, txMoveNeo))
|
||||
b := bc.newBlock(minerTx, txMoveNeo)
|
||||
require.NoError(t, signTx(bc, txMoveNeo))
|
||||
b := bc.newBlock(txMoveNeo)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE())
|
||||
|
||||
|
@ -264,10 +242,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
})
|
||||
txNeoRound.Data = new(transaction.ContractTX)
|
||||
require.NoError(t, acc0.SignTx(txNeoRound))
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, txNeoRound)
|
||||
b = bc.newBlock(txNeoRound)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
t.Logf("txNeoRound: %s", txNeoRound.Hash().StringLE())
|
||||
|
||||
|
@ -291,10 +266,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
Position: 0,
|
||||
})
|
||||
require.NoError(t, acc0.SignTx(txClaim))
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, txClaim)
|
||||
b = bc.newBlock(txClaim)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
t.Logf("txClaim: %s", txClaim.Hash().StringLE())
|
||||
|
||||
|
@ -337,10 +309,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
})
|
||||
gasOwned -= invFee
|
||||
require.NoError(t, acc0.SignTx(txDeploy))
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, txDeploy)
|
||||
b = bc.newBlock(txDeploy)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
t.Logf("txDeploy: %s", txDeploy.Hash().StringLE())
|
||||
|
||||
|
@ -353,10 +322,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
txInv.ValidUntilBlock = validUntilBlock
|
||||
txInv.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(txInv))
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, txInv)
|
||||
b = bc.newBlock(txInv)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
t.Logf("txInv: %s", txInv.Hash().StringLE())
|
||||
|
||||
|
@ -382,10 +348,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
})
|
||||
|
||||
require.NoError(t, acc0.SignTx(txNeo0to1))
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, txNeo0to1)
|
||||
b = bc.newBlock(txNeo0to1)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
|
||||
sh := hash.Hash160(avm)
|
||||
|
@ -402,10 +365,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
transferTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(transferTx))
|
||||
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, initTx, transferTx)
|
||||
b = bc.newBlock(initTx, transferTx)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
|
||||
transferTx = newNEP5Transfer(sh, priv0.GetScriptHash(), priv1.GetScriptHash(), 123)
|
||||
|
@ -414,10 +374,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
transferTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(transferTx))
|
||||
|
||||
minerTx = nextMinerTx(validUntilBlock)
|
||||
minerTx.Sender = priv0ScriptHash
|
||||
require.NoError(t, acc0.SignTx(minerTx))
|
||||
b = bc.newBlock(minerTx, transferTx)
|
||||
b = bc.newBlock(transferTx)
|
||||
require.NoError(t, bc.AddBlock(b))
|
||||
|
||||
if saveChain {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue