From 79f8c3e33cd69ca1baa7595db761a770ed742172 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 6 Oct 2023 11:40:59 -0600 Subject: [PATCH] wip: start refactor --- .../src/bellatrix/execution_engine.rs | 27 +- .../src/deneb/block_processing.rs | 11 +- .../src/deneb/execution_engine.rs | 157 +++++---- ethereum-consensus/src/deneb/spec/mod.rs | 5 +- ethereum-consensus/src/execution_engine.rs | 44 +++ ethereum-consensus/src/fork.rs | 8 + ethereum-consensus/src/lib.rs | 4 + .../src/state_transition/beacon_block.rs | 227 ------------ .../src/state_transition/beacon_state.rs | 323 ------------------ .../src/state_transition/context.rs | 22 +- .../src/state_transition/error.rs | 8 +- .../src/state_transition/execution_engine.rs | 48 --- .../src/state_transition/executor.rs | 78 ++++- .../src/state_transition/mod.rs | 6 - .../src/state_transition/presets/mainnet.rs | 16 +- .../src/state_transition/presets/minimal.rs | 16 +- .../src/types/execution_engine.rs | 223 ++++++++++++ ethereum-consensus/src/types/mod.rs | 2 + 18 files changed, 478 insertions(+), 747 deletions(-) create mode 100644 ethereum-consensus/src/execution_engine.rs create mode 100644 ethereum-consensus/src/fork.rs delete mode 100644 ethereum-consensus/src/state_transition/beacon_block.rs delete mode 100644 ethereum-consensus/src/state_transition/beacon_state.rs delete mode 100644 ethereum-consensus/src/state_transition/execution_engine.rs create mode 100644 ethereum-consensus/src/types/execution_engine.rs diff --git a/ethereum-consensus/src/bellatrix/execution_engine.rs b/ethereum-consensus/src/bellatrix/execution_engine.rs index 132710184..6c3ca7775 100644 --- a/ethereum-consensus/src/bellatrix/execution_engine.rs +++ b/ethereum-consensus/src/bellatrix/execution_engine.rs @@ -1,6 +1,6 @@ use crate::{ bellatrix::execution_payload::ExecutionPayload, - state_transition::{self, ExecutionEngineError, Result}, + state_transition::{ExecutionEngineError, Result}, }; pub struct NewPayloadRequest< @@ -123,28 +123,3 @@ impl< self.notify_new_payload(new_payload_request.0) } } - -impl< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - B: ExecutionEngine< - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - >, - > From - for state_transition::ExecutionEngine< - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - B, - > -{ - fn from(value: B) -> Self { - Self::Bellatrix(value) - } -} diff --git a/ethereum-consensus/src/deneb/block_processing.rs b/ethereum-consensus/src/deneb/block_processing.rs index 7c0d0caf0..ab49ccc87 100644 --- a/ethereum-consensus/src/deneb/block_processing.rs +++ b/ethereum-consensus/src/deneb/block_processing.rs @@ -8,10 +8,11 @@ use crate::{ is_valid_indexed_attestation, kzg_commitment_to_versioned_hash, process_block_header, process_eth1_data, process_operations, process_randao, process_sync_aggregate, process_withdrawals, Attestation, BeaconBlock, BeaconBlockBody, BeaconState, - ExecutionEngine, ExecutionPayloadHeader, NewPayloadRequest, SignedVoluntaryExit, - PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR, + ExecutionPayloadHeader, SignedVoluntaryExit, PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, + WEIGHT_DENOMINATOR, }, domains::DomainType, + execution_engine::{ExecutionEngine, NewPayloadRequest}, primitives::FAR_FUTURE_EPOCH, signing::verify_signed_data, ssz::prelude::*, @@ -19,6 +20,7 @@ use crate::{ invalid_operation_error, Context, InvalidAttestation, InvalidExecutionPayload, InvalidOperation, InvalidVoluntaryExit, Result, }, + types::ExecutionPayloadRef, }; pub fn process_attestation< @@ -243,10 +245,11 @@ pub fn process_execution_payload< let versioned_hashes = body.blob_kzg_commitments.iter().map(kzg_commitment_to_versioned_hash).collect::>(); + let payload_ref = ExecutionPayloadRef::from(&*payload); let new_payload_request = NewPayloadRequest { - execution_payload: &*payload, + execution_payload: payload_ref, versioned_hashes: &versioned_hashes, - parent_beacon_block_root: state.latest_block_header.parent_root, + parent_beacon_block_root: Some(state.latest_block_header.parent_root), }; execution_engine.verify_and_notify_new_payload(&new_payload_request)?; diff --git a/ethereum-consensus/src/deneb/execution_engine.rs b/ethereum-consensus/src/deneb/execution_engine.rs index 9463b9ce9..a10c1a625 100644 --- a/ethereum-consensus/src/deneb/execution_engine.rs +++ b/ethereum-consensus/src/deneb/execution_engine.rs @@ -1,74 +1,101 @@ use crate::{ deneb::execution_payload::ExecutionPayload, - kzg::VersionedHash, + execution_engine::{ExecutionEngine, NewPayloadRequest}, primitives::Root, state_transition::{ExecutionEngineError, Result}, + Fork, }; -pub struct NewPayloadRequest< - 'a, - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize, -> { - pub execution_payload: &'a ExecutionPayload< +impl< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + > + ExecutionEngine< BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, MAX_WITHDRAWALS_PER_PAYLOAD, - >, - pub versioned_hashes: &'a [VersionedHash], - pub parent_beacon_block_root: Root, -} - -pub trait ExecutionEngine< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize, -> + > + for DefaultExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + > { fn verify_and_notify_new_payload( &self, new_payload_request: &NewPayloadRequest< + '_, BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, MAX_WITHDRAWALS_PER_PAYLOAD, >, - ) -> Result<()>; + ) -> Result<()> { + self.verify_and_notify_new_payload(new_payload_request) + } } // The `DefaultExecutionEngine` performs no operations and validation // is determined by `execution_is_valid`. #[derive(Debug)] -pub struct DefaultExecutionEngine { +pub struct DefaultExecutionEngine< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +> { execution_is_valid: bool, } -impl Default for DefaultExecutionEngine { +impl< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + > Default + for DefaultExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + > +{ fn default() -> Self { Self { execution_is_valid: true } } } -impl DefaultExecutionEngine { - pub fn new(execution_is_valid: bool) -> Self { - Self { execution_is_valid } - } - - fn is_valid_block_hash< +impl< const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize, const MAX_BYTES_PER_TRANSACTION: usize, const MAX_TRANSACTIONS_PER_PAYLOAD: usize, const MAX_WITHDRAWALS_PER_PAYLOAD: usize, - >( + > + DefaultExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + > +{ + pub fn new(execution_is_valid: bool) -> Self { + Self { execution_is_valid } + } + + fn is_valid_block_hash( &self, _payload: &ExecutionPayload< BYTES_PER_LOGS_BLOOM, @@ -86,13 +113,7 @@ impl DefaultExecutionEngine { } } - fn is_valid_versioned_hashes< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize, - >( + fn is_valid_versioned_hashes( &self, _new_payload_request: &NewPayloadRequest< BYTES_PER_LOGS_BLOOM, @@ -109,13 +130,7 @@ impl DefaultExecutionEngine { } } - fn notify_new_payload< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize, - >( + fn notify_new_payload( &self, _payload: &ExecutionPayload< BYTES_PER_LOGS_BLOOM, @@ -132,23 +147,7 @@ impl DefaultExecutionEngine { Ok(()) } } -} -impl< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize, - > - ExecutionEngine< - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD, - > for DefaultExecutionEngine -{ fn verify_and_notify_new_payload( &self, new_payload_request: &NewPayloadRequest< @@ -159,16 +158,34 @@ impl< MAX_WITHDRAWALS_PER_PAYLOAD, >, ) -> Result<()> { - self.is_valid_block_hash( - new_payload_request.execution_payload, - &new_payload_request.parent_beacon_block_root, - )?; + let payload = new_payload_request + .execution_payload + .deneb() + .ok_or(ExecutionEngineError::MissingPayloadForFork(Fork::Deneb))?; + let parent_beacon_block_root = new_payload_request + .parent_beacon_block_root + .ok_or(ExecutionEngineError::MissingParentBeaconBlockRoot)?; + self.is_valid_block_hash(payload, &parent_beacon_block_root)?; self.is_valid_versioned_hashes(new_payload_request)?; - self.notify_new_payload( - new_payload_request.execution_payload, - &new_payload_request.parent_beacon_block_root, - ) + self.notify_new_payload(payload, &parent_beacon_block_root) } } + +// impl< +// const BYTES_PER_LOGS_BLOOM: usize, +// const MAX_EXTRA_DATA_BYTES: usize, +// const MAX_BYTES_PER_TRANSACTION: usize, +// const MAX_TRANSACTIONS_PER_PAYLOAD: usize, +// const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +// > +// ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// > for DefaultExecutionEngine +// { +// } diff --git a/ethereum-consensus/src/deneb/spec/mod.rs b/ethereum-consensus/src/deneb/spec/mod.rs index cb3977538..0512a2844 100644 --- a/ethereum-consensus/src/deneb/spec/mod.rs +++ b/ethereum-consensus/src/deneb/spec/mod.rs @@ -23,6 +23,7 @@ pub use crate::{ bellatrix::{execution_payload::Transaction, fork_choice::PowBlock}, capella::{ bls_to_execution_change::{BlsToExecutionChange, SignedBlsToExecutionChange}, + execution_engine::NewPayloadRequest, withdrawal::Withdrawal, }, deneb::{ @@ -40,7 +41,7 @@ pub use crate::{ process_attestation, process_block, process_execution_payload, process_voluntary_exit, }, epoch_processing::process_registry_updates, - execution_engine::{DefaultExecutionEngine, NewPayloadRequest}, + execution_engine::DefaultExecutionEngine, execution_payload::{ExecutionPayload, ExecutionPayloadHeader}, fork::upgrade_to_deneb, genesis::initialize_beacon_state_from_eth1, @@ -3383,4 +3384,4 @@ pub fn state_transition< process_slots(state, signed_block.message.slot, context)?; state_transition_block_in_slot(state, signed_block, execution_engine, validation, context) } -pub use crate::deneb::execution_engine::ExecutionEngine; +pub use crate::capella::execution_engine::ExecutionEngine; diff --git a/ethereum-consensus/src/execution_engine.rs b/ethereum-consensus/src/execution_engine.rs new file mode 100644 index 000000000..f167ff907 --- /dev/null +++ b/ethereum-consensus/src/execution_engine.rs @@ -0,0 +1,44 @@ +use crate::{ + kzg::VersionedHash, primitives::Root, state_transition::Result, types::ExecutionPayloadRef, +}; + +pub struct NewPayloadRequest< + 'a, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +> { + pub execution_payload: ExecutionPayloadRef< + 'a, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + pub versioned_hashes: &'a [VersionedHash], + pub parent_beacon_block_root: Option, +} + +pub trait ExecutionEngine< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +> +{ + fn verify_and_notify_new_payload( + &self, + new_payload_request: &NewPayloadRequest< + '_, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + ) -> Result<()>; +} diff --git a/ethereum-consensus/src/fork.rs b/ethereum-consensus/src/fork.rs new file mode 100644 index 000000000..1155ee52b --- /dev/null +++ b/ethereum-consensus/src/fork.rs @@ -0,0 +1,8 @@ +#[derive(Debug)] +pub enum Fork { + Phase0, + Altair, + Bellatrix, + Capella, + Deneb, +} diff --git a/ethereum-consensus/src/lib.rs b/ethereum-consensus/src/lib.rs index 05bdbb90f..efba4b910 100644 --- a/ethereum-consensus/src/lib.rs +++ b/ethereum-consensus/src/lib.rs @@ -7,6 +7,8 @@ pub mod configs; pub mod crypto; pub mod deneb; pub mod domains; +pub mod execution_engine; +pub mod fork; pub mod kzg; pub mod networking; pub mod networks; @@ -18,3 +20,5 @@ pub mod signing; pub mod ssz; pub mod state_transition; pub mod types; + +pub use fork::Fork; 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/context.rs b/ethereum-consensus/src/state_transition/context.rs index f0ce24620..7ce63ea66 100644 --- a/ethereum-consensus/src/state_transition/context.rs +++ b/ethereum-consensus/src/state_transition/context.rs @@ -7,17 +7,9 @@ use crate::{ phase0, primitives::{Epoch, ExecutionAddress, Gwei, Hash32, Slot, Version, U256}, state_transition::Error, + Fork, }; -#[derive(Debug)] -pub enum Forks { - Phase0, - Altair, - Bellatrix, - Capella, - Deneb, -} - #[derive(Debug, Default, Clone)] #[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub struct Context { @@ -357,18 +349,18 @@ impl Context { ) } - pub fn fork_for(&self, slot: Slot) -> Forks { + pub fn fork_for(&self, slot: Slot) -> Fork { let epoch = slot / self.slots_per_epoch; if epoch >= self.deneb_fork_epoch { - Forks::Deneb + Fork::Deneb } else if epoch >= self.capella_fork_epoch { - Forks::Capella + Fork::Capella } else if epoch >= self.bellatrix_fork_epoch { - Forks::Bellatrix + Fork::Bellatrix } else if epoch >= self.altair_fork_epoch { - Forks::Altair + Fork::Altair } else { - Forks::Phase0 + Fork::Phase0 } } diff --git a/ethereum-consensus/src/state_transition/error.rs b/ethereum-consensus/src/state_transition/error.rs index 99dda66b4..3649ca42b 100644 --- a/ethereum-consensus/src/state_transition/error.rs +++ b/ethereum-consensus/src/state_transition/error.rs @@ -4,7 +4,7 @@ use crate::{ phase0::{AttestationData, BeaconBlockHeader, Checkpoint}, primitives::{BlsPublicKey, BlsSignature, Bytes32, Epoch, Hash32, Root, Slot, ValidatorIndex}, ssz::prelude::*, - state_transition::Forks, + Fork, }; use thiserror::Error; @@ -47,7 +47,7 @@ pub enum Error { #[error( "transition requested from a later fork {destination_fork:?} to an earlier fork {source_fork:?}" )] - IncompatibleForks { source_fork: Forks, destination_fork: Forks }, + IncompatibleFork { source_fork: Fork, destination_fork: Fork }, #[error("genesis time unknown for network {0}")] UnknownGenesisTime(String), #[cfg(feature = "serde")] @@ -235,4 +235,8 @@ pub enum ExecutionEngineError { InvalidPayload, #[error("invalid versioned hashes in payload")] InvalidVersionedHashes, + #[error("missing payload for fork {0:?} in request")] + MissingPayloadForFork(Fork), + #[error("missing parent beacon block root in request")] + MissingParentBeaconBlockRoot, } diff --git a/ethereum-consensus/src/state_transition/execution_engine.rs b/ethereum-consensus/src/state_transition/execution_engine.rs deleted file mode 100644 index bacd818c1..000000000 --- a/ethereum-consensus/src/state_transition/execution_engine.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::bellatrix; - -#[derive(Debug)] -pub enum ExecutionEngine< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - B: bellatrix::ExecutionEngine< - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - >, -> { - Bellatrix(B), -} - -impl< - const BYTES_PER_LOGS_BLOOM: usize, - const MAX_EXTRA_DATA_BYTES: usize, - const MAX_BYTES_PER_TRANSACTION: usize, - const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - B: bellatrix::ExecutionEngine< - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - >, - > - ExecutionEngine< - BYTES_PER_LOGS_BLOOM, - MAX_EXTRA_DATA_BYTES, - MAX_BYTES_PER_TRANSACTION, - MAX_TRANSACTIONS_PER_PAYLOAD, - B, - > -{ - pub fn new(bellatrix: B) -> Self { - Self::Bellatrix(bellatrix) - } - - pub fn bellatrix(&self) -> &B { - match self { - Self::Bellatrix(engine) => engine, - } - } -} diff --git a/ethereum-consensus/src/state_transition/executor.rs b/ethereum-consensus/src/state_transition/executor.rs index b36b8c56b..f207934f0 100644 --- a/ethereum-consensus/src/state_transition/executor.rs +++ b/ethereum-consensus/src/state_transition/executor.rs @@ -1,9 +1,8 @@ use crate::{ - altair, bellatrix, phase0, - state_transition::{ - execution_engine::ExecutionEngine, BeaconState, Context, Error, Forks, Result, - SignedBeaconBlock, Validation, - }, + altair, bellatrix, capella, deneb, phase0, + state_transition::{Context, Error, Result, Validation}, + types::{BeaconState, ExecutionEngine, SignedBeaconBlock}, + Fork, }; #[derive(Debug)] @@ -26,12 +25,29 @@ 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, B: bellatrix::ExecutionEngine< BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, >, + C: capella::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + D: deneb::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, > { pub state: BeaconState< SLOTS_PER_HISTORICAL_ROOT, @@ -51,7 +67,10 @@ pub struct Executor< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, B, + C, + D, >, pub context: Context, } @@ -75,12 +94,29 @@ 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, B: bellatrix::ExecutionEngine< BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, >, + C: capella::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + D: deneb::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, > Executor< SLOTS_PER_HISTORICAL_ROOT, @@ -101,7 +137,12 @@ impl< MAX_ATTESTATIONS, MAX_DEPOSITS, MAX_VOLUNTARY_EXITS, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_BLOB_COMMITMENTS_PER_BLOCK, B, + C, + D, > { pub fn new( @@ -123,7 +164,10 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, B, + C, + D, >, context: Context, ) -> Self { @@ -144,6 +188,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) @@ -163,6 +210,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<()> { @@ -195,13 +245,13 @@ impl< BeaconState::Phase0(state) => { phase0::state_transition(state, signed_block, validation, &self.context) } - BeaconState::Altair(_) => Err(Error::IncompatibleForks { - source_fork: Forks::Altair, - destination_fork: Forks::Phase0, + BeaconState::Altair(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Altair, + destination_fork: Fork::Phase0, }), - BeaconState::Bellatrix(_) => Err(Error::IncompatibleForks { - source_fork: Forks::Bellatrix, - destination_fork: Forks::Phase0, + BeaconState::Bellatrix(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Bellatrix, + destination_fork: Fork::Phase0, }), } } @@ -240,9 +290,9 @@ impl< BeaconState::Altair(state) => { altair::state_transition(state, signed_block, validation, &self.context) } - BeaconState::Bellatrix(_) => Err(Error::IncompatibleForks { - source_fork: Forks::Bellatrix, - destination_fork: Forks::Altair, + BeaconState::Bellatrix(_) => Err(Error::IncompatibleFork { + source_fork: Fork::Bellatrix, + destination_fork: Fork::Altair, }), } } diff --git a/ethereum-consensus/src/state_transition/mod.rs b/ethereum-consensus/src/state_transition/mod.rs index cad034880..374bff7a6 100644 --- a/ethereum-consensus/src/state_transition/mod.rs +++ b/ethereum-consensus/src/state_transition/mod.rs @@ -1,16 +1,10 @@ -mod beacon_block; -mod beacon_state; mod context; pub mod error; -mod execution_engine; mod executor; mod presets; -pub use beacon_block::*; -pub use beacon_state::*; pub use context::*; pub use error::*; -pub use execution_engine::*; pub use executor::*; pub type Result = std::result::Result; diff --git a/ethereum-consensus/src/state_transition/presets/mainnet.rs b/ethereum-consensus/src/state_transition/presets/mainnet.rs index 927e704a7..1e308e2ed 100644 --- a/ethereum-consensus/src/state_transition/presets/mainnet.rs +++ b/ethereum-consensus/src/state_transition/presets/mainnet.rs @@ -4,20 +4,21 @@ 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, MAX_PROPOSER_SLASHINGS, MAX_VALIDATORS_PER_COMMITTEE, MAX_VOLUNTARY_EXITS, PENDING_ATTESTATIONS_BOUND, SLOTS_PER_HISTORICAL_ROOT, VALIDATOR_REGISTRY_LIMIT, }, - state_transition, + state_transition, types, }; -pub use state_transition::{ - BeaconState, Context, Error, ExecutionEngine, SignedBeaconBlock, Validation, -}; +pub use state_transition::{Context, Error, Validation}; +pub use types::{BeaconState, ExecutionEngine, SignedBeaconBlock}; -pub type Executor = state_transition::Executor< +pub type Executor = state_transition::Executor< SLOTS_PER_HISTORICAL_ROOT, HISTORICAL_ROOTS_LIMIT, ETH1_DATA_VOTES_BOUND, @@ -36,5 +37,10 @@ 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, B, + C, + D, >; diff --git a/ethereum-consensus/src/state_transition/presets/minimal.rs b/ethereum-consensus/src/state_transition/presets/minimal.rs index 09b452cf9..3f30091d4 100644 --- a/ethereum-consensus/src/state_transition/presets/minimal.rs +++ b/ethereum-consensus/src/state_transition/presets/minimal.rs @@ -4,20 +4,21 @@ 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, MAX_PROPOSER_SLASHINGS, MAX_VALIDATORS_PER_COMMITTEE, MAX_VOLUNTARY_EXITS, PENDING_ATTESTATIONS_BOUND, SLOTS_PER_HISTORICAL_ROOT, VALIDATOR_REGISTRY_LIMIT, }, - state_transition, + state_transition, types, }; -pub use state_transition::{ - BeaconState, Context, Error, ExecutionEngine, SignedBeaconBlock, Validation, -}; +pub use state_transition::{Context, Error, Validation}; +pub use types::{BeaconState, ExecutionEngine, SignedBeaconBlock}; -pub type Executor = state_transition::Executor< +pub type Executor = state_transition::Executor< SLOTS_PER_HISTORICAL_ROOT, HISTORICAL_ROOTS_LIMIT, ETH1_DATA_VOTES_BOUND, @@ -36,5 +37,10 @@ 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, B, + C, + D, >; diff --git a/ethereum-consensus/src/types/execution_engine.rs b/ethereum-consensus/src/types/execution_engine.rs new file mode 100644 index 000000000..602de9a94 --- /dev/null +++ b/ethereum-consensus/src/types/execution_engine.rs @@ -0,0 +1,223 @@ +use crate::{bellatrix, capella, deneb}; + +#[derive(Debug)] +pub enum ExecutionEngine< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + B: bellatrix::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + >, + C: capella::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + D: deneb::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, +> { + Bellatrix(B), + Capella(C), + Deneb(D), +} + +impl< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + B: bellatrix::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + >, + C: capella::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + D: deneb::ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + > + ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + B, + C, + D, + > +{ + pub fn bellatrix(&self) -> Option<&B> { + match self { + Self::Bellatrix(inner) => Some(inner), + _ => None, + } + } + + pub fn capella(&self) -> Option<&C> { + match self { + Self::Capella(inner) => Some(inner), + _ => None, + } + } + + pub fn deneb(&self) -> Option<&D> { + match self { + Self::Deneb(inner) => Some(inner), + _ => None, + } + } +} + +// impl< +// const BYTES_PER_LOGS_BLOOM: usize, +// const MAX_EXTRA_DATA_BYTES: usize, +// const MAX_BYTES_PER_TRANSACTION: usize, +// const MAX_TRANSACTIONS_PER_PAYLOAD: usize, +// const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +// B: bellatrix::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// >, +// C: capella::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// >, +// D: deneb::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// >, +// > From +// for ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// B, +// C, +// D, +// > +// { +// fn from(value: B) -> Self { +// Self::Bellatrix(value) +// } +// } + +// impl< +// const BYTES_PER_LOGS_BLOOM: usize, +// const MAX_EXTRA_DATA_BYTES: usize, +// const MAX_BYTES_PER_TRANSACTION: usize, +// const MAX_TRANSACTIONS_PER_PAYLOAD: usize, +// const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +// B: bellatrix::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// >, +// C: capella::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// >, +// D: deneb::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// >, +// > From +// for ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// B, +// C, +// D, +// > +// { +// fn from(value: C) -> Self { +// Self::Capella(value) +// } +// } + +// impl< +// const BYTES_PER_LOGS_BLOOM: usize, +// const MAX_EXTRA_DATA_BYTES: usize, +// const MAX_BYTES_PER_TRANSACTION: usize, +// const MAX_TRANSACTIONS_PER_PAYLOAD: usize, +// const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +// B: bellatrix::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// >, +// C: capella::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// >, +// D: deneb::ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// >, +// > From +// for ExecutionEngine< +// BYTES_PER_LOGS_BLOOM, +// MAX_EXTRA_DATA_BYTES, +// MAX_BYTES_PER_TRANSACTION, +// MAX_TRANSACTIONS_PER_PAYLOAD, +// MAX_WITHDRAWALS_PER_PAYLOAD, +// B, +// C, +// D, +// > +// { +// fn from(value: D) -> Self { +// Self::Deneb(value) +// } +// } diff --git a/ethereum-consensus/src/types/mod.rs b/ethereum-consensus/src/types/mod.rs index db004817a..b65578cdb 100644 --- a/ethereum-consensus/src/types/mod.rs +++ b/ethereum-consensus/src/types/mod.rs @@ -9,6 +9,7 @@ mod beacon_block_body; mod beacon_state; mod blinded_beacon_block; mod blinded_beacon_block_body; +mod execution_engine; mod execution_payload; mod execution_payload_header; mod signed_beacon_block; @@ -19,6 +20,7 @@ pub use beacon_block_body::*; pub use beacon_state::*; pub use blinded_beacon_block::*; pub use blinded_beacon_block_body::*; +pub use execution_engine::*; pub use execution_payload::*; pub use execution_payload_header::*; pub use signed_beacon_block::*;