diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index c19da15385..14d902d50f 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -7267,7 +7267,10 @@ impl BeaconChain { ) } - pub async fn set_unsatisfied_inclusion_list_block(self: &Arc, block_root: Hash256) -> Result<(), Error> { + pub async fn set_unsatisfied_inclusion_list_block( + self: &Arc, + block_root: Hash256, + ) -> Result<(), Error> { let chain = self.clone(); let fork_choice_result = self .spawn_blocking_handle( @@ -7294,7 +7297,9 @@ impl BeaconChain { } pub fn on_verified_inclusion_list(&self, signed_il: SignedInclusionList) { - self.inclusion_list_cache.write().on_inclusion_list(signed_il); + self.inclusion_list_cache + .write() + .on_inclusion_list(signed_il); } pub fn metrics(&self) -> BeaconChainMetrics { diff --git a/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs b/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs index 2fc35f1b58..8c19b8ad0d 100644 --- a/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs +++ b/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs @@ -356,8 +356,8 @@ where self.unsatisfied_inclusion_list_block = block_root; } - fn unsatisfied_inclusion_list_block(&self) -> Hash256 { - self.unsatisfied_inclusion_list_block + fn unsatisfied_inclusion_list_block(&self) -> &Hash256 { + &self.unsatisfied_inclusion_list_block } } diff --git a/beacon_node/beacon_chain/src/execution_payload.rs b/beacon_node/beacon_chain/src/execution_payload.rs index e69d706be8..ef4b81e9ff 100644 --- a/beacon_node/beacon_chain/src/execution_payload.rs +++ b/beacon_node/beacon_chain/src/execution_payload.rs @@ -205,7 +205,9 @@ async fn notify_new_payload<'a, T: BeaconChainTypes>( // transactions for this slot, update the fork choice store before processing // the invalid EL payload. if *validation_error == Some("INVALID_INCLUSION_LIST".to_string()) { - chain.set_unsatisfied_inclusion_list_block(block.tree_hash_root()).await?; + chain + .set_unsatisfied_inclusion_list_block(block.tree_hash_root()) + .await?; } chain diff --git a/beacon_node/network/src/network_beacon_processor/gossip_methods.rs b/beacon_node/network/src/network_beacon_processor/gossip_methods.rs index 6c1ced94d1..8640df38e1 100644 --- a/beacon_node/network/src/network_beacon_processor/gossip_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/gossip_methods.rs @@ -2178,7 +2178,8 @@ impl NetworkBeaconProcessor { debug!(self.log, "Successfully verified gossip inclusion list"); // Store validated inclusion list in the IL cache. This also catches // equivocating IL's and handles them accordingly. - self.chain.on_verified_inclusion_list(gossip_verified_il.signed_il); + self.chain + .on_verified_inclusion_list(gossip_verified_il.signed_il); } Err(err) => match err { GossipInclusionListError::FutureSlot { .. } diff --git a/consensus/fork_choice/src/fork_choice.rs b/consensus/fork_choice/src/fork_choice.rs index eeba8fc095..dc6ea98240 100644 --- a/consensus/fork_choice/src/fork_choice.rs +++ b/consensus/fork_choice/src/fork_choice.rs @@ -390,6 +390,7 @@ where *fc_store.finalized_checkpoint(), current_epoch_shuffling_id, next_epoch_shuffling_id, + *fc_store.unsatisfied_inclusion_list_block(), execution_status, )?; @@ -489,7 +490,6 @@ where store.justified_balances(), store.proposer_boost_root(), store.equivocating_indices(), - store.unsatisfied_inclusion_list_block(), current_slot, spec, )?; @@ -628,11 +628,9 @@ where } // 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); + 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. diff --git a/consensus/fork_choice/src/fork_choice_store.rs b/consensus/fork_choice/src/fork_choice_store.rs index 79403ee79b..b33622d7b9 100644 --- a/consensus/fork_choice/src/fork_choice_store.rs +++ b/consensus/fork_choice/src/fork_choice_store.rs @@ -81,7 +81,7 @@ pub trait ForkChoiceStore: Sized { fn extend_equivocating_indices(&mut self, indices: impl IntoIterator); /// Returns the `unsatisfied_inclusion_list_block`. - fn unsatisfied_inclusion_list_block(&self) -> Hash256; + fn unsatisfied_inclusion_list_block(&self) -> &Hash256; /// Sets the `unsatisfied_inclusion_list_block`. fn set_unsatisfied_inclusion_list_block(&mut self, block_root: Hash256); diff --git a/consensus/proto_array/src/fork_choice_test_definition.rs b/consensus/proto_array/src/fork_choice_test_definition.rs index dc13d63678..1a824c7ff5 100644 --- a/consensus/proto_array/src/fork_choice_test_definition.rs +++ b/consensus/proto_array/src/fork_choice_test_definition.rs @@ -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, ); diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index 9364a92738..9cb415839f 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -134,6 +134,7 @@ pub struct ProtoArray { pub finalized_checkpoint: Checkpoint, pub nodes: Vec, pub indices: HashMap, + 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()); diff --git a/consensus/proto_array/src/proto_array_fork_choice.rs b/consensus/proto_array/src/proto_array_fork_choice.rs index 85b568abce..6589a47734 100644 --- a/consensus/proto_array/src/proto_array_fork_choice.rs +++ b/consensus/proto_array/src/proto_array_fork_choice.rs @@ -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 { 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, - unsatisfied_inclusion_list_block: Hash256, current_slot: Slot, spec: &ChainSpec, ) -> Result { @@ -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(); diff --git a/consensus/proto_array/src/ssz_container.rs b/consensus/proto_array/src/ssz_container.rs index 8abb60d8e6..31c6afcbb8 100644 --- a/consensus/proto_array/src/ssz_container.rs +++ b/consensus/proto_array/src/ssz_container.rs @@ -27,6 +27,7 @@ pub struct SszContainer { pub nodes: Vec, 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 for ProtoArrayForkChoice { finalized_checkpoint: from.finalized_checkpoint, nodes: from.nodes, indices: from.indices.into_iter().collect::>(), + unsatisfied_inclusion_list_block: from.unsatisfied_inclusion_list_block, previous_proposer_boost: from.previous_proposer_boost, };