Skip to content

Commit 9eb1685

Browse files
Use epoch cache in block packing (#5223)
1 parent 8e2f7c5 commit 9eb1685

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ use slot_clock::SlotClock;
9494
use ssz::Encode;
9595
use state_processing::{
9696
common::get_attesting_indices_from_state,
97+
epoch_cache::initialize_epoch_cache,
9798
per_block_processing,
9899
per_block_processing::{
99100
errors::AttestationValidationError, get_expected_withdrawals,
@@ -4810,7 +4811,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
48104811
let attestation_packing_timer =
48114812
metrics::start_timer(&metrics::BLOCK_PRODUCTION_ATTESTATION_TIMES);
48124813

4814+
// Epoch cache and total balance cache are required for op pool packing.
48134815
state.build_total_active_balance_cache_at(state.current_epoch(), &self.spec)?;
4816+
initialize_epoch_cache(&mut state, &self.spec)?;
4817+
48144818
let mut prev_filter_cache = HashMap::new();
48154819
let prev_attestation_filter = |att: &AttestationRef<T::EthSpec>| {
48164820
self.filter_op_pool_attestation(&mut prev_filter_cache, att, &state)

beacon_node/beacon_chain/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ pub enum BlockProductionError {
256256
UnableToProduceAtSlot(Slot),
257257
SlotProcessingError(SlotProcessingError),
258258
BlockProcessingError(BlockProcessingError),
259+
EpochCacheError(EpochCacheError),
259260
ForkChoiceError(ForkChoiceError),
260261
Eth1ChainError(Eth1ChainError),
261262
BeaconStateError(BeaconStateError),
@@ -296,3 +297,4 @@ easy_from_to!(SlotProcessingError, BlockProductionError);
296297
easy_from_to!(Eth1ChainError, BlockProductionError);
297298
easy_from_to!(StateAdvanceError, BlockProductionError);
298299
easy_from_to!(ForkChoiceError, BlockProductionError);
300+
easy_from_to!(EpochCacheError, BlockProductionError);

beacon_node/operation_pool/src/attestation.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::attestation_storage::AttestationRef;
22
use crate::max_cover::MaxCover;
33
use crate::reward_cache::RewardCache;
44
use state_processing::common::{
5-
altair, base, get_attestation_participation_flag_indices, get_attesting_indices,
5+
base, get_attestation_participation_flag_indices, get_attesting_indices,
66
};
77
use std::collections::HashMap;
88
use types::{
@@ -30,7 +30,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
3030
if let BeaconState::Base(ref base_state) = state {
3131
Self::new_for_base(att, state, base_state, total_active_balance, spec)
3232
} else {
33-
Self::new_for_altair_deneb(att, state, reward_cache, total_active_balance, spec)
33+
Self::new_for_altair_deneb(att, state, reward_cache, spec)
3434
}
3535
}
3636

@@ -72,7 +72,6 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
7272
att: AttestationRef<'a, T>,
7373
state: &BeaconState<T>,
7474
reward_cache: &'a RewardCache,
75-
total_active_balance: u64,
7675
spec: &ChainSpec,
7776
) -> Option<Self> {
7877
let att_data = att.attestation_data();
@@ -81,8 +80,6 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
8180
let att_participation_flags =
8281
get_attestation_participation_flag_indices(state, &att_data, inclusion_delay, spec)
8382
.ok()?;
84-
let base_reward_per_increment =
85-
altair::BaseRewardPerIncrement::new(total_active_balance, spec).ok()?;
8683

8784
let fresh_validators_rewards = att
8885
.indexed
@@ -98,12 +95,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
9895

9996
let mut proposer_reward_numerator = 0;
10097

101-
// FIXME(sproul): store base_reward in reward cache
102-
// let effective_balance = reward_cache.get_effective_balance(index)?;
103-
let effective_balance = state.get_effective_balance(index as usize).ok()?;
104-
let base_reward =
105-
altair::get_base_reward(effective_balance, base_reward_per_increment, spec)
106-
.ok()?;
98+
let base_reward = state.get_base_reward(index as usize).ok()?;
10799

108100
for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
109101
if att_participation_flags.contains(&flag_index) {

0 commit comments

Comments
 (0)