Skip to content

Commit

Permalink
not so sure about this..
Browse files Browse the repository at this point in the history
  • Loading branch information
ethDreamer committed Apr 26, 2024
1 parent a16f78f commit 2594274
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
13 changes: 6 additions & 7 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub observed_proposer_slashings: Mutex<ObservedOperations<ProposerSlashing, T::EthSpec>>,
/// Maintains a record of which validators we've seen attester slashings for.
pub observed_attester_slashings:
Mutex<ObservedOperations<AttesterSlashing<T::EthSpec>, T::EthSpec>>,
Mutex<ObservedOperations<AttesterSlashingOnDisk<T::EthSpec>, T::EthSpec>>,
/// Maintains a record of which validators we've seen BLS to execution changes for.
pub observed_bls_to_execution_changes:
Mutex<ObservedOperations<SignedBlsToExecutionChange, T::EthSpec>>,
Expand Down Expand Up @@ -2443,10 +2443,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub fn verify_attester_slashing_for_gossip(
&self,
attester_slashing: AttesterSlashing<T::EthSpec>,
) -> Result<ObservationOutcome<AttesterSlashing<T::EthSpec>, T::EthSpec>, Error> {
) -> Result<ObservationOutcome<AttesterSlashingOnDisk<T::EthSpec>, T::EthSpec>, Error> {
let wall_clock_state = self.wall_clock_state()?;
Ok(self.observed_attester_slashings.lock().verify_and_observe(
attester_slashing,
attester_slashing.into(),
&wall_clock_state,
&self.spec,
)?)
Expand All @@ -2458,12 +2458,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// 2. Add it to the op pool.
pub fn import_attester_slashing(
&self,
attester_slashing: SigVerifiedOp<AttesterSlashing<T::EthSpec>, T::EthSpec>,
attester_slashing: SigVerifiedOp<AttesterSlashingOnDisk<T::EthSpec>, T::EthSpec>,
) {
// Add to fork choice.
self.canonical_head
.fork_choice_write_lock()
.on_attester_slashing(attester_slashing.as_inner());
.on_attester_slashing(attester_slashing.as_inner().to_ref());

// Add to the op pool (if we have the ability to propose blocks).
if self.eth1_chain.is_some() {
Expand Down Expand Up @@ -4941,8 +4941,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
});

attester_slashings.retain(|slashing| {
slashing
.clone()
AttesterSlashingOnDisk::from(slashing.clone())
.validate(&state, &self.spec)
.map_err(|e| {
warn!(
Expand Down
13 changes: 7 additions & 6 deletions beacon_node/beacon_chain/src/observed_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use state_processing::{SigVerifiedOp, VerifyOperation, VerifyOperationAt};
use std::collections::HashSet;
use std::marker::PhantomData;
use types::{
AttesterSlashing, BeaconState, ChainSpec, Epoch, EthSpec, ForkName, ProposerSlashing,
AttesterSlashingOnDisk, BeaconState, ChainSpec, Epoch, EthSpec, ForkName, ProposerSlashing,
SignedBlsToExecutionChange, SignedVoluntaryExit, Slot,
};

Expand Down Expand Up @@ -59,16 +59,17 @@ impl<E: EthSpec> ObservableOperation<E> for ProposerSlashing {
}
}

impl<E: EthSpec> ObservableOperation<E> for AttesterSlashing<E> {
impl<E: EthSpec> ObservableOperation<E> for AttesterSlashingOnDisk<E> {
fn observed_validators(&self) -> SmallVec<[u64; SMALL_VEC_SIZE]> {
let attestation_1_indices = self
.attestation_1
let slashing_ref = self.to_ref();
let attestation_1_indices = slashing_ref
.attestation_1()
.attesting_indices
.iter()
.copied()
.collect::<HashSet<u64>>();
let attestation_2_indices = self
.attestation_2
let attestation_2_indices = slashing_ref
.attestation_2()
.attesting_indices
.iter()
.copied()
Expand Down
10 changes: 6 additions & 4 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,10 +1526,11 @@ where
}
}

AttesterSlashing {
// TODO(electra): fix this test
AttesterSlashing::Base(AttesterSlashingBase {
attestation_1,
attestation_2,
}
})
}

pub fn make_attester_slashing_different_indices(
Expand Down Expand Up @@ -1584,10 +1585,11 @@ where
}
}

AttesterSlashing {
// TODO(electra): fix this test
AttesterSlashing::Base(AttesterSlashingBase {
attestation_1,
attestation_2,
}
})
}

pub fn make_proposer_slashing(&self, validator_index: u64) -> ProposerSlashing {
Expand Down
15 changes: 8 additions & 7 deletions beacon_node/beacon_chain/src/validator_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use types::consts::altair::{
TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX,
};
use types::{
Attestation, AttestationData, AttesterSlashing, BeaconBlockRef, BeaconState, BeaconStateError,
ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation, ProposerSlashing, PublicKeyBytes,
SignedAggregateAndProof, SignedContributionAndProof, Slot, SyncCommitteeMessage, VoluntaryExit,
Attestation, AttestationData, AttesterSlashingRef, BeaconBlockRef, BeaconState,
BeaconStateError, ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation, ProposerSlashing,
PublicKeyBytes, SignedAggregateAndProof, SignedContributionAndProof, Slot,
SyncCommitteeMessage, VoluntaryExit,
};

/// Used for Prometheus labels.
Expand Down Expand Up @@ -1783,21 +1784,21 @@ impl<E: EthSpec> ValidatorMonitor<E> {
}

/// Register an attester slashing from the gossip network.
pub fn register_gossip_attester_slashing(&self, slashing: &AttesterSlashing<E>) {
pub fn register_gossip_attester_slashing(&self, slashing: AttesterSlashingRef<'_, E>) {
self.register_attester_slashing("gossip", slashing)
}

/// Register an attester slashing from the HTTP API.
pub fn register_api_attester_slashing(&self, slashing: &AttesterSlashing<E>) {
pub fn register_api_attester_slashing(&self, slashing: AttesterSlashingRef<'_, E>) {
self.register_attester_slashing("api", slashing)
}

/// Register an attester slashing included in a *valid* `BeaconBlock`.
pub fn register_block_attester_slashing(&self, slashing: &AttesterSlashing<E>) {
pub fn register_block_attester_slashing(&self, slashing: AttesterSlashingRef<'_, E>) {
self.register_attester_slashing("block", slashing)
}

fn register_attester_slashing(&self, src: &str, slashing: &AttesterSlashing<E>) {
fn register_attester_slashing(&self, src: &str, slashing: AttesterSlashingRef<'_, E>) {
let data = &slashing.attestation_1.data;
let attestation_1_indices: HashSet<u64> = slashing
.attestation_1
Expand Down
6 changes: 3 additions & 3 deletions consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::marker::PhantomData;
use std::time::Duration;
use types::{
consts::merge::INTERVALS_PER_SLOT, AbstractExecPayload, AttestationShufflingId,
AttesterSlashing, BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, Checkpoint, Epoch,
EthSpec, ExecPayload, ExecutionBlockHash, Hash256, IndexedAttestation, RelativeEpoch,
AttesterSlashingRef, BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, Checkpoint,
Epoch, EthSpec, ExecPayload, ExecutionBlockHash, Hash256, IndexedAttestation, RelativeEpoch,
SignedBeaconBlock, Slot,
};

Expand Down Expand Up @@ -1086,7 +1086,7 @@ where
/// Apply an attester slashing to fork choice.
///
/// We assume that the attester slashing provided to this function has already been verified.
pub fn on_attester_slashing(&mut self, slashing: &AttesterSlashing<E>) {
pub fn on_attester_slashing(&mut self, slashing: AttesterSlashingRef<'_, E>) {
let attesting_indices_set = |att: &IndexedAttestation<E>| {
att.attesting_indices
.iter()
Expand Down

0 comments on commit 2594274

Please sign in to comment.