From 8f746e44463b9fd66ad010cfec2d05370dc63b07 Mon Sep 17 00:00:00 2001 From: jianguo Date: Tue, 6 Aug 2024 14:10:04 +0800 Subject: [PATCH] Add a lock to fix the panic while starting and loading the pool db. --- zk/txpool/pool_zk.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zk/txpool/pool_zk.go b/zk/txpool/pool_zk.go index 8fd32e327d7..f53c7965c68 100644 --- a/zk/txpool/pool_zk.go +++ b/zk/txpool/pool_zk.go @@ -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 { @@ -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