diff --git a/txpool/pool.go b/txpool/pool.go index 21e6ca3ea..ada2ee2b2 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -220,9 +220,11 @@ func (p *TxPool) OnNewTxs(newTxs TxSlots) error { } notifyNewTxs = append(notifyNewTxs, newTxs.txs[i].idHash[:]...) } - select { - case p.newTxs <- notifyNewTxs: - default: + if len(notifyNewTxs) > 0 { + select { + case p.newTxs <- notifyNewTxs: + default: + } } return nil @@ -282,9 +284,11 @@ func (p *TxPool) OnNewBlock(unwindTxs, minedTxs TxSlots, protocolBaseFee, blockB } notifyNewTxs = append(notifyNewTxs, unwindTxs.txs[i].idHash[:]...) } - select { - case p.newTxs <- notifyNewTxs: - default: + if len(notifyNewTxs) > 0 { + select { + case p.newTxs <- notifyNewTxs: + default: + } } return nil @@ -339,6 +343,7 @@ func onNewBlock(senderInfo map[uint64]*senderInfo, unwindTxs TxSlots, minedTxs [ if len(unwindTxs.txs) > 0 { //TODO: restore isLocal flag in unwindTxs unsafeAddToPool(senderInfo, unwindTxs, pending, func(i *MetaTx) { + //fmt.Printf("add: %d,%d\n", i.Tx.senderID, i.Tx.nonce) if _, ok := localsHistory.Get(i.Tx.idHash); ok { //TODO: also check if sender is in list of local-senders i.SubPool |= IsLocal @@ -357,6 +362,8 @@ func onNewBlock(senderInfo map[uint64]*senderInfo, unwindTxs TxSlots, minedTxs [ queued.EnforceInvariants() promote(pending, baseFee, queued, func(i *MetaTx) { + //fmt.Printf("del1 nonce: %d, %t\n", i.Tx.senderID, senderInfo[i.Tx.senderID].nonce < i.Tx.nonce) + //fmt.Printf("del2 balance: %x,%x,%x\n", i.Tx.value, i.Tx.tip, senderInfo[i.Tx.senderID].balance) delete(byHash, string(i.Tx.idHash[:])) senderInfo[i.Tx.senderID].txNonce2Tx.Delete(&nonce2TxItem{i}) if i.SubPool&IsLocal != 0 { diff --git a/txpool/pool_fuzz_test.go b/txpool/pool_fuzz_test.go index 5b2164144..aa725165b 100644 --- a/txpool/pool_fuzz_test.go +++ b/txpool/pool_fuzz_test.go @@ -329,9 +329,6 @@ func FuzzOnNewBlocks5(f *testing.F) { _, ok = pool.byHash[string(minedTxs.txs[i].idHash[:])] assert.False(ok) } - newHashes := <-ch - //assert.Equal(len(unwindTxs.txs), newHashes.Len()) - _ = newHashes } // go to first fork @@ -339,13 +336,34 @@ func FuzzOnNewBlocks5(f *testing.F) { err := pool.OnNewBlock(unwindTxs, minedTxs1, protocolBaseFee, blockBaseFee) assert.NoError(err) check(unwindTxs, minedTxs1) + select { + case newHashes := <-ch: + assert.Greater(len(newHashes), 0) + //TODO: all notified hashes must be in given list + default: + //TODO: no notifications - means pools must be empty (unchanged) + } + //assert.Equal(len(unwindTxs.txs), newHashes.Len()) + // unwind everything and switch to new fork (need unwind mined now) err = pool.OnNewBlock(minedTxs1, minedTxs2, protocolBaseFee, blockBaseFee) assert.NoError(err) check(minedTxs1, minedTxs2) + select { + case newHashes := <-ch: + assert.Greater(len(newHashes), 0) + default: + } + // add some remote txs from p2p err = pool.OnNewTxs(p2pReceived) assert.NoError(err) + check(TxSlots{}, p2pReceived) + select { + case newHashes := <-ch: + assert.Greater(len(newHashes), 0) + default: + } }) }