Skip to content

Commit

Permalink
ForkChoice: remove head_block_root field (sigp#4590)
Browse files Browse the repository at this point in the history
This field is redundant with `ForkchoiceUpdateParameters.head_root`, the same `head_root` is assigned to both fields in [`get_head`](https://github.com/sigp/lighthouse/blob/dfcb3363c757671eb19d5f8e519b4b94ac74677a/consensus/fork_choice/src/fork_choice.rs#L508-L523).
  • Loading branch information
zhiqiangxu authored and Woodpile37 committed Jan 6, 2024
1 parent 4f41413 commit 0833331
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,10 @@ pub enum AttestationFromBlock {
False,
}

/// Parameters which are cached between calls to `Self::get_head`.
/// Parameters which are cached between calls to `ForkChoice::get_head`.
#[derive(Clone, Copy)]
pub struct ForkchoiceUpdateParameters {
/// The most recent result of running `ForkChoice::get_head`.
pub head_root: Hash256,
pub head_hash: Option<ExecutionBlockHash>,
pub justified_hash: Option<ExecutionBlockHash>,
Expand Down Expand Up @@ -319,8 +320,6 @@ pub struct ForkChoice<T, E> {
queued_attestations: Vec<QueuedAttestation>,
/// Stores a cache of the values required to be sent to the execution layer.
forkchoice_update_parameters: ForkchoiceUpdateParameters,
/// The most recent result of running `Self::get_head`.
head_block_root: Hash256,
_phantom: PhantomData<E>,
}

Expand Down Expand Up @@ -405,14 +404,13 @@ where
head_hash: None,
justified_hash: None,
finalized_hash: None,
// This will be updated during the next call to `Self::get_head`.
head_root: Hash256::zero(),
},
// This will be updated during the next call to `Self::get_head`.
head_block_root: Hash256::zero(),
_phantom: PhantomData,
};

// Ensure that `fork_choice.head_block_root` is updated.
// Ensure that `fork_choice.forkchoice_update_parameters.head_root` is updated.
fork_choice.get_head(current_slot, spec)?;

Ok(fork_choice)
Expand Down Expand Up @@ -497,8 +495,6 @@ where
spec,
)?;

self.head_block_root = head_root;

// Cache some values for the next forkchoiceUpdate call to the execution layer.
let head_hash = self
.get_block(&head_root)
Expand Down Expand Up @@ -602,7 +598,7 @@ where
/// have *differing* finalized and justified information.
pub fn cached_fork_choice_view(&self) -> ForkChoiceView {
ForkChoiceView {
head_block_root: self.head_block_root,
head_block_root: self.forkchoice_update_parameters.head_root,
justified_checkpoint: self.justified_checkpoint(),
finalized_checkpoint: self.finalized_checkpoint(),
}
Expand Down Expand Up @@ -1479,10 +1475,9 @@ where
head_hash: None,
justified_hash: None,
finalized_hash: None,
// Will be updated in the following call to `Self::get_head`.
head_root: Hash256::zero(),
},
// Will be updated in the following call to `Self::get_head`.
head_block_root: Hash256::zero(),
_phantom: PhantomData,
};

Expand Down

0 comments on commit 0833331

Please sign in to comment.