mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-09 12:49:03 +00:00
core: check rewind head is later than older
Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
parent
d761acaa06
commit
8788d37829
1 changed files with 8 additions and 0 deletions
|
|
@ -735,6 +735,14 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
|
|||
// was snap synced or full synced and in which state, the method will try to
|
||||
// delete minimal data from disk whilst retaining chain consistency.
|
||||
func (bc *BlockChain) SetHead(head uint64) error {
|
||||
// Only allowed to rewind to a block that is later than the oldest state block.
|
||||
firstStateBlock, err := bc.triedb.FirstStateBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if head < firstStateBlock {
|
||||
return fmt.Errorf("cannot rewind to block %d, oldest available state is at block %d", head, firstStateBlock)
|
||||
}
|
||||
if _, err := bc.setHeadBeyondRoot(head, 0, common.Hash{}, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue