core/mempool: fix AddBlock and tx pooling concurrency issues

Eliminate races between tx checks and adding them to the mempool, ensure the
chain doesn't change while we're working with the new tx. Ensure only one
block addition attempt could be in progress.
This commit is contained in:
Roman Khimov 2020-02-04 18:43:21 +03:00
parent f0bb886be3
commit 70b3839fd0
7 changed files with 120 additions and 29 deletions

View file

@ -43,7 +43,7 @@ func TestService_GetVerified(t *testing.T) {
pool := srv.Chain.GetMemPool()
item := mempool.NewPoolItem(txs[3], new(feer))
require.True(t, pool.TryAdd(txs[3].Hash(), item))
require.NoError(t, pool.TryAdd(txs[3].Hash(), item))
hashes := []util.Uint256{txs[0].Hash(), txs[1].Hash(), txs[2].Hash()}
@ -69,7 +69,7 @@ func TestService_GetVerified(t *testing.T) {
t.Run("more than half of the last proposal will be reused", func(t *testing.T) {
for _, tx := range txs[:2] {
item := mempool.NewPoolItem(tx, new(feer))
require.True(t, pool.TryAdd(tx.Hash(), item))
require.NoError(t, pool.TryAdd(tx.Hash(), item))
}
txx := srv.getVerifiedTx(10)