From 24c6273a1a3b3f621c47eb2919cd8b7301bd269e Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 5 May 2022 16:19:50 -0400 Subject: [PATCH] cargo fmt and fix --- beacon_node/beacon_chain/src/schema_change.rs | 4 +- .../src/schema_change/migration_schema_v7.rs | 1 - .../src/schema_change/migration_schema_v9.rs | 39 ++++++++++--------- .../beacon_chain/src/schema_change/types.rs | 2 +- .../http_api/src/attestation_performance.rs | 4 +- .../http_api/src/validator_inclusion.rs | 7 +--- consensus/fork_choice/src/fork_choice.rs | 5 ++- consensus/proto_array/src/proto_array.rs | 32 +++++++++------ .../src/proto_array_fork_choice.rs | 8 +++- consensus/state_processing/src/lib.rs | 11 +++--- .../src/per_epoch_processing/altair.rs | 16 ++++---- .../altair/justification_and_finalization.rs | 1 - .../altair/rewards_and_penalties.rs | 1 - .../epoch_processing_summary.rs | 4 +- .../weigh_justification_and_finalization.rs | 3 +- consensus/types/src/beacon_state.rs | 22 +++++------ .../src/beacon_state/participation_cache.rs | 13 +++---- consensus/types/src/lib.rs | 3 +- .../ef_tests/src/cases/epoch_processing.rs | 32 ++++++++++----- testing/ef_tests/src/cases/rewards.rs | 2 +- 20 files changed, 118 insertions(+), 92 deletions(-) diff --git a/beacon_node/beacon_chain/src/schema_change.rs b/beacon_node/beacon_chain/src/schema_change.rs index d22c0243e01..778ac85066e 100644 --- a/beacon_node/beacon_chain/src/schema_change.rs +++ b/beacon_node/beacon_chain/src/schema_change.rs @@ -6,7 +6,9 @@ mod migration_schema_v9; mod types; use crate::beacon_chain::{BeaconChainTypes, FORK_CHOICE_DB_KEY, OP_POOL_DB_KEY}; -use crate::persisted_fork_choice::{PersistedForkChoiceV1, PersistedForkChoiceV7, PersistedForkChoiceV8}; +use crate::persisted_fork_choice::{ + PersistedForkChoiceV1, PersistedForkChoiceV7, PersistedForkChoiceV8, +}; use crate::validator_pubkey_cache::ValidatorPubkeyCache; use operation_pool::{PersistedOperationPool, PersistedOperationPoolBase}; use slog::{warn, Logger}; diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs index a1269683807..dd105f3006e 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs @@ -94,7 +94,6 @@ pub(crate) fn update_fork_choice( update_store_justified_checkpoint(persisted_fork_choice, &mut fork_choice) .map_err(StoreError::SchemaMigrationError)?; - // Need to downgrade the SSZ container to V7 so that all migrations can be applied in sequence. let ssz_container = SszContainer::from(&fork_choice); let ssz_container_v7 = SszContainerV7::from(ssz_container); diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v9.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v9.rs index ccc6b99862c..5da029cc9a6 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v9.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v9.rs @@ -1,29 +1,30 @@ -use std::collections::HashMap; +use crate::persisted_fork_choice::PersistedForkChoiceV8; +use crate::schema_change::{ + types::{SszContainerV7, SszContainerV9}, + StoreError, +}; use proto_array::core::SszContainer; -use proto_array::ProtoArrayForkChoice; use ssz::{Decode, Encode}; -use crate::beacon_fork_choice_store::PersistedForkChoiceStoreV8; -use crate::persisted_fork_choice::PersistedForkChoiceV8; -use crate::schema_change::{StoreError, types::{SszContainerV6, SszContainerV7, SszContainerV9}}; pub fn update_fork_choice( mut fork_choice: PersistedForkChoiceV8, ) -> Result { - let ssz_container_v7 = - SszContainerV7::from_ssz_bytes(&fork_choice.fork_choice.proto_array_bytes) - .map_err(|e| { - StoreError::SchemaMigrationError(format!( - "Failed to decode ProtoArrayForkChoice during schema migration: {:?}", - e - )) - })?; + let ssz_container_v7 = SszContainerV7::from_ssz_bytes( + &fork_choice.fork_choice.proto_array_bytes, + ) + .map_err(|e| { + StoreError::SchemaMigrationError(format!( + "Failed to decode ProtoArrayForkChoice during schema migration: {:?}", + e + )) + })?; - // These transformations instantiate `node.unrealized_justified_checkpoint` and - // `node.unrealized_finalized_checkpoint` to `None`. - let ssz_container_v9: SszContainerV9 = ssz_container_v7.into(); - let ssz_container: SszContainer = ssz_container_v9.into(); + // These transformations instantiate `node.unrealized_justified_checkpoint` and + // `node.unrealized_finalized_checkpoint` to `None`. + let ssz_container_v9: SszContainerV9 = ssz_container_v7.into(); + let ssz_container: SszContainer = ssz_container_v9.into(); - fork_choice.fork_choice.proto_array_bytes = ssz_container.as_ssz_bytes(); + fork_choice.fork_choice.proto_array_bytes = ssz_container.as_ssz_bytes(); - Ok(fork_choice) + Ok(fork_choice) } diff --git a/beacon_node/beacon_chain/src/schema_change/types.rs b/beacon_node/beacon_chain/src/schema_change/types.rs index a132c9e9118..4294257371c 100644 --- a/beacon_node/beacon_chain/src/schema_change/types.rs +++ b/beacon_node/beacon_chain/src/schema_change/types.rs @@ -275,4 +275,4 @@ impl From for SszContainerV7 { previous_proposer_boost: container.previous_proposer_boost, } } -} \ No newline at end of file +} diff --git a/beacon_node/http_api/src/attestation_performance.rs b/beacon_node/http_api/src/attestation_performance.rs index 938358b8274..4142d064cb1 100644 --- a/beacon_node/http_api/src/attestation_performance.rs +++ b/beacon_node/http_api/src/attestation_performance.rs @@ -3,11 +3,11 @@ use eth2::lighthouse::{ AttestationPerformance, AttestationPerformanceQuery, AttestationPerformanceStatistics, }; use state_processing::{ - BlockReplayer, BlockReplayError, per_epoch_processing::EpochProcessingSummary, + per_epoch_processing::EpochProcessingSummary, BlockReplayError, BlockReplayer, }; use std::sync::Arc; -use types::{BeaconState, BeaconStateError, EthSpec, Hash256, SignedBeaconBlock}; use types::beacon_state::participation_cache::Error as ParticipationCacheError; +use types::{BeaconState, BeaconStateError, EthSpec, Hash256, SignedBeaconBlock}; use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_error}; const MAX_REQUEST_RANGE_EPOCHS: usize = 100; diff --git a/beacon_node/http_api/src/validator_inclusion.rs b/beacon_node/http_api/src/validator_inclusion.rs index 39c8dc3d684..ff638c3111d 100644 --- a/beacon_node/http_api/src/validator_inclusion.rs +++ b/beacon_node/http_api/src/validator_inclusion.rs @@ -4,12 +4,9 @@ use eth2::{ lighthouse::{GlobalValidatorInclusionData, ValidatorInclusionData}, types::ValidatorId, }; -use state_processing::per_epoch_processing::{ - EpochProcessingSummary, - process_epoch, -}; -use types::{BeaconState, ChainSpec, Epoch, EthSpec}; +use state_processing::per_epoch_processing::{process_epoch, EpochProcessingSummary}; use types::beacon_state::participation_cache::Error as ParticipationCacheError; +use types::{BeaconState, ChainSpec, Epoch, EthSpec}; /// Returns the state in the last slot of `epoch`. fn end_of_epoch_state( diff --git a/consensus/fork_choice/src/fork_choice.rs b/consensus/fork_choice/src/fork_choice.rs index 42439ecc3d6..9fceffc56d9 100644 --- a/consensus/fork_choice/src/fork_choice.rs +++ b/consensus/fork_choice/src/fork_choice.rs @@ -51,7 +51,7 @@ pub enum Error { MissingFinalizedBlock { finalized_checkpoint: Checkpoint, }, - UnrealizedVoteProcessing(state_processing::EpochProcessingError) + UnrealizedVoteProcessing(state_processing::EpochProcessingError), } impl From for Error { @@ -661,7 +661,8 @@ where } // Update unrealized justified/finalized checkpoints. - let (mini_beacon_state, _ ) = state_processing::per_epoch_processing::altair::process_justifiable(state, spec)?; + let (mini_beacon_state, _) = + state_processing::per_epoch_processing::altair::process_justifiable(state, spec)?; let target_slot = block .slot() diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index fb5143b4e02..45319e6f319 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -858,21 +858,29 @@ impl ProtoArray { return false; } - - let predicate = |node_justified_checkpoint: Checkpoint, node_finalized_checkpoint: Checkpoint| { - let correct_justified = node_justified_checkpoint == self.justified_checkpoint || self.justified_checkpoint.epoch == Epoch::new(0); - let correct_finalized = node_finalized_checkpoint == self.finalized_checkpoint || self.finalized_checkpoint.epoch == Epoch::new(0); + let checkpoint_match_predicate = + |node_justified_checkpoint: Checkpoint, node_finalized_checkpoint: Checkpoint| { + let correct_justified = node_justified_checkpoint == self.justified_checkpoint + || self.justified_checkpoint.epoch == Epoch::new(0); + let correct_finalized = node_finalized_checkpoint == self.finalized_checkpoint + || self.finalized_checkpoint.epoch == Epoch::new(0); correct_justified && correct_finalized - }; + }; - if let (Some(unrealized_justified_checkpoint), Some(unrealized_finalized_checkpoint)) = (node.unrealized_justified_checkpoint, node.unrealized_finalized_checkpoint) { - predicate(unrealized_justified_checkpoint, unrealized_finalized_checkpoint) + if let (Some(unrealized_justified_checkpoint), Some(unrealized_finalized_checkpoint)) = ( + node.unrealized_justified_checkpoint, + node.unrealized_finalized_checkpoint, + ) { + checkpoint_match_predicate( + unrealized_justified_checkpoint, + unrealized_finalized_checkpoint, + ) + } else if let (Some(justified_checkpoint), Some(finalized_checkpoint)) = + (node.justified_checkpoint, node.finalized_checkpoint) + { + checkpoint_match_predicate(justified_checkpoint, finalized_checkpoint) } else { - if let (Some(justified_checkpoint), Some(finalized_checkpoint)) = (node.justified_checkpoint, node.finalized_checkpoint) { - predicate(justified_checkpoint, finalized_checkpoint) - } else { - false - } + false } } diff --git a/consensus/proto_array/src/proto_array_fork_choice.rs b/consensus/proto_array/src/proto_array_fork_choice.rs index c38f9bba01a..6400dad15ef 100644 --- a/consensus/proto_array/src/proto_array_fork_choice.rs +++ b/consensus/proto_array/src/proto_array_fork_choice.rs @@ -124,8 +124,8 @@ pub struct Block { /// Indicates if an execution node has marked this block as valid. Also contains the execution /// block hash. pub execution_status: ExecutionStatus, - pub unrealized_justified_checkpoint : Option, - pub unrealized_finalized_checkpoint : Option, + pub unrealized_justified_checkpoint: Option, + pub unrealized_finalized_checkpoint: Option, } /// A Vec-wrapper which will grow to match any request. @@ -540,6 +540,8 @@ mod test_compute_deltas { justified_checkpoint: genesis_checkpoint, finalized_checkpoint: genesis_checkpoint, execution_status, + unrealized_justified_checkpoint: None, + unrealized_finalized_checkpoint: None, }) .unwrap(); @@ -556,6 +558,8 @@ mod test_compute_deltas { justified_checkpoint: genesis_checkpoint, finalized_checkpoint: genesis_checkpoint, execution_status, + unrealized_justified_checkpoint: None, + unrealized_finalized_checkpoint: None, }) .unwrap(); diff --git a/consensus/state_processing/src/lib.rs b/consensus/state_processing/src/lib.rs index 70f92c5a9dc..edda3de71fb 100644 --- a/consensus/state_processing/src/lib.rs +++ b/consensus/state_processing/src/lib.rs @@ -26,17 +26,18 @@ pub mod state_advance; pub mod upgrade; pub mod verify_operation; -pub use block_replayer::{BlockReplayer, BlockReplayError, StateRootStrategy}; +pub use block_replayer::{BlockReplayError, BlockReplayer, StateRootStrategy}; pub use genesis::{ eth2_genesis_time, initialize_beacon_state_from_eth1, is_valid_genesis_state, process_activations, }; pub use per_block_processing::{ - altair::sync_committee, block_signature_verifier, BlockSignatureStrategy, BlockSignatureVerifier, - errors::BlockProcessingError, per_block_processing, signature_sets, VerifyBlockRoot, VerifySignatures + altair::sync_committee, block_signature_verifier, errors::BlockProcessingError, + per_block_processing, signature_sets, BlockSignatureStrategy, BlockSignatureVerifier, + VerifyBlockRoot, VerifySignatures, }; pub use per_epoch_processing::{ - errors::EpochProcessingError, process_epoch as per_epoch_processing + errors::EpochProcessingError, process_epoch as per_epoch_processing, }; -pub use per_slot_processing::{Error as SlotProcessingError, per_slot_processing}; +pub use per_slot_processing::{per_slot_processing, Error as SlotProcessingError}; pub use verify_operation::{SigVerifiedOp, VerifyOperation}; diff --git a/consensus/state_processing/src/per_epoch_processing/altair.rs b/consensus/state_processing/src/per_epoch_processing/altair.rs index a267b7624f6..f0a28e43be0 100644 --- a/consensus/state_processing/src/per_epoch_processing/altair.rs +++ b/consensus/state_processing/src/per_epoch_processing/altair.rs @@ -1,5 +1,4 @@ -use itertools::min; -use super::{EpochProcessingSummary, Error, process_registry_updates, process_slashings}; +use super::{process_registry_updates, process_slashings, EpochProcessingSummary, Error}; use crate::per_epoch_processing::{ effective_balance_updates::process_effective_balance_updates, historical_roots_update::process_historical_roots_update, @@ -7,12 +6,12 @@ use crate::per_epoch_processing::{ }; pub use inactivity_updates::process_inactivity_updates; pub use justification_and_finalization::process_justification_and_finalization; -pub use types::beacon_state::participation_cache::ParticipationCache; pub use participation_flag_updates::process_participation_flag_updates; pub use rewards_and_penalties::process_rewards_and_penalties; pub use sync_committee_updates::process_sync_committee_updates; -use types::{BeaconState, ChainSpec, EthSpec, MiniBeaconState, RelativeEpoch}; use types::beacon_state::participation_cache::CurrentEpochParticipationCache; +pub use types::beacon_state::participation_cache::ParticipationCache; +use types::{BeaconState, ChainSpec, EthSpec, MiniBeaconState, RelativeEpoch}; pub mod inactivity_updates; pub mod justification_and_finalization; @@ -24,7 +23,6 @@ pub fn process_epoch( state: &mut BeaconState, spec: &ChainSpec, ) -> Result, Error> { - state.build_committee_cache(RelativeEpoch::Next, spec)?; let (mini_beacon_state, participation_cache) = process_justifiable(state, spec)?; @@ -76,7 +74,10 @@ pub fn process_epoch( }) } -pub fn process_justifiable(state: &mut BeaconState, spec: &ChainSpec) -> Result<(MiniBeaconState, ParticipationCache), Error> { +pub fn process_justifiable( + state: &mut BeaconState, + spec: &ChainSpec, +) -> Result<(MiniBeaconState, ParticipationCache), Error> { // Ensure the committee caches are built. state.build_committee_cache(RelativeEpoch::Previous, spec)?; state.build_committee_cache(RelativeEpoch::Current, spec)?; @@ -86,7 +87,8 @@ pub fn process_justifiable(state: &mut BeaconState, spec: &ChainS let current_participation_cache = CurrentEpochParticipationCache::new(state, spec)?; - let participation_cache = ParticipationCache::new(prev_participation_cache, current_participation_cache); + let participation_cache = + ParticipationCache::new(prev_participation_cache, current_participation_cache); // Justification and finalization. let mini_beacon_state = process_justification_and_finalization(state, &participation_cache)?; diff --git a/consensus/state_processing/src/per_epoch_processing/altair/justification_and_finalization.rs b/consensus/state_processing/src/per_epoch_processing/altair/justification_and_finalization.rs index 5bf4458acb6..47323ed965b 100644 --- a/consensus/state_processing/src/per_epoch_processing/altair/justification_and_finalization.rs +++ b/consensus/state_processing/src/per_epoch_processing/altair/justification_and_finalization.rs @@ -4,7 +4,6 @@ use crate::per_epoch_processing::Error; use safe_arith::SafeArith; use types::consts::altair::TIMELY_TARGET_FLAG_INDEX; use types::{BeaconState, EthSpec, MiniBeaconState}; -use types::beacon_state::participation_cache::CurrentEpochParticipationCache; /// Update the justified and finalized checkpoints for matching target attestations. pub fn process_justification_and_finalization( diff --git a/consensus/state_processing/src/per_epoch_processing/altair/rewards_and_penalties.rs b/consensus/state_processing/src/per_epoch_processing/altair/rewards_and_penalties.rs index 86acb7f9bc5..ce102694f58 100644 --- a/consensus/state_processing/src/per_epoch_processing/altair/rewards_and_penalties.rs +++ b/consensus/state_processing/src/per_epoch_processing/altair/rewards_and_penalties.rs @@ -8,7 +8,6 @@ use types::{BeaconState, ChainSpec, EthSpec}; use crate::common::{altair::get_base_reward, decrease_balance, increase_balance}; use crate::per_epoch_processing::{Delta, Error}; -use types::beacon_state::participation_cache::CurrentEpochParticipationCache; /// Apply attester and proposer rewards. /// diff --git a/consensus/state_processing/src/per_epoch_processing/epoch_processing_summary.rs b/consensus/state_processing/src/per_epoch_processing/epoch_processing_summary.rs index fae8d62689f..7ea83c4b15e 100644 --- a/consensus/state_processing/src/per_epoch_processing/epoch_processing_summary.rs +++ b/consensus/state_processing/src/per_epoch_processing/epoch_processing_summary.rs @@ -1,11 +1,11 @@ use super::{ altair::ParticipationCache, - base::{TotalBalances, validator_statuses::InclusionInfo, ValidatorStatus}, + base::{validator_statuses::InclusionInfo, TotalBalances, ValidatorStatus}, }; use crate::metrics; use std::sync::Arc; -use types::{EthSpec, SyncCommittee}; use types::beacon_state::participation_cache::Error as ParticipationCacheError; +use types::{EthSpec, SyncCommittee}; /// Provides a summary of validator participation during the epoch. #[derive(PartialEq, Debug)] diff --git a/consensus/state_processing/src/per_epoch_processing/weigh_justification_and_finalization.rs b/consensus/state_processing/src/per_epoch_processing/weigh_justification_and_finalization.rs index d1f9f70032b..3de1f262e6f 100644 --- a/consensus/state_processing/src/per_epoch_processing/weigh_justification_and_finalization.rs +++ b/consensus/state_processing/src/per_epoch_processing/weigh_justification_and_finalization.rs @@ -25,7 +25,8 @@ pub fn weigh_justification_and_finalization( }; // Process justifications - mini_beacon_state.previous_justified_checkpoint = mini_beacon_state.current_justified_checkpoint; + mini_beacon_state.previous_justified_checkpoint = + mini_beacon_state.current_justified_checkpoint; mini_beacon_state.justification_bits.shift_up(1)?; if previous_target_balance.safe_mul(3)? >= total_active_balance.safe_mul(2)? { diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index adb8cb50353..2256afc3e1f 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -7,12 +7,13 @@ use compare_fields_derive::CompareFields; use derivative::Derivative; use eth2_hashing::hash; use int_to_bytes::{int_to_bytes4, int_to_bytes8}; +use participation_cache::PreviousParticipationCache; use pubkey_cache::PubkeyCache; use safe_arith::{ArithError, SafeArith}; use serde_derive::{Deserialize, Serialize}; -use ssz::{Decode, DecodeError, Encode, ssz_encode}; +use ssz::{ssz_encode, Decode, DecodeError, Encode}; use ssz_derive::{Decode, Encode}; -use ssz_types::{BitVector, FixedVector, typenum::Unsigned}; +use ssz_types::{typenum::Unsigned, BitVector, FixedVector}; use std::convert::TryInto; use std::{fmt, mem, sync::Arc}; use superstruct::superstruct; @@ -20,11 +21,10 @@ use swap_or_not_shuffle::compute_shuffled_index; use test_random_derive::TestRandom; use tree_hash::TreeHash; use tree_hash_derive::TreeHash; -use participation_cache::PreviousParticipationCache; pub use self::committee_cache::{ - CommitteeCache, compute_committee_index_in_epoch, compute_committee_range_in_epoch, - epoch_committee_count, + compute_committee_index_in_epoch, compute_committee_range_in_epoch, epoch_committee_count, + CommitteeCache, }; pub use clone_config::CloneConfig; pub use eth_spec::*; @@ -36,10 +36,10 @@ mod committee_cache; mod clone_config; mod exit_cache; mod iter; +pub mod participation_cache; mod pubkey_cache; mod tests; mod tree_hash_cache; -pub mod participation_cache; pub const CACHED_EPOCHS: usize = 3; const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1; @@ -1363,7 +1363,10 @@ impl BeaconState { Ok(()) } - pub fn get_previous_epoch_participation_cache(&mut self, spec: &ChainSpec) -> Result { + pub fn get_previous_epoch_participation_cache( + &mut self, + spec: &ChainSpec, + ) -> Result { if let Some(cache) = self.previous_epoch_participation_cache() { if cache.initialized_epoch() == self.current_epoch() { Ok(cache.clone()) @@ -1664,10 +1667,7 @@ impl BeaconState { Ok(sync_committee) } - pub fn update_justifiable( - &mut self, - mini_beacon_state: MiniBeaconState, - ) { + pub fn update_justifiable(&mut self, mini_beacon_state: MiniBeaconState) { *self.current_justified_checkpoint_mut() = mini_beacon_state.current_justified_checkpoint; *self.previous_justified_checkpoint_mut() = mini_beacon_state.previous_justified_checkpoint; *self.finalized_checkpoint_mut() = mini_beacon_state.finalized_checkpoint; diff --git a/consensus/types/src/beacon_state/participation_cache.rs b/consensus/types/src/beacon_state/participation_cache.rs index ab9ed0cb30f..9305ed90dad 100644 --- a/consensus/types/src/beacon_state/participation_cache.rs +++ b/consensus/types/src/beacon_state/participation_cache.rs @@ -11,8 +11,6 @@ //! Additionally, this cache is returned from the `altair::process_epoch` function and can be used //! to get useful summaries about the validator participation in an epoch. -use safe_arith::{ArithError, SafeArith}; -use std::collections::HashMap; use crate::{ consts::altair::{ NUM_FLAG_INDICES, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, @@ -20,8 +18,8 @@ use crate::{ }, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, ParticipationFlags, RelativeEpoch, }; -use crate::test_utils::{RngCore, TestRandom}; -use test_random_derive::TestRandom; +use safe_arith::{ArithError, SafeArith}; +use std::collections::HashMap; #[derive(Debug, PartialEq)] pub enum Error { @@ -214,7 +212,6 @@ impl PreviousParticipationCache { // Care is taken to ensure that the ordering of `eligible_indices` is the same as the // `get_eligible_validator_indices` function in the spec. for (val_index, val) in state.validators().iter().enumerate() { - if val.is_active_at(previous_epoch) { previous_epoch_participation.process_active_validator( val_index, @@ -333,7 +330,10 @@ pub struct ParticipationCache { } impl ParticipationCache { - pub fn new(prev_cache: PreviousParticipationCache, current_cache: CurrentEpochParticipationCache) -> ParticipationCache { + pub fn new( + prev_cache: PreviousParticipationCache, + current_cache: CurrentEpochParticipationCache, + ) -> ParticipationCache { ParticipationCache { current_epoch: current_cache.current_epoch, current_epoch_participation: current_cache.current_epoch_participation, @@ -372,7 +372,6 @@ impl ParticipationCache { * Balances */ - pub fn previous_epoch_total_active_balance(&self) -> u64 { self.previous_epoch_participation.total_active_balance.get() } diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 5ddd1ce2412..7c586366558 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -173,10 +173,9 @@ pub use bls::{ pub use ssz_types::{typenum, typenum::Unsigned, BitList, BitVector, FixedVector, VariableList}; pub use superstruct::superstruct; - pub struct MiniBeaconState { pub current_justified_checkpoint: Checkpoint, pub previous_justified_checkpoint: Checkpoint, pub justification_bits: BitVector, pub finalized_checkpoint: Checkpoint, -} \ No newline at end of file +} diff --git a/testing/ef_tests/src/cases/epoch_processing.rs b/testing/ef_tests/src/cases/epoch_processing.rs index 530bcc98759..6f28eb33132 100644 --- a/testing/ef_tests/src/cases/epoch_processing.rs +++ b/testing/ef_tests/src/cases/epoch_processing.rs @@ -15,8 +15,8 @@ use state_processing::per_epoch_processing::{ use state_processing::EpochProcessingError; use std::marker::PhantomData; use std::path::{Path, PathBuf}; -use types::{BeaconState, ChainSpec, EthSpec, ForkName}; use types::participation_cache::{CurrentEpochParticipationCache, PreviousParticipationCache}; +use types::{BeaconState, ChainSpec, EthSpec, ForkName}; #[derive(Debug, Clone, Default, Deserialize)] pub struct Metadata { @@ -96,11 +96,15 @@ impl EpochTransition for JustificationAndFinalization { ) } BeaconState::Altair(_) | BeaconState::Merge(_) => { - let prev_participation_cache = state.get_previous_epoch_participation_cache(spec)?; + let prev_participation_cache = + state.get_previous_epoch_participation_cache(spec)?; let current_participation_cache = CurrentEpochParticipationCache::new(state, spec)?; let mini_beacon_state = altair::process_justification_and_finalization( state, - &altair::ParticipationCache::new(prev_participation_cache, current_participation_cache), + &altair::ParticipationCache::new( + prev_participation_cache, + current_participation_cache, + ), )?; state.update_justifiable(mini_beacon_state); Ok(()) @@ -118,11 +122,15 @@ impl EpochTransition for RewardsAndPenalties { base::process_rewards_and_penalties(state, &mut validator_statuses, spec) } BeaconState::Altair(_) | BeaconState::Merge(_) => { - let prev_participation_cache = state.get_previous_epoch_participation_cache(spec)?; + let prev_participation_cache = + state.get_previous_epoch_participation_cache(spec)?; let current_participation_cache = CurrentEpochParticipationCache::new(state, spec)?; altair::process_rewards_and_penalties( state, - &altair::ParticipationCache::new(prev_participation_cache, current_participation_cache), + &altair::ParticipationCache::new( + prev_participation_cache, + current_participation_cache, + ), spec, ) } @@ -153,8 +161,11 @@ impl EpochTransition for Slashings { let current_participation_cache = CurrentEpochParticipationCache::new(state, spec)?; process_slashings( state, - altair::ParticipationCache::new(prev_participation_cache, current_participation_cache) - .current_epoch_total_active_balance(), + altair::ParticipationCache::new( + prev_participation_cache, + current_participation_cache, + ) + .current_epoch_total_active_balance(), spec, )?; } @@ -223,10 +234,13 @@ impl EpochTransition for InactivityUpdates { let current_participation_cache = CurrentEpochParticipationCache::new(state, spec)?; altair::process_inactivity_updates( state, - &altair::ParticipationCache::new(prev_participation_cache, current_participation_cache), + &altair::ParticipationCache::new( + prev_participation_cache, + current_participation_cache, + ), spec, ) - }, + } } } } diff --git a/testing/ef_tests/src/cases/rewards.rs b/testing/ef_tests/src/cases/rewards.rs index 28fb3a6579b..f9760899d5c 100644 --- a/testing/ef_tests/src/cases/rewards.rs +++ b/testing/ef_tests/src/cases/rewards.rs @@ -14,11 +14,11 @@ use state_processing::{ EpochProcessingError, }; use std::path::{Path, PathBuf}; +use types::participation_cache::{CurrentEpochParticipationCache, PreviousParticipationCache}; use types::{ consts::altair::{TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX}, BeaconState, EthSpec, ForkName, }; -use types::participation_cache::{CurrentEpochParticipationCache, PreviousParticipationCache}; #[derive(Debug, Clone, PartialEq, Decode, Encode, CompareFields)] pub struct Deltas {