Op pool and gossip for BLS to execution changes (#3726)

This commit is contained in:
Michael Sproul
2022-11-25 07:09:26 +11:00
committed by GitHub
parent 58b54f0a53
commit 788b337951
27 changed files with 539 additions and 69 deletions

View File

@@ -1,5 +1,5 @@
use derivative::Derivative;
use smallvec::SmallVec;
use smallvec::{smallvec, SmallVec};
use ssz::{Decode, Encode};
use state_processing::{SigVerifiedOp, VerifyOperation};
use std::collections::HashSet;
@@ -9,6 +9,9 @@ use types::{
SignedVoluntaryExit, Slot,
};
#[cfg(feature = "withdrawals-processing")]
use types::SignedBlsToExecutionChange;
/// Number of validator indices to store on the stack in `observed_validators`.
pub const SMALL_VEC_SIZE: usize = 8;
@@ -39,7 +42,7 @@ pub enum ObservationOutcome<T: Encode + Decode, E: EthSpec> {
AlreadyKnown,
}
/// Trait for exits and slashings which can be observed using `ObservedOperations`.
/// Trait for operations which can be observed using `ObservedOperations`.
pub trait ObservableOperation<E: EthSpec>: VerifyOperation<E> + Sized {
/// The set of validator indices involved in this operation.
///
@@ -49,13 +52,13 @@ pub trait ObservableOperation<E: EthSpec>: VerifyOperation<E> + Sized {
impl<E: EthSpec> ObservableOperation<E> for SignedVoluntaryExit {
fn observed_validators(&self) -> SmallVec<[u64; SMALL_VEC_SIZE]> {
std::iter::once(self.message.validator_index).collect()
smallvec![self.message.validator_index]
}
}
impl<E: EthSpec> ObservableOperation<E> for ProposerSlashing {
fn observed_validators(&self) -> SmallVec<[u64; SMALL_VEC_SIZE]> {
std::iter::once(self.signed_header_1.message.proposer_index).collect()
smallvec![self.signed_header_1.message.proposer_index]
}
}
@@ -80,6 +83,13 @@ impl<E: EthSpec> ObservableOperation<E> for AttesterSlashing<E> {
}
}
#[cfg(feature = "withdrawals-processing")]
impl<E: EthSpec> ObservableOperation<E> for SignedBlsToExecutionChange {
fn observed_validators(&self) -> SmallVec<[u64; SMALL_VEC_SIZE]> {
smallvec![self.message.validator_index]
}
}
impl<T: ObservableOperation<E>, E: EthSpec> ObservedOperations<T, E> {
pub fn verify_and_observe(
&mut self,