Skip to content

Commit

Permalink
refactor: move mainnet builder to handler crate (#2138)
Browse files Browse the repository at this point in the history
* fix(op): Move loading of l1block data

* comment

* optimize and dont load l1block every time

* refactor: move mainnet builder to handler crate

* rm no_std
  • Loading branch information
rakita authored Mar 4, 2025
1 parent d16a749 commit 4a42c45
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 175 deletions.
145 changes: 4 additions & 141 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/context/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl<SPEC: Into<SpecId> + Copy> Cfg for CfgEnv<SPEC> {
}
}

/// Returns `true` if the block gas limit is disabled.
fn is_block_gas_limit_disabled(&self) -> bool {
cfg_if::cfg_if! {
if #[cfg(feature = "optional_block_gas_limit")] {
Expand Down
6 changes: 5 additions & 1 deletion crates/handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ context.workspace = true
primitives.workspace = true
state.workspace = true
specification.workspace = true
bytecode.workspace = true
bytecode.workspace = true
auto_impl.workspace = true

# Optional
Expand All @@ -42,6 +42,10 @@ serde = { version = "1.0", default-features = false, features = [

[dev-dependencies]
database.workspace = true
alloy-eip7702.workspace = true
alloy-provider.workspace = true
alloy-signer.workspace = true
alloy-signer-local.workspace = true

[features]
default = ["std"]
Expand Down
2 changes: 2 additions & 0 deletions crates/handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod frame_data;
pub mod handler;
pub mod instructions;
mod item_or_result;
mod mainnet_builder;
mod mainnet_handler;
pub mod post_execution;
pub mod pre_execution;
Expand All @@ -26,5 +27,6 @@ pub use frame::{return_create, return_eofcreate, ContextTrDbError, EthFrame, Fra
pub use frame_data::{FrameData, FrameResult};
pub use handler::{EvmTr, EvmTrError, Handler};
pub use item_or_result::{FrameInitOrResult, FrameOrResult, ItemOrResult};
pub use mainnet_builder::{MainBuilder, MainContext, MainnetEvm};
pub use mainnet_handler::MainnetHandler;
pub use precompile_provider::{EthPrecompiles, PrecompileProvider};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{instructions::EthInstructions, EthPrecompiles};
use context::{BlockEnv, Cfg, CfgEnv, Context, Evm, EvmData, JournaledState, TxEnv};
use context_interface::{Block, Database, Journal, Transaction};
use database_interface::EmptyDB;
use handler::{instructions::EthInstructions, EthPrecompiles};
use interpreter::interpreter::EthInterpreter;
use primitives::Log;
use specification::hardfork::SpecId;
Expand Down Expand Up @@ -69,6 +69,7 @@ impl MainContext for Context<BlockEnv, TxEnv, CfgEnv, EmptyDB, JournaledState<Em

#[cfg(test)]
mod test {
use crate::ExecuteEvm;
use crate::{MainBuilder, MainContext};
use alloy_signer::SignerSync;
use alloy_signer_local::PrivateKeySigner;
Expand All @@ -79,7 +80,6 @@ mod test {
use context::Context;
use context_interface::{transaction::Authorization, TransactionType};
use database::{BenchmarkDB, EEADDRESS, FFADDRESS};
use handler::ExecuteEvm;
use primitives::{TxKind, U256};
use specification::hardfork::SpecId;

Expand Down
3 changes: 1 addition & 2 deletions crates/inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ serde = { workspace = true, features = ["derive", "rc"], optional = true }
serde_json = { workspace = true, features = ["alloc"], optional = true }

[dev-dependencies]
revm = { workspace = true, features = ["serde"] }
database = { workspace = true, features = ["serde"] }

[features]
default = ["std"]
# Preserve order of json field
std = ["serde?/std", "serde_json?/std", "serde_json?/preserve_order"]
serde = ["dep:serde", "revm/serde", "database/serde"]
serde = ["dep:serde", "database/serde"]
serde-json = ["serde", "dep:serde_json"]
15 changes: 7 additions & 8 deletions crates/inspector/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ impl GasInspector {
mod tests {
use super::*;
use crate::{InspectEvm, Inspector};
use context::Context;
use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
use revm::{
bytecode::{opcode, Bytecode},
interpreter::{
interpreter_types::{Jumps, LoopControl},
CallInputs, CreateInputs, Interpreter, InterpreterTypes,
},
primitives::{Bytes, TxKind},
Context, MainBuilder, MainContext,
use handler::{MainBuilder, MainContext};
use interpreter::{
interpreter_types::{Jumps, LoopControl},
CallInputs, CreateInputs, Interpreter, InterpreterTypes,
};
use primitives::{Bytes, TxKind};
use state::bytecode::{opcode, Bytecode};

#[derive(Default, Debug)]
struct StackInspector {
Expand Down
Loading

0 comments on commit 4a42c45

Please sign in to comment.