From bc3314aed93f87ba2eb1847f0db37bdd8dfef40f Mon Sep 17 00:00:00 2001 From: jsvisa Date: Fri, 20 Jun 2025 19:06:57 +0800 Subject: [PATCH] core: stop insert and re-enable Signed-off-by: jsvisa --- core/blockchain.go | 5 +++++ eth/api_backend.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index 25b37b5cce..ce4a0e90c1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1307,6 +1307,11 @@ func (bc *BlockChain) StopInsert() { bc.procInterrupt.Store(true) } +// ResumeInsert re-enables the blockchain insertion, which is used to rewinding the chain to +func (bc *BlockChain) ResumeInsert() { + bc.procInterrupt.Store(false) +} + // insertStopped returns true after StopInsert has been called. func (bc *BlockChain) insertStopped() bool { return bc.procInterrupt.Load() diff --git a/eth/api_backend.go b/eth/api_backend.go index 8ec19308f9..86fc2f81c9 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -62,8 +62,10 @@ func (b *EthAPIBackend) CurrentBlock() *types.Header { } func (b *EthAPIBackend) SetHead(number uint64) { + b.eth.blockchain.StopInsert() b.eth.handler.downloader.Cancel() b.eth.blockchain.SetHead(number) + b.eth.blockchain.ResumeInsert() } func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {