From 5a34031b8483c121a969469df3419480b41ab386 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Fri, 22 May 2026 14:08:31 +0300 Subject: [PATCH] fix tests --- .../gossip_verified_proposer_preferences.rs | 38 +++++++------------ .../tests.rs | 5 ++- .../gossip_methods.rs | 4 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/beacon_node/beacon_chain/src/proposer_preferences_verification/gossip_verified_proposer_preferences.rs b/beacon_node/beacon_chain/src/proposer_preferences_verification/gossip_verified_proposer_preferences.rs index 8997c4d239..99ea0f29ba 100644 --- a/beacon_node/beacon_chain/src/proposer_preferences_verification/gossip_verified_proposer_preferences.rs +++ b/beacon_node/beacon_chain/src/proposer_preferences_verification/gossip_verified_proposer_preferences.rs @@ -92,45 +92,35 @@ impl GossipVerifiedProposerPreferences { return Err(ProposerPreferencesError::DependentRootNotCanonical { dependent_root }); } let dependent_state_root = dependent_block.state_root; - let dependent_block_slot = dependent_block.slot; drop(fork_choice); - // Fetch the state at the dependent_root block. - // Per spec, we need the checkpoint state at epoch (proposal_epoch - MIN_SEED_LOOKAHEAD). - // The dependent_root is the block root at the proposer shuffling decision slot. - let (state_root, mut dependent_state) = ctx - .store - .get_advanced_hot_state(dependent_root, dependent_block_slot, dependent_state_root) - .map_err(crate::BeaconChainError::DBError)? - .ok_or(ProposerPreferencesError::DependentRootUnknown { dependent_root })?; - - // We need to advance the state to `target_epoch` so epoch transition runs and - // `process_proposer_lookahead` populates the lookahead for the proposal epoch. + // We need a state at `target_epoch` so we have the correct proposer lookahead. let proposal_epoch = proposal_slot.epoch(T::EthSpec::slots_per_epoch()); let target_epoch = proposal_epoch.saturating_sub(ctx.spec.min_seed_lookahead); let target_slot = target_epoch.start_slot(T::EthSpec::slots_per_epoch()); - if dependent_state.current_epoch() < target_epoch { - partial_state_advance( - &mut dependent_state, - Some(state_root), - target_slot, - ctx.spec, - ) - .map_err(crate::BeaconChainError::StateAdvanceError)?; + let (state_root, mut state) = ctx + .store + .get_advanced_hot_state(dependent_root, target_slot, dependent_state_root) + .map_err(crate::BeaconChainError::DBError)? + .ok_or(ProposerPreferencesError::DependentRootUnknown { dependent_root })?; + + if state.current_epoch() < target_epoch { + partial_state_advance(&mut state, Some(state_root), target_slot, ctx.spec) + .map_err(crate::BeaconChainError::StateAdvanceError)?; } - if !dependent_state.is_valid_proposal_slot(&signed_preferences.message, ctx.spec)? { + if !state.is_valid_proposal_slot(&signed_preferences.message, ctx.spec)? { return Err(ProposerPreferencesError::InvalidProposalSlot { validator_index, proposal_slot, }); } - // Verify signature using the dependent state (which has the validator pubkeys) + // Verify signature proposer_preferences_signature_set( - &dependent_state, - |i| get_pubkey_from_state(&dependent_state, i), + &state, + |i| get_pubkey_from_state(&state, i), &signed_preferences, ctx.spec, ) diff --git a/beacon_node/beacon_chain/src/proposer_preferences_verification/tests.rs b/beacon_node/beacon_chain/src/proposer_preferences_verification/tests.rs index 53c1c4ded3..f8fcdcc830 100644 --- a/beacon_node/beacon_chain/src/proposer_preferences_verification/tests.rs +++ b/beacon_node/beacon_chain/src/proposer_preferences_verification/tests.rs @@ -6,7 +6,7 @@ use fork_choice::ForkChoice; use genesis::{generate_deterministic_keypairs, interop_genesis_state}; use proto_array::PayloadStatus; use slot_clock::{SlotClock, TestingSlotClock}; -use store::{HotColdDB, StoreConfig}; +use store::{HotColdDB, MemoryStore, StoreConfig}; use types::{ Address, BeaconBlock, ChainSpec, Checkpoint, Epoch, EthSpec, Hash256, MinimalEthSpec, ProposerPreferences, SignedBeaconBlock, SignedProposerPreferences, Slot, @@ -36,6 +36,7 @@ struct TestContext { preferences_cache: GossipVerifiedProposerPreferenceCache, slot_clock: TestingSlotClock, spec: ChainSpec, + store: Arc>, } impl TestContext { @@ -91,6 +92,7 @@ impl TestContext { preferences_cache: GossipVerifiedProposerPreferenceCache::default(), slot_clock, spec, + store, } } @@ -100,6 +102,7 @@ impl TestContext { gossip_verified_proposer_preferences_cache: &self.preferences_cache, slot_clock: &self.slot_clock, spec: &self.spec, + store: &self.store, } } diff --git a/beacon_node/network/src/network_beacon_processor/gossip_methods.rs b/beacon_node/network/src/network_beacon_processor/gossip_methods.rs index 3e8845f017..488c9915fe 100644 --- a/beacon_node/network/src/network_beacon_processor/gossip_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/gossip_methods.rs @@ -4113,7 +4113,9 @@ impl NetworkBeaconProcessor { | ProposerPreferencesError::ProposalSlotAlreadyPassed { .. } | ProposerPreferencesError::BeaconChainError(_) | ProposerPreferencesError::BeaconStateError(_) - | ProposerPreferencesError::UnableToReadSlot, + | ProposerPreferencesError::UnableToReadSlot + | ProposerPreferencesError::DependentRootUnknown { .. } + | ProposerPreferencesError::DependentRootNotCanonical { .. }, ) => { self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Ignore); }