Skip to content

Commit

Permalink
Add a lock to fix the panic while starting and loading the pool db. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 authored Aug 12, 2024
1 parent 12cc95c commit f3ba2f7
Showing 1 changed file with 5 additions and 0 deletions.
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

0 comments on commit f3ba2f7

Please sign in to comment.