core: fix mempool.Add

Unlucky transaction could also have OracleResponce attribute.
This commit is contained in:
Anna Shaleva 2021-01-15 16:12:27 +03:00
parent 36b5751262
commit 09f0f03775
2 changed files with 20 additions and 1 deletions

View file

@ -245,6 +245,9 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...interface{}) e
if fee.P2PSigExtensionsEnabled() { if fee.P2PSigExtensionsEnabled() {
mp.removeConflictsOf(unlucky.txn) mp.removeConflictsOf(unlucky.txn)
} }
if attrs := unlucky.txn.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 {
delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID)
}
mp.verifiedTxes[len(mp.verifiedTxes)-1] = pItem mp.verifiedTxes[len(mp.verifiedTxes)-1] = pItem
} else { } else {
mp.verifiedTxes = append(mp.verifiedTxes, pItem) mp.verifiedTxes = append(mp.verifiedTxes, pItem)

View file

@ -361,7 +361,7 @@ func TestMempoolItemsOrder(t *testing.T) {
} }
func TestMempoolAddRemoveOracleResponse(t *testing.T) { func TestMempoolAddRemoveOracleResponse(t *testing.T) {
mp := New(5, 0) mp := New(3, 0)
nonce := uint32(0) nonce := uint32(0)
fs := &FeerStub{balance: 10000} fs := &FeerStub{balance: 10000}
newTx := func(netFee int64, id uint64) *transaction.Transaction { newTx := func(netFee int64, id uint64) *transaction.Transaction {
@ -411,6 +411,22 @@ func TestMempoolAddRemoveOracleResponse(t *testing.T) {
// check that oracle id was removed. // check that oracle id was removed.
tx5 := newTx(3, 2) tx5 := newTx(3, 2)
require.NoError(t, mp.Add(tx5, fs)) require.NoError(t, mp.Add(tx5, fs))
// another oracle response ID with high net fee
tx6 := newTx(6, 3)
require.NoError(t, mp.Add(tx6, fs))
// check respIds
for _, i := range []uint64{1, 2, 3} {
_, ok := mp.oracleResp[i]
require.True(t, ok)
}
// reach capacity, check that response ID is removed together with tx5
tx7 := newTx(6, 4)
require.NoError(t, mp.Add(tx7, fs))
for _, i := range []uint64{1, 4, 3} {
_, ok := mp.oracleResp[i]
require.True(t, ok)
}
} }
func TestMempoolAddRemoveConflicts(t *testing.T) { func TestMempoolAddRemoveConflicts(t *testing.T) {