Skip to content

Commit

Permalink
feat: enhance block execution with new error handling and improved da…
Browse files Browse the repository at this point in the history
…ta structures
  • Loading branch information
johntaiko committed Dec 23, 2024
1 parent 47299a6 commit 80643d5
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 80 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion crates/evm/execution-types/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_eips::eip7685::Requests;
use alloy_primitives::U256;
use reth_primitives::TransactionSigned;
use reth_primitives::{BlockWithSenders, TransactionSigned};
use revm::db::BundleState;

/// A helper type for ethereum block inputs that consists of a block and the total difficulty.
Expand Down Expand Up @@ -72,3 +72,13 @@ pub struct BlockExecutionOutput<T> {
/// The skipped transactions when `BlockExecutionInput::enable_skip`.
pub skipped_list: Vec<usize>,
}

impl<T> BlockExecutionOutput<T> {
/// Remote the skipped transactions from the block.
pub fn apply_skip(&self, block: &mut BlockWithSenders) {
for i in &self.skipped_list {
block.senders.remove(*i);
block.body.transactions.remove(*i);
}
}
}
1 change: 1 addition & 0 deletions crates/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ where

/// A generic block executor provider that can create executors using a strategy factory.
#[allow(missing_debug_implementations)]
#[derive(Debug)]
pub struct BasicBlockExecutorProvider<F> {
strategy_factory: F,
}
Expand Down
5 changes: 4 additions & 1 deletion crates/payload/primitives/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use alloy_primitives::B256;
use alloy_rpc_types_engine::ForkchoiceUpdateError;
use reth_errors::{ProviderError, RethError};
use reth_errors::{BlockExecutionError, ProviderError, RethError};
use revm_primitives::EVMError;
use tokio::sync::oneshot;

Expand Down Expand Up @@ -30,6 +30,9 @@ pub enum PayloadBuilderError {
/// Any other payload building errors.
#[error(transparent)]
Other(Box<dyn core::error::Error + Send + Sync>),
/// Error during block execution.
#[error(transparent)]
BlockExecutionError(#[from] BlockExecutionError),
}

impl PayloadBuilderError {
Expand Down
2 changes: 1 addition & 1 deletion crates/taiko/consensus/proposer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Storage {
excess_blob_gas: None,
extra_data: Default::default(),
parent_beacon_block_root: None,
requests_root: requests.map(|r| proofs::calculate_requests_root(&r.0)),
requests_hash: requests.map(|r| r.requests_hash()),
};

if chain_spec.is_cancun_active_at_timestamp(timestamp) {
Expand Down
14 changes: 7 additions & 7 deletions crates/taiko/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use reth_revm::{Database, State};
use reth_taiko_chainspec::TaikoChainSpec;
use reth_taiko_consensus::{check_anchor_tx, decode_ontake_extra_data};
use reth_taiko_forks::TaikoHardforks;
use revm::{interpreter::Host, Evm, JournaledState};
use revm::{interpreter::Host, JournaledState};
use revm_primitives::{db::DatabaseCommit, EnvWithHandlerCfg, HashSet, ResultAndState, U256};
use std::io::{self, Write};
use tracing::debug;
Expand Down Expand Up @@ -135,14 +135,14 @@ where
let mut buf_len: u64 = 0;

for i in 0..block.body.transactions.len() {
let ref transaction = block.body.transactions[i];
let transaction = &block.body.transactions[i];
let sender = block.senders.get(i).unwrap();
let block_available_gas = block.header.gas_limit - cumulative_gas_used;
if transaction.gas_limit() > block_available_gas {
break;
}

self.evm_config.fill_tx_env(evm.tx_mut(), &transaction, *sender);
self.evm_config.fill_tx_env(evm.tx_mut(), transaction, *sender);

// Execute transaction.
let ResultAndState { result, state } = match evm.transact() {
Expand Down Expand Up @@ -259,7 +259,7 @@ where
let mut evm = self.evm_config.evm_with_env(&mut self.state, env);
let mut cumulative_gas_used = 0;
let mut receipts = Vec::with_capacity(block.body.transactions.len());
let mut skipped_transactions = Vec::with_capacity(block.body.transactions.len());
let mut skipped_list = Vec::with_capacity(block.body.transactions.len());
let treasury = self.chain_spec.treasury();

for (idx, (sender, transaction)) in block.transactions_with_sender().enumerate() {
Expand All @@ -282,7 +282,7 @@ where
if transaction.gas_limit() > block_available_gas {
if !is_anchor && enable_skip {
debug!(target: "taiko::executor", hash = ?transaction.hash(), want = ?transaction.gas_limit(), got = block_available_gas, "Invalid gas limit for tx");
skipped_transactions.push(idx);
skipped_list.push(idx);
continue;
}
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
Expand Down Expand Up @@ -326,7 +326,7 @@ where
HashSet::default(),
);
debug!(target: "taiko::executor", hash = ?transaction.hash(), error = ?err, "Invalid execute for tx");
skipped_transactions.push(idx);
skipped_list.push(idx);
continue;
}
return Err(err.into());
Expand Down Expand Up @@ -358,7 +358,7 @@ where
Ok(ExecuteOutput {
receipts,
gas_used: cumulative_gas_used,
skipped_list: skipped_transactions,
skipped_list,
target_list: vec![],
})
}
Expand Down
7 changes: 7 additions & 0 deletions crates/taiko/payload/builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ reth-basic-payload-builder.workspace = true
reth-evm = { workspace = true }
reth-errors.workspace = true
reth-chainspec = { workspace = true }
reth-payload-primitives.workspace = true
reth-chain-state.workspace = true

revm-primitives = { workspace = true, features = ["taiko"] }

# taiko
reth-taiko-evm.workspace = true
reth-taiko-engine-primitives.workspace = true
reth-taiko-primitives.workspace = true
reth-taiko-provider.workspace = true
reth-taiko-consensus.workspace = true
reth-taiko-chainspec.workspace = true

# crypto
alloy-rlp.workspace = true
alloy-primitives.workspace = true
alloy-eips.workspace = true
alloy-consensus.workspace = true

# misc
tracing.workspace = true
Expand Down
Loading

0 comments on commit 80643d5

Please sign in to comment.