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

Add a lock to fix the panic while starting and loading the pool db. #920

Merged
merged 3 commits into from
Aug 12, 2024
Merged
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
5 changes: 5 additions & 0 deletions zk/txpool/pool_zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func (p *TxPool) MarkForDiscardFromPendingBest(txHash common.Hash) {
}

func (p *TxPool) StartIfNotStarted(ctx context.Context, txPoolDb kv.RoDB, coreTx kv.Tx) error {
p.lock.Lock()
defer p.lock.Unlock()
if !p.started.Load() {
txPoolDbTx, err := txPoolDb.BeginRo(ctx)
if err != nil {
Expand All @@ -270,6 +272,9 @@ func (p *TxPool) StartIfNotStarted(ctx context.Context, txPoolDb kv.RoDB, coreTx
if err := p.fromDB(ctx, txPoolDbTx, coreTx); err != nil {
return fmt.Errorf("loading txs from DB: %w", err)
}
if p.started.CompareAndSwap(false, true) {
log.Info("[txpool] Start if not started")
}
}

return nil
Expand Down
Loading