Skip to content

Commit 33e34ee

Browse files
authored
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`
1 parent 2d9586a commit 33e34ee

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

beacon_chain/consensus_object_pools/blockchain_dag.nim

+6-2
Original file line numberDiff line numberDiff line change
@@ -1968,12 +1968,16 @@ proc pruneBlocksDAG(dag: ChainDAGRef) =
19681968
dagPruneDur = Moment.now() - startTick
19691969

19701970
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/sync/optimistic.md#helpers
1971-
template is_optimistic*(dag: ChainDAGRef, bid: BlockId): bool =
1971+
func is_optimistic*(dag: ChainDAGRef, bid: BlockId): bool =
19721972
let blck =
19731973
if bid.slot <= dag.finalizedHead.slot:
19741974
dag.finalizedHead.blck
19751975
else:
1976-
dag.getBlockRef(bid.root).expect("Non-finalized block is known")
1976+
dag.getBlockRef(bid.root).valueOr:
1977+
# The block is part of the DB but is not reachable via `BlockRef`;
1978+
# it could have been orphaned or the DB is slightly inconsistent.
1979+
# Report it as optimistic until it becomes reachable or gets deleted
1980+
return true
19771981
not blck.executionValid
19781982

19791983
proc markBlockVerified*(dag: ChainDAGRef, blck: BlockRef) =

0 commit comments

Comments
 (0)