*: 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
|
@ -36,7 +36,8 @@ func (fs *FeerStub) SystemFee(*transaction.Transaction) util.Fixed8 {
|
|||
|
||||
func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) {
|
||||
mp := NewMemPool(10)
|
||||
tx := transaction.NewMinerTXWithNonce(0)
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = 0
|
||||
_, _, ok := mp.TryGetValue(tx.Hash())
|
||||
require.Equal(t, false, ok)
|
||||
require.NoError(t, mp.Add(tx, fs))
|
||||
|
@ -72,8 +73,8 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
|
|||
mpLessClaims := func(i, j int) bool {
|
||||
return mp.claims[i].Cmp(mp.claims[j]) < 0
|
||||
}
|
||||
|
||||
txm1 := transaction.NewMinerTXWithNonce(1)
|
||||
txm1 := transaction.NewContractTX()
|
||||
txm1.Nonce = 1
|
||||
txc1, claim1 := newClaimTX()
|
||||
for i := 0; i < 5; i++ {
|
||||
txm1.Inputs = append(txm1.Inputs, transaction.Input{PrevHash: hash1, PrevIndex: uint16(100 - i)})
|
||||
|
@ -87,7 +88,8 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
|
|||
assert.Equal(t, len(claim1.Claims), len(mp.claims))
|
||||
assert.True(t, sort.SliceIsSorted(mp.claims, mpLessClaims))
|
||||
|
||||
txm2 := transaction.NewMinerTXWithNonce(1)
|
||||
txm2 := transaction.NewContractTX()
|
||||
txm2.Nonce = 1
|
||||
txc2, claim2 := newClaimTX()
|
||||
for i := 0; i < 10; i++ {
|
||||
txm2.Inputs = append(txm2.Inputs, transaction.Input{PrevHash: hash2, PrevIndex: uint16(i)})
|
||||
|
@ -128,19 +130,22 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
|
|||
|
||||
func TestMemPoolVerifyInputs(t *testing.T) {
|
||||
mp := NewMemPool(10)
|
||||
tx := transaction.NewMinerTXWithNonce(1)
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = 1
|
||||
inhash1 := random.Uint256()
|
||||
tx.Inputs = append(tx.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 0})
|
||||
require.Equal(t, true, mp.Verify(tx))
|
||||
require.NoError(t, mp.Add(tx, &FeerStub{}))
|
||||
|
||||
tx2 := transaction.NewMinerTXWithNonce(2)
|
||||
tx2 := transaction.NewContractTX()
|
||||
tx2.Nonce = 2
|
||||
inhash2 := random.Uint256()
|
||||
tx2.Inputs = append(tx2.Inputs, transaction.Input{PrevHash: inhash2, PrevIndex: 0})
|
||||
require.Equal(t, true, mp.Verify(tx2))
|
||||
require.NoError(t, mp.Add(tx2, &FeerStub{}))
|
||||
|
||||
tx3 := transaction.NewMinerTXWithNonce(3)
|
||||
tx3 := transaction.NewContractTX()
|
||||
tx3.Nonce = 3
|
||||
// Different index number, but the same PrevHash as in tx1.
|
||||
tx3.Inputs = append(tx3.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 1})
|
||||
require.Equal(t, true, mp.Verify(tx3))
|
||||
|
@ -211,7 +216,8 @@ func TestOverCapacity(t *testing.T) {
|
|||
mp := NewMemPool(mempoolSize)
|
||||
|
||||
for i := 0; i < mempoolSize; i++ {
|
||||
tx := transaction.NewMinerTXWithNonce(uint32(i))
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = uint32(i)
|
||||
require.NoError(t, mp.Add(tx, fs))
|
||||
}
|
||||
txcnt := uint32(mempoolSize)
|
||||
|
@ -231,7 +237,8 @@ func TestOverCapacity(t *testing.T) {
|
|||
// Fees are also prioritized.
|
||||
fs.netFee = util.Fixed8FromFloat(0.0001)
|
||||
for i := 0; i < mempoolSize-1; i++ {
|
||||
tx := transaction.NewMinerTXWithNonce(txcnt)
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = txcnt
|
||||
txcnt++
|
||||
require.NoError(t, mp.Add(tx, fs))
|
||||
require.Equal(t, mempoolSize, mp.Count())
|
||||
|
@ -239,7 +246,8 @@ func TestOverCapacity(t *testing.T) {
|
|||
}
|
||||
// Less prioritized txes are not allowed anymore.
|
||||
fs.netFee = util.Fixed8FromFloat(0.00001)
|
||||
tx := transaction.NewMinerTXWithNonce(txcnt)
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = txcnt
|
||||
txcnt++
|
||||
require.Error(t, mp.Add(tx, fs))
|
||||
require.Equal(t, mempoolSize, mp.Count())
|
||||
|
@ -250,7 +258,8 @@ func TestOverCapacity(t *testing.T) {
|
|||
|
||||
// Low net fee, but higher per-byte fee is still a better combination.
|
||||
fs.perByteFee = util.Fixed8FromFloat(0.001)
|
||||
tx = transaction.NewMinerTXWithNonce(txcnt)
|
||||
tx = transaction.NewContractTX()
|
||||
tx.Nonce = txcnt
|
||||
txcnt++
|
||||
require.NoError(t, mp.Add(tx, fs))
|
||||
require.Equal(t, mempoolSize, mp.Count())
|
||||
|
@ -259,7 +268,8 @@ func TestOverCapacity(t *testing.T) {
|
|||
// High priority always wins over low priority.
|
||||
fs.lowPriority = false
|
||||
for i := 0; i < mempoolSize; i++ {
|
||||
tx := transaction.NewMinerTXWithNonce(txcnt)
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = txcnt
|
||||
txcnt++
|
||||
require.NoError(t, mp.Add(tx, fs))
|
||||
require.Equal(t, mempoolSize, mp.Count())
|
||||
|
@ -267,7 +277,8 @@ func TestOverCapacity(t *testing.T) {
|
|||
}
|
||||
// Good luck with low priority now.
|
||||
fs.lowPriority = true
|
||||
tx = transaction.NewMinerTXWithNonce(txcnt)
|
||||
tx = transaction.NewContractTX()
|
||||
tx.Nonce = txcnt
|
||||
require.Error(t, mp.Add(tx, fs))
|
||||
require.Equal(t, mempoolSize, mp.Count())
|
||||
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
||||
|
@ -280,7 +291,8 @@ func TestGetVerified(t *testing.T) {
|
|||
|
||||
txes := make([]*transaction.Transaction, 0, mempoolSize)
|
||||
for i := 0; i < mempoolSize; i++ {
|
||||
tx := transaction.NewMinerTXWithNonce(uint32(i))
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = uint32(i)
|
||||
txes = append(txes, tx)
|
||||
require.NoError(t, mp.Add(tx, fs))
|
||||
}
|
||||
|
@ -305,7 +317,8 @@ func TestRemoveStale(t *testing.T) {
|
|||
txes1 := make([]*transaction.Transaction, 0, mempoolSize/2)
|
||||
txes2 := make([]*transaction.Transaction, 0, mempoolSize/2)
|
||||
for i := 0; i < mempoolSize; i++ {
|
||||
tx := transaction.NewMinerTXWithNonce(uint32(i))
|
||||
tx := transaction.NewContractTX()
|
||||
tx.Nonce = uint32(i)
|
||||
if i%2 == 0 {
|
||||
txes1 = append(txes1, tx)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue