From be959ab4c32e9288899cf18fbb4415489ff3e44d Mon Sep 17 00:00:00 2001 From: Mark Mackey Date: Mon, 10 Nov 2025 13:59:39 -0600 Subject: [PATCH] fix linter complaints --- .../beacon_chain/src/envelope_verification.rs | 82 +++++++++---------- .../src/envelope_processing.rs | 18 ++-- consensus/types/src/beacon_state/tests.rs | 19 ++--- 3 files changed, 57 insertions(+), 62 deletions(-) diff --git a/beacon_node/beacon_chain/src/envelope_verification.rs b/beacon_node/beacon_chain/src/envelope_verification.rs index 3c0a8363e2..ad8a6ea539 100644 --- a/beacon_node/beacon_chain/src/envelope_verification.rs +++ b/beacon_node/beacon_chain/src/envelope_verification.rs @@ -159,50 +159,46 @@ fn load_snapshot( // TODO(EIP-7732): add metrics here - let result = { - // Load the parent block's state from the database, returning an error if it is not found. - // It is an error because if we know the parent block we should also know the parent state. - // Retrieve any state that is advanced through to at most `block.slot()`: this is - // particularly important if `block` descends from the finalized/split block, but at a slot - // prior to the finalized slot (which is invalid and inaccessible in our DB schema). - let (parent_state_root, state) = chain - .store - // TODO(EIP-7732): the state doesn't need to be advanced here because we're applying an envelope - // but this function does use a lot of caches that could be more efficient. Is there - // a better way to do this? - .get_advanced_hot_state( - beacon_block_root, - proto_beacon_block.slot, - proto_beacon_block.state_root, - ) - .map_err(|e| EnvelopeError::BeaconChainError(Arc::new(e.into())))? - .ok_or_else(|| { - BeaconChainError::DBInconsistent(format!( - "Missing state for parent block {beacon_block_root:?}", - )) - })?; - - if state.slot() == proto_beacon_block.slot { - // Sanity check. - if parent_state_root != proto_beacon_block.state_root { - return Err(BeaconChainError::DBInconsistent(format!( - "Parent state at slot {} has the wrong state root: {:?} != {:?}", - state.slot(), - parent_state_root, - proto_beacon_block.state_root, - )) - .into()); - } - } - - Ok(EnvelopeProcessingSnapshot { - pre_state: state, - state_root: parent_state_root, + // Load the parent block's state from the database, returning an error if it is not found. + // It is an error because if we know the parent block we should also know the parent state. + // Retrieve any state that is advanced through to at most `block.slot()`: this is + // particularly important if `block` descends from the finalized/split block, but at a slot + // prior to the finalized slot (which is invalid and inaccessible in our DB schema). + let (parent_state_root, state) = chain + .store + // TODO(EIP-7732): the state doesn't need to be advanced here because we're applying an envelope + // but this function does use a lot of caches that could be more efficient. Is there + // a better way to do this? + .get_advanced_hot_state( beacon_block_root, - }) - }; + proto_beacon_block.slot, + proto_beacon_block.state_root, + ) + .map_err(|e| EnvelopeError::BeaconChainError(Arc::new(e.into())))? + .ok_or_else(|| { + BeaconChainError::DBInconsistent(format!( + "Missing state for parent block {beacon_block_root:?}", + )) + })?; - result + if state.slot() == proto_beacon_block.slot { + // Sanity check. + if parent_state_root != proto_beacon_block.state_root { + return Err(BeaconChainError::DBInconsistent(format!( + "Parent state at slot {} has the wrong state root: {:?} != {:?}", + state.slot(), + parent_state_root, + proto_beacon_block.state_root, + )) + .into()); + } + } + + Ok(EnvelopeProcessingSnapshot { + pre_state: state, + state_root: parent_state_root, + beacon_block_root, + }) } /// A wrapper around a `SignedExecutionPayloadEnvelope` that indicates it has been approved for re-gossiping on @@ -320,7 +316,7 @@ impl GossipVerifiedEnvelope { builder_index: envelope.builder_index(), })?; signed_envelope.verify_signature( - &builder_pubkey, + builder_pubkey, &fork, chain.genesis_validators_root, &chain.spec, diff --git a/consensus/state_processing/src/envelope_processing.rs b/consensus/state_processing/src/envelope_processing.rs index 6de94f1c80..af2b309c1e 100644 --- a/consensus/state_processing/src/envelope_processing.rs +++ b/consensus/state_processing/src/envelope_processing.rs @@ -119,7 +119,7 @@ pub fn envelope_processing( if verify_signatures.is_true() { // Verify Signed Envelope Signature // TODO(EIP-7732): there is probably a more efficient way to do this.. - if !signed_envelope.verify_signature_with_state(&state, spec)? { + if !signed_envelope.verify_signature_with_state(state, spec)? { return Err(EnvelopeProcessingError::BadSignature); } } @@ -205,18 +205,16 @@ pub fn envelope_processing( state: *state.get_randao_mix(state.current_epoch())?, envelope: payload.prev_randao(), } - .into() ); // Verify the timestamp - let state_timestamp = compute_timestamp_at_slot(&state, state.slot(), spec)?; + let state_timestamp = compute_timestamp_at_slot(state, state.slot(), spec)?; envelope_verify!( payload.timestamp() == state_timestamp, EnvelopeProcessingError::TimestampMismatch { state: state_timestamp, envelope: payload.timestamp(), } - .into() ); // Verify the commitments are under limit @@ -227,7 +225,6 @@ pub fn envelope_processing( max: max_blobs, envelope: envelope.blob_kzg_commitments().len(), } - .into() ); // process electra operations @@ -242,7 +239,9 @@ pub fn envelope_processing( let mut payment = state .builder_pending_payments()? .get(payment_index) - .ok_or_else(|| EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds(payment_index))? + .ok_or(EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds( + payment_index, + ))? .clone(); let amount = payment.withdrawal.amount; if amount > 0 { @@ -257,8 +256,9 @@ pub fn envelope_processing( *state .builder_pending_payments_mut()? .get_mut(payment_index) - .ok_or_else(|| EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds(payment_index))? = - BuilderPendingPayment::default(); + .ok_or(EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds( + payment_index, + ))? = BuilderPendingPayment::default(); // cache the execution payload hash let availability_index = state @@ -268,7 +268,7 @@ pub fn envelope_processing( state .execution_payload_availability_mut()? .set(availability_index, true) - .map_err(|e| EnvelopeProcessingError::BitFieldError(e))?; + .map_err(EnvelopeProcessingError::BitFieldError)?; *state.latest_block_hash_mut()? = payload.block_hash(); // verify the state root diff --git a/consensus/types/src/beacon_state/tests.rs b/consensus/types/src/beacon_state/tests.rs index ec6a2efa25..99bf0c8e7f 100644 --- a/consensus/types/src/beacon_state/tests.rs +++ b/consensus/types/src/beacon_state/tests.rs @@ -53,16 +53,15 @@ async fn build_state(validator_count: usize) -> BeaconState { .head_beacon_state_cloned() } -/// TODO(EIP-7732): Add tests for PTC (Payload Timeliness Committee) functions: -/// - get_ptc: Test committee selection, size, balance-weighted selection -/// - get_ptc_attester_seed: Test seed generation and determinism -/// - compute_balance_weighted_selection: Test selection algorithm with various balances -/// - compute_balance_weighted_acceptance: Test acceptance probability -/// These tests require being able to build Gloas states with initialized committee caches, -/// which currently fails due to incomplete Gloas block structure as mentioned here: -/// https://github.com/sigp/lighthouse/pull/8273 -/// Similar to existing committee_consistency_test suite for get_beacon_committee. - +// TODO(EIP-7732): Add tests for PTC (Payload Timeliness Committee) functions: +// - get_ptc: Test committee selection, size, balance-weighted selection +// - get_ptc_attester_seed: Test seed generation and determinism +// - compute_balance_weighted_selection: Test selection algorithm with various balances +// - compute_balance_weighted_acceptance: Test acceptance probability +// These tests require being able to build Gloas states with initialized committee caches, +// which currently fails due to incomplete Gloas block structure as mentioned here: +// https://github.com/sigp/lighthouse/pull/8273 +// Similar to existing committee_consistency_test suite for get_beacon_committee. async fn test_beacon_proposer_index() { let spec = E::default_spec();