diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index df7c9cfeab..c7ce729efa 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -3280,7 +3280,7 @@ impl BeaconChain { metrics::start_timer(&metrics::BLOCK_PRODUCTION_UNAGGREGATED_TIMES); for attestation in self.naive_aggregation_pool.read().iter() { let import = |attestation: &Attestation| { - let attesting_indices = get_attesting_indices_from_state(&state, &attestation)?; + let attesting_indices = get_attesting_indices_from_state(&state, attestation)?; self.op_pool .insert_attestation(attestation.clone(), attesting_indices) }; @@ -3342,8 +3342,8 @@ impl BeaconChain { "err" => ?e, "block_slot" => state.slot(), ); - assert!(false); - false + panic!("Attempted to include an invalid attestation"); + // false } else { true } diff --git a/beacon_node/beacon_chain/src/block_reward.rs b/beacon_node/beacon_chain/src/block_reward.rs index 478c21add8..3bddd2a521 100644 --- a/beacon_node/beacon_chain/src/block_reward.rs +++ b/beacon_node/beacon_chain/src/block_reward.rs @@ -13,14 +13,13 @@ impl BeaconChain { block: BeaconBlockRef<'_, T::EthSpec, Payload>, block_root: Hash256, state: &BeaconState, + reward_cache: &mut RewardCache, include_attestations: bool, ) -> Result { if block.slot() != state.slot() { return Err(BeaconChainError::BlockRewardSlotError); } - // FIXME(sproul): pass this in - let mut reward_cache = RewardCache::default(); reward_cache.update(state)?; let total_active_balance = state.get_total_active_balance()?; @@ -41,7 +40,7 @@ impl BeaconChain { AttMaxCover::new( att.as_ref(), state, - &reward_cache, + reward_cache, total_active_balance, &self.spec, ) diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index a64fb387e3..07f8f7cc24 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -1278,8 +1278,14 @@ impl ExecutionPendingBlock { */ if let Some(ref event_handler) = chain.event_handler { if event_handler.has_block_reward_subscribers() { - let block_reward = - chain.compute_block_reward(block.message(), block_root, &state, true)?; + let mut reward_cache = Default::default(); + let block_reward = chain.compute_block_reward( + block.message(), + block_root, + &state, + &mut reward_cache, + true, + )?; event_handler.register(EventKind::BlockReward(block_reward)); } } diff --git a/beacon_node/http_api/src/block_rewards.rs b/beacon_node/http_api/src/block_rewards.rs index 682828aee4..3b81b894db 100644 --- a/beacon_node/http_api/src/block_rewards.rs +++ b/beacon_node/http_api/src/block_rewards.rs @@ -52,6 +52,7 @@ pub fn get_block_rewards( .build_all_caches(&chain.spec) .map_err(beacon_state_error)?; + let mut reward_cache = Default::default(); let mut block_rewards = Vec::with_capacity(blocks.len()); let block_replayer = BlockReplayer::new(state, &chain.spec) @@ -63,6 +64,7 @@ pub fn get_block_rewards( block.message(), block.canonical_root(), state, + &mut reward_cache, query.include_attestations, )?; block_rewards.push(block_reward); @@ -100,6 +102,7 @@ pub fn compute_block_rewards( ) -> Result, warp::Rejection> { let mut block_rewards = Vec::with_capacity(blocks.len()); let mut state_cache = LruCache::new(STATE_CACHE_SIZE); + let mut reward_cache = Default::default(); for block in blocks { let parent_root = block.parent_root(); @@ -170,7 +173,13 @@ pub fn compute_block_rewards( // Compute block reward. let block_reward = chain - .compute_block_reward(block.to_ref(), block.canonical_root(), state, true) + .compute_block_reward( + block.to_ref(), + block.canonical_root(), + state, + &mut reward_cache, + true, + ) .map_err(beacon_chain_error)?; block_rewards.push(block_reward); } diff --git a/beacon_node/operation_pool/src/attestation_storage.rs b/beacon_node/operation_pool/src/attestation_storage.rs index 56e2240e7b..036bed10b4 100644 --- a/beacon_node/operation_pool/src/attestation_storage.rs +++ b/beacon_node/operation_pool/src/attestation_storage.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use std::collections::HashMap; use types::{ AggregateSignature, Attestation, AttestationData, BeaconState, BitList, Checkpoint, Epoch, - EthSpec, Hash256, IndexedAttestation, Slot, + EthSpec, Hash256, Slot, }; #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] @@ -188,7 +188,7 @@ impl AttestationMap { } /// Iterate all attestations in the map. - pub fn iter<'a>(&'a self) -> impl Iterator> + 'a { + pub fn iter(&self) -> impl Iterator> { self.checkpoint_map .iter() .flat_map(|(checkpoint_key, attestation_map)| attestation_map.iter(checkpoint_key)) diff --git a/beacon_node/operation_pool/src/lib.rs b/beacon_node/operation_pool/src/lib.rs index 0003841db4..86bda5cb8f 100644 --- a/beacon_node/operation_pool/src/lib.rs +++ b/beacon_node/operation_pool/src/lib.rs @@ -30,7 +30,7 @@ use std::ptr; use types::{ sync_aggregate::Error as SyncAggregateError, typenum::Unsigned, Attestation, AttestationData, AttesterSlashing, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, Fork, ForkVersion, - Hash256, ProposerSlashing, SignedVoluntaryExit, Slot, SyncAggregate, SyncCommitteeContribution, + ProposerSlashing, SignedVoluntaryExit, Slot, SyncAggregate, SyncCommitteeContribution, Validator, }; @@ -206,6 +206,7 @@ impl OperationPool { } /// Return all valid attestations for the given epoch, for use in max cover. + #[allow(clippy::too_many_arguments)] fn get_valid_attestations_for_epoch<'a>( &'a self, checkpoint_key: &'a CheckpointKey, diff --git a/consensus/state_processing/src/common/get_attesting_indices.rs b/consensus/state_processing/src/common/get_attesting_indices.rs index 4cb2f2e0e5..d7d02c3601 100644 --- a/consensus/state_processing/src/common/get_attesting_indices.rs +++ b/consensus/state_processing/src/common/get_attesting_indices.rs @@ -28,5 +28,5 @@ pub fn get_attesting_indices_from_state( att: &Attestation, ) -> Result, BeaconStateError> { let committee = state.get_beacon_committee(att.data.slot, att.data.index)?; - get_attesting_indices::(&committee.committee, &att.aggregation_bits) + get_attesting_indices::(committee.committee, &att.aggregation_bits) }