Skip to content

Commit

Permalink
refactor: re-export all crates from revm (bluealloy#2088)
Browse files Browse the repository at this point in the history
* refactor: re-export all crates from revm

* fix

* interface
  • Loading branch information
klkvr authored Feb 18, 2025
1 parent f463fb8 commit 6662e10
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 194 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#[cfg(not(feature = "std"))]
extern crate alloc as std;

pub use context_interface::*;

pub mod block;
pub mod cfg;
pub mod context;
Expand Down
2 changes: 2 additions & 0 deletions crates/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extern crate alloc as std;
#[cfg(feature = "alloydb")]
mod alloydb;

pub use database_interface::*;

pub mod in_memory_db;
pub mod states;

Expand Down
1 change: 1 addition & 0 deletions crates/handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ all = "warn"

[dependencies]
# revm
database-interface.workspace = true
interpreter.workspace = true
precompile.workspace = true
context-interface.workspace = true
Expand Down
73 changes: 73 additions & 0 deletions crates/handler/src/evm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use crate::{instructions::EthInstructions, EthFrame, Handler, MainnetHandler, PrecompileProvider};
use context::{
result::{EVMError, ExecutionResult, HaltReason, InvalidTransaction, ResultAndState},
setters::ContextSetters,
ContextTr, Database, Evm, Journal,
};
use database_interface::DatabaseCommit;
use interpreter::{interpreter::EthInterpreter, InterpreterResult};
use primitives::Log;
use state::EvmState;
use std::vec::Vec;

/// Execute EVM transactions.
pub trait ExecuteEvm: ContextSetters {
type Output;

fn transact_previous(&mut self) -> Self::Output;

fn transact(&mut self, tx: Self::Tx) -> Self::Output {
self.set_tx(tx);
self.transact_previous()
}
}

/// Execute EVM transactions and commit to the state.
/// TODO this trait can be implemented for all ExecuteEvm for specific Output/CommitOutput
pub trait ExecuteCommitEvm: ExecuteEvm {
type CommitOutput;

fn transact_commit_previous(&mut self) -> Self::CommitOutput;

fn transact_commit(&mut self, tx: Self::Tx) -> Self::CommitOutput {
self.set_tx(tx);
self.transact_commit_previous()
}
}

impl<CTX, INSP, PRECOMPILES> ExecuteEvm
for Evm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILES>
where
CTX: ContextSetters + ContextTr<Journal: Journal<FinalOutput = (EvmState, Vec<Log>)>>,
PRECOMPILES: PrecompileProvider<Context = CTX, Output = InterpreterResult>,
{
type Output = Result<
ResultAndState<HaltReason>,
EVMError<<CTX::Db as Database>::Error, InvalidTransaction>,
>;

fn transact_previous(&mut self) -> Self::Output {
let mut t = MainnetHandler::<_, _, EthFrame<_, _, _>>::default();
t.run(self)
}
}

impl<CTX, INSP, PRECOMPILES> ExecuteCommitEvm
for Evm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILES>
where
CTX: ContextSetters
+ ContextTr<Journal: Journal<FinalOutput = (EvmState, Vec<Log>)>, Db: DatabaseCommit>,
PRECOMPILES: PrecompileProvider<Context = CTX, Output = InterpreterResult>,
{
type CommitOutput = Result<
ExecutionResult<HaltReason>,
EVMError<<CTX::Db as Database>::Error, InvalidTransaction>,
>;

fn transact_commit_previous(&mut self) -> Self::CommitOutput {
self.transact_previous().map(|r| {
self.db().commit(r.state);
r.result
})
}
}
2 changes: 2 additions & 0 deletions crates/handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate alloc as std;

// Mainnet related handlers.

pub mod evm;
pub mod execution;
mod frame;
mod frame_data;
Expand All @@ -20,6 +21,7 @@ mod precompile_provider;
pub mod validation;

// Public exports
pub use evm::{ExecuteCommitEvm, ExecuteEvm};
pub use frame::{return_create, return_eofcreate, ContextTrDbError, EthFrame, Frame};
pub use frame_data::{FrameData, FrameResult};
pub use handler::{EvmTr, EvmTrError, Handler};
Expand Down
9 changes: 8 additions & 1 deletion crates/inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ all = "warn"

[dependencies]
# revm
revm.workspace = true
context.workspace = true
database-interface.workspace = true
handler.workspace = true
precompile.workspace = true
primitives.workspace = true
state.workspace = true
interpreter.workspace = true

auto_impl.workspace = true

# Optional
Expand Down
18 changes: 7 additions & 11 deletions crates/inspector/src/eip3155.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use crate::inspectors::GasInspector;
use crate::Inspector;
use revm::interpreter::interpreter_types::{RuntimeFlag, SubRoutineStack};
use revm::{
bytecode::opcode::OpCode,
context::Cfg,
context_interface::{ContextTr, Journal, Transaction},
interpreter::{
interpreter_types::{Jumps, LoopControl, MemoryTr, StackTr},
CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult,
InterpreterTypes, Stack,
},
primitives::{hex, HashMap, B256, U256},
use context::{Cfg, ContextTr, Journal, Transaction};
use interpreter::{
interpreter_types::{Jumps, LoopControl, MemoryTr, RuntimeFlag, StackTr, SubRoutineStack},
CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult,
InterpreterTypes, Stack,
};
use primitives::{hex, HashMap, B256, U256};
use serde::Serialize;
use state::bytecode::opcode::OpCode;
use std::io::Write;

/// [EIP-3155](https://eips.ethereum.org/EIPS/eip-3155) tracer [Inspector].
Expand Down
2 changes: 1 addition & 1 deletion crates/inspector/src/gas.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! GasIspector. Helper Inspector to calculate gas for others.
use revm::interpreter::{CallOutcome, CreateOutcome, Gas};
use interpreter::{CallOutcome, CreateOutcome, Gas};

/// Helper that keeps track of gas.
#[allow(dead_code)]
Expand Down
3 changes: 2 additions & 1 deletion crates/inspector/src/inspect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use revm::{context::setters::ContextSetters, ExecuteCommitEvm, ExecuteEvm};
use context::setters::ContextSetters;
use handler::evm::{ExecuteCommitEvm, ExecuteEvm};

pub trait InspectEvm: ExecuteEvm {
type Inspector;
Expand Down
30 changes: 14 additions & 16 deletions crates/inspector/src/inspector.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use crate::{InspectorEvmTr, InspectorFrame};
use auto_impl::auto_impl;
use revm::{
context::{Cfg, JournalEntry, JournaledState},
context_interface::{result::ResultAndState, ContextTr, Database, Transaction},
handler::{
execution, EvmTr, Frame, FrameInitOrResult, FrameOrResult, FrameResult, Handler,
ItemOrResult,
},
interpreter::{
interpreter::EthInterpreter,
interpreter_types::{Jumps, LoopControl},
table::InstructionTable,
CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, FrameInput, Host,
InitialAndFloorGas, InstructionResult, Interpreter, InterpreterAction, InterpreterTypes,
},
primitives::{Address, Log, U256},
state::EvmState,
use context::{
result::ResultAndState, Cfg, ContextTr, Database, JournalEntry, JournaledState, Transaction,
};
use handler::{
execution, EvmTr, Frame, FrameInitOrResult, FrameOrResult, FrameResult, Handler, ItemOrResult,
};
use interpreter::{
interpreter::EthInterpreter,
interpreter_types::{Jumps, LoopControl},
table::InstructionTable,
CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, FrameInput, Host,
InitialAndFloorGas, InstructionResult, Interpreter, InterpreterAction, InterpreterTypes,
};
use primitives::{Address, Log, U256};
use state::EvmState;
use std::{vec, vec::Vec};

/// EVM [Interpreter] callbacks.
Expand Down
23 changes: 10 additions & 13 deletions crates/inspector/src/mainnet_inspect.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use revm::{
context::{setters::ContextSetters, Evm},
context_interface::{ContextTr, Journal},
handler::{
instructions::EthInstructions, EthFrame, EvmTr, EvmTrError, Frame, FrameResult, Handler,
MainnetHandler, PrecompileProvider,
},
interpreter::{interpreter::EthInterpreter, FrameInput, InterpreterResult},
primitives::Log,
state::EvmState,
DatabaseCommit,
use context::{setters::ContextSetters, ContextTr, Evm, Journal};
use database_interface::DatabaseCommit;
use handler::{
instructions::EthInstructions, EthFrame, EvmTr, EvmTrError, Frame, FrameResult, Handler,
MainnetHandler, PrecompileProvider,
};
use interpreter::{interpreter::EthInterpreter, FrameInput, InterpreterResult};
use primitives::Log;
use state::EvmState;
use std::vec::Vec;

use crate::{
InspectCommitEvm, InspectEvm, Inspector, InspectorEvmTr, InspectorFrame, InspectorHandler,
JournalExt,
inspect::{InspectCommitEvm, InspectEvm},
Inspector, InspectorEvmTr, InspectorFrame, InspectorHandler, JournalExt,
};

impl<EVM, ERROR, FRAME> InspectorHandler for MainnetHandler<EVM, ERROR, FRAME>
Expand Down
2 changes: 1 addition & 1 deletion crates/inspector/src/noop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::inspector::Inspector;
use revm::interpreter::InterpreterTypes;
use interpreter::InterpreterTypes;

/// Dummy [Inspector], helpful as standalone replacement.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
21 changes: 9 additions & 12 deletions crates/inspector/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::{inspect_instructions, Inspector, JournalExt};
use revm::{
context::{setters::ContextSetters, Evm},
context_interface::ContextTr,
handler::{
instructions::InstructionProvider, ContextTrDbError, EthFrame, EvmTr, Frame,
FrameInitOrResult, PrecompileProvider,
},
interpreter::{
interpreter::EthInterpreter, FrameInput, Interpreter, InterpreterAction, InterpreterResult,
InterpreterTypes,
},
precompile::PrecompileErrors,
use context::{setters::ContextSetters, ContextTr, Evm};
use handler::{
instructions::InstructionProvider, ContextTrDbError, EthFrame, EvmTr, Frame, FrameInitOrResult,
PrecompileProvider,
};
use interpreter::{
interpreter::EthInterpreter, FrameInput, Interpreter, InterpreterAction, InterpreterResult,
InterpreterTypes,
};
use precompile::PrecompileErrors;

/// Inspector EVM trait.
pub trait InspectorEvmTr: EvmTr {
Expand Down
2 changes: 2 additions & 0 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ all = "warn"
[dependencies]
# revm
interpreter.workspace = true
inspector.workspace = true
precompile.workspace = true
primitives.workspace = true
database.workspace = true
database-interface.workspace = true
state.workspace = true
specification.workspace = true
Expand Down
26 changes: 0 additions & 26 deletions crates/revm/src/exec_inspect.rs

This file was deleted.

7 changes: 4 additions & 3 deletions crates/revm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ extern crate alloc as std;
pub use bytecode;
pub use context;
pub use context_interface;
pub use database;
pub use database_interface;
pub use handler;
pub use inspector;
pub use interpreter;
pub use precompile;
pub use primitives;
Expand All @@ -19,14 +21,13 @@ pub use state;

// Modules.

mod exec_inspect;
mod mainnet_builder;
mod mainnet_exec;

// Export items.

pub use context::journaled_state::{JournalEntry, JournaledState};
pub use context::Context;
pub use database_interface::{Database, DatabaseCommit, DatabaseRef};
pub use exec_inspect::{ExecuteCommitEvm, ExecuteEvm};
pub use handler::{ExecuteCommitEvm, ExecuteEvm};
pub use inspector::{InspectCommitEvm, InspectEvm, Inspector};
pub use mainnet_builder::{MainBuilder, MainContext, MainnetEvm};
Loading

0 comments on commit 6662e10

Please sign in to comment.