mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: address comment
This commit is contained in:
parent
2f0f190f36
commit
d131a9583c
1 changed files with 16 additions and 20 deletions
|
|
@ -688,17 +688,28 @@ func (bc *BlockChain) rewindHashHead(root common.Hash) (*types.Header, uint64) {
|
||||||
// rewindPathHead implements the logic of rewindHead in the context of path scheme.
|
// rewindPathHead implements the logic of rewindHead in the context of path scheme.
|
||||||
func (bc *BlockChain) rewindPathHead(root common.Hash) (*types.Header, uint64) {
|
func (bc *BlockChain) rewindPathHead(root common.Hash) (*types.Header, uint64) {
|
||||||
var (
|
var (
|
||||||
beyondRoot = root == common.Hash{} // Flag whether we're beyond the requested root (no root, always true)
|
|
||||||
headBlock = bc.CurrentBlock() // Head block of the chain
|
headBlock = bc.CurrentBlock() // Head block of the chain
|
||||||
pivot = rawdb.ReadLastPivotNumber(bc.db) // Associated block number of pivot point state
|
pivot = rawdb.ReadLastPivotNumber(bc.db) // Associated block number of pivot block
|
||||||
rootNumber uint64 // Associated block number of requested root
|
rootNumber uint64 // Associated block number of requested root
|
||||||
)
|
)
|
||||||
|
// BeyondRoot represents whether the requested root is already crossed.
|
||||||
|
// The flag value is set to true if the root is empty, or reaching the
|
||||||
|
// root is deemed impossible.
|
||||||
|
beyondRoot := root == common.Hash{}
|
||||||
|
if !beyondRoot && !bc.HasState(root) && !bc.stateRecoverable(root) {
|
||||||
|
beyondRoot = true
|
||||||
|
}
|
||||||
// Rewind the head block tag until an available state is found.
|
// Rewind the head block tag until an available state is found.
|
||||||
for !bc.HasState(headBlock.Root) {
|
for {
|
||||||
// If a root threshold was requested but not yet crossed, check
|
// If a root threshold was requested but not yet crossed, check
|
||||||
if !beyondRoot && headBlock.Root == root {
|
if !beyondRoot && headBlock.Root == root {
|
||||||
beyondRoot, rootNumber = true, headBlock.Number.Uint64()
|
beyondRoot, rootNumber = true, headBlock.Number.Uint64()
|
||||||
}
|
}
|
||||||
|
// Check if the associated state is available or recoverable if
|
||||||
|
// the requested root has already been crossed.
|
||||||
|
if beyondRoot && (bc.HasState(headBlock.Root) || bc.stateRecoverable(headBlock.Root)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
// If pivot block is reached, return the genesis block as the
|
// If pivot block is reached, return the genesis block as the
|
||||||
// new chain head. Theoretically there must be a persistent
|
// new chain head. Theoretically there must be a persistent
|
||||||
// state before or at the pivot block, prevent endless rewinding
|
// state before or at the pivot block, prevent endless rewinding
|
||||||
|
|
@ -709,25 +720,10 @@ func (bc *BlockChain) rewindPathHead(root common.Hash) (*types.Header, uint64) {
|
||||||
}
|
}
|
||||||
headBlock = bc.GetHeader(headBlock.ParentHash, headBlock.Number.Uint64()-1) // Keep rewinding
|
headBlock = bc.GetHeader(headBlock.ParentHash, headBlock.Number.Uint64()-1) // Keep rewinding
|
||||||
}
|
}
|
||||||
// The requested root has already been crossed. Return the block
|
// Recover if the target state if it's not available yet.
|
||||||
// corresponding to the available state as the new chain head.
|
|
||||||
if beyondRoot {
|
|
||||||
return headBlock, rootNumber
|
|
||||||
}
|
|
||||||
// If the requested root has not yet been crossed, prevent further
|
|
||||||
// backward rewinding if reaching the root is deemed impossible.
|
|
||||||
if !bc.HasState(root) && !bc.stateRecoverable(root) {
|
|
||||||
return headBlock, 0
|
|
||||||
}
|
|
||||||
// Rewind the head block tag until the requested root is reached.
|
|
||||||
for !beyondRoot {
|
|
||||||
headBlock = bc.GetHeader(headBlock.ParentHash, headBlock.Number.Uint64()-1) // Keep rewinding
|
|
||||||
beyondRoot = headBlock.Root == root
|
|
||||||
}
|
|
||||||
// Recover if the target state is not available.
|
|
||||||
if !bc.HasState(root) {
|
if !bc.HasState(root) {
|
||||||
if err := bc.triedb.Recover(root); err != nil {
|
if err := bc.triedb.Recover(root); err != nil {
|
||||||
log.Crit("Failed to rollback state", "err", err) // Shouldn't happen
|
log.Crit("Failed to rollback state", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return headBlock, rootNumber
|
return headBlock, rootNumber
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue