diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2f0da3abc53..b73b6037f7b 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -94,6 +94,7 @@ use slot_clock::SlotClock; use ssz::Encode; use state_processing::{ common::get_attesting_indices_from_state, + epoch_cache::initialize_epoch_cache, per_block_processing, per_block_processing::{ errors::AttestationValidationError, get_expected_withdrawals, @@ -4810,7 +4811,10 @@ impl BeaconChain { let attestation_packing_timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_ATTESTATION_TIMES); + // Epoch cache and total balance cache are required for op pool packing. state.build_total_active_balance_cache_at(state.current_epoch(), &self.spec)?; + initialize_epoch_cache(&mut state, &self.spec)?; + let mut prev_filter_cache = HashMap::new(); let prev_attestation_filter = |att: &AttestationRef| { self.filter_op_pool_attestation(&mut prev_filter_cache, att, &state) diff --git a/beacon_node/beacon_chain/src/errors.rs b/beacon_node/beacon_chain/src/errors.rs index 6d2a178faa7..a4f694e411f 100644 --- a/beacon_node/beacon_chain/src/errors.rs +++ b/beacon_node/beacon_chain/src/errors.rs @@ -256,6 +256,7 @@ pub enum BlockProductionError { UnableToProduceAtSlot(Slot), SlotProcessingError(SlotProcessingError), BlockProcessingError(BlockProcessingError), + EpochCacheError(EpochCacheError), ForkChoiceError(ForkChoiceError), Eth1ChainError(Eth1ChainError), BeaconStateError(BeaconStateError), @@ -296,3 +297,4 @@ easy_from_to!(SlotProcessingError, BlockProductionError); easy_from_to!(Eth1ChainError, BlockProductionError); easy_from_to!(StateAdvanceError, BlockProductionError); easy_from_to!(ForkChoiceError, BlockProductionError); +easy_from_to!(EpochCacheError, BlockProductionError); diff --git a/beacon_node/operation_pool/src/attestation.rs b/beacon_node/operation_pool/src/attestation.rs index 9133157dbe8..8d8e3796745 100644 --- a/beacon_node/operation_pool/src/attestation.rs +++ b/beacon_node/operation_pool/src/attestation.rs @@ -2,7 +2,7 @@ use crate::attestation_storage::AttestationRef; use crate::max_cover::MaxCover; use crate::reward_cache::RewardCache; use state_processing::common::{ - altair, base, get_attestation_participation_flag_indices, get_attesting_indices, + base, get_attestation_participation_flag_indices, get_attesting_indices, }; use std::collections::HashMap; use types::{ @@ -30,7 +30,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> { if let BeaconState::Base(ref base_state) = state { Self::new_for_base(att, state, base_state, total_active_balance, spec) } else { - Self::new_for_altair_deneb(att, state, reward_cache, total_active_balance, spec) + Self::new_for_altair_deneb(att, state, reward_cache, spec) } } @@ -72,7 +72,6 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> { att: AttestationRef<'a, T>, state: &BeaconState, reward_cache: &'a RewardCache, - total_active_balance: u64, spec: &ChainSpec, ) -> Option { let att_data = att.attestation_data(); @@ -81,8 +80,6 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> { let att_participation_flags = get_attestation_participation_flag_indices(state, &att_data, inclusion_delay, spec) .ok()?; - let base_reward_per_increment = - altair::BaseRewardPerIncrement::new(total_active_balance, spec).ok()?; let fresh_validators_rewards = att .indexed @@ -98,12 +95,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> { let mut proposer_reward_numerator = 0; - // FIXME(sproul): store base_reward in reward cache - // let effective_balance = reward_cache.get_effective_balance(index)?; - let effective_balance = state.get_effective_balance(index as usize).ok()?; - let base_reward = - altair::get_base_reward(effective_balance, base_reward_per_increment, spec) - .ok()?; + let base_reward = state.get_base_reward(index as usize).ok()?; for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() { if att_participation_flags.contains(&flag_index) {