Squash of "Gloas modify process_attestations #8283"

This commit is contained in:
shane-moore
2025-08-17 11:38:18 -07:00
committed by Michael Sproul
parent 2d96b3f193
commit 91f483415a
6 changed files with 244 additions and 16 deletions

View File

@@ -25,8 +25,8 @@ use typenum::Unsigned;
use crate::{
BuilderPendingPayment, BuilderPendingWithdrawal, ExecutionBlockHash, ExecutionPayloadBid,
attestation::{
AttestationDuty, BeaconCommittee, Checkpoint, CommitteeIndex, PTC, ParticipationFlags,
PendingAttestation,
AttestationData, AttestationDuty, BeaconCommittee, Checkpoint, CommitteeIndex, PTC,
ParticipationFlags, PendingAttestation,
},
block::{BeaconBlock, BeaconBlockHeader, SignedBeaconBlockHash},
consolidation::PendingConsolidation,
@@ -175,6 +175,8 @@ pub enum BeaconStateError {
NonExecutionAddressWithdrawalCredential,
NoCommitteeFound(CommitteeIndex),
InvalidCommitteeIndex(CommitteeIndex),
/// `Attestation.data.index` field is invalid in overloaded data index scenario.
BadOverloadedDataIndex(u64),
InvalidSelectionProof {
aggregator_index: u64,
},
@@ -198,6 +200,7 @@ pub enum BeaconStateError {
},
InvalidIndicesCount,
PleaseNotifyTheDevs(String),
InvalidExecutionPayloadAvailabilityIndex(usize),
}
/// Control whether an epoch-indexed field can be indexed at the next epoch or not.
@@ -2055,6 +2058,25 @@ impl<E: EthSpec> BeaconState<E> {
Ok(cache.get_attestation_duties(validator_index))
}
/// Check if the attestation is for the block proposed at the attestation slot.
///
/// Returns `true` if the attestation's block root matches the block root at the
/// attestation's slot, and the block root differs from the previous slot's root.
pub fn is_attestation_same_slot(
&self,
data: &AttestationData,
) -> Result<bool, BeaconStateError> {
if data.slot == 0 {
return Ok(true);
}
let blockroot = data.beacon_block_root;
let slot_blockroot = *self.get_block_root(data.slot)?;
let prev_blockroot = *self.get_block_root(data.slot.safe_sub(1)?)?;
Ok(blockroot == slot_blockroot && blockroot != prev_blockroot)
}
/// Compute the total active balance cache from scratch.
///
/// This method should rarely be invoked because single-pass epoch processing keeps the total