mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
debugging
This commit is contained in:
@@ -390,7 +390,7 @@ where
|
||||
*fc_store.finalized_checkpoint(),
|
||||
current_epoch_shuffling_id,
|
||||
next_epoch_shuffling_id,
|
||||
*fc_store.unsatisfied_inclusion_list_block(),
|
||||
fc_store.unsatisfied_inclusion_list_blocks().clone(),
|
||||
execution_status,
|
||||
)?;
|
||||
|
||||
@@ -628,9 +628,9 @@ where
|
||||
}
|
||||
|
||||
// TODO(focil) add documentation
|
||||
pub fn on_invalid_inclusion_list_payload(&mut self, block_root: Hash256) {
|
||||
pub fn on_invalid_inclusion_list_payload(&mut self, slot: Slot, block_root: Hash256) {
|
||||
self.fc_store
|
||||
.set_unsatisfied_inclusion_list_block(block_root);
|
||||
.set_unsatisfied_inclusion_list_block(slot, block_root);
|
||||
}
|
||||
|
||||
/// Add `block` to the fork choice DAG.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use proto_array::JustifiedBalances;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
use types::{AbstractExecPayload, BeaconBlockRef, BeaconState, Checkpoint, EthSpec, Hash256, Slot};
|
||||
|
||||
/// Approximates the `Store` in "Ethereum 2.0 Phase 0 -- Beacon Chain Fork Choice":
|
||||
///
|
||||
/// https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/fork-choice.md#store
|
||||
@@ -80,9 +80,12 @@ 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;
|
||||
/// Returns the `unsatisfied_inclusion_list_blocks` mapping.
|
||||
fn unsatisfied_inclusion_list_blocks(&self) -> &HashMap<Slot, Hash256>;
|
||||
|
||||
/// Returns the `unsatisfied_inclusion_list_block` for the given slot.
|
||||
fn unsatisfied_inclusion_list_block(&self, slot: Slot) -> Option<&Hash256>;
|
||||
|
||||
/// Sets the `unsatisfied_inclusion_list_block`.
|
||||
fn set_unsatisfied_inclusion_list_block(&mut self, block_root: Hash256);
|
||||
fn set_unsatisfied_inclusion_list_block(&mut self, slot: Slot, block_root: Hash256);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ mod votes;
|
||||
use crate::proto_array_fork_choice::{Block, ExecutionStatus, ProtoArrayForkChoice};
|
||||
use crate::{InvalidationOperation, JustifiedBalances};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use types::{
|
||||
AttestationShufflingId, Checkpoint, Epoch, EthSpec, ExecutionBlockHash, FixedBytesExtended,
|
||||
Hash256, MainnetEthSpec, Slot,
|
||||
@@ -87,7 +87,7 @@ impl ForkChoiceTestDefinition {
|
||||
self.finalized_checkpoint,
|
||||
junk_shuffling_id.clone(),
|
||||
junk_shuffling_id,
|
||||
Hash256::ZERO,
|
||||
HashMap::new(),
|
||||
ExecutionStatus::Optimistic(ExecutionBlockHash::zero()),
|
||||
)
|
||||
.expect("should create fork choice struct");
|
||||
|
||||
@@ -134,7 +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 unsatisfied_inclusion_list_blocks: HashMap<Slot, Hash256>,
|
||||
pub previous_proposer_boost: ProposerBoost,
|
||||
}
|
||||
|
||||
@@ -197,8 +197,14 @@ impl ProtoArray {
|
||||
let execution_status_is_invalid = node.execution_status.is_invalid();
|
||||
|
||||
// TODO(focil) seems sketchy...
|
||||
// modify is viable for head
|
||||
// debug/fork_choice
|
||||
let mut node_delta = if execution_status_is_invalid
|
||||
|| node.root == self.unsatisfied_inclusion_list_block
|
||||
|| node.root
|
||||
== *self
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
.get(¤t_slot)
|
||||
.unwrap_or(&Hash256::ZERO)
|
||||
{
|
||||
// If the node has an invalid execution payload, or the payload doesn't satisfy
|
||||
// an inclusion list, reduce its weight to zero.
|
||||
@@ -892,7 +898,13 @@ impl ProtoArray {
|
||||
return false;
|
||||
}
|
||||
|
||||
if node.root == self.unsatisfied_inclusion_list_block {
|
||||
// TODO(focil) unwrap_or
|
||||
if node.root
|
||||
== *self
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
.get(¤t_slot)
|
||||
.unwrap_or(&Hash256::ZERO)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ impl ProtoArrayForkChoice {
|
||||
finalized_checkpoint: Checkpoint,
|
||||
current_epoch_shuffling_id: AttestationShufflingId,
|
||||
next_epoch_shuffling_id: AttestationShufflingId,
|
||||
unsatisfied_inclusion_list_block: Hash256,
|
||||
unsatisfied_inclusion_list_blocks: HashMap<Slot, Hash256>,
|
||||
execution_status: ExecutionStatus,
|
||||
) -> Result<Self, String> {
|
||||
let mut proto_array = ProtoArray {
|
||||
@@ -379,7 +379,7 @@ impl ProtoArrayForkChoice {
|
||||
finalized_checkpoint,
|
||||
nodes: Vec::with_capacity(1),
|
||||
indices: HashMap::with_capacity(1),
|
||||
unsatisfied_inclusion_list_block,
|
||||
unsatisfied_inclusion_list_blocks,
|
||||
previous_proposer_boost: ProposerBoost::default(),
|
||||
};
|
||||
|
||||
@@ -1033,7 +1033,7 @@ mod test_compute_deltas {
|
||||
genesis_checkpoint,
|
||||
junk_shuffling_id.clone(),
|
||||
junk_shuffling_id.clone(),
|
||||
Hash256::ZERO,
|
||||
HashMap::new(),
|
||||
execution_status,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1160,7 +1160,7 @@ mod test_compute_deltas {
|
||||
genesis_checkpoint,
|
||||
junk_shuffling_id.clone(),
|
||||
junk_shuffling_id.clone(),
|
||||
Hash256::ZERO,
|
||||
HashMap::new(),
|
||||
execution_status,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -8,7 +8,7 @@ use ssz::{four_byte_option_impl, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use superstruct::superstruct;
|
||||
use types::{Checkpoint, Hash256};
|
||||
use types::{Checkpoint, Hash256, Slot};
|
||||
|
||||
// Define a "legacy" implementation of `Option<usize>` which uses four bytes for encoding the union
|
||||
// selector.
|
||||
@@ -27,7 +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,
|
||||
pub unsatisfied_inclusion_list_blocks: Vec<(Slot, Hash256)>,
|
||||
}
|
||||
|
||||
impl From<&ProtoArrayForkChoice> for SszContainer {
|
||||
@@ -43,7 +43,11 @@ 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,
|
||||
unsatisfied_inclusion_list_blocks: proto_array
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
.iter()
|
||||
.map(|(k, v)| (*k, *v))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,8 +62,11 @@ 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,
|
||||
unsatisfied_inclusion_list_blocks: from
|
||||
.unsatisfied_inclusion_list_blocks
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>(),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -1824,6 +1824,7 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
|
||||
pub fn get_inclusion_list_duties(
|
||||
&self,
|
||||
pubkey: PublicKeyBytes,
|
||||
validator_index: usize,
|
||||
epoch: Epoch,
|
||||
spec: &ChainSpec,
|
||||
@@ -1837,6 +1838,7 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
slot,
|
||||
validator_index,
|
||||
committee_root,
|
||||
pubkey,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,41 +19,24 @@ struct Inner<E: EthSpec> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> InclusionListCache<E> {
|
||||
pub fn initialize(&mut self, slot: Slot) {
|
||||
let inner = Inner {
|
||||
inclusion_lists: HashSet::new(),
|
||||
inclusion_lists_seen: HashSet::new(),
|
||||
inclusion_list_equivocators: HashSet::new(),
|
||||
inclusion_list_transactions: HashSet::new(),
|
||||
};
|
||||
|
||||
self.inner_map.insert(slot, inner);
|
||||
}
|
||||
|
||||
pub fn clear_cache(&mut self, slot: Slot) {
|
||||
self.inner_map.remove(&slot);
|
||||
}
|
||||
|
||||
pub fn on_inclusion_list(&mut self, inclusion_list: SignedInclusionList<E>, log: &Logger) {
|
||||
let Some(inner) = self.inner_map.get_mut(&inclusion_list.message.slot) else {
|
||||
return;
|
||||
};
|
||||
let slot = inclusion_list.message.slot;
|
||||
let inner = self.inner_map.entry(slot).or_default();
|
||||
|
||||
if inner
|
||||
.inclusion_list_equivocators
|
||||
.contains(&inclusion_list.message.validator_index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
debug!(
|
||||
log,
|
||||
"This validator was flagged for an equivocating inclusion list";
|
||||
"slot" => slot,
|
||||
"validator_index" => inclusion_list.message.validator_index
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,6 +46,27 @@ impl<E: EthSpec> InclusionListCache<E> {
|
||||
.contains(&inclusion_list.message.validator_index)
|
||||
&& inner.inclusion_lists.contains(&inclusion_list)
|
||||
{
|
||||
debug!(
|
||||
log,
|
||||
"Already seen identical inclusion list from this validator";
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if inner
|
||||
.inclusion_lists_seen
|
||||
.contains(&inclusion_list.message.validator_index)
|
||||
&& !inner.inclusion_lists.contains(&inclusion_list)
|
||||
{
|
||||
debug!(
|
||||
log,
|
||||
"Equivocating inclusion list";
|
||||
"slot" => slot,
|
||||
"validator_index" => inclusion_list.message.validator_index
|
||||
);
|
||||
inner
|
||||
.inclusion_list_equivocators
|
||||
.insert(inclusion_list.message.validator_index);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,7 +82,9 @@ impl<E: EthSpec> InclusionListCache<E> {
|
||||
|
||||
debug!(
|
||||
log,
|
||||
"Successfully added inclusion list transactions to the cache"
|
||||
"Successfully added inclusion list transactions to the cache";
|
||||
"slot" => slot,
|
||||
"total_count" => inner.inclusion_list_transactions.len()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,7 +92,7 @@ impl<E: EthSpec> InclusionListCache<E> {
|
||||
&self,
|
||||
slot: Slot,
|
||||
) -> Option<InclusionListTransactions<E>> {
|
||||
let Some(inner) = &self.inner_map.get(&slot) else {
|
||||
let Some(inner) = self.inner_map.get(&slot) else {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(arbitrary::Arbitrary, Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)]
|
||||
#[derive(arbitrary::Arbitrary, Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct InclusionListDuty {
|
||||
/// The slot during which the validator must produce an inclusion list.
|
||||
pub slot: Slot,
|
||||
@@ -10,4 +10,6 @@ pub struct InclusionListDuty {
|
||||
pub validator_index: u64,
|
||||
/// The hash tree root of the inclusion list committee.
|
||||
pub committee_root: Hash256,
|
||||
/// The pubkey of the validator.
|
||||
pub pubkey: PublicKeyBytes,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user