mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 12:47:05 +00:00
Fork choice changes
This commit is contained in:
@@ -452,7 +452,7 @@ where
|
||||
*fc_store.finalized_checkpoint(),
|
||||
current_epoch_shuffling_id,
|
||||
next_epoch_shuffling_id,
|
||||
fc_store.unsatisfied_inclusion_list_blocks().clone(),
|
||||
fc_store.payload_inclusion_list_satisfaction().clone(),
|
||||
execution_status,
|
||||
execution_payload_parent_hash,
|
||||
execution_payload_block_hash,
|
||||
@@ -724,10 +724,20 @@ where
|
||||
.map_err(Error::FailedToProcessInvalidExecutionPayload)
|
||||
}
|
||||
|
||||
// TODO(focil) add documentation
|
||||
pub fn on_invalid_inclusion_list_payload(&mut self, slot: Slot, block_root: Hash256) {
|
||||
/// Record whether a block root satisfies the inclusion list.
|
||||
pub fn record_payload_inclusion_list_satisfaction(
|
||||
&mut self,
|
||||
block_root: Hash256,
|
||||
satisfied: bool,
|
||||
) {
|
||||
self.fc_store
|
||||
.set_unsatisfied_inclusion_list_block(slot, block_root);
|
||||
.record_payload_inclusion_list_satisfaction(block_root, satisfied);
|
||||
}
|
||||
|
||||
/// Returns `true` if the block root has been recorded as satisfying the inclusion list.
|
||||
pub fn is_payload_inclusion_list_satisfied(&self, block_root: &Hash256) -> bool {
|
||||
self.fc_store
|
||||
.is_payload_inclusion_list_satisfied(block_root)
|
||||
}
|
||||
|
||||
/// Add `block` to the fork choice DAG.
|
||||
|
||||
@@ -90,12 +90,16 @@ 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_blocks` mapping.
|
||||
fn unsatisfied_inclusion_list_blocks(&self) -> &HashMap<Slot, Hash256>;
|
||||
/// Returns the `payload_inclusion_list_satisfaction` mapping.
|
||||
fn payload_inclusion_list_satisfaction(&self) -> &HashMap<Hash256, bool>;
|
||||
|
||||
/// Returns the `unsatisfied_inclusion_list_block` for the given slot.
|
||||
fn unsatisfied_inclusion_list_block(&self, slot: Slot) -> Option<&Hash256>;
|
||||
/// Returns `true` if the block root is in the map AND the value is `true`.
|
||||
fn is_payload_inclusion_list_satisfied(&self, block_root: &Hash256) -> bool;
|
||||
|
||||
/// Sets the `unsatisfied_inclusion_list_block`.
|
||||
fn set_unsatisfied_inclusion_list_block(&mut self, slot: Slot, block_root: Hash256);
|
||||
/// Records whether a block root satisfies the inclusion list.
|
||||
fn record_payload_inclusion_list_satisfaction(
|
||||
&mut self,
|
||||
block_root: Hash256,
|
||||
satisfied: bool,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ pub struct ProtoArray {
|
||||
pub prune_threshold: usize,
|
||||
pub nodes: Vec<ProtoNode>,
|
||||
pub indices: HashMap<Hash256, usize>,
|
||||
pub unsatisfied_inclusion_list_blocks: HashMap<Slot, Hash256>,
|
||||
pub payload_inclusion_list_satisfaction: HashMap<Hash256, bool>,
|
||||
pub previous_proposer_boost: ProposerBoost,
|
||||
}
|
||||
|
||||
@@ -1510,6 +1510,16 @@ impl ProtoArray {
|
||||
proto_node: &ProtoNode,
|
||||
proposer_boost_root: Hash256,
|
||||
) -> Result<bool, Error> {
|
||||
// If the block's inclusion list satisfaction has been recorded as false,
|
||||
// do not extend the payload.
|
||||
if self
|
||||
.payload_inclusion_list_satisfaction
|
||||
.get(&fc_node.root)
|
||||
== Some(&false)
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
// Per spec: `proposer_root == Root()` is one of the `or` conditions that
|
||||
// makes `should_extend_payload` return True.
|
||||
if proposer_boost_root.is_zero() {
|
||||
@@ -1616,12 +1626,10 @@ impl ProtoArray {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(focil) unwrap_or
|
||||
if node.root()
|
||||
== *self
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
.get(¤t_slot)
|
||||
.unwrap_or(&Hash256::zero())
|
||||
if self
|
||||
.payload_inclusion_list_satisfaction
|
||||
.get(&node.root())
|
||||
== Some(&false)
|
||||
{
|
||||
info!(
|
||||
?current_slot,
|
||||
|
||||
@@ -505,7 +505,7 @@ impl ProtoArrayForkChoice {
|
||||
finalized_checkpoint: Checkpoint,
|
||||
current_epoch_shuffling_id: AttestationShufflingId,
|
||||
next_epoch_shuffling_id: AttestationShufflingId,
|
||||
unsatisfied_inclusion_list_blocks: HashMap<Slot, Hash256>,
|
||||
payload_inclusion_list_satisfaction: HashMap<Hash256, bool>,
|
||||
execution_status: ExecutionStatus,
|
||||
execution_payload_parent_hash: Option<ExecutionBlockHash>,
|
||||
execution_payload_block_hash: Option<ExecutionBlockHash>,
|
||||
@@ -516,7 +516,7 @@ impl ProtoArrayForkChoice {
|
||||
prune_threshold: DEFAULT_PRUNE_THRESHOLD,
|
||||
nodes: Vec::with_capacity(1),
|
||||
indices: HashMap::with_capacity(1),
|
||||
unsatisfied_inclusion_list_blocks,
|
||||
payload_inclusion_list_satisfaction,
|
||||
previous_proposer_boost: ProposerBoost::default(),
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use ssz::{Encode, four_byte_option_impl};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use superstruct::superstruct;
|
||||
use types::{Checkpoint, Hash256, Slot};
|
||||
use types::{Checkpoint, Hash256};
|
||||
|
||||
// Define a "legacy" implementation of `Option<usize>` which uses four bytes for encoding the union
|
||||
// selector.
|
||||
@@ -40,7 +40,7 @@ pub struct SszContainer {
|
||||
pub indices: Vec<(Hash256, usize)>,
|
||||
#[superstruct(only(V28))]
|
||||
pub previous_proposer_boost: ProposerBoost,
|
||||
pub unsatisfied_inclusion_list_blocks: Vec<(Slot, Hash256)>,
|
||||
pub payload_inclusion_list_satisfaction: Vec<(Hash256, bool)>,
|
||||
}
|
||||
|
||||
impl SszContainerV29 {
|
||||
@@ -52,8 +52,8 @@ impl SszContainerV29 {
|
||||
prune_threshold: proto_array.prune_threshold,
|
||||
nodes: proto_array.nodes.clone(),
|
||||
indices: proto_array.indices.iter().map(|(k, v)| (*k, *v)).collect(),
|
||||
unsatisfied_inclusion_list_blocks: proto_array
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
payload_inclusion_list_satisfaction: proto_array
|
||||
.payload_inclusion_list_satisfaction
|
||||
.iter()
|
||||
.map(|(k, v)| (*k, *v))
|
||||
.collect(),
|
||||
@@ -70,8 +70,8 @@ impl TryFrom<(SszContainerV29, JustifiedBalances)> for ProtoArrayForkChoice {
|
||||
nodes: from.nodes,
|
||||
indices: from.indices.into_iter().collect::<HashMap<_, _>>(),
|
||||
previous_proposer_boost: ProposerBoost::default(),
|
||||
unsatisfied_inclusion_list_blocks: from
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
payload_inclusion_list_satisfaction: from
|
||||
.payload_inclusion_list_satisfaction
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>(),
|
||||
};
|
||||
@@ -102,7 +102,7 @@ impl From<SszContainerV28> for SszContainerV29 {
|
||||
})
|
||||
.collect(),
|
||||
indices: v28.indices,
|
||||
unsatisfied_inclusion_list_blocks: vec![],
|
||||
payload_inclusion_list_satisfaction: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ impl From<SszContainerV29> for SszContainerV28 {
|
||||
indices: v29.indices,
|
||||
// Proposer boost is not tracked in V29 (computed on-the-fly), so reset it.
|
||||
previous_proposer_boost: ProposerBoost::default(),
|
||||
unsatisfied_inclusion_list_blocks: v29.unsatisfied_inclusion_list_blocks,
|
||||
payload_inclusion_list_satisfaction: v29.payload_inclusion_list_satisfaction,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user