core: export stateRecoverable

This commit is contained in:
Gary Rong 2026-07-01 10:31:58 +08:00
parent f78f04a604
commit 593b9d82bb
2 changed files with 7 additions and 13 deletions

View file

@ -913,7 +913,7 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash) (*typ
// noState represents if the target state requested for search
// is unavailable and impossible to be recovered.
noState = !bc.HasState(root) && !bc.stateRecoverable(root)
noState = !bc.HasState(root) && !bc.StateRecoverable(root)
start = time.Now() // Timestamp the rewinding is restarted
logged = time.Now() // Timestamp last progress log was printed
@ -940,7 +940,7 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash) (*typ
}
// Check if the associated state is available or recoverable if
// the requested root has already been crossed.
if beyondRoot && (bc.HasState(head.Root) || bc.stateRecoverable(head.Root)) {
if beyondRoot && (bc.HasState(head.Root) || bc.StateRecoverable(head.Root)) {
break
}
// If pivot block is reached, return the genesis block as the
@ -1109,7 +1109,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
// rewinding a large number of blocks.
if newHeadBlock := bc.CurrentBlock(); !bc.HasState(newHeadBlock.Root) {
switch {
case bc.stateRecoverable(newHeadBlock.Root):
case bc.StateRecoverable(newHeadBlock.Root):
if err := bc.triedb.Recover(newHeadBlock.Root); err != nil {
// The state was confirmed recoverable just above, so a failure here
// can only stem from an unexpected I/O error. There is no safe way to
@ -2416,7 +2416,7 @@ func (bc *BlockChain) insertSideChain(ctx context.Context, block *types.Block, i
)
parent := it.previous()
for parent != nil && !bc.HasState(parent.Root) {
if bc.stateRecoverable(parent.Root) {
if bc.StateRecoverable(parent.Root) {
if err := bc.triedb.Recover(parent.Root); err != nil {
return nil, 0, err
}
@ -2478,7 +2478,7 @@ func (bc *BlockChain) recoverAncestors(ctx context.Context, block *types.Block,
parent = block
)
for parent != nil && !bc.HasState(parent.Root()) {
if bc.stateRecoverable(parent.Root()) {
if bc.StateRecoverable(parent.Root()) {
if err := bc.triedb.Recover(parent.Root()); err != nil {
return common.Hash{}, err
}

View file

@ -395,11 +395,11 @@ func (bc *BlockChain) HasBlockAndState(hash common.Hash, number uint64) bool {
return bc.HasState(block.Root())
}
// stateRecoverable checks if the specified state is recoverable.
// StateRecoverable checks if the specified state is recoverable.
// Note, this function assumes the state is not present, because
// state is not treated as recoverable if it's available, thus
// false will be returned in this case.
func (bc *BlockChain) stateRecoverable(root common.Hash) bool {
func (bc *BlockChain) StateRecoverable(root common.Hash) bool {
if bc.triedb.Scheme() == rawdb.HashScheme {
return false
}
@ -407,12 +407,6 @@ func (bc *BlockChain) stateRecoverable(root common.Hash) bool {
return result
}
// StateRecoverable checks if the specified state is recoverable by applying
// state histories on top of the persistent state.
func (bc *BlockChain) StateRecoverable(root common.Hash) bool {
return bc.stateRecoverable(root)
}
// ContractCodeWithPrefix retrieves a blob of data associated with a contract
// hash either from ephemeral in-memory cache, or from persistent storage.
func (bc *BlockChain) ContractCodeWithPrefix(hash common.Hash) []byte {