mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
core: add additional judgement when repair the blockchain
This commit is contained in:
parent
92c6d13083
commit
ba89df28da
1 changed files with 15 additions and 3 deletions
|
|
@ -48,7 +48,9 @@ import (
|
||||||
var (
|
var (
|
||||||
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
|
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
|
||||||
|
|
||||||
ErrNoGenesis = errors.New("Genesis not found in chain")
|
ErrNoGenesis = errors.New("Genesis not found in chain")
|
||||||
|
errGenesisStateIncomplete = errors.New("genesis state is incomplete")
|
||||||
|
errMissingBlock = errors.New("missing block")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -432,8 +434,18 @@ func (bc *BlockChain) repair(head **types.Block) error {
|
||||||
log.Info("Rewound blockchain to past state", "number", (*head).Number(), "hash", (*head).Hash())
|
log.Info("Rewound blockchain to past state", "number", (*head).Number(), "hash", (*head).Hash())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Otherwise rewind one block and recheck state availability there
|
// Abort if the genesis block's state is still incomplete.
|
||||||
(*head) = bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1)
|
if (*head).NumberU64() == 0 {
|
||||||
|
log.Info("The state of genesis block is incomplete")
|
||||||
|
return errGenesisStateIncomplete
|
||||||
|
}
|
||||||
|
// Rewind one block and recheck state availability there
|
||||||
|
block := bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1)
|
||||||
|
if block == nil {
|
||||||
|
log.Info("Rewound to a missing block", "number", (*head).NumberU64()-1)
|
||||||
|
return errMissingBlock
|
||||||
|
}
|
||||||
|
*head = block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue