handle case of unreachable block in `is_optimstic` helper (#6124)
* handle case of unreachable block in `is_optimstic` helper When a non-canonical block is still in the DB, it can be accessed via `BlockId`, but `BlockRef` may be unavailable if the block was not properly cleaned when it got orphaned. Report it as optimistic. * `template` -> `func`
This commit is contained in:
parent
2d9586a5a8
commit
33e34ee8bd
|
@ -1968,12 +1968,16 @@ proc pruneBlocksDAG(dag: ChainDAGRef) =
|
|||
dagPruneDur = Moment.now() - startTick
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/sync/optimistic.md#helpers
|
||||
template is_optimistic*(dag: ChainDAGRef, bid: BlockId): bool =
|
||||
func is_optimistic*(dag: ChainDAGRef, bid: BlockId): bool =
|
||||
let blck =
|
||||
if bid.slot <= dag.finalizedHead.slot:
|
||||
dag.finalizedHead.blck
|
||||
else:
|
||||
dag.getBlockRef(bid.root).expect("Non-finalized block is known")
|
||||
dag.getBlockRef(bid.root).valueOr:
|
||||
# The block is part of the DB but is not reachable via `BlockRef`;
|
||||
# it could have been orphaned or the DB is slightly inconsistent.
|
||||
# Report it as optimistic until it becomes reachable or gets deleted
|
||||
return true
|
||||
not blck.executionValid
|
||||
|
||||
proc markBlockVerified*(dag: ChainDAGRef, blck: BlockRef) =
|
||||
|
|
Loading…
Reference in New Issue