Implement get_attester_head logic

This commit is contained in:
Eitan Seri-Levi
2025-01-16 13:19:07 +07:00
parent 3069b36243
commit f87f83873a
9 changed files with 94 additions and 14 deletions

View File

@@ -110,6 +110,7 @@ impl ForkChoiceTestDefinition {
&justified_balances,
Hash256::zero(),
&equivocating_indices,
Hash256::zero(),
Slot::new(0),
&spec,
)
@@ -141,6 +142,7 @@ impl ForkChoiceTestDefinition {
&justified_balances,
proposer_boost_root,
&equivocating_indices,
Hash256::zero(),
Slot::new(0),
&spec,
)
@@ -169,6 +171,7 @@ impl ForkChoiceTestDefinition {
&justified_balances,
Hash256::zero(),
&equivocating_indices,
Hash256::zero(),
Slot::new(0),
&spec,
);

View File

@@ -159,6 +159,7 @@ 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> {
@@ -195,17 +196,20 @@ impl ProtoArray {
let execution_status_is_invalid = node.execution_status.is_invalid();
let mut node_delta = if execution_status_is_invalid {
// If the node has an invalid execution payload, 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))?
};
// 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))?
};
// If we find the node for which the proposer boost was previously applied, decrease
// the delta by the previous score amount.

View File

@@ -467,6 +467,7 @@ 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> {
@@ -489,6 +490,7 @@ impl ProtoArrayForkChoice {
finalized_checkpoint,
new_balances,
proposer_boost_root,
unsatisfied_inclusion_list_block,
current_slot,
spec,
)