mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Strict count unrealized (#3522)
## Issue Addressed Add a flag that can increase count unrealized strictness, defaults to false ## Proposed Changes Please list or describe the changes introduced by this PR. ## Additional Info Please provide any additional information. For example, future considerations or information useful for reviewers. Co-authored-by: realbigsean <seananderson33@gmail.com> Co-authored-by: sean <seananderson33@gmail.com>
This commit is contained in:
@@ -118,6 +118,24 @@ impl Default for ProposerBoost {
|
||||
}
|
||||
}
|
||||
|
||||
/// Indicate whether we should strictly count unrealized justification/finalization votes.
|
||||
#[derive(Default, PartialEq, Eq, Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
pub enum CountUnrealizedFull {
|
||||
True,
|
||||
#[default]
|
||||
False,
|
||||
}
|
||||
|
||||
impl From<bool> for CountUnrealizedFull {
|
||||
fn from(b: bool) -> Self {
|
||||
if b {
|
||||
CountUnrealizedFull::True
|
||||
} else {
|
||||
CountUnrealizedFull::False
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ProtoArray {
|
||||
/// Do not attempt to prune the tree unless it has at least this many nodes. Small prunes
|
||||
@@ -128,6 +146,7 @@ pub struct ProtoArray {
|
||||
pub nodes: Vec<ProtoNode>,
|
||||
pub indices: HashMap<Hash256, usize>,
|
||||
pub previous_proposer_boost: ProposerBoost,
|
||||
pub count_unrealized_full: CountUnrealizedFull,
|
||||
}
|
||||
|
||||
impl ProtoArray {
|
||||
@@ -878,12 +897,14 @@ impl ProtoArray {
|
||||
return false;
|
||||
}
|
||||
|
||||
let genesis_epoch = Epoch::new(0);
|
||||
|
||||
let checkpoint_match_predicate =
|
||||
|node_justified_checkpoint: Checkpoint, node_finalized_checkpoint: Checkpoint| {
|
||||
let correct_justified = node_justified_checkpoint == self.justified_checkpoint
|
||||
|| self.justified_checkpoint.epoch == Epoch::new(0);
|
||||
|| self.justified_checkpoint.epoch == genesis_epoch;
|
||||
let correct_finalized = node_finalized_checkpoint == self.finalized_checkpoint
|
||||
|| self.finalized_checkpoint.epoch == Epoch::new(0);
|
||||
|| self.finalized_checkpoint.epoch == genesis_epoch;
|
||||
correct_justified && correct_finalized
|
||||
};
|
||||
|
||||
@@ -898,13 +919,26 @@ impl ProtoArray {
|
||||
node.justified_checkpoint,
|
||||
node.finalized_checkpoint,
|
||||
) {
|
||||
if node.slot.epoch(E::slots_per_epoch()) < current_slot.epoch(E::slots_per_epoch()) {
|
||||
checkpoint_match_predicate(
|
||||
unrealized_justified_checkpoint,
|
||||
unrealized_finalized_checkpoint,
|
||||
)
|
||||
let current_epoch = current_slot.epoch(E::slots_per_epoch());
|
||||
|
||||
// If previous epoch is justified, pull up all tips to at least the previous epoch
|
||||
if CountUnrealizedFull::True == self.count_unrealized_full
|
||||
&& (current_epoch > genesis_epoch
|
||||
&& self.justified_checkpoint.epoch + 1 == current_epoch)
|
||||
{
|
||||
unrealized_justified_checkpoint.epoch + 1 >= current_epoch
|
||||
// If previous epoch is not justified, pull up only tips from past epochs up to the current epoch
|
||||
} else {
|
||||
checkpoint_match_predicate(justified_checkpoint, finalized_checkpoint)
|
||||
// If block is from a previous epoch, filter using unrealized justification & finalization information
|
||||
if node.slot.epoch(E::slots_per_epoch()) < current_epoch {
|
||||
checkpoint_match_predicate(
|
||||
unrealized_justified_checkpoint,
|
||||
unrealized_finalized_checkpoint,
|
||||
)
|
||||
// If block is from the current epoch, filter using the head state's justification & finalization information
|
||||
} else {
|
||||
checkpoint_match_predicate(justified_checkpoint, finalized_checkpoint)
|
||||
}
|
||||
}
|
||||
} else if let (Some(justified_checkpoint), Some(finalized_checkpoint)) =
|
||||
(node.justified_checkpoint, node.finalized_checkpoint)
|
||||
|
||||
Reference in New Issue
Block a user