From d889b62b79d3395add3ea2be32adeb07755a1275 Mon Sep 17 00:00:00 2001 From: tersec Date: Sun, 20 Aug 2023 07:19:07 +0000 Subject: [PATCH] remove assumption of shared finalized-block ancestery between fork choice and chaindag in getDebugForkChoice (#5328) --- beacon_chain/rpc/rest_debug_api.nim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/beacon_chain/rpc/rest_debug_api.nim b/beacon_chain/rpc/rest_debug_api.nim index a1a6c66af..2a6f65a4e 100644 --- a/beacon_chain/rpc/rest_debug_api.nim +++ b/beacon_chain/rpc/rest_debug_api.nim @@ -113,10 +113,17 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) = validity: if item.invalid: RestNodeValidity.invalid - elif node.dag.is_optimistic(item.bid): - RestNodeValidity.optimistic else: - RestNodeValidity.valid, + # Fork choice doesn't necessarily prune finalized blocks in a + # synchronized way to the chaindag, so can't assume that when + # item.bid.slot is before finalizedHead, it has shared status + # regarding optimistic/validity as finalizedHead, so fallback + # to optimistic is more appropriate for this REST endpoint. + let blck = node.dag.getBlockRef(item.bid.root) + if blck.isNone() or not blck.get.executionValid: + RestNodeValidity.optimistic + else: + RestNodeValidity.valid, execution_block_hash: node.dag.loadExecutionBlockHash(item.bid), extra_data: some RestNodeExtraData( justified_root: item.checkpoints.justified.root,