Skip to content

Commit

Permalink
chore: tie journal database with database getter (#1923)
Browse files Browse the repository at this point in the history
* chore: Simplify GasInspector

* fmt

* chore: add depth to GasInspector

* rm doc

* chore: tie journal database with database getter

* use exec

* fmt

* include box
  • Loading branch information
rakita authored Dec 17, 2024
1 parent 62c33ec commit ca85e67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use revm::{
bytecode::{Bytecode, BytecodeDecodeError},
handler::EthHandler,
primitives::{address, hex, Address, TxKind},
Context, Database, MainEvm,
Context, Database, EvmExec, MainEvm,
};
use std::io::Error as IoError;
use std::path::PathBuf;
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Cmd {
inspector_handler(),
);

evm.transact().map_err(|_| Errors::EVMError)?
evm.exec().map_err(|_| Errors::EVMError)?
} else {
let out = evm.transact().map_err(|_| Errors::EVMError)?;
println!("Result: {:#?}", out.result);
Expand Down
25 changes: 20 additions & 5 deletions crates/context/interface/src/journaled_state.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use auto_impl::auto_impl;
use core::ops::{Deref, DerefMut};
use database_interface::Database;
use database_interface::{Database, DatabaseGetter};
use primitives::{Address, B256, U256};
use specification::hardfork::SpecId;
use state::{Account, Bytecode};
use std::boxed::Box;

pub trait JournaledState {
type Database: Database;
Expand Down Expand Up @@ -240,9 +240,24 @@ impl<T> Eip7702CodeLoad<T> {
pub type JournalStateGetterDBError<CTX> =
<<<CTX as JournalStateGetter>::Journal as JournaledState>::Database as Database>::Error;

#[auto_impl(&mut, Box)]
pub trait JournalStateGetter {
type Journal: JournaledState;
pub trait JournalStateGetter: DatabaseGetter {
type Journal: JournaledState<Database = <Self as DatabaseGetter>::Database>;

fn journal(&mut self) -> &mut Self::Journal;
}

impl<T: JournalStateGetter> JournalStateGetter for &mut T {
type Journal = T::Journal;

fn journal(&mut self) -> &mut Self::Journal {
T::journal(*self)
}
}

impl<T: JournalStateGetter> JournalStateGetter for Box<T> {
type Journal = T::Journal;

fn journal(&mut self) -> &mut Self::Journal {
T::journal(self.as_mut())
}
}
1 change: 1 addition & 0 deletions crates/context/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl<BLOCK: Block + Default, TX: Transaction + Default, DB: Database, CHAIN: Def
}
}
}

impl<BLOCK, TX, CFG, DB, CHAIN> Context<BLOCK, TX, CFG, DB, CHAIN>
where
BLOCK: Block,
Expand Down

0 comments on commit ca85e67

Please sign in to comment.