Merge pull request #1623 from nspcc-dev/2x/core/mempool_fix

[master-2.x] core: fix bug with mempool.verifiedMap
This commit is contained in:
Roman Khimov 2020-12-16 16:54:46 +03:00 committed by GitHub
commit 50f477b2af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View file

@ -180,7 +180,6 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
return ErrDup
}
mp.verifiedMap[t.Hash()] = pItem
// Insert into sorted array (from max to min, that could also be done
// using sort.Sort(sort.Reverse()), but it incurs more overhead. Notice
// also that we're searching for position that is strictly more
@ -209,6 +208,7 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
copy(mp.verifiedTxes[n+1:], mp.verifiedTxes[n:])
mp.verifiedTxes[n] = pItem
}
mp.verifiedMap[t.Hash()] = pItem
// For lots of inputs it might be easier to push them all and sort
// afterwards, but that requires benchmarking.

View file

@ -303,6 +303,9 @@ func TestOverCapacity(t *testing.T) {
txcnt++
require.Error(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count())
require.Equal(t, mempoolSize, len(mp.verifiedMap))
require.Equal(t, mempoolSize, len(mp.verifiedTxes))
require.False(t, mp.containsKey(tx.Hash()))
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
// But claim tx should still be there.