Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test reliability #1118

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ func New(gasTip *big.Int, chain BlockChain, subpools []SubPool) (*TxPool, error)
return nil, err
}
}
go pool.loop(head, chain)

// Subscribe to chain head events to trigger subpool resets
var (
newHeadCh = make(chan core.ChainHeadEvent)
newHeadSub = chain.SubscribeChainHeadEvent(newHeadCh)
)
go func() {
pool.loop(head, newHeadCh)
newHeadSub.Unsubscribe()
}()
return pool, nil
}

Expand Down Expand Up @@ -192,14 +201,7 @@ func (p *TxPool) Close() error {
// loop is the transaction pool's main event loop, waiting for and reacting to
// outside blockchain events as well as for various reporting and transaction
// eviction events.
func (p *TxPool) loop(head *types.Header, chain BlockChain) {
// Subscribe to chain head events to trigger subpool resets
var (
newHeadCh = make(chan core.ChainHeadEvent)
newHeadSub = chain.SubscribeChainHeadEvent(newHeadCh)
)
defer newHeadSub.Unsubscribe()

func (p *TxPool) loop(head *types.Header, newHeadCh <-chan core.ChainHeadEvent) {
// Track the previous and current head to feed to an idle reset
var (
oldHead = head
Expand All @@ -224,8 +226,8 @@ func (p *TxPool) loop(head *types.Header, chain BlockChain) {
for _, subpool := range p.subpools {
subpool.Reset(oldHead, newHead)
}
resetDone <- newHead
p.reorgFeed.Send(core.NewTxPoolReorgEvent{Head: newHead})
resetDone <- newHead
}(oldHead, newHead)

default:
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i i
t.Fatalf("block %d: failed to accept into chain: %v", block.NumberU64(), err)
}
}
chain.DrainAcceptorQueue()

backend := &testBackend{db: db, chain: chain}
return backend
Expand Down
Loading