core: stop insert and re-enable

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-06-20 19:06:57 +08:00
parent e5d6f7d933
commit bc3314aed9
2 changed files with 7 additions and 0 deletions

View file

@ -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()

View file

@ -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) {