Skip to content

Commit

Permalink
handle case of unreachable block in is_optimstic helper (#6124)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
etan-status authored Mar 22, 2024
1 parent 2d9586a commit 33e34ee
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down

0 comments on commit 33e34ee

Please sign in to comment.