mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-03 21:04:28 +00:00
Use epoch cache in block packing (#5223)
This commit is contained in:
@@ -94,6 +94,7 @@ use slot_clock::SlotClock;
|
|||||||
use ssz::Encode;
|
use ssz::Encode;
|
||||||
use state_processing::{
|
use state_processing::{
|
||||||
common::get_attesting_indices_from_state,
|
common::get_attesting_indices_from_state,
|
||||||
|
epoch_cache::initialize_epoch_cache,
|
||||||
per_block_processing,
|
per_block_processing,
|
||||||
per_block_processing::{
|
per_block_processing::{
|
||||||
errors::AttestationValidationError, get_expected_withdrawals,
|
errors::AttestationValidationError, get_expected_withdrawals,
|
||||||
@@ -4810,7 +4811,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
let attestation_packing_timer =
|
let attestation_packing_timer =
|
||||||
metrics::start_timer(&metrics::BLOCK_PRODUCTION_ATTESTATION_TIMES);
|
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)?;
|
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 mut prev_filter_cache = HashMap::new();
|
||||||
let prev_attestation_filter = |att: &AttestationRef<T::EthSpec>| {
|
let prev_attestation_filter = |att: &AttestationRef<T::EthSpec>| {
|
||||||
self.filter_op_pool_attestation(&mut prev_filter_cache, att, &state)
|
self.filter_op_pool_attestation(&mut prev_filter_cache, att, &state)
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ pub enum BlockProductionError {
|
|||||||
UnableToProduceAtSlot(Slot),
|
UnableToProduceAtSlot(Slot),
|
||||||
SlotProcessingError(SlotProcessingError),
|
SlotProcessingError(SlotProcessingError),
|
||||||
BlockProcessingError(BlockProcessingError),
|
BlockProcessingError(BlockProcessingError),
|
||||||
|
EpochCacheError(EpochCacheError),
|
||||||
ForkChoiceError(ForkChoiceError),
|
ForkChoiceError(ForkChoiceError),
|
||||||
Eth1ChainError(Eth1ChainError),
|
Eth1ChainError(Eth1ChainError),
|
||||||
BeaconStateError(BeaconStateError),
|
BeaconStateError(BeaconStateError),
|
||||||
@@ -296,3 +297,4 @@ easy_from_to!(SlotProcessingError, BlockProductionError);
|
|||||||
easy_from_to!(Eth1ChainError, BlockProductionError);
|
easy_from_to!(Eth1ChainError, BlockProductionError);
|
||||||
easy_from_to!(StateAdvanceError, BlockProductionError);
|
easy_from_to!(StateAdvanceError, BlockProductionError);
|
||||||
easy_from_to!(ForkChoiceError, BlockProductionError);
|
easy_from_to!(ForkChoiceError, BlockProductionError);
|
||||||
|
easy_from_to!(EpochCacheError, BlockProductionError);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::attestation_storage::AttestationRef;
|
|||||||
use crate::max_cover::MaxCover;
|
use crate::max_cover::MaxCover;
|
||||||
use crate::reward_cache::RewardCache;
|
use crate::reward_cache::RewardCache;
|
||||||
use state_processing::common::{
|
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 std::collections::HashMap;
|
||||||
use types::{
|
use types::{
|
||||||
@@ -30,7 +30,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
|
|||||||
if let BeaconState::Base(ref base_state) = state {
|
if let BeaconState::Base(ref base_state) = state {
|
||||||
Self::new_for_base(att, state, base_state, total_active_balance, spec)
|
Self::new_for_base(att, state, base_state, total_active_balance, spec)
|
||||||
} else {
|
} 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>,
|
att: AttestationRef<'a, T>,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
reward_cache: &'a RewardCache,
|
reward_cache: &'a RewardCache,
|
||||||
total_active_balance: u64,
|
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
let att_data = att.attestation_data();
|
let att_data = att.attestation_data();
|
||||||
@@ -81,8 +80,6 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
|
|||||||
let att_participation_flags =
|
let att_participation_flags =
|
||||||
get_attestation_participation_flag_indices(state, &att_data, inclusion_delay, spec)
|
get_attestation_participation_flag_indices(state, &att_data, inclusion_delay, spec)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let base_reward_per_increment =
|
|
||||||
altair::BaseRewardPerIncrement::new(total_active_balance, spec).ok()?;
|
|
||||||
|
|
||||||
let fresh_validators_rewards = att
|
let fresh_validators_rewards = att
|
||||||
.indexed
|
.indexed
|
||||||
@@ -98,12 +95,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
|
|||||||
|
|
||||||
let mut proposer_reward_numerator = 0;
|
let mut proposer_reward_numerator = 0;
|
||||||
|
|
||||||
// FIXME(sproul): store base_reward in reward cache
|
let base_reward = state.get_base_reward(index as usize).ok()?;
|
||||||
// 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()?;
|
|
||||||
|
|
||||||
for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
|
for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
|
||||||
if att_participation_flags.contains(&flag_index) {
|
if att_participation_flags.contains(&flag_index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user