Update fork choice

This commit is contained in:
Eitan Seri-Levi
2025-01-26 10:52:44 +03:00
parent 77551ea1b7
commit d3368f59a3
10 changed files with 46 additions and 32 deletions

View File

@@ -87,6 +87,7 @@ impl ForkChoiceTestDefinition {
self.finalized_checkpoint,
junk_shuffling_id.clone(),
junk_shuffling_id,
Hash256::ZERO,
ExecutionStatus::Optimistic(ExecutionBlockHash::zero()),
)
.expect("should create fork choice struct");
@@ -110,7 +111,6 @@ impl ForkChoiceTestDefinition {
&justified_balances,
Hash256::zero(),
&equivocating_indices,
Hash256::zero(),
Slot::new(0),
&spec,
)
@@ -142,7 +142,6 @@ impl ForkChoiceTestDefinition {
&justified_balances,
proposer_boost_root,
&equivocating_indices,
Hash256::zero(),
Slot::new(0),
&spec,
)
@@ -171,7 +170,6 @@ impl ForkChoiceTestDefinition {
&justified_balances,
Hash256::zero(),
&equivocating_indices,
Hash256::zero(),
Slot::new(0),
&spec,
);

View File

@@ -134,6 +134,7 @@ pub struct ProtoArray {
pub finalized_checkpoint: Checkpoint,
pub nodes: Vec<ProtoNode>,
pub indices: HashMap<Hash256, usize>,
pub unsatisfied_inclusion_list_block: Hash256,
pub previous_proposer_boost: ProposerBoost,
}
@@ -159,7 +160,6 @@ impl ProtoArray {
finalized_checkpoint: Checkpoint,
new_justified_balances: &JustifiedBalances,
proposer_boost_root: Hash256,
unsatisfied_inclusion_list_block: Hash256,
current_slot: Slot,
spec: &ChainSpec,
) -> Result<(), Error> {
@@ -197,19 +197,20 @@ impl ProtoArray {
let execution_status_is_invalid = node.execution_status.is_invalid();
// TODO(focil) seems sketchy...
let mut node_delta =
if execution_status_is_invalid || node.root == unsatisfied_inclusion_list_block {
// If the node has an invalid execution payload, or the payload doesn't satisfy
// an inclusion list, reduce its weight to zero.
0_i64
.checked_sub(node.weight as i64)
.ok_or(Error::InvalidExecutionDeltaOverflow(node_index))?
} else {
deltas
.get(node_index)
.copied()
.ok_or(Error::InvalidNodeDelta(node_index))?
};
let mut node_delta = if execution_status_is_invalid
|| node.root == self.unsatisfied_inclusion_list_block
{
// If the node has an invalid execution payload, or the payload doesn't satisfy
// an inclusion list, reduce its weight to zero.
0_i64
.checked_sub(node.weight as i64)
.ok_or(Error::InvalidExecutionDeltaOverflow(node_index))?
} else {
deltas
.get(node_index)
.copied()
.ok_or(Error::InvalidNodeDelta(node_index))?
};
// If we find the node for which the proposer boost was previously applied, decrease
// the delta by the previous score amount.
@@ -891,6 +892,10 @@ impl ProtoArray {
return false;
}
if node.root == self.unsatisfied_inclusion_list_block {
return false;
}
let genesis_epoch = Epoch::new(0);
let current_epoch = current_slot.epoch(E::slots_per_epoch());
let node_epoch = node.slot.epoch(E::slots_per_epoch());

View File

@@ -370,6 +370,7 @@ impl ProtoArrayForkChoice {
finalized_checkpoint: Checkpoint,
current_epoch_shuffling_id: AttestationShufflingId,
next_epoch_shuffling_id: AttestationShufflingId,
unsatisfied_inclusion_list_block: Hash256,
execution_status: ExecutionStatus,
) -> Result<Self, String> {
let mut proto_array = ProtoArray {
@@ -378,6 +379,7 @@ impl ProtoArrayForkChoice {
finalized_checkpoint,
nodes: Vec::with_capacity(1),
indices: HashMap::with_capacity(1),
unsatisfied_inclusion_list_block,
previous_proposer_boost: ProposerBoost::default(),
};
@@ -467,7 +469,6 @@ impl ProtoArrayForkChoice {
justified_state_balances: &JustifiedBalances,
proposer_boost_root: Hash256,
equivocating_indices: &BTreeSet<u64>,
unsatisfied_inclusion_list_block: Hash256,
current_slot: Slot,
spec: &ChainSpec,
) -> Result<Hash256, String> {
@@ -490,7 +491,6 @@ impl ProtoArrayForkChoice {
finalized_checkpoint,
new_balances,
proposer_boost_root,
unsatisfied_inclusion_list_block,
current_slot,
spec,
)
@@ -1033,6 +1033,7 @@ mod test_compute_deltas {
genesis_checkpoint,
junk_shuffling_id.clone(),
junk_shuffling_id.clone(),
Hash256::ZERO,
execution_status,
)
.unwrap();
@@ -1159,6 +1160,7 @@ mod test_compute_deltas {
genesis_checkpoint,
junk_shuffling_id.clone(),
junk_shuffling_id.clone(),
Hash256::ZERO,
execution_status,
)
.unwrap();

View File

@@ -27,6 +27,7 @@ pub struct SszContainer {
pub nodes: Vec<ProtoNodeV17>,
pub indices: Vec<(Hash256, usize)>,
pub previous_proposer_boost: ProposerBoost,
pub unsatisfied_inclusion_list_block: Hash256,
}
impl From<&ProtoArrayForkChoice> for SszContainer {
@@ -42,6 +43,7 @@ impl From<&ProtoArrayForkChoice> for SszContainer {
nodes: proto_array.nodes.clone(),
indices: proto_array.indices.iter().map(|(k, v)| (*k, *v)).collect(),
previous_proposer_boost: proto_array.previous_proposer_boost,
unsatisfied_inclusion_list_block: proto_array.unsatisfied_inclusion_list_block,
}
}
}
@@ -56,6 +58,7 @@ impl TryFrom<SszContainer> for ProtoArrayForkChoice {
finalized_checkpoint: from.finalized_checkpoint,
nodes: from.nodes,
indices: from.indices.into_iter().collect::<HashMap<_, _>>(),
unsatisfied_inclusion_list_block: from.unsatisfied_inclusion_list_block,
previous_proposer_boost: from.previous_proposer_boost,
};