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