mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
Implement get_attester_head logic
This commit is contained in:
@@ -489,6 +489,7 @@ where
|
||||
store.justified_balances(),
|
||||
store.proposer_boost_root(),
|
||||
store.equivocating_indices(),
|
||||
store.unsatisfied_inclusion_list_block(),
|
||||
current_slot,
|
||||
spec,
|
||||
)?;
|
||||
@@ -626,6 +627,14 @@ where
|
||||
.map_err(Error::FailedToProcessInvalidExecutionPayload)
|
||||
}
|
||||
|
||||
// TODO(focil) add documentation
|
||||
pub fn on_invalid_inclusion_list_payload(
|
||||
&mut self,
|
||||
block_root: Hash256,
|
||||
) {
|
||||
self.fc_store.set_unsatisfied_inclusion_list_block(block_root);
|
||||
}
|
||||
|
||||
/// Add `block` to the fork choice DAG.
|
||||
///
|
||||
/// - `block_root` is the root of `block.
|
||||
|
||||
@@ -79,4 +79,10 @@ pub trait ForkChoiceStore<E: EthSpec>: Sized {
|
||||
|
||||
/// Adds to the set of equivocating indices.
|
||||
fn extend_equivocating_indices(&mut self, indices: impl IntoIterator<Item = u64>);
|
||||
|
||||
/// Returns the `unsatisfied_inclusion_list_block`.
|
||||
fn unsatisfied_inclusion_list_block(&self) -> Hash256;
|
||||
|
||||
/// Sets the `unsatisfied_inclusion_list_block`.
|
||||
fn set_unsatisfied_inclusion_list_block(&mut self, block_root: Hash256);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -46,7 +46,11 @@ impl<E: EthSpec> InclusionListCache<E> {
|
||||
return;
|
||||
}
|
||||
|
||||
if inner.inclusion_lists_seen.contains(&inclusion_list.message.validator_index) && !inner.inclusion_lists.contains(&inclusion_list) {
|
||||
if inner
|
||||
.inclusion_lists_seen
|
||||
.contains(&inclusion_list.message.validator_index)
|
||||
&& !inner.inclusion_lists.contains(&inclusion_list)
|
||||
{
|
||||
inner
|
||||
.inclusion_list_equivocators
|
||||
.insert(inclusion_list.message.validator_index);
|
||||
@@ -54,7 +58,11 @@ impl<E: EthSpec> InclusionListCache<E> {
|
||||
}
|
||||
|
||||
// Skip inserting into the cache if we've already seen an identical IL
|
||||
if inner.inclusion_lists_seen.contains(&inclusion_list.message.validator_index) && inner.inclusion_lists.contains(&inclusion_list) {
|
||||
if inner
|
||||
.inclusion_lists_seen
|
||||
.contains(&inclusion_list.message.validator_index)
|
||||
&& inner.inclusion_lists.contains(&inclusion_list)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,7 +71,9 @@ impl<E: EthSpec> InclusionListCache<E> {
|
||||
.inclusion_list_transactions
|
||||
.insert(transaction.clone());
|
||||
}
|
||||
inner.inclusion_lists_seen.insert(inclusion_list.message.validator_index);
|
||||
inner
|
||||
.inclusion_lists_seen
|
||||
.insert(inclusion_list.message.validator_index);
|
||||
inner.inclusion_lists.insert(inclusion_list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user