Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop old polymorphic types in favor new ones #279

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions ethereum-consensus/src/bellatrix/execution_engine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
bellatrix::execution_payload::ExecutionPayload,
state_transition::{self, ExecutionEngineError, Result},
state_transition::{ExecutionEngineError, Result},
};

pub struct NewPayloadRequest<
Expand Down Expand Up @@ -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<B>
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)
}
}
11 changes: 7 additions & 4 deletions ethereum-consensus/src/deneb/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ 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::*,
state_transition::{
invalid_operation_error, Context, InvalidAttestation, InvalidExecutionPayload,
InvalidOperation, InvalidVoluntaryExit, Result,
},
types::ExecutionPayloadRef,
};

pub fn process_attestation<
Expand Down Expand Up @@ -243,10 +245,11 @@ pub fn process_execution_payload<
let versioned_hashes =
body.blob_kzg_commitments.iter().map(kzg_commitment_to_versioned_hash).collect::<Vec<_>>();

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)?;

Expand Down
157 changes: 87 additions & 70 deletions ethereum-consensus/src/deneb/execution_engine.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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<
Expand All @@ -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
// {
// }
5 changes: 3 additions & 2 deletions ethereum-consensus/src/deneb/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand Down Expand Up @@ -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;
44 changes: 44 additions & 0 deletions ethereum-consensus/src/execution_engine.rs
Original file line number Diff line number Diff line change
@@ -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<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,
>
{
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<()>;
}
8 changes: 8 additions & 0 deletions ethereum-consensus/src/fork.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(Debug)]
pub enum Fork {
Phase0,
Altair,
Bellatrix,
Capella,
Deneb,
}
4 changes: 4 additions & 0 deletions ethereum-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,3 +20,5 @@ pub mod signing;
pub mod ssz;
pub mod state_transition;
pub mod types;

pub use fork::Fork;
Loading