From c0593a2721f4e3132ae9874a7d104c3e3d4477dd Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 25 Mar 2024 12:49:01 -0600 Subject: [PATCH 1/6] Refactor `Executor` to use polymorphic types --- .../src/state_transition/beacon_block.rs | 227 ------------ .../src/state_transition/beacon_state.rs | 323 ------------------ .../src/state_transition/executor.rs | 54 ++- .../src/state_transition/mod.rs | 4 - .../src/state_transition/presets/mainnet.rs | 7 +- .../src/state_transition/presets/minimal.rs | 7 +- 6 files changed, 62 insertions(+), 560 deletions(-) delete mode 100644 ethereum-consensus/src/state_transition/beacon_block.rs delete mode 100644 ethereum-consensus/src/state_transition/beacon_state.rs diff --git a/ethereum-consensus/src/state_transition/beacon_block.rs b/ethereum-consensus/src/state_transition/beacon_block.rs deleted file mode 100644 index da84d2388..000000000 --- a/ethereum-consensus/src/state_transition/beacon_block.rs +++ /dev/null @@ -1,227 +0,0 @@ -/// This module contains "wrapper" types for beacon blocks so that -/// the state transition machinery can be polymorphic with respect to forks. -use crate::altair; -use crate::{bellatrix, phase0}; - -#[derive(Debug)] -pub enum SignedBeaconBlock< - const MAX_PROPOSER_SLASHINGS: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const MAX_ATTESTER_SLASHINGS: usize, - const MAX_ATTESTATIONS: usize, - const MAX_DEPOSITS: usize, - const MAX_VOLUNTARY_EXITS: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, -> { - Phase0( - Box< - phase0::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - >, - >, - ), - Altair( - Box< - altair::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - >, - >, - ), - Bellatrix( - Box< - bellatrix::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - >, - >, - ), -} - -impl< - const MAX_PROPOSER_SLASHINGS: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const MAX_ATTESTER_SLASHINGS: usize, - const MAX_ATTESTATIONS: usize, - const MAX_DEPOSITS: usize, - const MAX_VOLUNTARY_EXITS: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - > - From< - phase0::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - >, - > - for SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - > -{ - fn from( - block: phase0::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - >, - ) -> Self { - Self::Phase0(Box::new(block)) - } -} - -impl< - const MAX_PROPOSER_SLASHINGS: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const MAX_ATTESTER_SLASHINGS: usize, - const MAX_ATTESTATIONS: usize, - const MAX_DEPOSITS: usize, - const MAX_VOLUNTARY_EXITS: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - > - From< - altair::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - >, - > - for SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - > -{ - fn from( - block: altair::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - >, - ) -> Self { - Self::Altair(Box::new(block)) - } -} - -impl< - const MAX_PROPOSER_SLASHINGS: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const MAX_ATTESTER_SLASHINGS: usize, - const MAX_ATTESTATIONS: usize, - const MAX_DEPOSITS: usize, - const MAX_VOLUNTARY_EXITS: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - > - From< - bellatrix::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - >, - > - for SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - > -{ - fn from( - block: bellatrix::SignedBeaconBlock< - MAX_PROPOSER_SLASHINGS, - MAX_VALIDATORS_PER_COMMITTEE, - MAX_ATTESTER_SLASHINGS, - MAX_ATTESTATIONS, - MAX_DEPOSITS, - MAX_VOLUNTARY_EXITS, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - >, - ) -> Self { - Self::Bellatrix(Box::new(block)) - } -} diff --git a/ethereum-consensus/src/state_transition/beacon_state.rs b/ethereum-consensus/src/state_transition/beacon_state.rs deleted file mode 100644 index 1bf4bc82f..000000000 --- a/ethereum-consensus/src/state_transition/beacon_state.rs +++ /dev/null @@ -1,323 +0,0 @@ -/// This module contains "wrapper" types for beacon states so that -/// the state transition machinery can be polymorphic with respect to forks. -use crate::altair; -use crate::{bellatrix, phase0}; - -#[derive(Debug)] -pub enum BeaconState< - const SLOTS_PER_HISTORICAL_ROOT: usize, - const HISTORICAL_ROOTS_LIMIT: usize, - const ETH1_DATA_VOTES_BOUND: usize, - const VALIDATOR_REGISTRY_LIMIT: usize, - const EPOCHS_PER_HISTORICAL_VECTOR: usize, - const EPOCHS_PER_SLASHINGS_VECTOR: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const PENDING_ATTESTATIONS_BOUND: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, -> { - Phase0( - Box< - phase0::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - >, - >, - ), - Altair( - Box< - altair::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - >, - >, - ), - Bellatrix( - Box< - bellatrix::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - >, - >, - ), -} - -impl< - const SLOTS_PER_HISTORICAL_ROOT: usize, - const HISTORICAL_ROOTS_LIMIT: usize, - const ETH1_DATA_VOTES_BOUND: usize, - const VALIDATOR_REGISTRY_LIMIT: usize, - const EPOCHS_PER_HISTORICAL_VECTOR: usize, - const EPOCHS_PER_SLASHINGS_VECTOR: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const PENDING_ATTESTATIONS_BOUND: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - > - From< - phase0::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - >, - > - for BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - > -{ - fn from( - state: phase0::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - >, - ) -> Self { - Self::Phase0(Box::new(state)) - } -} - -impl< - const SLOTS_PER_HISTORICAL_ROOT: usize, - const HISTORICAL_ROOTS_LIMIT: usize, - const ETH1_DATA_VOTES_BOUND: usize, - const VALIDATOR_REGISTRY_LIMIT: usize, - const EPOCHS_PER_HISTORICAL_VECTOR: usize, - const EPOCHS_PER_SLASHINGS_VECTOR: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const PENDING_ATTESTATIONS_BOUND: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - > - From< - altair::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - >, - > - for BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - > -{ - fn from( - state: altair::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - >, - ) -> Self { - Self::Altair(Box::new(state)) - } -} - -impl< - const SLOTS_PER_HISTORICAL_ROOT: usize, - const HISTORICAL_ROOTS_LIMIT: usize, - const ETH1_DATA_VOTES_BOUND: usize, - const VALIDATOR_REGISTRY_LIMIT: usize, - const EPOCHS_PER_HISTORICAL_VECTOR: usize, - const EPOCHS_PER_SLASHINGS_VECTOR: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const PENDING_ATTESTATIONS_BOUND: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - > - From< - bellatrix::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - >, - > - for BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - > -{ - fn from( - state: bellatrix::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - >, - ) -> Self { - Self::Bellatrix(Box::new(state)) - } -} - -impl< - const SLOTS_PER_HISTORICAL_ROOT: usize, - const HISTORICAL_ROOTS_LIMIT: usize, - const ETH1_DATA_VOTES_BOUND: usize, - const VALIDATOR_REGISTRY_LIMIT: usize, - const EPOCHS_PER_HISTORICAL_VECTOR: usize, - const EPOCHS_PER_SLASHINGS_VECTOR: usize, - const MAX_VALIDATORS_PER_COMMITTEE: usize, - const PENDING_ATTESTATIONS_BOUND: usize, - const SYNC_COMMITTEE_SIZE: usize, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - > - BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - > -{ - pub fn phase0( - self, - ) -> Option< - phase0::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - PENDING_ATTESTATIONS_BOUND, - >, - > { - match self { - Self::Phase0(state) => Some(*state), - _ => None, - } - } - - pub fn altair( - self, - ) -> Option< - altair::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - >, - > { - match self { - Self::Altair(state) => Some(*state), - _ => None, - } - } - - pub fn bellatrix( - self, - ) -> Option< - bellatrix::BeaconState< - SLOTS_PER_HISTORICAL_ROOT, - HISTORICAL_ROOTS_LIMIT, - ETH1_DATA_VOTES_BOUND, - VALIDATOR_REGISTRY_LIMIT, - EPOCHS_PER_HISTORICAL_VECTOR, - EPOCHS_PER_SLASHINGS_VECTOR, - MAX_VALIDATORS_PER_COMMITTEE, - SYNC_COMMITTEE_SIZE, - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - >, - > { - match self { - Self::Bellatrix(state) => Some(*state), - _ => None, - } - } -} diff --git a/ethereum-consensus/src/state_transition/executor.rs b/ethereum-consensus/src/state_transition/executor.rs index b767c359c..d6ed2dad4 100644 --- a/ethereum-consensus/src/state_transition/executor.rs +++ b/ethereum-consensus/src/state_transition/executor.rs @@ -1,6 +1,7 @@ use crate::{ altair, bellatrix, phase0, - state_transition::{BeaconState, Context, Result, SignedBeaconBlock, Validation}, + state_transition::{Context, Result, Validation}, + types::{BeaconState, SignedBeaconBlock}, Error, Fork, }; @@ -23,6 +24,9 @@ pub struct Executor< const MAX_ATTESTATIONS: usize, const MAX_DEPOSITS: usize, const MAX_VOLUNTARY_EXITS: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, + const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize, > { pub state: BeaconState< SLOTS_PER_HISTORICAL_ROOT, @@ -59,6 +63,9 @@ impl< const MAX_ATTESTATIONS: usize, const MAX_DEPOSITS: usize, const MAX_VOLUNTARY_EXITS: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, + const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize, > Executor< SLOTS_PER_HISTORICAL_ROOT, @@ -79,6 +86,9 @@ impl< MAX_ATTESTATIONS, MAX_DEPOSITS, MAX_VOLUNTARY_EXITS, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_BLOB_COMMITMENTS_PER_BLOCK, > { pub fn new( @@ -114,6 +124,9 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_BLOB_COMMITMENTS_PER_BLOCK, >, ) -> Result<()> { self.apply_block_with_validation(signed_block, Validation::Enabled) @@ -133,6 +146,9 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_BLOB_COMMITMENTS_PER_BLOCK, >, validation: Validation, ) -> Result<()> { @@ -146,6 +162,12 @@ impl< SignedBeaconBlock::Bellatrix(signed_block) => { self.apply_bellatrix_block_with_validation(signed_block, validation) } + SignedBeaconBlock::Capella(_) => { + todo!() + } + SignedBeaconBlock::Deneb(_) => { + todo!() + } } } @@ -173,6 +195,14 @@ impl< source_fork: Fork::Bellatrix, destination_fork: Fork::Phase0, }), + BeaconState::Capella(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Capella, + destination_fork: Fork::Phase0, + }), + BeaconState::Deneb(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Deneb, + destination_fork: Fork::Phase0, + }), } } @@ -204,7 +234,7 @@ impl< } else { altair::state_transition(&mut state, signed_block, validation, &self.context)?; } - self.state = state.into(); + self.state = BeaconState::Altair(state); Ok(()) } BeaconState::Altair(state) => { @@ -214,6 +244,14 @@ impl< source_fork: Fork::Bellatrix, destination_fork: Fork::Altair, }), + BeaconState::Capella(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Capella, + destination_fork: Fork::Altair, + }), + BeaconState::Deneb(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Deneb, + destination_fork: Fork::Altair, + }), } } @@ -258,7 +296,7 @@ impl< &self.context, )?; } - self.state = state.into(); + self.state = BeaconState::Bellatrix(state); Ok(()) } BeaconState::Altair(state) => { @@ -280,12 +318,20 @@ impl< &self.context, )?; } - self.state = state.into(); + self.state = BeaconState::Bellatrix(state); Ok(()) } BeaconState::Bellatrix(state) => { bellatrix::state_transition(state, signed_block, validation, &self.context) } + BeaconState::Capella(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Capella, + destination_fork: Fork::Bellatrix, + }), + BeaconState::Deneb(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Deneb, + destination_fork: Fork::Bellatrix, + }), } } } diff --git a/ethereum-consensus/src/state_transition/mod.rs b/ethereum-consensus/src/state_transition/mod.rs index 99e3cd918..579b3c597 100644 --- a/ethereum-consensus/src/state_transition/mod.rs +++ b/ethereum-consensus/src/state_transition/mod.rs @@ -1,11 +1,7 @@ -mod beacon_block; -mod beacon_state; mod context; mod executor; mod presets; -pub use beacon_block::*; -pub use beacon_state::*; pub use context::*; pub use executor::*; diff --git a/ethereum-consensus/src/state_transition/presets/mainnet.rs b/ethereum-consensus/src/state_transition/presets/mainnet.rs index 895d87fe3..a3799fef4 100644 --- a/ethereum-consensus/src/state_transition/presets/mainnet.rs +++ b/ethereum-consensus/src/state_transition/presets/mainnet.rs @@ -4,6 +4,8 @@ use crate::{ BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, }, + capella::mainnet::{MAX_BLS_TO_EXECUTION_CHANGES, MAX_WITHDRAWALS_PER_PAYLOAD}, + deneb::mainnet::MAX_BLOB_COMMITMENTS_PER_BLOCK, phase0::mainnet::{ EPOCHS_PER_HISTORICAL_VECTOR, EPOCHS_PER_SLASHINGS_VECTOR, ETH1_DATA_VOTES_BOUND, HISTORICAL_ROOTS_LIMIT, MAX_ATTESTATIONS, MAX_ATTESTER_SLASHINGS, MAX_DEPOSITS, @@ -14,7 +16,7 @@ use crate::{ }; pub use crate::Error; -pub use state_transition::{BeaconState, Context, SignedBeaconBlock, Validation}; +pub use state_transition::{Context, Validation}; pub type Executor = state_transition::Executor< SLOTS_PER_HISTORICAL_ROOT, @@ -35,4 +37,7 @@ pub type Executor = state_transition::Executor< MAX_ATTESTATIONS, MAX_DEPOSITS, MAX_VOLUNTARY_EXITS, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_BLOB_COMMITMENTS_PER_BLOCK, >; diff --git a/ethereum-consensus/src/state_transition/presets/minimal.rs b/ethereum-consensus/src/state_transition/presets/minimal.rs index 41723d7d0..02b5b5b8b 100644 --- a/ethereum-consensus/src/state_transition/presets/minimal.rs +++ b/ethereum-consensus/src/state_transition/presets/minimal.rs @@ -4,6 +4,8 @@ use crate::{ BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, }, + capella::minimal::{MAX_BLS_TO_EXECUTION_CHANGES, MAX_WITHDRAWALS_PER_PAYLOAD}, + deneb::minimal::MAX_BLOB_COMMITMENTS_PER_BLOCK, phase0::minimal::{ EPOCHS_PER_HISTORICAL_VECTOR, EPOCHS_PER_SLASHINGS_VECTOR, ETH1_DATA_VOTES_BOUND, HISTORICAL_ROOTS_LIMIT, MAX_ATTESTATIONS, MAX_ATTESTER_SLASHINGS, MAX_DEPOSITS, @@ -14,7 +16,7 @@ use crate::{ }; pub use crate::Error; -pub use state_transition::{BeaconState, Context, SignedBeaconBlock, Validation}; +pub use state_transition::{Context, Validation}; pub type Executor = state_transition::Executor< SLOTS_PER_HISTORICAL_ROOT, @@ -35,4 +37,7 @@ pub type Executor = state_transition::Executor< MAX_ATTESTATIONS, MAX_DEPOSITS, MAX_VOLUNTARY_EXITS, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_BLOB_COMMITMENTS_PER_BLOCK, >; From 289a8b4284892a5dde9ce3943f19ff263d0c7d39 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 25 Mar 2024 14:25:59 -0600 Subject: [PATCH 2/6] bugfix: type-gen with mutable refs and copy types --- ethereum-consensus/src/types/beacon_block.rs | 72 +++++++++++ ethereum-consensus/src/types/beacon_state.rs | 108 +++++++++++++++++ .../src/types/blinded_beacon_block.rs | 56 +++++++++ .../src/types/execution_payload.rs | 84 +++++++++++++ .../src/types/execution_payload_header.rs | 112 ++++++++++++++++++ spec-gen/src/type_generator.rs | 12 +- 6 files changed, 437 insertions(+), 7 deletions(-) diff --git a/ethereum-consensus/src/types/beacon_block.rs b/ethereum-consensus/src/types/beacon_block.rs index 5f0e0281c..ab0cfd495 100644 --- a/ethereum-consensus/src/types/beacon_block.rs +++ b/ethereum-consensus/src/types/beacon_block.rs @@ -364,6 +364,15 @@ impl< Self::Deneb(inner) => inner.slot, } } + pub fn slot_mut(&mut self) -> &mut Slot { + match self { + Self::Phase0(inner) => &mut inner.slot, + Self::Altair(inner) => &mut inner.slot, + Self::Bellatrix(inner) => &mut inner.slot, + Self::Capella(inner) => &mut inner.slot, + Self::Deneb(inner) => &mut inner.slot, + } + } pub fn proposer_index(&self) -> ValidatorIndex { match self { Self::Phase0(inner) => inner.proposer_index, @@ -373,6 +382,15 @@ impl< Self::Deneb(inner) => inner.proposer_index, } } + pub fn proposer_index_mut(&mut self) -> &mut ValidatorIndex { + match self { + Self::Phase0(inner) => &mut inner.proposer_index, + Self::Altair(inner) => &mut inner.proposer_index, + Self::Bellatrix(inner) => &mut inner.proposer_index, + Self::Capella(inner) => &mut inner.proposer_index, + Self::Deneb(inner) => &mut inner.proposer_index, + } + } pub fn parent_root(&self) -> Root { match self { Self::Phase0(inner) => inner.parent_root, @@ -382,6 +400,15 @@ impl< Self::Deneb(inner) => inner.parent_root, } } + pub fn parent_root_mut(&mut self) -> &mut Root { + match self { + Self::Phase0(inner) => &mut inner.parent_root, + Self::Altair(inner) => &mut inner.parent_root, + Self::Bellatrix(inner) => &mut inner.parent_root, + Self::Capella(inner) => &mut inner.parent_root, + Self::Deneb(inner) => &mut inner.parent_root, + } + } pub fn state_root(&self) -> Root { match self { Self::Phase0(inner) => inner.state_root, @@ -391,6 +418,15 @@ impl< Self::Deneb(inner) => inner.state_root, } } + pub fn state_root_mut(&mut self) -> &mut Root { + match self { + Self::Phase0(inner) => &mut inner.state_root, + Self::Altair(inner) => &mut inner.state_root, + Self::Bellatrix(inner) => &mut inner.state_root, + Self::Capella(inner) => &mut inner.state_root, + Self::Deneb(inner) => &mut inner.state_root, + } + } pub fn body( &self, ) -> BeaconBlockBodyRef< @@ -1492,6 +1528,15 @@ impl< Self::Deneb(inner) => inner.slot, } } + pub fn slot_mut(&mut self) -> &mut Slot { + match self { + Self::Phase0(inner) => &mut inner.slot, + Self::Altair(inner) => &mut inner.slot, + Self::Bellatrix(inner) => &mut inner.slot, + Self::Capella(inner) => &mut inner.slot, + Self::Deneb(inner) => &mut inner.slot, + } + } pub fn proposer_index(&self) -> ValidatorIndex { match self { Self::Phase0(inner) => inner.proposer_index, @@ -1501,6 +1546,15 @@ impl< Self::Deneb(inner) => inner.proposer_index, } } + pub fn proposer_index_mut(&mut self) -> &mut ValidatorIndex { + match self { + Self::Phase0(inner) => &mut inner.proposer_index, + Self::Altair(inner) => &mut inner.proposer_index, + Self::Bellatrix(inner) => &mut inner.proposer_index, + Self::Capella(inner) => &mut inner.proposer_index, + Self::Deneb(inner) => &mut inner.proposer_index, + } + } pub fn parent_root(&self) -> Root { match self { Self::Phase0(inner) => inner.parent_root, @@ -1510,6 +1564,15 @@ impl< Self::Deneb(inner) => inner.parent_root, } } + pub fn parent_root_mut(&mut self) -> &mut Root { + match self { + Self::Phase0(inner) => &mut inner.parent_root, + Self::Altair(inner) => &mut inner.parent_root, + Self::Bellatrix(inner) => &mut inner.parent_root, + Self::Capella(inner) => &mut inner.parent_root, + Self::Deneb(inner) => &mut inner.parent_root, + } + } pub fn state_root(&self) -> Root { match self { Self::Phase0(inner) => inner.state_root, @@ -1519,6 +1582,15 @@ impl< Self::Deneb(inner) => inner.state_root, } } + pub fn state_root_mut(&mut self) -> &mut Root { + match self { + Self::Phase0(inner) => &mut inner.state_root, + Self::Altair(inner) => &mut inner.state_root, + Self::Bellatrix(inner) => &mut inner.state_root, + Self::Capella(inner) => &mut inner.state_root, + Self::Deneb(inner) => &mut inner.state_root, + } + } pub fn body( &self, ) -> BeaconBlockBodyRef< diff --git a/ethereum-consensus/src/types/beacon_state.rs b/ethereum-consensus/src/types/beacon_state.rs index b975020d7..fc7a5a288 100644 --- a/ethereum-consensus/src/types/beacon_state.rs +++ b/ethereum-consensus/src/types/beacon_state.rs @@ -346,6 +346,15 @@ impl< Self::Deneb(inner) => inner.genesis_time, } } + pub fn genesis_time_mut(&mut self) -> &mut u64 { + match self { + Self::Phase0(inner) => &mut inner.genesis_time, + Self::Altair(inner) => &mut inner.genesis_time, + Self::Bellatrix(inner) => &mut inner.genesis_time, + Self::Capella(inner) => &mut inner.genesis_time, + Self::Deneb(inner) => &mut inner.genesis_time, + } + } pub fn genesis_validators_root(&self) -> Root { match self { Self::Phase0(inner) => inner.genesis_validators_root, @@ -355,6 +364,15 @@ impl< Self::Deneb(inner) => inner.genesis_validators_root, } } + pub fn genesis_validators_root_mut(&mut self) -> &mut Root { + match self { + Self::Phase0(inner) => &mut inner.genesis_validators_root, + Self::Altair(inner) => &mut inner.genesis_validators_root, + Self::Bellatrix(inner) => &mut inner.genesis_validators_root, + Self::Capella(inner) => &mut inner.genesis_validators_root, + Self::Deneb(inner) => &mut inner.genesis_validators_root, + } + } pub fn slot(&self) -> Slot { match self { Self::Phase0(inner) => inner.slot, @@ -364,6 +382,15 @@ impl< Self::Deneb(inner) => inner.slot, } } + pub fn slot_mut(&mut self) -> &mut Slot { + match self { + Self::Phase0(inner) => &mut inner.slot, + Self::Altair(inner) => &mut inner.slot, + Self::Bellatrix(inner) => &mut inner.slot, + Self::Capella(inner) => &mut inner.slot, + Self::Deneb(inner) => &mut inner.slot, + } + } pub fn fork(&self) -> &Fork { match self { Self::Phase0(inner) => &inner.fork, @@ -499,6 +526,15 @@ impl< Self::Deneb(inner) => inner.eth1_deposit_index, } } + pub fn eth1_deposit_index_mut(&mut self) -> &mut u64 { + match self { + Self::Phase0(inner) => &mut inner.eth1_deposit_index, + Self::Altair(inner) => &mut inner.eth1_deposit_index, + Self::Bellatrix(inner) => &mut inner.eth1_deposit_index, + Self::Capella(inner) => &mut inner.eth1_deposit_index, + Self::Deneb(inner) => &mut inner.eth1_deposit_index, + } + } pub fn validators(&self) -> &List { match self { Self::Phase0(inner) => &inner.validators, @@ -824,6 +860,15 @@ impl< Self::Deneb(inner) => Some(inner.next_withdrawal_index), } } + pub fn next_withdrawal_index_mut(&mut self) -> Option<&mut WithdrawalIndex> { + match self { + Self::Phase0(_) => None, + Self::Altair(_) => None, + Self::Bellatrix(_) => None, + Self::Capella(inner) => Some(&mut inner.next_withdrawal_index), + Self::Deneb(inner) => Some(&mut inner.next_withdrawal_index), + } + } pub fn next_withdrawal_validator_index(&self) -> Option { match self { Self::Phase0(_) => None, @@ -833,6 +878,15 @@ impl< Self::Deneb(inner) => Some(inner.next_withdrawal_validator_index), } } + pub fn next_withdrawal_validator_index_mut(&mut self) -> Option<&mut ValidatorIndex> { + match self { + Self::Phase0(_) => None, + Self::Altair(_) => None, + Self::Bellatrix(_) => None, + Self::Capella(inner) => Some(&mut inner.next_withdrawal_validator_index), + Self::Deneb(inner) => Some(&mut inner.next_withdrawal_validator_index), + } + } pub fn historical_summaries(&self) -> Option<&List> { match self { Self::Phase0(_) => None, @@ -2033,6 +2087,15 @@ impl< Self::Deneb(inner) => inner.genesis_time, } } + pub fn genesis_time_mut(&mut self) -> &mut u64 { + match self { + Self::Phase0(inner) => &mut inner.genesis_time, + Self::Altair(inner) => &mut inner.genesis_time, + Self::Bellatrix(inner) => &mut inner.genesis_time, + Self::Capella(inner) => &mut inner.genesis_time, + Self::Deneb(inner) => &mut inner.genesis_time, + } + } pub fn genesis_validators_root(&self) -> Root { match self { Self::Phase0(inner) => inner.genesis_validators_root, @@ -2042,6 +2105,15 @@ impl< Self::Deneb(inner) => inner.genesis_validators_root, } } + pub fn genesis_validators_root_mut(&mut self) -> &mut Root { + match self { + Self::Phase0(inner) => &mut inner.genesis_validators_root, + Self::Altair(inner) => &mut inner.genesis_validators_root, + Self::Bellatrix(inner) => &mut inner.genesis_validators_root, + Self::Capella(inner) => &mut inner.genesis_validators_root, + Self::Deneb(inner) => &mut inner.genesis_validators_root, + } + } pub fn slot(&self) -> Slot { match self { Self::Phase0(inner) => inner.slot, @@ -2051,6 +2123,15 @@ impl< Self::Deneb(inner) => inner.slot, } } + pub fn slot_mut(&mut self) -> &mut Slot { + match self { + Self::Phase0(inner) => &mut inner.slot, + Self::Altair(inner) => &mut inner.slot, + Self::Bellatrix(inner) => &mut inner.slot, + Self::Capella(inner) => &mut inner.slot, + Self::Deneb(inner) => &mut inner.slot, + } + } pub fn fork(&self) -> &Fork { match self { Self::Phase0(inner) => &inner.fork, @@ -2186,6 +2267,15 @@ impl< Self::Deneb(inner) => inner.eth1_deposit_index, } } + pub fn eth1_deposit_index_mut(&mut self) -> &mut u64 { + match self { + Self::Phase0(inner) => &mut inner.eth1_deposit_index, + Self::Altair(inner) => &mut inner.eth1_deposit_index, + Self::Bellatrix(inner) => &mut inner.eth1_deposit_index, + Self::Capella(inner) => &mut inner.eth1_deposit_index, + Self::Deneb(inner) => &mut inner.eth1_deposit_index, + } + } pub fn validators(&self) -> &List { match self { Self::Phase0(inner) => &inner.validators, @@ -2511,6 +2601,15 @@ impl< Self::Deneb(inner) => Some(inner.next_withdrawal_index), } } + pub fn next_withdrawal_index_mut(&mut self) -> Option<&mut WithdrawalIndex> { + match self { + Self::Phase0(_) => None, + Self::Altair(_) => None, + Self::Bellatrix(_) => None, + Self::Capella(inner) => Some(&mut inner.next_withdrawal_index), + Self::Deneb(inner) => Some(&mut inner.next_withdrawal_index), + } + } pub fn next_withdrawal_validator_index(&self) -> Option { match self { Self::Phase0(_) => None, @@ -2520,6 +2619,15 @@ impl< Self::Deneb(inner) => Some(inner.next_withdrawal_validator_index), } } + pub fn next_withdrawal_validator_index_mut(&mut self) -> Option<&mut ValidatorIndex> { + match self { + Self::Phase0(_) => None, + Self::Altair(_) => None, + Self::Bellatrix(_) => None, + Self::Capella(inner) => Some(&mut inner.next_withdrawal_validator_index), + Self::Deneb(inner) => Some(&mut inner.next_withdrawal_validator_index), + } + } pub fn historical_summaries(&self) -> Option<&List> { match self { Self::Phase0(_) => None, diff --git a/ethereum-consensus/src/types/blinded_beacon_block.rs b/ethereum-consensus/src/types/blinded_beacon_block.rs index f3fc7a136..3663093fe 100644 --- a/ethereum-consensus/src/types/blinded_beacon_block.rs +++ b/ethereum-consensus/src/types/blinded_beacon_block.rs @@ -234,6 +234,13 @@ impl< Self::Deneb(inner) => inner.slot, } } + pub fn slot_mut(&mut self) -> &mut Slot { + match self { + Self::Bellatrix(inner) => &mut inner.slot, + Self::Capella(inner) => &mut inner.slot, + Self::Deneb(inner) => &mut inner.slot, + } + } pub fn proposer_index(&self) -> ValidatorIndex { match self { Self::Bellatrix(inner) => inner.proposer_index, @@ -241,6 +248,13 @@ impl< Self::Deneb(inner) => inner.proposer_index, } } + pub fn proposer_index_mut(&mut self) -> &mut ValidatorIndex { + match self { + Self::Bellatrix(inner) => &mut inner.proposer_index, + Self::Capella(inner) => &mut inner.proposer_index, + Self::Deneb(inner) => &mut inner.proposer_index, + } + } pub fn parent_root(&self) -> Root { match self { Self::Bellatrix(inner) => inner.parent_root, @@ -248,6 +262,13 @@ impl< Self::Deneb(inner) => inner.parent_root, } } + pub fn parent_root_mut(&mut self) -> &mut Root { + match self { + Self::Bellatrix(inner) => &mut inner.parent_root, + Self::Capella(inner) => &mut inner.parent_root, + Self::Deneb(inner) => &mut inner.parent_root, + } + } pub fn state_root(&self) -> Root { match self { Self::Bellatrix(inner) => inner.state_root, @@ -255,6 +276,13 @@ impl< Self::Deneb(inner) => inner.state_root, } } + pub fn state_root_mut(&mut self) -> &mut Root { + match self { + Self::Bellatrix(inner) => &mut inner.state_root, + Self::Capella(inner) => &mut inner.state_root, + Self::Deneb(inner) => &mut inner.state_root, + } + } pub fn body( &self, ) -> BlindedBeaconBlockBodyRef< @@ -958,6 +986,13 @@ impl< Self::Deneb(inner) => inner.slot, } } + pub fn slot_mut(&mut self) -> &mut Slot { + match self { + Self::Bellatrix(inner) => &mut inner.slot, + Self::Capella(inner) => &mut inner.slot, + Self::Deneb(inner) => &mut inner.slot, + } + } pub fn proposer_index(&self) -> ValidatorIndex { match self { Self::Bellatrix(inner) => inner.proposer_index, @@ -965,6 +1000,13 @@ impl< Self::Deneb(inner) => inner.proposer_index, } } + pub fn proposer_index_mut(&mut self) -> &mut ValidatorIndex { + match self { + Self::Bellatrix(inner) => &mut inner.proposer_index, + Self::Capella(inner) => &mut inner.proposer_index, + Self::Deneb(inner) => &mut inner.proposer_index, + } + } pub fn parent_root(&self) -> Root { match self { Self::Bellatrix(inner) => inner.parent_root, @@ -972,6 +1014,13 @@ impl< Self::Deneb(inner) => inner.parent_root, } } + pub fn parent_root_mut(&mut self) -> &mut Root { + match self { + Self::Bellatrix(inner) => &mut inner.parent_root, + Self::Capella(inner) => &mut inner.parent_root, + Self::Deneb(inner) => &mut inner.parent_root, + } + } pub fn state_root(&self) -> Root { match self { Self::Bellatrix(inner) => inner.state_root, @@ -979,6 +1028,13 @@ impl< Self::Deneb(inner) => inner.state_root, } } + pub fn state_root_mut(&mut self) -> &mut Root { + match self { + Self::Bellatrix(inner) => &mut inner.state_root, + Self::Capella(inner) => &mut inner.state_root, + Self::Deneb(inner) => &mut inner.state_root, + } + } pub fn body( &self, ) -> BlindedBeaconBlockBodyRef< diff --git a/ethereum-consensus/src/types/execution_payload.rs b/ethereum-consensus/src/types/execution_payload.rs index 6f3ac5356..76c890cd2 100644 --- a/ethereum-consensus/src/types/execution_payload.rs +++ b/ethereum-consensus/src/types/execution_payload.rs @@ -251,6 +251,13 @@ impl< Self::Deneb(inner) => inner.block_number, } } + pub fn block_number_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.block_number, + Self::Capella(inner) => &mut inner.block_number, + Self::Deneb(inner) => &mut inner.block_number, + } + } pub fn gas_limit(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_limit, @@ -258,6 +265,13 @@ impl< Self::Deneb(inner) => inner.gas_limit, } } + pub fn gas_limit_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_limit, + Self::Capella(inner) => &mut inner.gas_limit, + Self::Deneb(inner) => &mut inner.gas_limit, + } + } pub fn gas_used(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_used, @@ -265,6 +279,13 @@ impl< Self::Deneb(inner) => inner.gas_used, } } + pub fn gas_used_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_used, + Self::Capella(inner) => &mut inner.gas_used, + Self::Deneb(inner) => &mut inner.gas_used, + } + } pub fn timestamp(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.timestamp, @@ -272,6 +293,13 @@ impl< Self::Deneb(inner) => inner.timestamp, } } + pub fn timestamp_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.timestamp, + Self::Capella(inner) => &mut inner.timestamp, + Self::Deneb(inner) => &mut inner.timestamp, + } + } pub fn extra_data(&self) -> &ByteList { match self { Self::Bellatrix(inner) => &inner.extra_data, @@ -355,6 +383,13 @@ impl< Self::Deneb(inner) => Some(inner.blob_gas_used), } } + pub fn blob_gas_used_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.blob_gas_used), + } + } pub fn excess_blob_gas(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -362,6 +397,13 @@ impl< Self::Deneb(inner) => Some(inner.excess_blob_gas), } } + pub fn excess_blob_gas_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.excess_blob_gas), + } + } } impl< 'de, @@ -983,6 +1025,13 @@ impl< Self::Deneb(inner) => inner.block_number, } } + pub fn block_number_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.block_number, + Self::Capella(inner) => &mut inner.block_number, + Self::Deneb(inner) => &mut inner.block_number, + } + } pub fn gas_limit(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_limit, @@ -990,6 +1039,13 @@ impl< Self::Deneb(inner) => inner.gas_limit, } } + pub fn gas_limit_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_limit, + Self::Capella(inner) => &mut inner.gas_limit, + Self::Deneb(inner) => &mut inner.gas_limit, + } + } pub fn gas_used(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_used, @@ -997,6 +1053,13 @@ impl< Self::Deneb(inner) => inner.gas_used, } } + pub fn gas_used_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_used, + Self::Capella(inner) => &mut inner.gas_used, + Self::Deneb(inner) => &mut inner.gas_used, + } + } pub fn timestamp(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.timestamp, @@ -1004,6 +1067,13 @@ impl< Self::Deneb(inner) => inner.timestamp, } } + pub fn timestamp_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.timestamp, + Self::Capella(inner) => &mut inner.timestamp, + Self::Deneb(inner) => &mut inner.timestamp, + } + } pub fn extra_data(&self) -> &ByteList { match self { Self::Bellatrix(inner) => &inner.extra_data, @@ -1087,6 +1157,13 @@ impl< Self::Deneb(inner) => Some(inner.blob_gas_used), } } + pub fn blob_gas_used_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.blob_gas_used), + } + } pub fn excess_blob_gas(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -1094,6 +1171,13 @@ impl< Self::Deneb(inner) => Some(inner.excess_blob_gas), } } + pub fn excess_blob_gas_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.excess_blob_gas), + } + } } impl< 'a, diff --git a/ethereum-consensus/src/types/execution_payload_header.rs b/ethereum-consensus/src/types/execution_payload_header.rs index 249793ed1..63e455e98 100644 --- a/ethereum-consensus/src/types/execution_payload_header.rs +++ b/ethereum-consensus/src/types/execution_payload_header.rs @@ -171,6 +171,13 @@ impl Self::Deneb(inner) => inner.block_number, } } + pub fn block_number_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.block_number, + Self::Capella(inner) => &mut inner.block_number, + Self::Deneb(inner) => &mut inner.block_number, + } + } pub fn gas_limit(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_limit, @@ -178,6 +185,13 @@ impl Self::Deneb(inner) => inner.gas_limit, } } + pub fn gas_limit_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_limit, + Self::Capella(inner) => &mut inner.gas_limit, + Self::Deneb(inner) => &mut inner.gas_limit, + } + } pub fn gas_used(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_used, @@ -185,6 +199,13 @@ impl Self::Deneb(inner) => inner.gas_used, } } + pub fn gas_used_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_used, + Self::Capella(inner) => &mut inner.gas_used, + Self::Deneb(inner) => &mut inner.gas_used, + } + } pub fn timestamp(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.timestamp, @@ -192,6 +213,13 @@ impl Self::Deneb(inner) => inner.timestamp, } } + pub fn timestamp_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.timestamp, + Self::Capella(inner) => &mut inner.timestamp, + Self::Deneb(inner) => &mut inner.timestamp, + } + } pub fn extra_data(&self) -> &ByteList { match self { Self::Bellatrix(inner) => &inner.extra_data, @@ -241,6 +269,13 @@ impl Self::Deneb(inner) => inner.transactions_root, } } + pub fn transactions_root_mut(&mut self) -> &mut Root { + match self { + Self::Bellatrix(inner) => &mut inner.transactions_root, + Self::Capella(inner) => &mut inner.transactions_root, + Self::Deneb(inner) => &mut inner.transactions_root, + } + } pub fn withdrawals_root(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -248,6 +283,13 @@ impl Self::Deneb(inner) => Some(inner.withdrawals_root), } } + pub fn withdrawals_root_mut(&mut self) -> Option<&mut Root> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(inner) => Some(&mut inner.withdrawals_root), + Self::Deneb(inner) => Some(&mut inner.withdrawals_root), + } + } pub fn blob_gas_used(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -255,6 +297,13 @@ impl Self::Deneb(inner) => Some(inner.blob_gas_used), } } + pub fn blob_gas_used_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.blob_gas_used), + } + } pub fn excess_blob_gas(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -262,6 +311,13 @@ impl Self::Deneb(inner) => Some(inner.excess_blob_gas), } } + pub fn excess_blob_gas_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.excess_blob_gas), + } + } } impl<'de, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> serde::Deserialize<'de> for ExecutionPayloadHeader @@ -644,6 +700,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => inner.block_number, } } + pub fn block_number_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.block_number, + Self::Capella(inner) => &mut inner.block_number, + Self::Deneb(inner) => &mut inner.block_number, + } + } pub fn gas_limit(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_limit, @@ -651,6 +714,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => inner.gas_limit, } } + pub fn gas_limit_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_limit, + Self::Capella(inner) => &mut inner.gas_limit, + Self::Deneb(inner) => &mut inner.gas_limit, + } + } pub fn gas_used(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.gas_used, @@ -658,6 +728,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => inner.gas_used, } } + pub fn gas_used_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.gas_used, + Self::Capella(inner) => &mut inner.gas_used, + Self::Deneb(inner) => &mut inner.gas_used, + } + } pub fn timestamp(&self) -> u64 { match self { Self::Bellatrix(inner) => inner.timestamp, @@ -665,6 +742,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => inner.timestamp, } } + pub fn timestamp_mut(&mut self) -> &mut u64 { + match self { + Self::Bellatrix(inner) => &mut inner.timestamp, + Self::Capella(inner) => &mut inner.timestamp, + Self::Deneb(inner) => &mut inner.timestamp, + } + } pub fn extra_data(&self) -> &ByteList { match self { Self::Bellatrix(inner) => &inner.extra_data, @@ -714,6 +798,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => inner.transactions_root, } } + pub fn transactions_root_mut(&mut self) -> &mut Root { + match self { + Self::Bellatrix(inner) => &mut inner.transactions_root, + Self::Capella(inner) => &mut inner.transactions_root, + Self::Deneb(inner) => &mut inner.transactions_root, + } + } pub fn withdrawals_root(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -721,6 +812,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => Some(inner.withdrawals_root), } } + pub fn withdrawals_root_mut(&mut self) -> Option<&mut Root> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(inner) => Some(&mut inner.withdrawals_root), + Self::Deneb(inner) => Some(&mut inner.withdrawals_root), + } + } pub fn blob_gas_used(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -728,6 +826,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => Some(inner.blob_gas_used), } } + pub fn blob_gas_used_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.blob_gas_used), + } + } pub fn excess_blob_gas(&self) -> Option { match self { Self::Bellatrix(_) => None, @@ -735,6 +840,13 @@ impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> Self::Deneb(inner) => Some(inner.excess_blob_gas), } } + pub fn excess_blob_gas_mut(&mut self) -> Option<&mut u64> { + match self { + Self::Bellatrix(_) => None, + Self::Capella(_) => None, + Self::Deneb(inner) => Some(&mut inner.excess_blob_gas), + } + } } impl<'a, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> From<&'a mut bellatrix::ExecutionPayloadHeader> diff --git a/spec-gen/src/type_generator.rs b/spec-gen/src/type_generator.rs index 8a4bd0672..3ce29a11f 100644 --- a/spec-gen/src/type_generator.rs +++ b/spec-gen/src/type_generator.rs @@ -467,9 +467,8 @@ fn derive_method_set( } } else { let type_def = &field_defn.type_def; - let ref_item: Option = - if is_type_copy { None } else { Some(parse_quote!(&)) }; - let mutability = if is_type_copy { None } else { Some(Mut::default()) }; + let ref_item: syn::Token!(&) = parse_quote!(&); + let mutability = Mut::default(); parse_quote! { #ref_item #mutability #type_def } @@ -482,7 +481,8 @@ fn derive_method_set( true, is_polymorphic, is_optional, - is_type_copy, + // NOTE: make this false so we generate mutable refs, rather than just a copy + false, deletion_fork, ); let mut_ref = parse_quote! { @@ -496,9 +496,7 @@ fn derive_method_set( Some(RefType::Immutable) => vec![immut_ref], Some(RefType::Mutable) | None => { let mut result = vec![immut_ref]; - if !is_type_copy { - result.push(mut_ref); - } + result.push(mut_ref); result } } From 8c9dd26928103a61eb4bd73b380d064702bf56ec Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 25 Mar 2024 14:33:19 -0600 Subject: [PATCH 3/6] fix example for latest `Executor` --- .../state_transition_across_multiple_forks.rs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ethereum-consensus/examples/state_transition_across_multiple_forks.rs b/ethereum-consensus/examples/state_transition_across_multiple_forks.rs index 5f5a2c914..390707846 100644 --- a/ethereum-consensus/examples/state_transition_across_multiple_forks.rs +++ b/ethereum-consensus/examples/state_transition_across_multiple_forks.rs @@ -1,33 +1,33 @@ use ethereum_consensus::{ - altair::mainnet as altair, - bellatrix::mainnet as bellatrix, - phase0::mainnet as phase0, ssz::prelude::*, state_transition::mainnet::{Context, Executor}, + types::mainnet::{BeaconState, SignedBeaconBlock}, }; use std::error::Error; fn main() -> std::result::Result<(), Box> { - println!("this example is for illustration purposes..."); - println!("to get to the end, we need utilities to make correct blocks with respect to the state transition"); + println!("this example illustrates how to use the codebase when applying state transitions"); + println!("note: the code currently does not run to the end as the input data is not correct"); - let genesis_state = phase0::BeaconState::default(); + let genesis_state = BeaconState::Phase0(Default::default()); let context = Context::for_mainnet(); - let mut executor = Executor::new(genesis_state.into(), context); + let mut executor = Executor::new(genesis_state, context); - let mut block = phase0::SignedBeaconBlock::default(); - block.message.slot = 1; - executor.apply_block(&mut block.into())?; + let mut block = SignedBeaconBlock::Phase0(Default::default()); + *block.message_mut().slot_mut() = 1; + executor.apply_block(&mut block)?; - let mut block = altair::SignedBeaconBlock::default(); - block.message.slot = executor.context.altair_fork_epoch * executor.context.slots_per_epoch; - executor.apply_block(&mut block.into())?; + let mut block = SignedBeaconBlock::Altair(Default::default()); + *block.message_mut().slot_mut() = + executor.context.altair_fork_epoch * executor.context.slots_per_epoch; + executor.apply_block(&mut block)?; - let mut block = bellatrix::SignedBeaconBlock::default(); - block.message.slot = executor.context.bellatrix_fork_epoch * executor.context.slots_per_epoch; - executor.apply_block(&mut block.into())?; + let mut block = SignedBeaconBlock::Bellatrix(Default::default()); + *block.message_mut().slot_mut() = + executor.context.bellatrix_fork_epoch * executor.context.slots_per_epoch; + executor.apply_block(&mut block)?; - let mut state = executor.state.bellatrix().unwrap(); + let state = executor.state.bellatrix_mut().unwrap(); let state_root = state.hash_tree_root()?; dbg!(state_root); Ok(()) From 72eafc863f2c5ebd319d9fddeb5d5347b009d588 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 25 Mar 2024 14:45:50 -0600 Subject: [PATCH 4/6] impl `transition` tests --- spec-tests/runners/transition.rs | 196 +++++++++++++++++++------------ 1 file changed, 119 insertions(+), 77 deletions(-) diff --git a/spec-tests/runners/transition.rs b/spec-tests/runners/transition.rs index 8dc491dda..26c00fe55 100644 --- a/spec-tests/runners/transition.rs +++ b/spec-tests/runners/transition.rs @@ -4,7 +4,11 @@ use crate::{ test_meta::{Config, Fork}, test_utils::{load_snappy_ssz, load_yaml, Error}, }; -use ethereum_consensus::{primitives::Epoch, state_transition::Context}; +use ethereum_consensus::{ + primitives::Epoch, + state_transition::{self, Context}, + types::{BeaconState, SignedBeaconBlock}, +}; use serde::Deserialize; #[derive(Deserialize)] @@ -54,78 +58,22 @@ fn load_test< (pre, post, pre_blocks, post_blocks, meta) } -fn run_test( - _pre: S, - _expected: T, - mut _pre_blocks: Vec, - mut _post_blocks: Vec, - meta: &Meta, - _context: &Context, -) -> Result<(), Error> { - todo!( - "read for now to silence warning... {} {}", - meta.post_fork, - meta.fork_epoch, - /* - let mut context = $context.clone(); - let meta = $meta; - match meta.post_fork.as_ref() { - "altair" => { - context.altair_fork_epoch = meta.fork_epoch; - context.bellatrix_fork_epoch = Epoch::MAX; - } - "bellatrix" => { - context.altair_fork_epoch = 0; - context.bellatrix_fork_epoch = meta.fork_epoch; - todo!("set other epochs?"); - } - _ => todo!(), - } - let execution_engine = ethereum_consensus::bellatrix::DefaultExecutionEngine::default(); - let mut executor = Executor::< - { spec::SLOTS_PER_HISTORICAL_ROOT }, - { spec::HISTORICAL_ROOTS_LIMIT }, - { spec::ETH1_DATA_VOTES_BOUND }, - { spec::VALIDATOR_REGISTRY_LIMIT }, - { spec::EPOCHS_PER_HISTORICAL_VECTOR }, - { spec::EPOCHS_PER_SLASHINGS_VECTOR }, - { spec::MAX_VALIDATORS_PER_COMMITTEE }, - { phase0_spec::PENDING_ATTESTATIONS_BOUND }, - { spec::SYNC_COMMITTEE_SIZE }, - { bellatrix_spec::BYTES_PER_LOGS_BLOOM }, - { bellatrix_spec::MAX_EXTRA_DATA_BYTES }, - { bellatrix_spec::MAX_BYTES_PER_TRANSACTION }, - { bellatrix_spec::MAX_TRANSACTIONS_PER_PAYLOAD }, - { spec::MAX_PROPOSER_SLASHINGS }, - { spec::MAX_ATTESTER_SLASHINGS }, - { spec::MAX_ATTESTATIONS }, - { spec::MAX_DEPOSITS }, - { spec::MAX_VOLUNTARY_EXITS }, - ethereum_consensus::bellatrix::DefaultExecutionEngine, - >::new($pre.into(), execution_engine.into(), context); - for block in $pre_blocks.into_iter() { - let mut block = block.into(); - executor.apply_block(&mut block)?; +fn set_fork_epochs(meta: &mut Meta, context: &mut Context) { + context.altair_fork_epoch = Epoch::MAX; + context.bellatrix_fork_epoch = Epoch::MAX; + context.capella_fork_epoch = Epoch::MAX; + context.deneb_fork_epoch = Epoch::MAX; + + match meta.post_fork.as_ref() { + "altair" => { + context.altair_fork_epoch = meta.fork_epoch; } - for block in $post_blocks.into_iter() { - let mut block = block.into(); - executor.apply_block(&mut block)?; + "bellatrix" => { + context.altair_fork_epoch = 0; + context.bellatrix_fork_epoch = meta.fork_epoch; } - todo!( - /* - match executor.state { - BeaconState::Altair(inner) => Ok(*inner), - _ => unreachable!(), - } - if pre == $post { - Ok(()) - } else { - Err(Error::InvalidState) - } - */ - ) - */ - ) + _ => todo!(), + } } pub fn dispatch(test: &TestCase) -> Result<(), Error> { @@ -139,8 +87,25 @@ pub fn dispatch(test: &TestCase) -> Result<(), Error> { gen_exec! { test, load_test, - | (pre, expected, pre_blocks, post_blocks, meta): (pre_spec::BeaconState, spec::BeaconState, Vec, Vec, Meta), context: &Context| { - run_test(pre, expected, pre_blocks, post_blocks, &meta, context) + | (pre, expected, pre_blocks, post_blocks, mut meta): (pre_spec::BeaconState, spec::BeaconState, Vec, Vec, Meta), context: &Context| { + assert_eq!(meta.post_fork, "altair"); + let mut context = context.clone(); + set_fork_epochs(&mut meta, &mut context); + let mut executor = state_transition::mainnet::Executor::new(BeaconState::Phase0(pre), context); + for block in pre_blocks.into_iter() { + let mut block = SignedBeaconBlock::Phase0(block); + executor.apply_block(&mut block)?; + } + for block in post_blocks.into_iter() { + let mut block = SignedBeaconBlock::Altair(block); + executor.apply_block(&mut block)?; + } + let post = executor.state.altair().unwrap(); + if post != &expected { + Err(Error::InvalidState) + } else { + Ok(()) + } } } } @@ -151,14 +116,91 @@ pub fn dispatch(test: &TestCase) -> Result<(), Error> { gen_exec! { test, load_test, - | (pre, expected, pre_blocks, post_blocks, meta): (pre_spec::BeaconState, spec::BeaconState, Vec, Vec, Meta), context: &Context| { - run_test(pre, expected, pre_blocks, post_blocks, &meta, context) + | (pre, expected, pre_blocks, post_blocks, mut meta): (pre_spec::BeaconState, spec::BeaconState, Vec, Vec, Meta), context: &Context| { + assert_eq!(meta.post_fork, "bellatrix"); + let mut context = context.clone(); + set_fork_epochs(&mut meta, &mut context); + let mut executor = state_transition::mainnet::Executor::new(BeaconState::Altair(pre), context); + for block in pre_blocks.into_iter() { + let mut block = SignedBeaconBlock::Altair(block); + executor.apply_block(&mut block)?; + } + for block in post_blocks.into_iter() { + let mut block = SignedBeaconBlock::Bellatrix(block); + executor.apply_block(&mut block)?; + } + let post = executor.state.bellatrix().unwrap(); + if post != &expected { + Err(Error::InvalidState) + } else { + Ok(()) + } + } + } + } + _ => todo!(), + }, + Config::Minimal => match test.meta.fork { + Fork::Altair => { + use ethereum_consensus::{ + altair::minimal as spec, phase0::minimal as pre_spec, + }; + gen_exec! { + test, + load_test, + | (pre, expected, pre_blocks, post_blocks, mut meta): (pre_spec::BeaconState, spec::BeaconState, Vec, Vec, Meta), context: &Context| { + assert_eq!(meta.post_fork, "altair"); + let mut context = context.clone(); + set_fork_epochs(&mut meta, &mut context); + let mut executor = state_transition::minimal::Executor::new(BeaconState::Phase0(pre), context); + for block in pre_blocks.into_iter() { + let mut block = SignedBeaconBlock::Phase0(block); + executor.apply_block(&mut block)?; + } + for block in post_blocks.into_iter() { + let mut block = SignedBeaconBlock::Altair(block); + executor.apply_block(&mut block)?; + } + let post = executor.state.altair().unwrap(); + if post != &expected { + Err(Error::InvalidState) + } else { + Ok(()) + } + } + } + } + Fork::Bellatrix => { + use ethereum_consensus::{ + altair::minimal as pre_spec, bellatrix::minimal as spec, + }; + gen_exec! { + test, + load_test, + | (pre, expected, pre_blocks, post_blocks, mut meta): (pre_spec::BeaconState, spec::BeaconState, Vec, Vec, Meta), context: &Context| { + assert_eq!(meta.post_fork, "bellatrix"); + let mut context = context.clone(); + set_fork_epochs(&mut meta, &mut context); + let mut executor = state_transition::minimal::Executor::new(BeaconState::Altair(pre), context); + for block in pre_blocks.into_iter() { + let mut block = SignedBeaconBlock::Altair(block); + executor.apply_block(&mut block)?; + } + for block in post_blocks.into_iter() { + let mut block = SignedBeaconBlock::Bellatrix(block); + executor.apply_block(&mut block)?; + } + let post = executor.state.bellatrix().unwrap(); + if post != &expected { + Err(Error::InvalidState) + } else { + Ok(()) + } } } } - _ => todo!("implement after `run_test`"), + _ => todo!(), }, - Config::Minimal => todo!("implement after `run_test`"), config => unreachable!("no tests for {config:?}"), }, handler => unreachable!("no tests for {handler}"), From c08e2c8104042c19ea86106b7bd8b89a94b56f03 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 25 Mar 2024 14:55:56 -0600 Subject: [PATCH 5/6] bugfix for latest spec gen and run --- ethereum-consensus/src/altair/spec/mod.rs | 56 ++++++------- ethereum-consensus/src/bellatrix/spec/mod.rs | 83 ++++++++++---------- ethereum-consensus/src/capella/spec/mod.rs | 81 ++++++++++--------- ethereum-consensus/src/deneb/spec/mod.rs | 73 +++++++++-------- spec-gen/src/generator.rs | 2 - 5 files changed, 145 insertions(+), 150 deletions(-) diff --git a/ethereum-consensus/src/altair/spec/mod.rs b/ethereum-consensus/src/altair/spec/mod.rs index 00245b304..6d78d2334 100644 --- a/ethereum-consensus/src/altair/spec/mod.rs +++ b/ethereum-consensus/src/altair/spec/mod.rs @@ -90,7 +90,7 @@ pub fn process_proposer_slashing< if header_1.slot != header_2.slot { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::SlotMismatch(header_1.slot, header_2.slot), - ))) + ))); } if header_1.proposer_index != header_2.proposer_index { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( @@ -98,12 +98,12 @@ pub fn process_proposer_slashing< header_1.proposer_index, header_2.proposer_index, ), - ))) + ))); } if header_1 == header_2 { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::HeadersAreEqual(header_1.clone()), - ))) + ))); } let proposer_index = header_1.proposer_index; let proposer = state.validators.get(proposer_index).ok_or_else(|| { @@ -114,7 +114,7 @@ pub fn process_proposer_slashing< if !is_slashable_validator(proposer, get_current_epoch(state, context)) { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::ProposerIsNotSlashable(header_1.proposer_index), - ))) + ))); } let epoch = compute_epoch_at_slot(header_1.slot, context); let domain = get_domain(state, DomainType::BeaconProposer, Some(epoch), context)?; @@ -126,7 +126,7 @@ pub fn process_proposer_slashing< if verify_signature(public_key, signing_root.as_ref(), &signed_header.signature).is_err() { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::InvalidSignature(signed_header.signature.clone()), - ))) + ))); } } slash_validator(state, proposer_index, None, context) @@ -162,7 +162,7 @@ pub fn process_attester_slashing< Box::new(attestation_1.data.clone()), Box::new(attestation_2.data.clone()), ), - ))) + ))); } is_valid_indexed_attestation(state, attestation_1, context)?; is_valid_indexed_attestation(state, attestation_2, context)?; @@ -237,7 +237,7 @@ pub fn process_voluntary_exit< if !is_active_validator(validator, current_epoch) { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( InvalidVoluntaryExit::InactiveValidator(current_epoch), - ))) + ))); } if validator.exit_epoch != FAR_FUTURE_EPOCH { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( @@ -245,12 +245,12 @@ pub fn process_voluntary_exit< index: voluntary_exit.validator_index, epoch: validator.exit_epoch, }, - ))) + ))); } if current_epoch < voluntary_exit.epoch { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( InvalidVoluntaryExit::EarlyExit { current_epoch, exit_epoch: voluntary_exit.epoch }, - ))) + ))); } let minimum_time_active = validator.activation_eligibility_epoch + context.shard_committee_period; @@ -260,7 +260,7 @@ pub fn process_voluntary_exit< current_epoch, minimum_time_active, }, - ))) + ))); } let domain = get_domain(state, DomainType::VoluntaryExit, Some(voluntary_exit.epoch), context)?; let public_key = &validator.public_key; @@ -313,27 +313,27 @@ pub fn process_block_header< return Err(invalid_header_error(InvalidBeaconBlockHeader::StateSlotMismatch { state_slot: state.slot, block_slot: block.slot, - })) + })); } if block.slot <= state.latest_block_header.slot { return Err(invalid_header_error(InvalidBeaconBlockHeader::OlderThanLatestBlockHeader { block_slot: block.slot, latest_block_header_slot: state.latest_block_header.slot, - })) + })); } let proposer_index = get_beacon_proposer_index(state, context)?; if block.proposer_index != proposer_index { return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerIndexMismatch { block_proposer_index: block.proposer_index, proposer_index, - })) + })); } let expected_parent_root = state.latest_block_header.hash_tree_root()?; if block.parent_root != expected_parent_root { return Err(invalid_header_error(InvalidBeaconBlockHeader::ParentBlockRootMismatch { expected: expected_parent_root, provided: block.parent_root, - })) + })); } state.latest_block_header = BeaconBlockHeader { slot: block.slot, @@ -344,7 +344,7 @@ pub fn process_block_header< }; let proposer = &state.validators[block.proposer_index]; if proposer.slashed { - return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))) + return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))); } Ok(()) } @@ -394,7 +394,7 @@ pub fn process_randao< let domain = get_domain(state, DomainType::Randao, Some(epoch), context)?; let signing_root = compute_signing_root(&mut epoch, domain)?; if verify_signature(&proposer.public_key, signing_root.as_ref(), &body.randao_reveal).is_err() { - return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))) + return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))); } let mix = xor(get_randao_mix(state, epoch), &hash(body.randao_reveal.as_ref())); let mix_index = epoch % context.epochs_per_historical_vector; @@ -490,7 +490,7 @@ pub fn process_operations< expected: expected_deposit_count, count: body.deposits.len(), }, - ))) + ))); } body.proposer_slashings .iter_mut() @@ -871,7 +871,7 @@ pub fn is_valid_genesis_state< context: &Context, ) -> bool { if state.genesis_time < context.min_genesis_time { - return false + return false; } get_active_validator_indices(state, GENESIS_EPOCH).len() >= context.min_genesis_active_validator_count @@ -984,7 +984,7 @@ pub fn is_valid_indexed_attestation< if attesting_indices.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesEmpty, - ))) + ))); } let mut prev = attesting_indices[0]; let mut duplicates = HashSet::new(); @@ -992,7 +992,7 @@ pub fn is_valid_indexed_attestation< if index < prev { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesNotSorted, - ))) + ))); } if index == prev { duplicates.insert(index); @@ -1002,7 +1002,7 @@ pub fn is_valid_indexed_attestation< if !duplicates.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::DuplicateIndices(Vec::from_iter(duplicates)), - ))) + ))); } let mut public_keys = vec![]; for &index in &attesting_indices[..] { @@ -1132,7 +1132,7 @@ pub fn compute_shuffled_index( context: &Context, ) -> Result { if index >= index_count { - return Err(Error::InvalidShufflingIndex { index, total: index_count }) + return Err(Error::InvalidShufflingIndex { index, total: index_count }); } let mut pivot_input = [0u8; 33]; pivot_input[..32].copy_from_slice(seed.as_ref()); @@ -1179,7 +1179,7 @@ pub fn compute_proposer_index< context: &Context, ) -> Result { if indices.is_empty() { - return Err(Error::CollectionCannotBeEmpty) + return Err(Error::CollectionCannotBeEmpty); } let max_byte = u8::MAX as u64; let mut i = 0; @@ -1194,7 +1194,7 @@ pub fn compute_proposer_index< let random_byte = hash(hash_input).as_ref()[i % 32] as u64; let effective_balance = state.validators[candidate_index].effective_balance; if effective_balance * max_byte >= context.max_effective_balance * random_byte { - return Ok(candidate_index) + return Ok(candidate_index); } i += 1; } @@ -1336,7 +1336,7 @@ pub fn get_block_root_at_slot< requested: slot, lower_bound: state.slot - 1, upper_bound: state.slot + SLOTS_PER_HISTORICAL_ROOT as Slot, - }) + }); } Ok(&state.block_roots[slot as usize % SLOTS_PER_HISTORICAL_ROOT]) } @@ -1669,7 +1669,7 @@ pub fn get_attesting_indices< if bits.len() != committee.len() { return Err(invalid_operation_error(InvalidOperation::Attestation( InvalidAttestation::Bitfield { expected_length: committee.len(), length: bits.len() }, - ))) + ))); } let mut indices = HashSet::with_capacity(bits.capacity()); for (i, validator_index) in committee.iter().enumerate() { @@ -1757,7 +1757,7 @@ pub fn initiate_validator_exit< context: &Context, ) { if state.validators[index].exit_epoch != FAR_FUTURE_EPOCH { - return + return; } let mut exit_epochs: Vec = state .validators @@ -1834,7 +1834,7 @@ pub fn process_slots< context: &Context, ) -> Result<()> { if state.slot >= slot { - return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }) + return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }); } while state.slot < slot { process_slot(state, context)?; diff --git a/ethereum-consensus/src/bellatrix/spec/mod.rs b/ethereum-consensus/src/bellatrix/spec/mod.rs index 85f2ead86..7e9b56b50 100644 --- a/ethereum-consensus/src/bellatrix/spec/mod.rs +++ b/ethereum-consensus/src/bellatrix/spec/mod.rs @@ -39,7 +39,6 @@ pub use crate::{ state_transition::{state_transition, state_transition_block_in_slot}, }, error::*, - execution_engine::ExecutionEngine, phase0::{ beacon_block::{BeaconBlockHeader, SignedBeaconBlockHeader}, beacon_state::{Fork, ForkData, HistoricalBatch, HistoricalSummary}, @@ -107,7 +106,7 @@ pub fn process_attestation< target: data.target.epoch, current: current_epoch, }, - ))) + ))); } let attestation_epoch = compute_epoch_at_slot(data.slot, context); if data.target.epoch != attestation_epoch { @@ -117,7 +116,7 @@ pub fn process_attestation< epoch: attestation_epoch, target: data.target.epoch, }, - ))) + ))); } let attestation_has_delay = data.slot + context.min_attestation_inclusion_delay <= state.slot; let attestation_is_recent = state.slot <= data.slot + context.slots_per_epoch; @@ -130,13 +129,13 @@ pub fn process_attestation< lower_bound: data.slot + context.slots_per_epoch, upper_bound: data.slot + context.min_attestation_inclusion_delay, }, - ))) + ))); } let committee_count = get_committee_count_per_slot(state, data.target.epoch, context); if data.index >= committee_count { return Err(invalid_operation_error(InvalidOperation::Attestation( InvalidAttestation::InvalidIndex { index: data.index, upper_bound: committee_count }, - ))) + ))); } let committee = get_beacon_committee(state, data.slot, data.index, context)?; if attestation.aggregation_bits.len() != committee.len() { @@ -145,7 +144,7 @@ pub fn process_attestation< expected_length: committee.len(), length: attestation.aggregation_bits.len(), }, - ))) + ))); } let inclusion_delay = state.slot - data.slot; let participation_flag_indices = @@ -227,7 +226,7 @@ pub fn process_deposit< index, root, }, - ))) + ))); } state.eth1_deposit_index += 1; let public_key = &deposit.data.public_key; @@ -243,7 +242,7 @@ pub fn process_deposit< let domain = compute_domain(DomainType::Deposit, None, None, context)?; let signing_root = compute_signing_root(&mut deposit_message, domain)?; if verify_signature(public_key, signing_root.as_ref(), &deposit.data.signature).is_err() { - return Ok(()) + return Ok(()); } state.validators.push(get_validator_from_deposit(deposit, context)); state.balances.push(amount); @@ -309,7 +308,7 @@ pub fn process_sync_aggregate< signature: sync_aggregate.sync_committee_signature.clone(), root: signing_root, }, - ))) + ))); } let total_active_increments = get_total_active_balance(state, context)? / context.effective_balance_increment; @@ -375,7 +374,7 @@ pub fn process_proposer_slashing< if header_1.slot != header_2.slot { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::SlotMismatch(header_1.slot, header_2.slot), - ))) + ))); } if header_1.proposer_index != header_2.proposer_index { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( @@ -383,12 +382,12 @@ pub fn process_proposer_slashing< header_1.proposer_index, header_2.proposer_index, ), - ))) + ))); } if header_1 == header_2 { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::HeadersAreEqual(header_1.clone()), - ))) + ))); } let proposer_index = header_1.proposer_index; let proposer = state.validators.get(proposer_index).ok_or_else(|| { @@ -399,7 +398,7 @@ pub fn process_proposer_slashing< if !is_slashable_validator(proposer, get_current_epoch(state, context)) { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::ProposerIsNotSlashable(header_1.proposer_index), - ))) + ))); } let epoch = compute_epoch_at_slot(header_1.slot, context); let domain = get_domain(state, DomainType::BeaconProposer, Some(epoch), context)?; @@ -411,7 +410,7 @@ pub fn process_proposer_slashing< if verify_signature(public_key, signing_root.as_ref(), &signed_header.signature).is_err() { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::InvalidSignature(signed_header.signature.clone()), - ))) + ))); } } slash_validator(state, proposer_index, None, context) @@ -451,7 +450,7 @@ pub fn process_attester_slashing< Box::new(attestation_1.data.clone()), Box::new(attestation_2.data.clone()), ), - ))) + ))); } is_valid_indexed_attestation(state, attestation_1, context)?; is_valid_indexed_attestation(state, attestation_2, context)?; @@ -530,7 +529,7 @@ pub fn process_voluntary_exit< if !is_active_validator(validator, current_epoch) { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( InvalidVoluntaryExit::InactiveValidator(current_epoch), - ))) + ))); } if validator.exit_epoch != FAR_FUTURE_EPOCH { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( @@ -538,12 +537,12 @@ pub fn process_voluntary_exit< index: voluntary_exit.validator_index, epoch: validator.exit_epoch, }, - ))) + ))); } if current_epoch < voluntary_exit.epoch { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( InvalidVoluntaryExit::EarlyExit { current_epoch, exit_epoch: voluntary_exit.epoch }, - ))) + ))); } let minimum_time_active = validator.activation_eligibility_epoch + context.shard_committee_period; @@ -553,7 +552,7 @@ pub fn process_voluntary_exit< current_epoch, minimum_time_active, }, - ))) + ))); } let domain = get_domain(state, DomainType::VoluntaryExit, Some(voluntary_exit.epoch), context)?; let public_key = &validator.public_key; @@ -616,27 +615,27 @@ pub fn process_block_header< return Err(invalid_header_error(InvalidBeaconBlockHeader::StateSlotMismatch { state_slot: state.slot, block_slot: block.slot, - })) + })); } if block.slot <= state.latest_block_header.slot { return Err(invalid_header_error(InvalidBeaconBlockHeader::OlderThanLatestBlockHeader { block_slot: block.slot, latest_block_header_slot: state.latest_block_header.slot, - })) + })); } let proposer_index = get_beacon_proposer_index(state, context)?; if block.proposer_index != proposer_index { return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerIndexMismatch { block_proposer_index: block.proposer_index, proposer_index, - })) + })); } let expected_parent_root = state.latest_block_header.hash_tree_root()?; if block.parent_root != expected_parent_root { return Err(invalid_header_error(InvalidBeaconBlockHeader::ParentBlockRootMismatch { expected: expected_parent_root, provided: block.parent_root, - })) + })); } state.latest_block_header = BeaconBlockHeader { slot: block.slot, @@ -647,7 +646,7 @@ pub fn process_block_header< }; let proposer = &state.validators[block.proposer_index]; if proposer.slashed { - return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))) + return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))); } Ok(()) } @@ -707,7 +706,7 @@ pub fn process_randao< let domain = get_domain(state, DomainType::Randao, Some(epoch), context)?; let signing_root = compute_signing_root(&mut epoch, domain)?; if verify_signature(&proposer.public_key, signing_root.as_ref(), &body.randao_reveal).is_err() { - return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))) + return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))); } let mix = xor(get_randao_mix(state, epoch), &hash(body.randao_reveal.as_ref())); let mix_index = epoch % context.epochs_per_historical_vector; @@ -823,7 +822,7 @@ pub fn process_operations< expected: expected_deposit_count, count: body.deposits.len(), }, - ))) + ))); } body.proposer_slashings .iter_mut() @@ -897,7 +896,7 @@ pub fn process_justification_and_finalization< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch <= GENESIS_EPOCH + 1 { - return Ok(()) + return Ok(()); } let previous_indices = get_unslashed_participating_indices( state, @@ -950,7 +949,7 @@ pub fn process_inactivity_updates< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch == GENESIS_EPOCH { - return Ok(()) + return Ok(()); } let eligible_validator_indices = get_eligible_validator_indices(state, context).collect::>(); @@ -1002,7 +1001,7 @@ pub fn process_rewards_and_penalties< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch == GENESIS_EPOCH { - return Ok(()) + return Ok(()); } let mut deltas = Vec::new(); for flag_index in 0..PARTICIPATION_FLAG_WEIGHTS.len() { @@ -1495,7 +1494,7 @@ pub fn is_valid_genesis_state< context: &Context, ) -> bool { if state.genesis_time < context.min_genesis_time { - return false + return false; } get_active_validator_indices(state, GENESIS_EPOCH).len() >= context.min_genesis_active_validator_count @@ -1709,7 +1708,7 @@ pub fn get_unslashed_participating_indices< requested: epoch, previous: previous_epoch, current: current_epoch, - }) + }); } let epoch_participation = if is_current { &state.current_epoch_participation @@ -1766,7 +1765,7 @@ pub fn get_attestation_participation_flag_indices< source_checkpoint: data.source.clone(), current: get_current_epoch(state, context), }, - ))) + ))); } let is_matching_target = is_matching_source && (data.target.root == *get_block_root(state, data.target.epoch, context)?); @@ -1916,7 +1915,7 @@ pub fn is_valid_indexed_attestation< if attesting_indices.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesEmpty, - ))) + ))); } let mut prev = attesting_indices[0]; let mut duplicates = HashSet::new(); @@ -1924,7 +1923,7 @@ pub fn is_valid_indexed_attestation< if index < prev { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesNotSorted, - ))) + ))); } if index == prev { duplicates.insert(index); @@ -1934,7 +1933,7 @@ pub fn is_valid_indexed_attestation< if !duplicates.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::DuplicateIndices(Vec::from_iter(duplicates)), - ))) + ))); } let mut public_keys = vec![]; for &index in &attesting_indices[..] { @@ -2082,7 +2081,7 @@ pub fn compute_shuffled_index( context: &Context, ) -> Result { if index >= index_count { - return Err(Error::InvalidShufflingIndex { index, total: index_count }) + return Err(Error::InvalidShufflingIndex { index, total: index_count }); } let mut pivot_input = [0u8; 33]; pivot_input[..32].copy_from_slice(seed.as_ref()); @@ -2133,7 +2132,7 @@ pub fn compute_proposer_index< context: &Context, ) -> Result { if indices.is_empty() { - return Err(Error::CollectionCannotBeEmpty) + return Err(Error::CollectionCannotBeEmpty); } let max_byte = u8::MAX as u64; let mut i = 0; @@ -2148,7 +2147,7 @@ pub fn compute_proposer_index< let random_byte = hash(hash_input).as_ref()[i % 32] as u64; let effective_balance = state.validators[candidate_index].effective_balance; if effective_balance * max_byte >= context.max_effective_balance * random_byte { - return Ok(candidate_index) + return Ok(candidate_index); } i += 1; } @@ -2302,7 +2301,7 @@ pub fn get_block_root_at_slot< requested: slot, lower_bound: state.slot - 1, upper_bound: state.slot + SLOTS_PER_HISTORICAL_ROOT as Slot, - }) + }); } Ok(&state.block_roots[slot as usize % SLOTS_PER_HISTORICAL_ROOT]) } @@ -2679,7 +2678,7 @@ pub fn get_attesting_indices< if bits.len() != committee.len() { return Err(invalid_operation_error(InvalidOperation::Attestation( InvalidAttestation::Bitfield { expected_length: committee.len(), length: bits.len() }, - ))) + ))); } let mut indices = HashSet::with_capacity(bits.capacity()); for (i, validator_index) in committee.iter().enumerate() { @@ -2779,7 +2778,7 @@ pub fn initiate_validator_exit< context: &Context, ) { if state.validators[index].exit_epoch != FAR_FUTURE_EPOCH { - return + return; } let mut exit_epochs: Vec = state .validators @@ -2864,7 +2863,7 @@ pub fn process_slots< context: &Context, ) -> Result<()> { if state.slot >= slot { - return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }) + return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }); } while state.slot < slot { process_slot(state, context)?; diff --git a/ethereum-consensus/src/capella/spec/mod.rs b/ethereum-consensus/src/capella/spec/mod.rs index c66e3fe13..6871b6b66 100644 --- a/ethereum-consensus/src/capella/spec/mod.rs +++ b/ethereum-consensus/src/capella/spec/mod.rs @@ -43,7 +43,6 @@ pub use crate::{ withdrawal::Withdrawal, }, error::*, - execution_engine::ExecutionEngine, phase0::{ beacon_block::{BeaconBlockHeader, SignedBeaconBlockHeader}, beacon_state::{Fork, ForkData, HistoricalBatch, HistoricalSummary}, @@ -111,7 +110,7 @@ pub fn process_attestation< target: data.target.epoch, current: current_epoch, }, - ))) + ))); } let attestation_epoch = compute_epoch_at_slot(data.slot, context); if data.target.epoch != attestation_epoch { @@ -121,7 +120,7 @@ pub fn process_attestation< epoch: attestation_epoch, target: data.target.epoch, }, - ))) + ))); } let attestation_has_delay = data.slot + context.min_attestation_inclusion_delay <= state.slot; let attestation_is_recent = state.slot <= data.slot + context.slots_per_epoch; @@ -134,13 +133,13 @@ pub fn process_attestation< lower_bound: data.slot + context.slots_per_epoch, upper_bound: data.slot + context.min_attestation_inclusion_delay, }, - ))) + ))); } let committee_count = get_committee_count_per_slot(state, data.target.epoch, context); if data.index >= committee_count { return Err(invalid_operation_error(InvalidOperation::Attestation( InvalidAttestation::InvalidIndex { index: data.index, upper_bound: committee_count }, - ))) + ))); } let committee = get_beacon_committee(state, data.slot, data.index, context)?; if attestation.aggregation_bits.len() != committee.len() { @@ -149,7 +148,7 @@ pub fn process_attestation< expected_length: committee.len(), length: attestation.aggregation_bits.len(), }, - ))) + ))); } let inclusion_delay = state.slot - data.slot; let participation_flag_indices = @@ -231,7 +230,7 @@ pub fn process_deposit< index, root, }, - ))) + ))); } state.eth1_deposit_index += 1; let public_key = &deposit.data.public_key; @@ -247,7 +246,7 @@ pub fn process_deposit< let domain = compute_domain(DomainType::Deposit, None, None, context)?; let signing_root = compute_signing_root(&mut deposit_message, domain)?; if verify_signature(public_key, signing_root.as_ref(), &deposit.data.signature).is_err() { - return Ok(()) + return Ok(()); } state.validators.push(get_validator_from_deposit(deposit, context)); state.balances.push(amount); @@ -313,7 +312,7 @@ pub fn process_sync_aggregate< signature: sync_aggregate.sync_committee_signature.clone(), root: signing_root, }, - ))) + ))); } let total_active_increments = get_total_active_balance(state, context)? / context.effective_balance_increment; @@ -379,7 +378,7 @@ pub fn process_proposer_slashing< if header_1.slot != header_2.slot { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::SlotMismatch(header_1.slot, header_2.slot), - ))) + ))); } if header_1.proposer_index != header_2.proposer_index { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( @@ -387,12 +386,12 @@ pub fn process_proposer_slashing< header_1.proposer_index, header_2.proposer_index, ), - ))) + ))); } if header_1 == header_2 { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::HeadersAreEqual(header_1.clone()), - ))) + ))); } let proposer_index = header_1.proposer_index; let proposer = state.validators.get(proposer_index).ok_or_else(|| { @@ -403,7 +402,7 @@ pub fn process_proposer_slashing< if !is_slashable_validator(proposer, get_current_epoch(state, context)) { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::ProposerIsNotSlashable(header_1.proposer_index), - ))) + ))); } let epoch = compute_epoch_at_slot(header_1.slot, context); let domain = get_domain(state, DomainType::BeaconProposer, Some(epoch), context)?; @@ -415,7 +414,7 @@ pub fn process_proposer_slashing< if verify_signature(public_key, signing_root.as_ref(), &signed_header.signature).is_err() { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::InvalidSignature(signed_header.signature.clone()), - ))) + ))); } } slash_validator(state, proposer_index, None, context) @@ -455,7 +454,7 @@ pub fn process_attester_slashing< Box::new(attestation_1.data.clone()), Box::new(attestation_2.data.clone()), ), - ))) + ))); } is_valid_indexed_attestation(state, attestation_1, context)?; is_valid_indexed_attestation(state, attestation_2, context)?; @@ -534,7 +533,7 @@ pub fn process_voluntary_exit< if !is_active_validator(validator, current_epoch) { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( InvalidVoluntaryExit::InactiveValidator(current_epoch), - ))) + ))); } if validator.exit_epoch != FAR_FUTURE_EPOCH { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( @@ -542,12 +541,12 @@ pub fn process_voluntary_exit< index: voluntary_exit.validator_index, epoch: validator.exit_epoch, }, - ))) + ))); } if current_epoch < voluntary_exit.epoch { return Err(invalid_operation_error(InvalidOperation::VoluntaryExit( InvalidVoluntaryExit::EarlyExit { current_epoch, exit_epoch: voluntary_exit.epoch }, - ))) + ))); } let minimum_time_active = validator.activation_eligibility_epoch + context.shard_committee_period; @@ -557,7 +556,7 @@ pub fn process_voluntary_exit< current_epoch, minimum_time_active, }, - ))) + ))); } let domain = get_domain(state, DomainType::VoluntaryExit, Some(voluntary_exit.epoch), context)?; let public_key = &validator.public_key; @@ -624,27 +623,27 @@ pub fn process_block_header< return Err(invalid_header_error(InvalidBeaconBlockHeader::StateSlotMismatch { state_slot: state.slot, block_slot: block.slot, - })) + })); } if block.slot <= state.latest_block_header.slot { return Err(invalid_header_error(InvalidBeaconBlockHeader::OlderThanLatestBlockHeader { block_slot: block.slot, latest_block_header_slot: state.latest_block_header.slot, - })) + })); } let proposer_index = get_beacon_proposer_index(state, context)?; if block.proposer_index != proposer_index { return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerIndexMismatch { block_proposer_index: block.proposer_index, proposer_index, - })) + })); } let expected_parent_root = state.latest_block_header.hash_tree_root()?; if block.parent_root != expected_parent_root { return Err(invalid_header_error(InvalidBeaconBlockHeader::ParentBlockRootMismatch { expected: expected_parent_root, provided: block.parent_root, - })) + })); } state.latest_block_header = BeaconBlockHeader { slot: block.slot, @@ -655,7 +654,7 @@ pub fn process_block_header< }; let proposer = &state.validators[block.proposer_index]; if proposer.slashed { - return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))) + return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))); } Ok(()) } @@ -719,7 +718,7 @@ pub fn process_randao< let domain = get_domain(state, DomainType::Randao, Some(epoch), context)?; let signing_root = compute_signing_root(&mut epoch, domain)?; if verify_signature(&proposer.public_key, signing_root.as_ref(), &body.randao_reveal).is_err() { - return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))) + return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))); } let mix = xor(get_randao_mix(state, epoch), &hash(body.randao_reveal.as_ref())); let mix_index = epoch % context.epochs_per_historical_vector; @@ -888,7 +887,7 @@ pub fn process_justification_and_finalization< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch <= GENESIS_EPOCH + 1 { - return Ok(()) + return Ok(()); } let previous_indices = get_unslashed_participating_indices( state, @@ -941,7 +940,7 @@ pub fn process_inactivity_updates< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch == GENESIS_EPOCH { - return Ok(()) + return Ok(()); } let eligible_validator_indices = get_eligible_validator_indices(state, context).collect::>(); @@ -993,7 +992,7 @@ pub fn process_rewards_and_penalties< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch == GENESIS_EPOCH { - return Ok(()) + return Ok(()); } let mut deltas = Vec::new(); for flag_index in 0..PARTICIPATION_FLAG_WEIGHTS.len() { @@ -1486,7 +1485,7 @@ pub fn is_valid_genesis_state< context: &Context, ) -> bool { if state.genesis_time < context.min_genesis_time { - return false + return false; } get_active_validator_indices(state, GENESIS_EPOCH).len() >= context.min_genesis_active_validator_count @@ -1968,7 +1967,7 @@ pub fn get_unslashed_participating_indices< requested: epoch, previous: previous_epoch, current: current_epoch, - }) + }); } let epoch_participation = if is_current { &state.current_epoch_participation @@ -2025,7 +2024,7 @@ pub fn get_attestation_participation_flag_indices< source_checkpoint: data.source.clone(), current: get_current_epoch(state, context), }, - ))) + ))); } let is_matching_target = is_matching_source && (data.target.root == *get_block_root(state, data.target.epoch, context)?); @@ -2175,7 +2174,7 @@ pub fn is_valid_indexed_attestation< if attesting_indices.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesEmpty, - ))) + ))); } let mut prev = attesting_indices[0]; let mut duplicates = HashSet::new(); @@ -2183,7 +2182,7 @@ pub fn is_valid_indexed_attestation< if index < prev { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesNotSorted, - ))) + ))); } if index == prev { duplicates.insert(index); @@ -2193,7 +2192,7 @@ pub fn is_valid_indexed_attestation< if !duplicates.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::DuplicateIndices(Vec::from_iter(duplicates)), - ))) + ))); } let mut public_keys = vec![]; for &index in &attesting_indices[..] { @@ -2345,7 +2344,7 @@ pub fn compute_shuffled_index( context: &Context, ) -> Result { if index >= index_count { - return Err(Error::InvalidShufflingIndex { index, total: index_count }) + return Err(Error::InvalidShufflingIndex { index, total: index_count }); } let mut pivot_input = [0u8; 33]; pivot_input[..32].copy_from_slice(seed.as_ref()); @@ -2396,7 +2395,7 @@ pub fn compute_proposer_index< context: &Context, ) -> Result { if indices.is_empty() { - return Err(Error::CollectionCannotBeEmpty) + return Err(Error::CollectionCannotBeEmpty); } let max_byte = u8::MAX as u64; let mut i = 0; @@ -2411,7 +2410,7 @@ pub fn compute_proposer_index< let random_byte = hash(hash_input).as_ref()[i % 32] as u64; let effective_balance = state.validators[candidate_index].effective_balance; if effective_balance * max_byte >= context.max_effective_balance * random_byte { - return Ok(candidate_index) + return Ok(candidate_index); } i += 1; } @@ -2565,7 +2564,7 @@ pub fn get_block_root_at_slot< requested: slot, lower_bound: state.slot - 1, upper_bound: state.slot + SLOTS_PER_HISTORICAL_ROOT as Slot, - }) + }); } Ok(&state.block_roots[slot as usize % SLOTS_PER_HISTORICAL_ROOT]) } @@ -2942,7 +2941,7 @@ pub fn get_attesting_indices< if bits.len() != committee.len() { return Err(invalid_operation_error(InvalidOperation::Attestation( InvalidAttestation::Bitfield { expected_length: committee.len(), length: bits.len() }, - ))) + ))); } let mut indices = HashSet::with_capacity(bits.capacity()); for (i, validator_index) in committee.iter().enumerate() { @@ -3042,7 +3041,7 @@ pub fn initiate_validator_exit< context: &Context, ) { if state.validators[index].exit_epoch != FAR_FUTURE_EPOCH { - return + return; } let mut exit_epochs: Vec = state .validators @@ -3127,7 +3126,7 @@ pub fn process_slots< context: &Context, ) -> Result<()> { if state.slot >= slot { - return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }) + return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }); } while state.slot < slot { process_slot(state, context)?; diff --git a/ethereum-consensus/src/deneb/spec/mod.rs b/ethereum-consensus/src/deneb/spec/mod.rs index 6a0356d68..8200a72b1 100644 --- a/ethereum-consensus/src/deneb/spec/mod.rs +++ b/ethereum-consensus/src/deneb/spec/mod.rs @@ -49,7 +49,6 @@ pub use crate::{ }, }, error::*, - execution_engine::ExecutionEngine, phase0::{ beacon_block::{BeaconBlockHeader, SignedBeaconBlockHeader}, beacon_state::{Fork, ForkData, HistoricalBatch, HistoricalSummary}, @@ -111,14 +110,14 @@ pub fn process_bls_to_execution_change< if address_change.validator_index >= state.validators.len() { return Err(invalid_operation_error(InvalidOperation::BlsToExecutionChange( InvalidBlsToExecutionChange::ValidatorIndexOutOfBounds(address_change.validator_index), - ))) + ))); } let withdrawal_credentials = &mut state.validators[address_change.validator_index].withdrawal_credentials; if withdrawal_credentials[0] != BLS_WITHDRAWAL_PREFIX { return Err(invalid_operation_error(InvalidOperation::BlsToExecutionChange( InvalidBlsToExecutionChange::WithdrawalCredentialsPrefix(withdrawal_credentials[0]), - ))) + ))); } let domain = compute_domain( DomainType::BlsToExecutionChange, @@ -131,7 +130,7 @@ pub fn process_bls_to_execution_change< if withdrawal_credentials[1..] != hash(public_key.as_ref())[1..] { return Err(invalid_operation_error(InvalidOperation::BlsToExecutionChange( InvalidBlsToExecutionChange::PublicKeyMismatch(public_key.clone()), - ))) + ))); } verify_signature(public_key, signing_root.as_ref(), signature)?; withdrawal_credentials[0] = ETH1_ADDRESS_WITHDRAWAL_PREFIX; @@ -201,7 +200,7 @@ pub fn process_operations< expected: expected_deposit_count, count: body.deposits.len(), }, - ))) + ))); } body.proposer_slashings .iter_mut() @@ -262,7 +261,7 @@ pub fn process_withdrawals< provided: execution_payload.withdrawals.to_vec(), expected: expected_withdrawals, }, - ))) + ))); } for withdrawal in &expected_withdrawals { decrease_balance(state, withdrawal.validator_index, withdrawal.amount); @@ -339,7 +338,7 @@ pub fn get_expected_withdrawals< withdrawal_index += 1; } if withdrawals.len() == context.max_withdrawals_per_payload { - break + break; } validator_index = (validator_index + 1) % state.validators.len(); } @@ -389,7 +388,7 @@ pub fn process_deposit< index, root, }, - ))) + ))); } state.eth1_deposit_index += 1; let public_key = &deposit.data.public_key; @@ -405,7 +404,7 @@ pub fn process_deposit< let domain = compute_domain(DomainType::Deposit, None, None, context)?; let signing_root = compute_signing_root(&mut deposit_message, domain)?; if verify_signature(public_key, signing_root.as_ref(), &deposit.data.signature).is_err() { - return Ok(()) + return Ok(()); } state.validators.push(get_validator_from_deposit(deposit, context)); state.balances.push(amount); @@ -471,7 +470,7 @@ pub fn process_sync_aggregate< signature: sync_aggregate.sync_committee_signature.clone(), root: signing_root, }, - ))) + ))); } let total_active_increments = get_total_active_balance(state, context)? / context.effective_balance_increment; @@ -537,7 +536,7 @@ pub fn process_proposer_slashing< if header_1.slot != header_2.slot { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::SlotMismatch(header_1.slot, header_2.slot), - ))) + ))); } if header_1.proposer_index != header_2.proposer_index { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( @@ -545,12 +544,12 @@ pub fn process_proposer_slashing< header_1.proposer_index, header_2.proposer_index, ), - ))) + ))); } if header_1 == header_2 { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::HeadersAreEqual(header_1.clone()), - ))) + ))); } let proposer_index = header_1.proposer_index; let proposer = state.validators.get(proposer_index).ok_or_else(|| { @@ -561,7 +560,7 @@ pub fn process_proposer_slashing< if !is_slashable_validator(proposer, get_current_epoch(state, context)) { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::ProposerIsNotSlashable(header_1.proposer_index), - ))) + ))); } let epoch = compute_epoch_at_slot(header_1.slot, context); let domain = get_domain(state, DomainType::BeaconProposer, Some(epoch), context)?; @@ -573,7 +572,7 @@ pub fn process_proposer_slashing< if verify_signature(public_key, signing_root.as_ref(), &signed_header.signature).is_err() { return Err(invalid_operation_error(InvalidOperation::ProposerSlashing( InvalidProposerSlashing::InvalidSignature(signed_header.signature.clone()), - ))) + ))); } } slash_validator(state, proposer_index, None, context) @@ -613,7 +612,7 @@ pub fn process_attester_slashing< Box::new(attestation_1.data.clone()), Box::new(attestation_2.data.clone()), ), - ))) + ))); } is_valid_indexed_attestation(state, attestation_1, context)?; is_valid_indexed_attestation(state, attestation_2, context)?; @@ -711,27 +710,27 @@ pub fn process_block_header< return Err(invalid_header_error(InvalidBeaconBlockHeader::StateSlotMismatch { state_slot: state.slot, block_slot: block.slot, - })) + })); } if block.slot <= state.latest_block_header.slot { return Err(invalid_header_error(InvalidBeaconBlockHeader::OlderThanLatestBlockHeader { block_slot: block.slot, latest_block_header_slot: state.latest_block_header.slot, - })) + })); } let proposer_index = get_beacon_proposer_index(state, context)?; if block.proposer_index != proposer_index { return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerIndexMismatch { block_proposer_index: block.proposer_index, proposer_index, - })) + })); } let expected_parent_root = state.latest_block_header.hash_tree_root()?; if block.parent_root != expected_parent_root { return Err(invalid_header_error(InvalidBeaconBlockHeader::ParentBlockRootMismatch { expected: expected_parent_root, provided: block.parent_root, - })) + })); } state.latest_block_header = BeaconBlockHeader { slot: block.slot, @@ -742,7 +741,7 @@ pub fn process_block_header< }; let proposer = &state.validators[block.proposer_index]; if proposer.slashed { - return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))) + return Err(invalid_header_error(InvalidBeaconBlockHeader::ProposerSlashed(proposer_index))); } Ok(()) } @@ -808,7 +807,7 @@ pub fn process_randao< let domain = get_domain(state, DomainType::Randao, Some(epoch), context)?; let signing_root = compute_signing_root(&mut epoch, domain)?; if verify_signature(&proposer.public_key, signing_root.as_ref(), &body.randao_reveal).is_err() { - return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))) + return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone()))); } let mix = xor(get_randao_mix(state, epoch), &hash(body.randao_reveal.as_ref())); let mix_index = epoch % context.epochs_per_historical_vector; @@ -1055,7 +1054,7 @@ pub fn process_justification_and_finalization< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch <= GENESIS_EPOCH + 1 { - return Ok(()) + return Ok(()); } let previous_indices = get_unslashed_participating_indices( state, @@ -1108,7 +1107,7 @@ pub fn process_inactivity_updates< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch == GENESIS_EPOCH { - return Ok(()) + return Ok(()); } let eligible_validator_indices = get_eligible_validator_indices(state, context).collect::>(); @@ -1160,7 +1159,7 @@ pub fn process_rewards_and_penalties< ) -> Result<()> { let current_epoch = get_current_epoch(state, context); if current_epoch == GENESIS_EPOCH { - return Ok(()) + return Ok(()); } let mut deltas = Vec::new(); for flag_index in 0..PARTICIPATION_FLAG_WEIGHTS.len() { @@ -1591,7 +1590,7 @@ pub fn is_valid_genesis_state< context: &Context, ) -> bool { if state.genesis_time < context.min_genesis_time { - return false + return false; } get_active_validator_indices(state, GENESIS_EPOCH).len() >= context.min_genesis_active_validator_count @@ -2096,7 +2095,7 @@ pub fn get_unslashed_participating_indices< requested: epoch, previous: previous_epoch, current: current_epoch, - }) + }); } let epoch_participation = if is_current { &state.current_epoch_participation @@ -2244,7 +2243,7 @@ pub fn is_valid_indexed_attestation< if attesting_indices.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesEmpty, - ))) + ))); } let mut prev = attesting_indices[0]; let mut duplicates = HashSet::new(); @@ -2252,7 +2251,7 @@ pub fn is_valid_indexed_attestation< if index < prev { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::AttestingIndicesNotSorted, - ))) + ))); } if index == prev { duplicates.insert(index); @@ -2262,7 +2261,7 @@ pub fn is_valid_indexed_attestation< if !duplicates.is_empty() { return Err(invalid_operation_error(InvalidOperation::IndexedAttestation( InvalidIndexedAttestation::DuplicateIndices(Vec::from_iter(duplicates)), - ))) + ))); } let mut public_keys = vec![]; for &index in &attesting_indices[..] { @@ -2416,7 +2415,7 @@ pub fn compute_shuffled_index( context: &Context, ) -> Result { if index >= index_count { - return Err(Error::InvalidShufflingIndex { index, total: index_count }) + return Err(Error::InvalidShufflingIndex { index, total: index_count }); } let mut pivot_input = [0u8; 33]; pivot_input[..32].copy_from_slice(seed.as_ref()); @@ -2467,7 +2466,7 @@ pub fn compute_proposer_index< context: &Context, ) -> Result { if indices.is_empty() { - return Err(Error::CollectionCannotBeEmpty) + return Err(Error::CollectionCannotBeEmpty); } let max_byte = u8::MAX as u64; let mut i = 0; @@ -2482,7 +2481,7 @@ pub fn compute_proposer_index< let random_byte = hash(hash_input).as_ref()[i % 32] as u64; let effective_balance = state.validators[candidate_index].effective_balance; if effective_balance * max_byte >= context.max_effective_balance * random_byte { - return Ok(candidate_index) + return Ok(candidate_index); } i += 1; } @@ -2636,7 +2635,7 @@ pub fn get_block_root_at_slot< requested: slot, lower_bound: state.slot - 1, upper_bound: state.slot + SLOTS_PER_HISTORICAL_ROOT as Slot, - }) + }); } Ok(&state.block_roots[slot as usize % SLOTS_PER_HISTORICAL_ROOT]) } @@ -3013,7 +3012,7 @@ pub fn get_attesting_indices< if bits.len() != committee.len() { return Err(invalid_operation_error(InvalidOperation::Attestation( InvalidAttestation::Bitfield { expected_length: committee.len(), length: bits.len() }, - ))) + ))); } let mut indices = HashSet::with_capacity(bits.capacity()); for (i, validator_index) in committee.iter().enumerate() { @@ -3113,7 +3112,7 @@ pub fn initiate_validator_exit< context: &Context, ) { if state.validators[index].exit_epoch != FAR_FUTURE_EPOCH { - return + return; } let mut exit_epochs: Vec = state .validators @@ -3198,7 +3197,7 @@ pub fn process_slots< context: &Context, ) -> Result<()> { if state.slot >= slot { - return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }) + return Err(Error::TransitionToPreviousSlot { requested: slot, current: state.slot }); } while state.slot < slot { process_slot(state, context)?; diff --git a/spec-gen/src/generator.rs b/spec-gen/src/generator.rs index cb8b4c536..bc4da7e0b 100644 --- a/spec-gen/src/generator.rs +++ b/spec-gen/src/generator.rs @@ -60,7 +60,6 @@ impl Fork { "blinded_beacon_block", "block_processing", "epoch_processing", - "execution_engine", "execution_payload", "fork_choice", "genesis", @@ -74,7 +73,6 @@ impl Fork { "block_processing", "bls_to_execution_change", "epoch_processing", - "execution_engine", "execution_payload", "genesis", "helpers", From e477edc635cff228d2d6b07639702ae9782d8ba0 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 25 Mar 2024 14:56:47 -0600 Subject: [PATCH 6/6] gen latest types --- ethereum-consensus/src/types/beacon_block.rs | 10 +++++----- ethereum-consensus/src/types/beacon_block_body.rs | 10 +++++----- ethereum-consensus/src/types/beacon_state.rs | 10 +++++----- ethereum-consensus/src/types/blinded_beacon_block.rs | 6 +++--- .../src/types/blinded_beacon_block_body.rs | 6 +++--- ethereum-consensus/src/types/execution_payload.rs | 6 +++--- .../src/types/execution_payload_header.rs | 6 +++--- ethereum-consensus/src/types/signed_beacon_block.rs | 10 +++++----- .../src/types/signed_blinded_beacon_block.rs | 6 +++--- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/ethereum-consensus/src/types/beacon_block.rs b/ethereum-consensus/src/types/beacon_block.rs index ab0cfd495..771f666da 100644 --- a/ethereum-consensus/src/types/beacon_block.rs +++ b/ethereum-consensus/src/types/beacon_block.rs @@ -520,19 +520,19 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Altair(inner)) + return Ok(Self::Altair(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Phase0(inner)) + return Ok(Self::Phase0(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/beacon_block_body.rs b/ethereum-consensus/src/types/beacon_block_body.rs index 1b3a34186..98fe73a9e 100644 --- a/ethereum-consensus/src/types/beacon_block_body.rs +++ b/ethereum-consensus/src/types/beacon_block_body.rs @@ -653,19 +653,19 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Altair(inner)) + return Ok(Self::Altair(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Phase0(inner)) + return Ok(Self::Phase0(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/beacon_state.rs b/ethereum-consensus/src/types/beacon_state.rs index fc7a5a288..91aa098ea 100644 --- a/ethereum-consensus/src/types/beacon_state.rs +++ b/ethereum-consensus/src/types/beacon_state.rs @@ -942,19 +942,19 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Altair(inner)) + return Ok(Self::Altair(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Phase0(inner)) + return Ok(Self::Phase0(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/blinded_beacon_block.rs b/ethereum-consensus/src/types/blinded_beacon_block.rs index 3663093fe..fe1a3bdeb 100644 --- a/ethereum-consensus/src/types/blinded_beacon_block.rs +++ b/ethereum-consensus/src/types/blinded_beacon_block.rs @@ -360,13 +360,13 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/blinded_beacon_block_body.rs b/ethereum-consensus/src/types/blinded_beacon_block_body.rs index bcdc98f56..8b1a0cfef 100644 --- a/ethereum-consensus/src/types/blinded_beacon_block_body.rs +++ b/ethereum-consensus/src/types/blinded_beacon_block_body.rs @@ -456,13 +456,13 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/execution_payload.rs b/ethereum-consensus/src/types/execution_payload.rs index 76c890cd2..5a468812a 100644 --- a/ethereum-consensus/src/types/execution_payload.rs +++ b/ethereum-consensus/src/types/execution_payload.rs @@ -427,13 +427,13 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/execution_payload_header.rs b/ethereum-consensus/src/types/execution_payload_header.rs index 63e455e98..a2b3be13d 100644 --- a/ethereum-consensus/src/types/execution_payload_header.rs +++ b/ethereum-consensus/src/types/execution_payload_header.rs @@ -328,13 +328,13 @@ impl<'de, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize> { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/signed_beacon_block.rs b/ethereum-consensus/src/types/signed_beacon_block.rs index 3d780218c..10c8bd0d1 100644 --- a/ethereum-consensus/src/types/signed_beacon_block.rs +++ b/ethereum-consensus/src/types/signed_beacon_block.rs @@ -466,19 +466,19 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Altair(inner)) + return Ok(Self::Altair(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Phase0(inner)) + return Ok(Self::Phase0(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) } diff --git a/ethereum-consensus/src/types/signed_blinded_beacon_block.rs b/ethereum-consensus/src/types/signed_blinded_beacon_block.rs index a98818eb7..02f6879b6 100644 --- a/ethereum-consensus/src/types/signed_blinded_beacon_block.rs +++ b/ethereum-consensus/src/types/signed_blinded_beacon_block.rs @@ -318,13 +318,13 @@ impl< { let value = serde_json::Value::deserialize(deserializer)?; if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Deneb(inner)) + return Ok(Self::Deneb(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Capella(inner)) + return Ok(Self::Capella(inner)); } if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) { - return Ok(Self::Bellatrix(inner)) + return Ok(Self::Bellatrix(inner)); } Err(serde::de::Error::custom("no variant could be deserialized from input")) }