core: fix bug with mempool.verifiedMap

Changes ported from #1621.
This commit is contained in:
Anna Shaleva 2020-12-16 14:14:09 +03:00
parent 0333107327
commit 66a64dd4c9
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.