Use E for EthSpec globally (#5264)

* Use `E` for `EthSpec` globally

* Fix tests

* Merge branch 'unstable' into e-ethspec

* Merge branch 'unstable' into e-ethspec

# Conflicts:
#	beacon_node/execution_layer/src/engine_api.rs
#	beacon_node/execution_layer/src/engine_api/http.rs
#	beacon_node/execution_layer/src/engine_api/json_structures.rs
#	beacon_node/execution_layer/src/test_utils/handle_rpc.rs
#	beacon_node/store/src/partial_beacon_state.rs
#	consensus/types/src/beacon_block.rs
#	consensus/types/src/beacon_block_body.rs
#	consensus/types/src/beacon_state.rs
#	consensus/types/src/config_and_preset.rs
#	consensus/types/src/execution_payload.rs
#	consensus/types/src/execution_payload_header.rs
#	consensus/types/src/light_client_optimistic_update.rs
#	consensus/types/src/payload.rs
#	lcli/src/parse_ssz.rs
This commit is contained in:
Mac L
2024-04-03 02:12:25 +11:00
committed by GitHub
parent f8fdb71f50
commit 969d12dc6f
230 changed files with 2743 additions and 2792 deletions

View File

@@ -6,9 +6,9 @@ use std::borrow::Cow;
use types::consts::altair::{PROPOSER_WEIGHT, SYNC_REWARD_WEIGHT, WEIGHT_DENOMINATOR};
use types::{BeaconState, ChainSpec, EthSpec, PublicKeyBytes, SyncAggregate, Unsigned};
pub fn process_sync_aggregate<T: EthSpec>(
state: &mut BeaconState<T>,
aggregate: &SyncAggregate<T>,
pub fn process_sync_aggregate<E: EthSpec>(
state: &mut BeaconState<E>,
aggregate: &SyncAggregate<E>,
proposer_index: u64,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
@@ -65,8 +65,8 @@ pub fn process_sync_aggregate<T: EthSpec>(
/// Compute the `(participant_reward, proposer_reward)` for a sync aggregate.
///
/// The `state` should be the pre-state from the same slot as the block containing the aggregate.
pub fn compute_sync_aggregate_rewards<T: EthSpec>(
state: &BeaconState<T>,
pub fn compute_sync_aggregate_rewards<E: EthSpec>(
state: &BeaconState<E>,
spec: &ChainSpec,
) -> Result<(u64, u64), BlockProcessingError> {
let total_active_balance = state.get_total_active_balance()?;
@@ -78,8 +78,8 @@ pub fn compute_sync_aggregate_rewards<T: EthSpec>(
let max_participant_rewards = total_base_rewards
.safe_mul(SYNC_REWARD_WEIGHT)?
.safe_div(WEIGHT_DENOMINATOR)?
.safe_div(T::slots_per_epoch())?;
let participant_reward = max_participant_rewards.safe_div(T::SyncCommitteeSize::to_u64())?;
.safe_div(E::slots_per_epoch())?;
let participant_reward = max_participant_rewards.safe_div(E::SyncCommitteeSize::to_u64())?;
let proposer_reward = participant_reward
.safe_mul(PROPOSER_WEIGHT)?
.safe_div(WEIGHT_DENOMINATOR.safe_sub(PROPOSER_WEIGHT)?)?;

View File

@@ -71,15 +71,15 @@ impl From<BlockOperationError<AttestationInvalid>> for Error {
///
/// This allows for optimizations related to batch BLS operations (see the
/// `Self::verify_entire_block(..)` function).
pub struct BlockSignatureVerifier<'a, T, F, D>
pub struct BlockSignatureVerifier<'a, E, F, D>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>> + Clone,
D: Fn(&'a PublicKeyBytes) -> Option<Cow<'a, PublicKey>>,
{
get_pubkey: F,
decompressor: D,
state: &'a BeaconState<T>,
state: &'a BeaconState<E>,
spec: &'a ChainSpec,
sets: ParallelSignatureSets<'a>,
}
@@ -95,16 +95,16 @@ impl<'a> From<Vec<SignatureSet<'a>>> for ParallelSignatureSets<'a> {
}
}
impl<'a, T, F, D> BlockSignatureVerifier<'a, T, F, D>
impl<'a, E, F, D> BlockSignatureVerifier<'a, E, F, D>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>> + Clone,
D: Fn(&'a PublicKeyBytes) -> Option<Cow<'a, PublicKey>>,
{
/// Create a new verifier without any included signatures. See the `include...` functions to
/// add signatures, and the `verify`
pub fn new(
state: &'a BeaconState<T>,
state: &'a BeaconState<E>,
get_pubkey: F,
decompressor: D,
spec: &'a ChainSpec,
@@ -125,12 +125,12 @@ where
/// contains invalid signatures on deposits._
///
/// See `Self::verify` for more detail.
pub fn verify_entire_block<Payload: AbstractExecPayload<T>>(
state: &'a BeaconState<T>,
pub fn verify_entire_block<Payload: AbstractExecPayload<E>>(
state: &'a BeaconState<E>,
get_pubkey: F,
decompressor: D,
block: &'a SignedBeaconBlock<T, Payload>,
ctxt: &mut ConsensusContext<T>,
block: &'a SignedBeaconBlock<E, Payload>,
ctxt: &mut ConsensusContext<E>,
spec: &'a ChainSpec,
) -> Result<()> {
let mut verifier = Self::new(state, get_pubkey, decompressor, spec);
@@ -139,10 +139,10 @@ where
}
/// Includes all signatures on the block (except the deposit signatures) for verification.
pub fn include_all_signatures<Payload: AbstractExecPayload<T>>(
pub fn include_all_signatures<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
ctxt: &mut ConsensusContext<T>,
block: &'a SignedBeaconBlock<E, Payload>,
ctxt: &mut ConsensusContext<E>,
) -> Result<()> {
let block_root = Some(ctxt.get_current_block_root(block)?);
let verified_proposer_index =
@@ -156,10 +156,10 @@ where
/// Includes all signatures on the block (except the deposit signatures and the proposal
/// signature) for verification.
pub fn include_all_signatures_except_proposal<Payload: AbstractExecPayload<T>>(
pub fn include_all_signatures_except_proposal<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
ctxt: &mut ConsensusContext<T>,
block: &'a SignedBeaconBlock<E, Payload>,
ctxt: &mut ConsensusContext<E>,
) -> Result<()> {
let verified_proposer_index =
Some(ctxt.get_proposer_index_from_epoch_state(self.state, self.spec)?);
@@ -176,9 +176,9 @@ where
}
/// Includes the block signature for `self.block` for verification.
pub fn include_block_proposal<Payload: AbstractExecPayload<T>>(
pub fn include_block_proposal<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
block_root: Option<Hash256>,
verified_proposer_index: Option<u64>,
) -> Result<()> {
@@ -195,9 +195,9 @@ where
}
/// Includes the randao signature for `self.block` for verification.
pub fn include_randao_reveal<Payload: AbstractExecPayload<T>>(
pub fn include_randao_reveal<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
verified_proposer_index: Option<u64>,
) -> Result<()> {
let set = randao_signature_set(
@@ -212,9 +212,9 @@ where
}
/// Includes all signatures in `self.block.body.proposer_slashings` for verification.
pub fn include_proposer_slashings<Payload: AbstractExecPayload<T>>(
pub fn include_proposer_slashings<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
) -> Result<()> {
self.sets
.sets
@@ -241,9 +241,9 @@ where
}
/// Includes all signatures in `self.block.body.attester_slashings` for verification.
pub fn include_attester_slashings<Payload: AbstractExecPayload<T>>(
pub fn include_attester_slashings<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
) -> Result<()> {
self.sets
.sets
@@ -270,10 +270,10 @@ where
}
/// Includes all signatures in `self.block.body.attestations` for verification.
pub fn include_attestations<Payload: AbstractExecPayload<T>>(
pub fn include_attestations<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
ctxt: &mut ConsensusContext<T>,
block: &'a SignedBeaconBlock<E, Payload>,
ctxt: &mut ConsensusContext<E>,
) -> Result<()> {
self.sets
.sets
@@ -300,9 +300,9 @@ where
}
/// Includes all signatures in `self.block.body.voluntary_exits` for verification.
pub fn include_exits<Payload: AbstractExecPayload<T>>(
pub fn include_exits<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
) -> Result<()> {
self.sets
.sets
@@ -324,9 +324,9 @@ where
}
/// Include the signature of the block's sync aggregate (if it exists) for verification.
pub fn include_sync_aggregate<Payload: AbstractExecPayload<T>>(
pub fn include_sync_aggregate<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
) -> Result<()> {
if let Ok(sync_aggregate) = block.message().body().sync_aggregate() {
if let Some(signature_set) = sync_aggregate_signature_set(
@@ -344,9 +344,9 @@ where
}
/// Include the signature of the block's BLS to execution changes for verification.
pub fn include_bls_to_execution_changes<Payload: AbstractExecPayload<T>>(
pub fn include_bls_to_execution_changes<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<T, Payload>,
block: &'a SignedBeaconBlock<E, Payload>,
) -> Result<()> {
// To improve performance we might want to decompress the withdrawal pubkeys in parallel.
if let Ok(bls_to_execution_changes) = block.message().body().bls_to_execution_changes() {

View File

@@ -11,9 +11,9 @@ fn error(reason: Invalid) -> BlockOperationError<Invalid> {
}
/// Verify an `IndexedAttestation`.
pub fn is_valid_indexed_attestation<T: EthSpec>(
state: &BeaconState<T>,
indexed_attestation: &IndexedAttestation<T>,
pub fn is_valid_indexed_attestation<E: EthSpec>(
state: &BeaconState<E>,
indexed_attestation: &IndexedAttestation<E>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<()> {

View File

@@ -8,11 +8,11 @@ use crate::per_block_processing::errors::{BlockProcessingError, IntoWithIndex};
use crate::VerifySignatures;
use types::consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR};
pub fn process_operations<T: EthSpec, Payload: AbstractExecPayload<T>>(
state: &mut BeaconState<T>,
block_body: BeaconBlockBodyRef<T, Payload>,
pub fn process_operations<E: EthSpec, Payload: AbstractExecPayload<E>>(
state: &mut BeaconState<E>,
block_body: BeaconBlockBodyRef<E, Payload>,
verify_signatures: VerifySignatures,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
process_proposer_slashings(
@@ -47,11 +47,11 @@ pub mod base {
///
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
/// an `Err` describing the invalid object or cause of failure.
pub fn process_attestations<T: EthSpec>(
state: &mut BeaconState<T>,
attestations: &[Attestation<T>],
pub fn process_attestations<E: EthSpec>(
state: &mut BeaconState<E>,
attestations: &[Attestation<E>],
verify_signatures: VerifySignatures,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
// Ensure the previous epoch cache exists.
@@ -99,11 +99,11 @@ pub mod altair_deneb {
use crate::common::update_progressive_balances_cache::update_progressive_balances_on_attestation;
use types::consts::altair::TIMELY_TARGET_FLAG_INDEX;
pub fn process_attestations<T: EthSpec>(
state: &mut BeaconState<T>,
attestations: &[Attestation<T>],
pub fn process_attestations<E: EthSpec>(
state: &mut BeaconState<E>,
attestations: &[Attestation<E>],
verify_signatures: VerifySignatures,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
attestations
@@ -114,11 +114,11 @@ pub mod altair_deneb {
})
}
pub fn process_attestation<T: EthSpec>(
state: &mut BeaconState<T>,
attestation: &Attestation<T>,
pub fn process_attestation<E: EthSpec>(
state: &mut BeaconState<E>,
attestation: &Attestation<E>,
att_index: usize,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
@@ -190,11 +190,11 @@ pub mod altair_deneb {
///
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
/// an `Err` describing the invalid object or cause of failure.
pub fn process_proposer_slashings<T: EthSpec>(
state: &mut BeaconState<T>,
pub fn process_proposer_slashings<E: EthSpec>(
state: &mut BeaconState<E>,
proposer_slashings: &[ProposerSlashing],
verify_signatures: VerifySignatures,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
// Verify and apply proposer slashings in series.
@@ -223,11 +223,11 @@ pub fn process_proposer_slashings<T: EthSpec>(
///
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
/// an `Err` describing the invalid object or cause of failure.
pub fn process_attester_slashings<T: EthSpec>(
state: &mut BeaconState<T>,
attester_slashings: &[AttesterSlashing<T>],
pub fn process_attester_slashings<E: EthSpec>(
state: &mut BeaconState<E>,
attester_slashings: &[AttesterSlashing<E>],
verify_signatures: VerifySignatures,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
for (i, attester_slashing) in attester_slashings.iter().enumerate() {
@@ -245,11 +245,11 @@ pub fn process_attester_slashings<T: EthSpec>(
/// Wrapper function to handle calling the correct version of `process_attestations` based on
/// the fork.
pub fn process_attestations<T: EthSpec, Payload: AbstractExecPayload<T>>(
state: &mut BeaconState<T>,
block_body: BeaconBlockBodyRef<T, Payload>,
pub fn process_attestations<E: EthSpec, Payload: AbstractExecPayload<E>>(
state: &mut BeaconState<E>,
block_body: BeaconBlockBodyRef<E, Payload>,
verify_signatures: VerifySignatures,
ctxt: &mut ConsensusContext<T>,
ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
match block_body {
@@ -283,8 +283,8 @@ pub fn process_attestations<T: EthSpec, Payload: AbstractExecPayload<T>>(
///
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
/// an `Err` describing the invalid object or cause of failure.
pub fn process_exits<T: EthSpec>(
state: &mut BeaconState<T>,
pub fn process_exits<E: EthSpec>(
state: &mut BeaconState<E>,
voluntary_exits: &[SignedVoluntaryExit],
verify_signatures: VerifySignatures,
spec: &ChainSpec,
@@ -304,8 +304,8 @@ pub fn process_exits<T: EthSpec>(
///
/// Returns `Ok(())` if the validation and state updates completed successfully. Otherwise returns
/// an `Err` describing the invalid object or cause of failure.
pub fn process_bls_to_execution_changes<T: EthSpec>(
state: &mut BeaconState<T>,
pub fn process_bls_to_execution_changes<E: EthSpec>(
state: &mut BeaconState<E>,
bls_to_execution_changes: &[SignedBlsToExecutionChange],
verify_signatures: VerifySignatures,
spec: &ChainSpec,
@@ -329,13 +329,13 @@ pub fn process_bls_to_execution_changes<T: EthSpec>(
///
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
/// an `Err` describing the invalid object or cause of failure.
pub fn process_deposits<T: EthSpec>(
state: &mut BeaconState<T>,
pub fn process_deposits<E: EthSpec>(
state: &mut BeaconState<E>,
deposits: &[Deposit],
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
let expected_deposit_len = std::cmp::min(
T::MaxDeposits::to_u64(),
E::MaxDeposits::to_u64(),
state.get_outstanding_deposit_len()?,
);
block_verify!(
@@ -369,8 +369,8 @@ pub fn process_deposits<T: EthSpec>(
}
/// Process a single deposit, optionally verifying its merkle proof.
pub fn process_deposit<T: EthSpec>(
state: &mut BeaconState<T>,
pub fn process_deposit<E: EthSpec>(
state: &mut BeaconState<E>,
deposit: &Deposit,
spec: &ChainSpec,
verify_merkle_proof: bool,

View File

@@ -53,12 +53,12 @@ impl From<BeaconStateError> for Error {
}
/// Helper function to get a public key from a `state`.
pub fn get_pubkey_from_state<T>(
state: &BeaconState<T>,
pub fn get_pubkey_from_state<E>(
state: &BeaconState<E>,
validator_index: usize,
) -> Option<Cow<PublicKey>>
where
T: EthSpec,
E: EthSpec,
{
state
.validators()
@@ -71,16 +71,16 @@ where
}
/// A signature set that is valid if a block was signed by the expected block producer.
pub fn block_proposal_signature_set<'a, T, F, Payload: AbstractExecPayload<T>>(
state: &'a BeaconState<T>,
pub fn block_proposal_signature_set<'a, E, F, Payload: AbstractExecPayload<E>>(
state: &'a BeaconState<E>,
get_pubkey: F,
signed_block: &'a SignedBeaconBlock<T, Payload>,
signed_block: &'a SignedBeaconBlock<E, Payload>,
block_root: Option<Hash256>,
verified_proposer_index: Option<u64>,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let block = signed_block.message();
@@ -113,8 +113,8 @@ where
/// Unlike `block_proposal_signature_set` this does **not** check that the proposer index is
/// correct according to the shuffling. It should only be used if no suitable `BeaconState` is
/// available.
pub fn block_proposal_signature_set_from_parts<'a, T, F, Payload: AbstractExecPayload<T>>(
signed_block: &'a SignedBeaconBlock<T, Payload>,
pub fn block_proposal_signature_set_from_parts<'a, E, F, Payload: AbstractExecPayload<E>>(
signed_block: &'a SignedBeaconBlock<E, Payload>,
block_root: Option<Hash256>,
proposer_index: u64,
fork: &Fork,
@@ -123,7 +123,7 @@ pub fn block_proposal_signature_set_from_parts<'a, T, F, Payload: AbstractExecPa
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
// Verify that the `SignedBeaconBlock` instantiation matches the fork at `signed_block.slot()`.
@@ -133,7 +133,7 @@ where
let block = signed_block.message();
let domain = spec.get_domain(
block.slot().epoch(T::slots_per_epoch()),
block.slot().epoch(E::slots_per_epoch()),
Domain::BeaconProposer,
fork,
genesis_validators_root,
@@ -156,8 +156,8 @@ where
))
}
pub fn bls_execution_change_signature_set<'a, T: EthSpec>(
state: &'a BeaconState<T>,
pub fn bls_execution_change_signature_set<'a, E: EthSpec>(
state: &'a BeaconState<E>,
signed_address_change: &'a SignedBlsToExecutionChange,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>> {
@@ -183,15 +183,15 @@ pub fn bls_execution_change_signature_set<'a, T: EthSpec>(
}
/// A signature set that is valid if the block proposers randao reveal signature is correct.
pub fn randao_signature_set<'a, T, F, Payload: AbstractExecPayload<T>>(
state: &'a BeaconState<T>,
pub fn randao_signature_set<'a, E, F, Payload: AbstractExecPayload<E>>(
state: &'a BeaconState<E>,
get_pubkey: F,
block: BeaconBlockRef<'a, T, Payload>,
block: BeaconBlockRef<'a, E, Payload>,
verified_proposer_index: Option<u64>,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let proposer_index = if let Some(proposer_index) = verified_proposer_index {
@@ -201,7 +201,7 @@ where
};
let domain = spec.get_domain(
block.slot().epoch(T::slots_per_epoch()),
block.slot().epoch(E::slots_per_epoch()),
Domain::Randao,
&state.fork(),
state.genesis_validators_root(),
@@ -209,7 +209,7 @@ where
let message = block
.slot()
.epoch(T::slots_per_epoch())
.epoch(E::slots_per_epoch())
.signing_root(domain);
Ok(SignatureSet::single_pubkey(
@@ -220,14 +220,14 @@ where
}
/// Returns two signature sets, one for each `BlockHeader` included in the `ProposerSlashing`.
pub fn proposer_slashing_signature_set<'a, T, F>(
state: &'a BeaconState<T>,
pub fn proposer_slashing_signature_set<'a, E, F>(
state: &'a BeaconState<E>,
get_pubkey: F,
proposer_slashing: &'a ProposerSlashing,
spec: &'a ChainSpec,
) -> Result<(SignatureSet<'a>, SignatureSet<'a>)>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let proposer_index = proposer_slashing.signed_header_1.message.proposer_index as usize;
@@ -249,14 +249,14 @@ where
}
/// Returns a signature set that is valid if the given `pubkey` signed the `header`.
fn block_header_signature_set<'a, T: EthSpec>(
state: &'a BeaconState<T>,
fn block_header_signature_set<'a, E: EthSpec>(
state: &'a BeaconState<E>,
signed_header: &'a SignedBeaconBlockHeader,
pubkey: Cow<'a, PublicKey>,
spec: &'a ChainSpec,
) -> SignatureSet<'a> {
let domain = spec.get_domain(
signed_header.message.slot.epoch(T::slots_per_epoch()),
signed_header.message.slot.epoch(E::slots_per_epoch()),
Domain::BeaconProposer,
&state.fork(),
state.genesis_validators_root(),
@@ -268,15 +268,15 @@ fn block_header_signature_set<'a, T: EthSpec>(
}
/// Returns the signature set for the given `indexed_attestation`.
pub fn indexed_attestation_signature_set<'a, 'b, T, F>(
state: &'a BeaconState<T>,
pub fn indexed_attestation_signature_set<'a, 'b, E, F>(
state: &'a BeaconState<E>,
get_pubkey: F,
signature: &'a AggregateSignature,
indexed_attestation: &'b IndexedAttestation<T>,
indexed_attestation: &'b IndexedAttestation<E>,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let mut pubkeys = Vec::with_capacity(indexed_attestation.attesting_indices.len());
@@ -300,16 +300,16 @@ where
/// Returns the signature set for the given `indexed_attestation` but pubkeys are supplied directly
/// instead of from the state.
pub fn indexed_attestation_signature_set_from_pubkeys<'a, 'b, T, F>(
pub fn indexed_attestation_signature_set_from_pubkeys<'a, 'b, E, F>(
get_pubkey: F,
signature: &'a AggregateSignature,
indexed_attestation: &'b IndexedAttestation<T>,
indexed_attestation: &'b IndexedAttestation<E>,
fork: &Fork,
genesis_validators_root: Hash256,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let mut pubkeys = Vec::with_capacity(indexed_attestation.attesting_indices.len());
@@ -332,14 +332,14 @@ where
}
/// Returns the signature set for the given `attester_slashing` and corresponding `pubkeys`.
pub fn attester_slashing_signature_sets<'a, T, F>(
state: &'a BeaconState<T>,
pub fn attester_slashing_signature_sets<'a, E, F>(
state: &'a BeaconState<E>,
get_pubkey: F,
attester_slashing: &'a AttesterSlashing<T>,
attester_slashing: &'a AttesterSlashing<E>,
spec: &'a ChainSpec,
) -> Result<(SignatureSet<'a>, SignatureSet<'a>)>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>> + Clone,
{
Ok((
@@ -374,14 +374,14 @@ pub fn deposit_pubkey_signature_message(
/// Returns a signature set that is valid if the `SignedVoluntaryExit` was signed by the indicated
/// validator.
pub fn exit_signature_set<'a, T, F>(
state: &'a BeaconState<T>,
pub fn exit_signature_set<'a, E, F>(
state: &'a BeaconState<E>,
get_pubkey: F,
signed_exit: &'a SignedVoluntaryExit,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let exit = &signed_exit.message;
@@ -414,21 +414,21 @@ where
))
}
pub fn signed_aggregate_selection_proof_signature_set<'a, T, F>(
pub fn signed_aggregate_selection_proof_signature_set<'a, E, F>(
get_pubkey: F,
signed_aggregate_and_proof: &'a SignedAggregateAndProof<T>,
signed_aggregate_and_proof: &'a SignedAggregateAndProof<E>,
fork: &Fork,
genesis_validators_root: Hash256,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let slot = signed_aggregate_and_proof.message.aggregate.data.slot;
let domain = spec.get_domain(
slot.epoch(T::slots_per_epoch()),
slot.epoch(E::slots_per_epoch()),
Domain::SelectionProof,
fork,
genesis_validators_root,
@@ -444,15 +444,15 @@ where
))
}
pub fn signed_aggregate_signature_set<'a, T, F>(
pub fn signed_aggregate_signature_set<'a, E, F>(
get_pubkey: F,
signed_aggregate_and_proof: &'a SignedAggregateAndProof<T>,
signed_aggregate_and_proof: &'a SignedAggregateAndProof<E>,
fork: &Fork,
genesis_validators_root: Hash256,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let target_epoch = signed_aggregate_and_proof
@@ -479,21 +479,21 @@ where
))
}
pub fn signed_sync_aggregate_selection_proof_signature_set<'a, T, F>(
pub fn signed_sync_aggregate_selection_proof_signature_set<'a, E, F>(
get_pubkey: F,
signed_contribution_and_proof: &'a SignedContributionAndProof<T>,
signed_contribution_and_proof: &'a SignedContributionAndProof<E>,
fork: &Fork,
genesis_validators_root: Hash256,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let slot = signed_contribution_and_proof.message.contribution.slot;
let domain = spec.get_domain(
slot.epoch(T::slots_per_epoch()),
slot.epoch(E::slots_per_epoch()),
Domain::SyncCommitteeSelectionProof,
fork,
genesis_validators_root,
@@ -516,22 +516,22 @@ where
))
}
pub fn signed_sync_aggregate_signature_set<'a, T, F>(
pub fn signed_sync_aggregate_signature_set<'a, E, F>(
get_pubkey: F,
signed_contribution_and_proof: &'a SignedContributionAndProof<T>,
signed_contribution_and_proof: &'a SignedContributionAndProof<E>,
fork: &Fork,
genesis_validators_root: Hash256,
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
{
let epoch = signed_contribution_and_proof
.message
.contribution
.slot
.epoch(T::slots_per_epoch());
.epoch(E::slots_per_epoch());
let domain = spec.get_domain(
epoch,
@@ -551,7 +551,7 @@ where
}
#[allow(clippy::too_many_arguments)]
pub fn sync_committee_contribution_signature_set_from_pubkeys<'a, T, F>(
pub fn sync_committee_contribution_signature_set_from_pubkeys<'a, E, F>(
get_pubkey: F,
pubkey_bytes: &[PublicKeyBytes],
signature: &'a AggregateSignature,
@@ -562,10 +562,10 @@ pub fn sync_committee_contribution_signature_set_from_pubkeys<'a, T, F>(
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
F: Fn(&PublicKeyBytes) -> Option<Cow<'a, PublicKey>>,
{
let mut pubkeys = Vec::with_capacity(T::SyncSubcommitteeSize::to_usize());
let mut pubkeys = Vec::with_capacity(E::SyncSubcommitteeSize::to_usize());
for pubkey in pubkey_bytes {
pubkeys.push(get_pubkey(pubkey).ok_or(Error::ValidatorPubkeyUnknown(*pubkey))?);
}
@@ -577,7 +577,7 @@ where
Ok(SignatureSet::multiple_pubkeys(signature, pubkeys, message))
}
pub fn sync_committee_message_set_from_pubkeys<'a, T>(
pub fn sync_committee_message_set_from_pubkeys<'a, E>(
pubkey: Cow<'a, PublicKey>,
signature: &'a AggregateSignature,
epoch: Epoch,
@@ -587,7 +587,7 @@ pub fn sync_committee_message_set_from_pubkeys<'a, T>(
spec: &'a ChainSpec,
) -> Result<SignatureSet<'a>>
where
T: EthSpec,
E: EthSpec,
{
let domain = spec.get_domain(epoch, Domain::SyncCommittee, fork, genesis_validators_root);
@@ -607,16 +607,16 @@ where
/// uses a separate function `eth2_fast_aggregate_verify` for this, but we can equivalently
/// check the exceptional case eagerly and do a `fast_aggregate_verify` in the case where the
/// check fails (by returning `Some(signature_set)`).
pub fn sync_aggregate_signature_set<'a, T, D>(
pub fn sync_aggregate_signature_set<'a, E, D>(
decompressor: D,
sync_aggregate: &'a SyncAggregate<T>,
sync_aggregate: &'a SyncAggregate<E>,
slot: Slot,
block_root: Hash256,
state: &'a BeaconState<T>,
state: &'a BeaconState<E>,
spec: &ChainSpec,
) -> Result<Option<SignatureSet<'a>>>
where
T: EthSpec,
E: EthSpec,
D: Fn(&'a PublicKeyBytes) -> Option<Cow<'a, PublicKey>>,
{
// Allow the point at infinity to count as a signature for 0 validators as per
@@ -628,7 +628,7 @@ where
}
let committee_pubkeys = &state
.get_built_sync_committee(slot.epoch(T::slots_per_epoch()), spec)?
.get_built_sync_committee(slot.epoch(E::slots_per_epoch()), spec)?
.pubkeys;
let participant_pubkeys = committee_pubkeys
@@ -647,7 +647,7 @@ where
let previous_slot = slot.saturating_sub(1u64);
let domain = spec.get_domain(
previous_slot.epoch(T::slots_per_epoch()),
previous_slot.epoch(E::slots_per_epoch()),
Domain::SyncCommittee,
&state.fork(),
state.genesis_validators_root(),

View File

@@ -15,13 +15,13 @@ fn error(reason: Invalid) -> BlockOperationError<Invalid> {
/// to `state`. Otherwise, returns a descriptive `Err`.
///
/// Optionally verifies the aggregate signature, depending on `verify_signatures`.
pub fn verify_attestation_for_block_inclusion<'ctxt, T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation<T>,
ctxt: &'ctxt mut ConsensusContext<T>,
pub fn verify_attestation_for_block_inclusion<'ctxt, E: EthSpec>(
state: &BeaconState<E>,
attestation: &Attestation<E>,
ctxt: &'ctxt mut ConsensusContext<E>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<&'ctxt IndexedAttestation<T>> {
) -> Result<&'ctxt IndexedAttestation<E>> {
let data = &attestation.data;
verify!(
@@ -38,7 +38,7 @@ pub fn verify_attestation_for_block_inclusion<'ctxt, T: EthSpec>(
| BeaconState::Merge(_)
| BeaconState::Capella(_) => {
verify!(
state.slot() <= data.slot.safe_add(T::slots_per_epoch())?,
state.slot() <= data.slot.safe_add(E::slots_per_epoch())?,
Invalid::IncludedTooLate {
state: state.slot(),
attestation: data.slot,
@@ -59,13 +59,13 @@ pub fn verify_attestation_for_block_inclusion<'ctxt, T: EthSpec>(
/// prior blocks in `state`.
///
/// Spec v0.12.1
pub fn verify_attestation_for_state<'ctxt, T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation<T>,
ctxt: &'ctxt mut ConsensusContext<T>,
pub fn verify_attestation_for_state<'ctxt, E: EthSpec>(
state: &BeaconState<E>,
attestation: &Attestation<E>,
ctxt: &'ctxt mut ConsensusContext<E>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<&'ctxt IndexedAttestation<T>> {
) -> Result<&'ctxt IndexedAttestation<E>> {
let data = &attestation.data;
verify!(
@@ -86,16 +86,16 @@ pub fn verify_attestation_for_state<'ctxt, T: EthSpec>(
/// Check target epoch and source checkpoint.
///
/// Spec v0.12.1
fn verify_casper_ffg_vote<T: EthSpec>(
attestation: &Attestation<T>,
state: &BeaconState<T>,
fn verify_casper_ffg_vote<E: EthSpec>(
attestation: &Attestation<E>,
state: &BeaconState<E>,
) -> Result<()> {
let data = &attestation.data;
verify!(
data.target.epoch == data.slot.epoch(T::slots_per_epoch()),
data.target.epoch == data.slot.epoch(E::slots_per_epoch()),
Invalid::TargetEpochSlotMismatch {
target_epoch: data.target.epoch,
slot_epoch: data.slot.epoch(T::slots_per_epoch()),
slot_epoch: data.slot.epoch(E::slots_per_epoch()),
}
);
if data.target.epoch == state.current_epoch() {

View File

@@ -16,9 +16,9 @@ fn error(reason: Invalid) -> BlockOperationError<Invalid> {
/// Returns `Ok(indices)` with `indices` being a non-empty vec of validator indices in ascending
/// order if the `AttesterSlashing` is valid. Otherwise returns `Err(e)` with the reason for
/// invalidity.
pub fn verify_attester_slashing<T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing<T>,
pub fn verify_attester_slashing<E: EthSpec>(
state: &BeaconState<E>,
attester_slashing: &AttesterSlashing<E>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<Vec<u64>> {
@@ -43,9 +43,9 @@ pub fn verify_attester_slashing<T: EthSpec>(
/// For a given attester slashing, return the indices able to be slashed in ascending order.
///
/// Returns Ok(indices) if `indices.len() > 0`
pub fn get_slashable_indices<T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing<T>,
pub fn get_slashable_indices<E: EthSpec>(
state: &BeaconState<E>,
attester_slashing: &AttesterSlashing<E>,
) -> Result<Vec<u64>> {
get_slashable_indices_modular(state, attester_slashing, |_, validator| {
validator.is_slashable_at(state.current_epoch())
@@ -54,9 +54,9 @@ pub fn get_slashable_indices<T: EthSpec>(
/// Same as `gather_attester_slashing_indices` but allows the caller to specify the criteria
/// for determining whether a given validator should be considered slashable.
pub fn get_slashable_indices_modular<F, T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing<T>,
pub fn get_slashable_indices_modular<F, E: EthSpec>(
state: &BeaconState<E>,
attester_slashing: &AttesterSlashing<E>,
is_slashable: F,
) -> Result<Vec<u64>>
where

View File

@@ -14,8 +14,8 @@ fn error(reason: Invalid) -> BlockOperationError<Invalid> {
/// where the block is being applied to the given `state`.
///
/// Returns `Ok(())` if the `SignedBlsToExecutionChange` is valid, otherwise indicates the reason for invalidity.
pub fn verify_bls_to_execution_change<T: EthSpec>(
state: &BeaconState<T>,
pub fn verify_bls_to_execution_change<E: EthSpec>(
state: &BeaconState<E>,
signed_address_change: &SignedBlsToExecutionChange,
verify_signatures: VerifySignatures,
spec: &ChainSpec,

View File

@@ -30,8 +30,8 @@ pub fn verify_deposit_signature(deposit_data: &DepositData, spec: &ChainSpec) ->
/// otherwise returns `None`.
///
/// Builds the pubkey cache if it is not already built.
pub fn get_existing_validator_index<T: EthSpec>(
state: &mut BeaconState<T>,
pub fn get_existing_validator_index<E: EthSpec>(
state: &mut BeaconState<E>,
pub_key: &PublicKeyBytes,
) -> Result<Option<u64>> {
let validator_index = state.get_validator_index(pub_key)?;
@@ -44,8 +44,8 @@ pub fn get_existing_validator_index<T: EthSpec>(
/// before they're due to be processed, and in parallel.
///
/// Spec v0.12.1
pub fn verify_deposit_merkle_proof<T: EthSpec>(
state: &BeaconState<T>,
pub fn verify_deposit_merkle_proof<E: EthSpec>(
state: &BeaconState<E>,
deposit: &Deposit,
deposit_index: u64,
spec: &ChainSpec,

View File

@@ -18,8 +18,8 @@ fn error(reason: ExitInvalid) -> BlockOperationError<ExitInvalid> {
/// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.12.1
pub fn verify_exit<T: EthSpec>(
state: &BeaconState<T>,
pub fn verify_exit<E: EthSpec>(
state: &BeaconState<E>,
current_epoch: Option<Epoch>,
signed_exit: &SignedVoluntaryExit,
verify_signatures: VerifySignatures,

View File

@@ -15,9 +15,9 @@ fn error(reason: Invalid) -> BlockOperationError<Invalid> {
/// Returns `Ok(())` if the `ProposerSlashing` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.12.1
pub fn verify_proposer_slashing<T: EthSpec>(
pub fn verify_proposer_slashing<E: EthSpec>(
proposer_slashing: &ProposerSlashing,
state: &BeaconState<T>,
state: &BeaconState<E>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<()> {