Add extra data in /eth/v1/debug/fork_choice (#7845)

* #7829


  


Co-Authored-By: Tan Chee Keong <tanck@sigmaprime.io>

Co-Authored-By: chonghe <44791194+chong-he@users.noreply.github.com>
This commit is contained in:
chonghe
2025-11-12 15:01:52 +08:00
committed by GitHub
parent d54dc685a3
commit b5260db5e6
3 changed files with 70 additions and 3 deletions

View File

@@ -48,9 +48,9 @@ use bytes::Bytes;
use directory::DEFAULT_ROOT_DIR;
use eth2::types::{
self as api_types, BroadcastValidation, ContextDeserialize, EndpointVersion, ForkChoice,
ForkChoiceNode, LightClientUpdatesQuery, PublishBlockRequest, StateId as CoreStateId,
ValidatorBalancesRequestBody, ValidatorId, ValidatorIdentitiesRequestBody, ValidatorStatus,
ValidatorsRequestBody,
ForkChoiceExtraData, ForkChoiceNode, LightClientUpdatesQuery, PublishBlockRequest,
StateId as CoreStateId, ValidatorBalancesRequestBody, ValidatorId,
ValidatorIdentitiesRequestBody, ValidatorStatus, ValidatorsRequestBody,
};
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
use health_metrics::observe::Observe;
@@ -3033,6 +3033,32 @@ pub fn serve<T: BeaconChainTypes>(
.execution_status
.block_hash()
.map(|block_hash| block_hash.into_root()),
extra_data: ForkChoiceExtraData {
target_root: node.target_root,
justified_root: node.justified_checkpoint.root,
finalized_root: node.finalized_checkpoint.root,
unrealized_justified_root: node
.unrealized_justified_checkpoint
.map(|checkpoint| checkpoint.root),
unrealized_finalized_root: node
.unrealized_finalized_checkpoint
.map(|checkpoint| checkpoint.root),
unrealized_justified_epoch: node
.unrealized_justified_checkpoint
.map(|checkpoint| checkpoint.epoch),
unrealized_finalized_epoch: node
.unrealized_finalized_checkpoint
.map(|checkpoint| checkpoint.epoch),
execution_status: node.execution_status.to_string(),
best_child: node
.best_child
.and_then(|index| proto_array.nodes.get(index))
.map(|child| child.root),
best_descendant: node
.best_descendant
.and_then(|index| proto_array.nodes.get(index))
.map(|descendant| descendant.root),
},
}
})
.collect::<Vec<_>>();

View File

@@ -3088,6 +3088,32 @@ impl ApiTester {
.execution_status
.block_hash()
.map(|block_hash| block_hash.into_root()),
extra_data: ForkChoiceExtraData {
target_root: node.target_root,
justified_root: node.justified_checkpoint.root,
finalized_root: node.finalized_checkpoint.root,
unrealized_justified_root: node
.unrealized_justified_checkpoint
.map(|checkpoint| checkpoint.root),
unrealized_finalized_root: node
.unrealized_finalized_checkpoint
.map(|checkpoint| checkpoint.root),
unrealized_justified_epoch: node
.unrealized_justified_checkpoint
.map(|checkpoint| checkpoint.epoch),
unrealized_finalized_epoch: node
.unrealized_finalized_checkpoint
.map(|checkpoint| checkpoint.epoch),
execution_status: node.execution_status.to_string(),
best_child: node
.best_child
.and_then(|index| expected_proto_array.nodes.get(index))
.map(|child| child.root),
best_descendant: node
.best_descendant
.and_then(|index| expected_proto_array.nodes.get(index))
.map(|descendant| descendant.root),
},
}
})
.collect();