From 6c6e036e0947fad138d1627fc7e7b881e3b8947b Mon Sep 17 00:00:00 2001 From: clabby Date: Fri, 20 Sep 2024 23:30:24 -0400 Subject: [PATCH 1/2] feat(executor): Migrate to `thiserror` --- Cargo.lock | 1 + bin/client/src/kona.rs | 14 +-- crates/executor/Cargo.toml | 3 +- crates/executor/benches/execution.rs | 13 +-- crates/executor/src/builder.rs | 36 ++----- crates/executor/src/canyon.rs | 8 +- crates/executor/src/eip4788.rs | 30 +++--- crates/executor/src/errors.rs | 39 +++++++ crates/executor/src/lib.rs | 146 +++++++++++++++------------ 9 files changed, 168 insertions(+), 122 deletions(-) create mode 100644 crates/executor/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index 6f9bd0bd90..d7a7ff5af9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2394,6 +2394,7 @@ dependencies = [ "revm", "serde", "serde_json", + "thiserror 1.0.63 (git+https://github.com/quartiq/thiserror?branch=no-std)", "tracing", ] diff --git a/bin/client/src/kona.rs b/bin/client/src/kona.rs index 1386bd67a2..cb8e09d615 100644 --- a/bin/client/src/kona.rs +++ b/bin/client/src/kona.rs @@ -61,12 +61,14 @@ fn main() -> Result<()> { let OptimismAttributesWithParent { attributes, .. } = driver.produce_disputed_payload().await?; - let mut executor = StatelessL2BlockExecutor::builder(&boot.rollup_config) - .with_parent_header(driver.take_l2_safe_head_header()) - .with_provider(l2_provider.clone()) - .with_hinter(l2_provider) - .with_handle_register(fpvm_handle_register) - .build()?; + let mut executor = StatelessL2BlockExecutor::builder( + &boot.rollup_config, + l2_provider.clone(), + l2_provider, + ) + .with_parent_header(driver.take_l2_safe_head_header()) + .with_handle_register(fpvm_handle_register) + .build(); let Header { number, .. } = *executor.execute_payload(attributes)?; let output_root = executor.compute_output_root()?; diff --git a/crates/executor/Cargo.toml b/crates/executor/Cargo.toml index 6fe25ac207..f1ea6f2cc2 100644 --- a/crates/executor/Cargo.toml +++ b/crates/executor/Cargo.toml @@ -10,7 +10,7 @@ homepage.workspace = true [dependencies] # General -anyhow.workspace = true +thiserror.workspace = true tracing.workspace = true alloy-primitives = { workspace = true, features = ["rlp"] } alloy-eips.workspace = true @@ -24,6 +24,7 @@ revm = { workspace = true, features = ["optimism"] } kona-mpt.workspace = true [dev-dependencies] +anyhow.workspace = true alloy-rlp.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/crates/executor/benches/execution.rs b/crates/executor/benches/execution.rs index 06c4c0fe6c..140a1c2254 100644 --- a/crates/executor/benches/execution.rs +++ b/crates/executor/benches/execution.rs @@ -79,12 +79,13 @@ fn op_mainnet_exec_bench( // Bench the block execution. bencher.iter(|| { - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(pre_state_header.clone().seal_slow()) - .with_provider(TestdataTrieProvider::new(data_folder)) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new(data_folder), + NoopTrieHinter, + ) + .with_parent_header(pre_state_header.clone().seal_slow()) + .build(); l2_block_executor.execute_payload(payload_attrs.clone()).unwrap(); }); } diff --git a/crates/executor/src/builder.rs b/crates/executor/src/builder.rs index ca3cffb447..8a62c2f2c5 100644 --- a/crates/executor/src/builder.rs +++ b/crates/executor/src/builder.rs @@ -2,7 +2,6 @@ use crate::StatelessL2BlockExecutor; use alloy_consensus::{Header, Sealable, Sealed}; -use anyhow::Result; use kona_mpt::{TrieDB, TrieHinter, TrieProvider}; use op_alloy_genesis::RollupConfig; use revm::{db::State, handler::register::EvmHandler}; @@ -20,14 +19,14 @@ where { /// The [RollupConfig]. config: &'a RollupConfig, + /// The [TrieProvider] to fetch the state trie preimages. + provider: F, + /// The [TrieHinter] to hint the state trie preimages. + hinter: H, /// The parent [Header] to begin execution from. parent_header: Option>, /// The [KonaHandleRegister] to use during execution. handler_register: Option>, - /// The [TrieProvider] to fetch the state trie preimages. - fetcher: Option, - /// The [TrieHinter] to hint the state trie preimages. - hinter: Option, } impl<'a, F, H> StatelessL2BlockExecutorBuilder<'a, F, H> @@ -36,8 +35,8 @@ where H: TrieHinter, { /// Instantiate a new builder with the given [RollupConfig]. - pub fn with_config(config: &'a RollupConfig) -> Self { - Self { config, parent_header: None, handler_register: None, fetcher: None, hinter: None } + pub fn new(config: &'a RollupConfig, provider: F, hinter: H) -> Self { + Self { config, provider, hinter, parent_header: None, handler_register: None } } /// Set the [Header] to begin execution from. @@ -46,18 +45,6 @@ where self } - /// Set the [TrieProvider] to fetch the state trie preimages. - pub fn with_provider(mut self, fetcher: F) -> Self { - self.fetcher = Some(fetcher); - self - } - - /// Set the [TrieHinter] to hint the state trie preimages. - pub fn with_hinter(mut self, hinter: H) -> Self { - self.hinter = Some(hinter); - self - } - /// Set the [KonaHandleRegister] for execution. pub fn with_handle_register(mut self, handler_register: KonaHandleRegister) -> Self { self.handler_register = Some(handler_register); @@ -65,19 +52,18 @@ where } /// Build the [StatelessL2BlockExecutor] from the builder configuration. - pub fn build(self) -> Result> { - let fetcher = self.fetcher.ok_or(anyhow::anyhow!("Fetcher not set"))?; - let hinter = self.hinter.ok_or(anyhow::anyhow!("Hinter not set"))?; + pub fn build(self) -> StatelessL2BlockExecutor<'a, F, H> { let parent_header = self.parent_header.unwrap_or_else(|| { let default_header = Header::default(); default_header.seal_slow() }); - let trie_db = TrieDB::new(parent_header.state_root, parent_header, fetcher, hinter); - Ok(StatelessL2BlockExecutor { + let trie_db = + TrieDB::new(parent_header.state_root, parent_header, self.provider, self.hinter); + StatelessL2BlockExecutor { config: self.config, trie_db, handler_register: self.handler_register, - }) + } } } diff --git a/crates/executor/src/canyon.rs b/crates/executor/src/canyon.rs index 0687eb0a36..52444eb2af 100644 --- a/crates/executor/src/canyon.rs +++ b/crates/executor/src/canyon.rs @@ -1,7 +1,7 @@ //! Contains logic specific to Canyon hardfork activation. +use crate::errors::ExecutorResult; use alloy_primitives::{address, b256, hex, Address, Bytes, B256}; -use anyhow::Result; use kona_mpt::{TrieDB, TrieHinter, TrieProvider}; use op_alloy_genesis::RollupConfig; use revm::{ @@ -26,15 +26,15 @@ pub(crate) fn ensure_create2_deployer_canyon( db: &mut State<&mut TrieDB>, config: &RollupConfig, timestamp: u64, -) -> Result<()> +) -> ExecutorResult<()> where F: TrieProvider, H: TrieHinter, { // If the canyon hardfork is active at the current timestamp, and it was not active at the // previous block timestamp, then we need to force-deploy the create2 deployer contract. - if config.is_canyon_active(timestamp) && - !config.is_canyon_active(db.database.parent_block_header().timestamp) + if config.is_canyon_active(timestamp) + && !config.is_canyon_active(db.database.parent_block_header().timestamp) { // Load the create2 deployer account from the cache. let acc = db.load_cache_account(CREATE_2_DEPLOYER_ADDR)?; diff --git a/crates/executor/src/eip4788.rs b/crates/executor/src/eip4788.rs index c445c421aa..1e71662729 100644 --- a/crates/executor/src/eip4788.rs +++ b/crates/executor/src/eip4788.rs @@ -1,29 +1,32 @@ //! Contains the logic for executing the pre-block beacon root call. +use crate::errors::{ExecutorError, ExecutorResult}; use alloc::{boxed::Box, vec::Vec}; use alloy_eips::eip4788::BEACON_ROOTS_ADDRESS; use alloy_primitives::{Address, Bytes, B256, U256}; -use anyhow::{anyhow, Result}; +use kona_mpt::{TrieDB, TrieHinter, TrieProvider}; use op_alloy_genesis::RollupConfig; use op_alloy_rpc_types_engine::OptimismPayloadAttributes; use revm::{ + db::State, primitives::{ BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, OptimismFields, TransactTo, TxEnv, }, - Database, DatabaseCommit, Evm, + DatabaseCommit, Evm, }; /// Execute the EIP-4788 pre-block beacon root contract call. -pub(crate) fn pre_block_beacon_root_contract_call( - db: &mut DB, +pub(crate) fn pre_block_beacon_root_contract_call( + db: &mut State<&mut TrieDB>, config: &RollupConfig, block_number: u64, initialized_cfg: &CfgEnvWithHandlerCfg, initialized_block_env: &BlockEnv, payload: &OptimismPayloadAttributes, -) -> Result<()> +) -> ExecutorResult<()> where - DB::Error: core::fmt::Display, + F: TrieProvider, + H: TrieHinter, { // apply pre-block EIP-4788 contract call let mut evm_pre_block = Evm::builder() @@ -46,28 +49,29 @@ where } /// Apply the EIP-4788 pre-block beacon root contract call to a given EVM instance. -fn apply_beacon_root_contract_call( +fn apply_beacon_root_contract_call( config: &RollupConfig, timestamp: u64, block_number: u64, parent_beacon_block_root: Option, - evm: &mut Evm<'_, EXT, DB>, -) -> Result<()> + evm: &mut Evm<'_, (), &mut State<&mut TrieDB>>, +) -> ExecutorResult<()> where - DB::Error: core::fmt::Display, + F: TrieProvider, + H: TrieHinter, { if !config.is_ecotone_active(timestamp) { return Ok(()); } let parent_beacon_block_root = - parent_beacon_block_root.ok_or(anyhow!("missing parent beacon block root"))?; + parent_beacon_block_root.ok_or(ExecutorError::MissingParentBeaconBlockRoot)?; // if the block number is zero (genesis block) then the parent beacon block root must // be 0x0 and no system transaction may occur as per EIP-4788 if block_number == 0 { if parent_beacon_block_root != B256::ZERO { - anyhow::bail!("Cancun genesis block parent beacon block root must be 0x0"); + return Err(ExecutorError::MissingParentBeaconBlockRoot); } return Ok(()); } @@ -82,7 +86,7 @@ where Ok(res) => res.state, Err(e) => { evm.context.evm.env = previous_env; - anyhow::bail!("Failed to execute pre block call: {}", e); + return Err(ExecutorError::ExecutionError(e)); } }; diff --git a/crates/executor/src/errors.rs b/crates/executor/src/errors.rs new file mode 100644 index 0000000000..9c4f97d99d --- /dev/null +++ b/crates/executor/src/errors.rs @@ -0,0 +1,39 @@ +//! Errors for the `kona-executor` crate. + +use kona_mpt::TrieDBError; +use revm::primitives::EVMError; +use thiserror::Error; + +/// The error type for the [StatelessL2BlockExecutor]. +/// +/// [StatelessL2BlockExecutor]: crate::StatelessL2BlockExecutor +#[derive(Error, Debug)] +pub enum ExecutorError { + /// Missing gas limit in the payload attributes. + #[error("Gas limit not provided in payload attributes")] + MissingGasLimit, + /// Missing parent beacon block root in the payload attributes. + #[error("Parent beacon block root not provided in payload attributes")] + MissingParentBeaconBlockRoot, + /// Block gas limit exceeded. + #[error("Block gas limit exceeded")] + BlockGasLimitExceeded, + /// Unsupported transaction type. + #[error("Unsupported transaction type: {0}")] + UnsupportedTransactionType(u8), + /// Trie DB error. + #[error("Trie error: {0}")] + TrieDBError(#[from] TrieDBError), + /// Execution error. + #[error("Execution error: {0}")] + ExecutionError(EVMError), + /// Signature error. + #[error("Signature error: {0}")] + SignatureError(alloy_primitives::SignatureError), + /// RLP error. + #[error("RLP error: {0}")] + RLPError(alloy_eips::eip2718::Eip2718Error), +} + +/// A [Result] type for the [ExecutorError] enum. +pub type ExecutorResult = Result; diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index f1bc21d93e..1ed7ab555b 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -11,8 +11,7 @@ use alloc::vec::Vec; use alloy_consensus::{Header, Sealable, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH}; use alloy_eips::eip2718::{Decodable2718, Encodable2718}; use alloy_primitives::{address, keccak256, Address, Bytes, TxKind, B256, U256}; -use anyhow::{anyhow, Result}; -use kona_mpt::{ordered_trie_with_encoder, TrieDB, TrieHinter, TrieProvider}; +use kona_mpt::{ordered_trie_with_encoder, TrieDB, TrieDBError, TrieHinter, TrieProvider}; use op_alloy_consensus::{OpReceiptEnvelope, OpTxEnvelope}; use op_alloy_genesis::RollupConfig; use op_alloy_rpc_types_engine::OptimismPayloadAttributes; @@ -26,6 +25,9 @@ use revm::{ }; use tracing::{debug, info}; +mod errors; +pub use errors::{ExecutorError, ExecutorResult}; + mod builder; pub use builder::{KonaHandleRegister, StatelessL2BlockExecutorBuilder}; @@ -60,8 +62,12 @@ where H: TrieHinter, { /// Constructs a new [StatelessL2BlockExecutorBuilder] with the given [RollupConfig]. - pub fn builder(config: &'a RollupConfig) -> StatelessL2BlockExecutorBuilder<'a, F, H> { - StatelessL2BlockExecutorBuilder::with_config(config) + pub fn builder( + config: &'a RollupConfig, + provider: F, + hinter: H, + ) -> StatelessL2BlockExecutorBuilder<'a, F, H> { + StatelessL2BlockExecutorBuilder::new(config, provider, hinter) } /// Executes the given block, returning the resulting state root. @@ -80,7 +86,10 @@ where /// 4. Merge all state transitions into the cache state. /// 5. Compute the [state root, transactions root, receipts root, logs bloom] for the processed /// block. - pub fn execute_payload(&mut self, payload: OptimismPayloadAttributes) -> Result<&Header> { + pub fn execute_payload( + &mut self, + payload: OptimismPayloadAttributes, + ) -> ExecutorResult<&Header> { // Prepare the `revm` environment. let initialized_block_env = Self::prepare_block_env( self.revm_spec_id(payload.payload_attributes.timestamp), @@ -91,8 +100,7 @@ where let initialized_cfg = self.evm_cfg_env(payload.payload_attributes.timestamp); let block_number = initialized_block_env.number.to::(); let base_fee = initialized_block_env.basefee.to::(); - let gas_limit = - payload.gas_limit.ok_or(anyhow!("Gas limit not provided in payload attributes"))?; + let gas_limit = payload.gas_limit.ok_or(ExecutorError::MissingGasLimit)?; info!( target: "client_executor", @@ -150,11 +158,11 @@ where let transactions = if let Some(ref txs) = payload.transactions { txs.iter() .map(|raw_tx| { - let tx = - OpTxEnvelope::decode_2718(&mut raw_tx.as_ref()).map_err(|e| anyhow!(e))?; + let tx = OpTxEnvelope::decode_2718(&mut raw_tx.as_ref()) + .map_err(ExecutorError::RLPError)?; Ok((tx, raw_tx.as_ref())) }) - .collect::>>()? + .collect::>>()? } else { Vec::new() }; @@ -162,15 +170,15 @@ where // The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior, // must be no greater than the block’s gasLimit. let block_available_gas = (gas_limit - cumulative_gas_used) as u128; - if extract_tx_gas_limit(&transaction) > block_available_gas && - (is_regolith || !is_system_transaction(&transaction)) + if extract_tx_gas_limit(&transaction) > block_available_gas + && (is_regolith || !is_system_transaction(&transaction)) { - anyhow::bail!("Transaction gas limit exceeds block gas limit") + return Err(ExecutorError::BlockGasLimitExceeded); } // Reject any EIP-4844 transactions. if matches!(transaction, OpTxEnvelope::Eip4844(_)) { - anyhow::bail!("EIP-4844 transactions are not supported"); + return Err(ExecutorError::UnsupportedTransactionType(transaction.tx_type() as u8)); } // Modify the transaction environment with the current transaction. @@ -200,7 +208,7 @@ where target: "client_executor", "Executing transaction: {tx_hash}", ); - let result = evm.transact_commit().map_err(|e| anyhow!("Fatal EVM Error: {e}"))?; + let result = evm.transact_commit().map_err(ExecutorError::ExecutionError)?; debug!( target: "client_executor", "Transaction executed: {tx_hash} | Gas used: {gas_used} | Success: {status}", @@ -346,7 +354,7 @@ where /// ## Returns /// - `Ok(output_root)`: The computed output root. /// - `Err(_)`: If an error occurred while computing the output root. - pub fn compute_output_root(&mut self) -> Result { + pub fn compute_output_root(&mut self) -> ExecutorResult { const OUTPUT_ROOT_VERSION: u8 = 0; const L2_TO_L1_MESSAGE_PASSER_ADDRESS: Address = address!("4200000000000000000000000000000000000016"); @@ -354,13 +362,13 @@ where // Fetch the L2 to L1 message passer account from the cache or underlying trie. let storage_root = match self.trie_db.storage_roots().get(&L2_TO_L1_MESSAGE_PASSER_ADDRESS) { - Some(storage_root) => storage_root - .blinded_commitment() - .ok_or(anyhow!("Account storage root is unblinded"))?, + Some(storage_root) => { + storage_root.blinded_commitment().ok_or(TrieDBError::RootNotBlinded)? + } None => { self.trie_db .get_trie_account(&L2_TO_L1_MESSAGE_PASSER_ADDRESS)? - .ok_or(anyhow!("L2 to L1 message passer account not found in trie"))? + .ok_or(TrieDBError::MissingAccountInfo)? .storage_root } }; @@ -528,14 +536,15 @@ where /// ## Returns /// - `Ok(())` if the environment was successfully prepared. /// - `Err(_)` if an error occurred while preparing the environment. - fn prepare_tx_env(transaction: &OpTxEnvelope, encoded_transaction: &[u8]) -> Result { + fn prepare_tx_env( + transaction: &OpTxEnvelope, + encoded_transaction: &[u8], + ) -> ExecutorResult { let mut env = TxEnv::default(); match transaction { OpTxEnvelope::Legacy(signed_tx) => { let tx = signed_tx.tx(); - env.caller = signed_tx - .recover_signer() - .map_err(|e| anyhow!("Failed to recover signer: {}", e))?; + env.caller = signed_tx.recover_signer().map_err(ExecutorError::SignatureError)?; env.gas_limit = tx.gas_limit as u64; env.gas_price = U256::from(tx.gas_price); env.gas_priority_fee = None; @@ -560,9 +569,7 @@ where } OpTxEnvelope::Eip2930(signed_tx) => { let tx = signed_tx.tx(); - env.caller = signed_tx - .recover_signer() - .map_err(|e| anyhow!("Failed to recover signer: {}", e))?; + env.caller = signed_tx.recover_signer().map_err(ExecutorError::SignatureError)?; env.gas_limit = tx.gas_limit as u64; env.gas_price = U256::from(tx.gas_price); env.gas_priority_fee = None; @@ -587,9 +594,7 @@ where } OpTxEnvelope::Eip1559(signed_tx) => { let tx = signed_tx.tx(); - env.caller = signed_tx - .recover_signer() - .map_err(|e| anyhow!("Failed to recover signer: {}", e))?; + env.caller = signed_tx.recover_signer().map_err(ExecutorError::SignatureError)?; env.gas_limit = tx.gas_limit as u64; env.gas_price = U256::from(tx.max_fee_per_gas); env.gas_priority_fee = Some(U256::from(tx.max_priority_fee_per_gas)); @@ -634,7 +639,7 @@ where }; Ok(env) } - _ => anyhow::bail!("Unexpected tx type"), + _ => Err(ExecutorError::UnsupportedTransactionType(transaction.tx_type() as u8)), } } } @@ -647,6 +652,7 @@ mod test { use alloy_primitives::{address, b256, hex}; use alloy_rlp::Decodable; use alloy_rpc_types_engine::PayloadAttributes; + use anyhow::{anyhow, Result}; use kona_mpt::NoopTrieHinter; use op_alloy_genesis::{OP_BASE_FEE_PARAMS, OP_CANYON_BASE_FEE_PARAMS}; use serde::Deserialize; @@ -721,12 +727,13 @@ mod test { let expected_header = Header::decode(&mut &raw_expected_header[..]).unwrap(); // Initialize the block executor on block #120794431's post-state. - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(header.seal_slow()) - .with_provider(TestdataTrieProvider::new("block_120794432_exec")) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new("block_120794432_exec"), + NoopTrieHinter, + ) + .with_parent_header(header.seal_slow()) + .build(); let raw_tx = hex!("7ef8f8a003b511b9b71520cd62cad3b5fd5b1b8eaebd658447723c31c7f1eba87cfe98c894deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc5000000000000000300000000665a33a70000000001310e960000000000000000000000000000000000000000000000000000000214d2697300000000000000000000000000000000000000000000000000000000000000015346d208a396843018a2e666c8e7832067358433fb87ca421273c6a4e69f78d50000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985"); let payload_attrs = OptimismPayloadAttributes { @@ -778,12 +785,13 @@ mod test { let expected_header = Header::decode(&mut &raw_expected_header[..]).unwrap(); // Initialize the block executor on block #121049888's post-state. - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(parent_header.seal_slow()) - .with_provider(TestdataTrieProvider::new("block_121049889_exec")) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new("block_121049889_exec"), + NoopTrieHinter, + ) + .with_parent_header(parent_header.seal_slow()) + .build(); let raw_txs = alloc::vec![ hex!("7ef8f8a01e6036fa5dc5d76e0095f42fef2c4aa7d6589b4f496f9c4bea53daef1b4a24c194deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc50000000000000000000000006661ff73000000000131b40700000000000000000000000000000000000000000000000000000005c9ea450a0000000000000000000000000000000000000000000000000000000000000001e885b088376fedbd0490a7991be47854872f6467c476d255eed3151d5f6a95940000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985").into(), @@ -839,12 +847,13 @@ mod test { let expected_header = Header::decode(&mut &raw_expected_header[..]).unwrap(); // Initialize the block executor on block #121003240's post-state. - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(parent_header.seal_slow()) - .with_provider(TestdataTrieProvider::new("block_121003241_exec")) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new("block_121003241_exec"), + NoopTrieHinter, + ) + .with_parent_header(parent_header.seal_slow()) + .build(); let raw_txs = alloc::vec![ hex!("7ef8f8a02c3adbd572915b3ef2fe7c81418461cb32407df8cb1bd4c1f5f4b45e474bfce694deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc5000000000000000400000000666092ff00000000013195d800000000000000000000000000000000000000000000000000000004da0e1101000000000000000000000000000000000000000000000000000000000000000493a1359bf7a89d8b2b2073a153c47f9c399f8f7a864e4f25744d6832cb6fadd80000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985").into(), @@ -907,12 +916,13 @@ mod test { let expected_header = Header::decode(&mut &raw_expected_header[..]).unwrap(); // Initialize the block executor on block #121057302's post-state. - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(parent_header.seal_slow()) - .with_provider(TestdataTrieProvider::new("block_121057303_exec")) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new("block_121057303_exec"), + NoopTrieHinter, + ) + .with_parent_header(parent_header.seal_slow()) + .build(); let raw_txs = alloc::vec![ hex!("7ef8f8a01a2c45522a69a90b583aa08a0968847a6fbbdc5480fe6f967b5fcb9384f46e9594deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc500000000000000010000000066623963000000000131b8d700000000000000000000000000000000000000000000000000000003ec02c0240000000000000000000000000000000000000000000000000000000000000001c10a3bb5847ad354f9a70b56f253baaea1c3841647851c4c62e10b22fe4e86940000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985").into(), @@ -969,12 +979,13 @@ mod test { let expected_header = Header::decode(&mut &raw_expected_header[..]).unwrap(); // Initialize the block executor on block #121057302's post-state. - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(parent_header.seal_slow()) - .with_provider(TestdataTrieProvider::new("block_121065789_exec")) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new("block_121065789_exec"), + NoopTrieHinter, + ) + .with_parent_header(parent_header.seal_slow()) + .build(); let raw_txs = alloc::vec![ hex!("7ef8f8a0dd829082801fa06ba178080ec514ae92ae90b5fd6799fcedc5a582a54f1358c094deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc500000000000000050000000066627b9f000000000131be5400000000000000000000000000000000000000000000000000000001e05d6a160000000000000000000000000000000000000000000000000000000000000001dc97827f5090fcc3425f1f8a22ac4603b0b176a11997a423006eb61cf64d817a0000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985").into(), @@ -1040,12 +1051,13 @@ mod test { let expected_header = Header::decode(&mut &raw_expected_header[..]).unwrap(); // Initialize the block executor on block #121135703's post-state. - let mut l2_block_executor = StatelessL2BlockExecutor::builder(&rollup_config) - .with_parent_header(parent_header.seal_slow()) - .with_provider(TestdataTrieProvider::new("block_121135704_exec")) - .with_hinter(NoopTrieHinter) - .build() - .unwrap(); + let mut l2_block_executor = StatelessL2BlockExecutor::builder( + &rollup_config, + TestdataTrieProvider::new("block_121135704_exec"), + NoopTrieHinter, + ) + .with_parent_header(parent_header.seal_slow()) + .build(); let raw_txs = alloc::vec![ hex!("7ef8f8a0bd8a03d2faac7261a1627e834405975aa1c55c968b072ffa6db6c100d891c9b794deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc500000000000000070000000066649ddb000000000131eb9a000000000000000000000000000000000000000000000000000000023c03238b0000000000000000000000000000000000000000000000000000000000000001427035b1edf748d109f4a751c5e2e33122340b0e22961600d8b76cfde3c7a6b50000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985").into(), From 43c896e685e9b26fa090845f88a9183e1646ed66 Mon Sep 17 00:00:00 2001 From: clabby Date: Fri, 20 Sep 2024 23:32:01 -0400 Subject: [PATCH 2/2] lint --- crates/executor/src/canyon.rs | 4 ++-- crates/executor/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/executor/src/canyon.rs b/crates/executor/src/canyon.rs index 52444eb2af..849495a65b 100644 --- a/crates/executor/src/canyon.rs +++ b/crates/executor/src/canyon.rs @@ -33,8 +33,8 @@ where { // If the canyon hardfork is active at the current timestamp, and it was not active at the // previous block timestamp, then we need to force-deploy the create2 deployer contract. - if config.is_canyon_active(timestamp) - && !config.is_canyon_active(db.database.parent_block_header().timestamp) + if config.is_canyon_active(timestamp) && + !config.is_canyon_active(db.database.parent_block_header().timestamp) { // Load the create2 deployer account from the cache. let acc = db.load_cache_account(CREATE_2_DEPLOYER_ADDR)?; diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index 1ed7ab555b..9d309df97b 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -170,8 +170,8 @@ where // The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior, // must be no greater than the block’s gasLimit. let block_available_gas = (gas_limit - cumulative_gas_used) as u128; - if extract_tx_gas_limit(&transaction) > block_available_gas - && (is_regolith || !is_system_transaction(&transaction)) + if extract_tx_gas_limit(&transaction) > block_available_gas && + (is_regolith || !is_system_transaction(&transaction)) { return Err(ExecutorError::BlockGasLimitExceeded); }