Skip to content

Commit

Permalink
Merge pull request ralexstokes#339 from ralexstokes/more-ee
Browse files Browse the repository at this point in the history
Move `ExecutionEngine` abstraction to property of `Context` and add more spec tests
  • Loading branch information
ralexstokes authored Mar 25, 2024
2 parents c16f8b0 + 5453881 commit c21879c
Show file tree
Hide file tree
Showing 27 changed files with 222 additions and 750 deletions.
1 change: 1 addition & 0 deletions ethereum-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ serde = ["hex", "serde_json", "serde_yaml"]
async = ["tokio", "tokio-stream", "async-stream"]
secret-key-debug = [
] # enable if you want to be able to print `crypto::SecretKey`
spec-tests = [] # enable extra features for testing
ec = [
"secret-key-debug",
"clap",
Expand Down
10 changes: 2 additions & 8 deletions ethereum-consensus/examples/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ fn main() {
let current_epoch = bellatrix::get_current_epoch(&state, &context);
dbg!(current_epoch);

let execution_engine = bellatrix::DefaultExecutionEngine::default();
let _ = bellatrix::state_transition(
&mut state,
&mut signed_block,
&execution_engine,
Validation::Enabled,
&context,
);
let _ =
bellatrix::state_transition(&mut state, &mut signed_block, Validation::Enabled, &context);
dbg!(state.fork);
}
26 changes: 2 additions & 24 deletions ethereum-consensus/src/bellatrix/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ pub fn process_execution_payload<
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
E: ExecutionEngine<
NewPayloadRequest = ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
>,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand All @@ -51,7 +43,6 @@ pub fn process_execution_payload<
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
execution_engine: &E,
context: &Context,
) -> Result<()> {
let parent_hash_invalid =
Expand Down Expand Up @@ -89,6 +80,7 @@ pub fn process_execution_payload<
))
}

let execution_engine = context.execution_engine();
execution_engine.verify_and_notify_new_payload(&payload.clone())?;

state.latest_execution_payload_header = ExecutionPayloadHeader {
Expand Down Expand Up @@ -129,14 +121,6 @@ pub fn process_block<
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
E: ExecutionEngine<
NewPayloadRequest = ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
>,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand All @@ -163,17 +147,11 @@ pub fn process_block<
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
execution_engine: &E,
context: &Context,
) -> Result<()> {
process_block_header(state, block, context)?;
if is_execution_enabled(state, &block.body) {
process_execution_payload(
state,
&mut block.body.execution_payload,
execution_engine,
context,
)?;
process_execution_payload(state, &mut block.body.execution_payload, context)?;
}
process_randao(state, &block.body, context)?;
process_eth1_data(state, &block.body, context);
Expand Down
112 changes: 0 additions & 112 deletions ethereum-consensus/src/bellatrix/execution_engine.rs

This file was deleted.

16 changes: 16 additions & 0 deletions ethereum-consensus/src/bellatrix/execution_payload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
execution_engine::PayloadRequest,
primitives::{Bytes32, ExecutionAddress, Hash32, Root},
ssz::prelude::*,
Error,
Expand Down Expand Up @@ -36,6 +37,21 @@ pub struct ExecutionPayload<
pub transactions: List<Transaction<MAX_BYTES_PER_TRANSACTION>, MAX_TRANSACTIONS_PER_PAYLOAD>,
}

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,
> PayloadRequest
for ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>
{
}

#[derive(
Default, Debug, Clone, SimpleSerialize, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
Expand Down
1 change: 0 additions & 1 deletion ethereum-consensus/src/bellatrix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod beacon_state;
pub mod blinded_beacon_block;
pub mod block_processing;
pub mod epoch_processing;
pub mod execution_engine;
pub mod execution_payload;
pub mod fork;
pub mod fork_choice;
Expand Down
1 change: 0 additions & 1 deletion ethereum-consensus/src/bellatrix/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub use crate::{
},
block_processing::{process_block, process_execution_payload},
epoch_processing::{process_epoch, process_slashings},
execution_engine::DefaultExecutionEngine,
execution_payload::{ExecutionPayload, ExecutionPayloadHeader, Transaction},
fork::upgrade_to_bellatrix,
fork_choice::PowBlock,
Expand Down
25 changes: 3 additions & 22 deletions ethereum-consensus/src/bellatrix/state_transition.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
bellatrix::{
execution_payload::ExecutionPayload, process_block, process_slots, verify_block_signature,
BeaconState, ExecutionEngine, SignedBeaconBlock,
process_block, process_slots, verify_block_signature, BeaconState, SignedBeaconBlock,
},
ssz::prelude::Merkleized,
state_transition::{Context, Result, Validation},
Expand Down Expand Up @@ -29,14 +28,6 @@ pub fn state_transition_block_in_slot<
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
E: ExecutionEngine<
NewPayloadRequest = ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
>,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand All @@ -63,7 +54,6 @@ pub fn state_transition_block_in_slot<
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
execution_engine: &E,
validation: Validation,
context: &Context,
) -> Result<()> {
Expand All @@ -75,7 +65,7 @@ pub fn state_transition_block_in_slot<
verify_block_signature(state, signed_block, context)?;
}
let block = &mut signed_block.message;
process_block(state, block, execution_engine, context)?;
process_block(state, block, context)?;
if validate_result && block.state_root != state.hash_tree_root()? {
Err(Error::InvalidStateRoot)
} else {
Expand All @@ -101,14 +91,6 @@ pub fn state_transition<
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
E: ExecutionEngine<
NewPayloadRequest = ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
>,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand All @@ -135,11 +117,10 @@ pub fn state_transition<
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
execution_engine: &E,
validation: Validation,
context: &Context,
) -> Result<()> {
process_slots(state, signed_block.message.slot, context)?;

state_transition_block_in_slot(state, signed_block, execution_engine, validation, context)
state_transition_block_in_slot(state, signed_block, validation, context)
}
23 changes: 2 additions & 21 deletions ethereum-consensus/src/capella/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,6 @@ pub fn process_execution_payload<
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
E: ExecutionEngine<
NewPayloadRequest = ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
>,
>,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand All @@ -210,7 +201,6 @@ pub fn process_execution_payload<
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
>,
execution_engine: &E,
context: &Context,
) -> Result<()> {
let parent_hash_invalid =
Expand Down Expand Up @@ -248,6 +238,7 @@ pub fn process_execution_payload<
))
}

let execution_engine = context.execution_engine();
execution_engine.verify_and_notify_new_payload(&payload.clone())?;

state.latest_execution_payload_header = ExecutionPayloadHeader {
Expand Down Expand Up @@ -427,15 +418,6 @@ pub fn process_block<
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
E: ExecutionEngine<
NewPayloadRequest = ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
>,
>,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand Down Expand Up @@ -464,12 +446,11 @@ pub fn process_block<
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
>,
execution_engine: &E,
context: &Context,
) -> Result<()> {
process_block_header(state, block, context)?;
process_withdrawals(state, &block.body.execution_payload, context)?;
process_execution_payload(state, &mut block.body.execution_payload, execution_engine, context)?;
process_execution_payload(state, &mut block.body.execution_payload, context)?;
process_randao(state, &block.body, context)?;
process_eth1_data(state, &block.body, context);
process_operations(state, &mut block.body, context)?;
Expand Down
Loading

0 comments on commit c21879c

Please sign in to comment.