From 66a64dd4c959968de8eb80f32ab5c7420fcdddb2 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 16 Dec 2020 14:14:09 +0300 Subject: [PATCH] core: fix bug with mempool.verifiedMap Changes ported from #1621. --- pkg/core/mempool/mem_pool.go | 2 +- pkg/core/mempool/mem_pool_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/core/mempool/mem_pool.go b/pkg/core/mempool/mem_pool.go index e47ef11a1..70ea1de30 100644 --- a/pkg/core/mempool/mem_pool.go +++ b/pkg/core/mempool/mem_pool.go @@ -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. diff --git a/pkg/core/mempool/mem_pool_test.go b/pkg/core/mempool/mem_pool_test.go index 38fce9750..a06404fb3 100644 --- a/pkg/core/mempool/mem_pool_test.go +++ b/pkg/core/mempool/mem_pool_test.go @@ -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.