Skip to content

Commit b5260db

Browse files
authored
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>
1 parent d54dc68 commit b5260db

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

beacon_node/http_api/src/lib.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ use bytes::Bytes;
4848
use directory::DEFAULT_ROOT_DIR;
4949
use eth2::types::{
5050
self as api_types, BroadcastValidation, ContextDeserialize, EndpointVersion, ForkChoice,
51-
ForkChoiceNode, LightClientUpdatesQuery, PublishBlockRequest, StateId as CoreStateId,
52-
ValidatorBalancesRequestBody, ValidatorId, ValidatorIdentitiesRequestBody, ValidatorStatus,
53-
ValidatorsRequestBody,
51+
ForkChoiceExtraData, ForkChoiceNode, LightClientUpdatesQuery, PublishBlockRequest,
52+
StateId as CoreStateId, ValidatorBalancesRequestBody, ValidatorId,
53+
ValidatorIdentitiesRequestBody, ValidatorStatus, ValidatorsRequestBody,
5454
};
5555
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
5656
use health_metrics::observe::Observe;
@@ -3033,6 +3033,32 @@ pub fn serve<T: BeaconChainTypes>(
30333033
.execution_status
30343034
.block_hash()
30353035
.map(|block_hash| block_hash.into_root()),
3036+
extra_data: ForkChoiceExtraData {
3037+
target_root: node.target_root,
3038+
justified_root: node.justified_checkpoint.root,
3039+
finalized_root: node.finalized_checkpoint.root,
3040+
unrealized_justified_root: node
3041+
.unrealized_justified_checkpoint
3042+
.map(|checkpoint| checkpoint.root),
3043+
unrealized_finalized_root: node
3044+
.unrealized_finalized_checkpoint
3045+
.map(|checkpoint| checkpoint.root),
3046+
unrealized_justified_epoch: node
3047+
.unrealized_justified_checkpoint
3048+
.map(|checkpoint| checkpoint.epoch),
3049+
unrealized_finalized_epoch: node
3050+
.unrealized_finalized_checkpoint
3051+
.map(|checkpoint| checkpoint.epoch),
3052+
execution_status: node.execution_status.to_string(),
3053+
best_child: node
3054+
.best_child
3055+
.and_then(|index| proto_array.nodes.get(index))
3056+
.map(|child| child.root),
3057+
best_descendant: node
3058+
.best_descendant
3059+
.and_then(|index| proto_array.nodes.get(index))
3060+
.map(|descendant| descendant.root),
3061+
},
30363062
}
30373063
})
30383064
.collect::<Vec<_>>();

beacon_node/http_api/tests/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,6 +3088,32 @@ impl ApiTester {
30883088
.execution_status
30893089
.block_hash()
30903090
.map(|block_hash| block_hash.into_root()),
3091+
extra_data: ForkChoiceExtraData {
3092+
target_root: node.target_root,
3093+
justified_root: node.justified_checkpoint.root,
3094+
finalized_root: node.finalized_checkpoint.root,
3095+
unrealized_justified_root: node
3096+
.unrealized_justified_checkpoint
3097+
.map(|checkpoint| checkpoint.root),
3098+
unrealized_finalized_root: node
3099+
.unrealized_finalized_checkpoint
3100+
.map(|checkpoint| checkpoint.root),
3101+
unrealized_justified_epoch: node
3102+
.unrealized_justified_checkpoint
3103+
.map(|checkpoint| checkpoint.epoch),
3104+
unrealized_finalized_epoch: node
3105+
.unrealized_finalized_checkpoint
3106+
.map(|checkpoint| checkpoint.epoch),
3107+
execution_status: node.execution_status.to_string(),
3108+
best_child: node
3109+
.best_child
3110+
.and_then(|index| expected_proto_array.nodes.get(index))
3111+
.map(|child| child.root),
3112+
best_descendant: node
3113+
.best_descendant
3114+
.and_then(|index| expected_proto_array.nodes.get(index))
3115+
.map(|descendant| descendant.root),
3116+
},
30913117
}
30923118
})
30933119
.collect();

common/eth2/src/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,21 @@ pub struct ForkChoiceNode {
15201520
pub weight: u64,
15211521
pub validity: Option<String>,
15221522
pub execution_block_hash: Option<Hash256>,
1523+
pub extra_data: ForkChoiceExtraData,
1524+
}
1525+
1526+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
1527+
pub struct ForkChoiceExtraData {
1528+
pub target_root: Hash256,
1529+
pub justified_root: Hash256,
1530+
pub finalized_root: Hash256,
1531+
pub unrealized_justified_root: Option<Hash256>,
1532+
pub unrealized_finalized_root: Option<Hash256>,
1533+
pub unrealized_justified_epoch: Option<Epoch>,
1534+
pub unrealized_finalized_epoch: Option<Epoch>,
1535+
pub execution_status: String,
1536+
pub best_child: Option<Hash256>,
1537+
pub best_descendant: Option<Hash256>,
15231538
}
15241539

15251540
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]

0 commit comments

Comments
 (0)