Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,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;
Expand Down Expand Up @@ -2971,6 +2971,35 @@ 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),
timestamp: timestamp_now().as_secs().to_string(),
execution_status: serde_json::Value::String(
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<_>>();
Expand Down
30 changes: 30 additions & 0 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use beacon_chain::test_utils::RelativeSyncCommittee;
use beacon_chain::{
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
validator_monitor::timestamp_now,
BeaconChain, ChainConfig, StateSkipConfig, WhenSlotSkipped,
};
use eth2::{
Expand Down Expand Up @@ -2955,6 +2956,35 @@ 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),
timestamp: timestamp_now().as_secs().to_string(),
execution_status: serde_json::Value::String(
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();
Expand Down
18 changes: 17 additions & 1 deletion common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ impl<'de> ContextDeserialize<'de, ForkName> for SsePayloadAttributes {
return Err(serde::de::Error::custom(format!(
"SsePayloadAttributes failed to deserialize: unsupported fork '{}'",
context
)))
)));
}
ForkName::Bellatrix => {
Self::V1(Deserialize::deserialize(deserializer).map_err(convert_err)?)
Expand Down Expand Up @@ -1517,6 +1517,22 @@ pub struct ForkChoiceNode {
pub weight: u64,
pub validity: Option<String>,
pub execution_block_hash: Option<Hash256>,
pub extra_data: ForkChoiceExtraData,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct ForkChoiceExtraData {
pub target_root: Hash256,
pub justified_root: Hash256,
pub finalized_root: Hash256,
pub unrealized_justified_root: Option<Hash256>,
pub unrealized_finalized_root: Option<Hash256>,
pub unrealized_justified_epoch: Option<Epoch>,
pub unrealized_finalized_epoch: Option<Epoch>,
pub timestamp: String,
pub execution_status: serde_json::Value,
pub best_child: Option<Hash256>,
pub best_descendant: Option<Hash256>,
}

#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand Down