Skip to content

Commit

Permalink
Return correct justified and finalized checkpoint epochs for fork cho…
Browse files Browse the repository at this point in the history
…ice nodes in `GET /eth/v1/debug/fork_choice` endpoint
  • Loading branch information
povi committed Aug 19, 2024
1 parent 867ee7d commit f1a38b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 4 additions & 7 deletions fork_choice_control/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ where
pub fn fork_choice_context(&self) -> ForkChoiceContext {
let store = self.store_snapshot();

let justified_checkpoint = store.justified_checkpoint();
let finalized_checkpoint = store.finalized_checkpoint();

let fork_choice_nodes = store
.unfinalized()
.values()
Expand All @@ -213,8 +210,8 @@ where
slot: chain_link.slot(),
block_root: chain_link.block_root,
parent_root: chain_link.block.message().parent_root(),
justified_epoch: justified_checkpoint.epoch,
finalized_epoch: finalized_checkpoint.epoch,
justified_epoch: chain_link.justified_checkpoint.epoch,
finalized_epoch: chain_link.finalized_checkpoint.epoch,
validity: chain_link.payload_status,
weight: unfinalized_block.attesting_balance,
execution_block_hash: chain_link.execution_block_hash().unwrap_or_default(),
Expand All @@ -223,8 +220,8 @@ where
.collect();

ForkChoiceContext {
justified_checkpoint,
finalized_checkpoint,
justified_checkpoint: store.justified_checkpoint(),
finalized_checkpoint: store.finalized_checkpoint(),
fork_choice_nodes,
}
}
Expand Down
2 changes: 2 additions & 0 deletions fork_choice_store/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct ChainLink<P: Preset> {
pub block: Arc<SignedBeaconBlock<P>>,
#[derivative(Debug(format_with = "fmt_as_wildcard"))]
pub state: Option<Arc<BeaconState<P>>>,
pub justified_checkpoint: Checkpoint,
pub finalized_checkpoint: Checkpoint,
pub unrealized_justified_checkpoint: Checkpoint,
pub unrealized_finalized_checkpoint: Checkpoint,
pub payload_status: PayloadStatus,
Expand Down
5 changes: 5 additions & 0 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ impl<P: Preset> Store<P> {
block_root,
block: anchor_block,
state: Some(anchor_state.clone_arc()),
justified_checkpoint: checkpoint,
finalized_checkpoint: checkpoint,
unrealized_justified_checkpoint: checkpoint,
unrealized_finalized_checkpoint: checkpoint,
payload_status: Self::initial_payload_status(&anchor_state),
Expand Down Expand Up @@ -1031,6 +1033,7 @@ impl<P: Preset> Store<P> {
.collect();

let justified_checkpoint = state.current_justified_checkpoint();
let finalized_checkpoint = state.finalized_checkpoint();

// TODO(Grandine Team): Optimize computation of unrealized checkpoints.
// Unrealized checkpoints must be computed for every block,
Expand Down Expand Up @@ -1058,6 +1061,8 @@ impl<P: Preset> Store<P> {
block_root,
block: block.clone_arc(),
state: Some(state),
justified_checkpoint,
finalized_checkpoint,
unrealized_justified_checkpoint,
unrealized_finalized_checkpoint,
payload_status,
Expand Down

0 comments on commit f1a38b9

Please sign in to comment.