Skip to content

Commit

Permalink
fix: remove dbgs, improve imports (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Sep 18, 2024
1 parent d1f3b45 commit 375459f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::{
};
use alloy_primitives::{Address, Bytes, U256};
use revm::{
db::{states::bundle_state::BundleRetention, BundleState},
db::{states::bundle_state::BundleRetention, BundleState, State},
primitives::{
AccountInfo, Bytecode, EVMError, EvmState, ExecutionResult, InvalidTransaction,
ResultAndState, SpecId,
},
Database, DatabaseCommit, DatabaseRef, Evm, State,
Database, DatabaseCommit, DatabaseRef, Evm,
};
use std::{convert::Infallible, fmt};

Expand Down Expand Up @@ -892,7 +892,6 @@ impl<'a, Ext, Db: Database> EvmNeedsBlock<'a, Ext, State<Db>> {
/// See [`State::merge_transitions`] and [`State::take_bundle`].
pub fn finish(self) -> BundleState {
let Self { inner: mut evm, .. } = self;

evm.db_mut().merge_transitions(BundleRetention::Reverts);
let bundle = evm.db_mut().take_bundle();

Expand Down
17 changes: 9 additions & 8 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use alloy_primitives::{Address, B256, U256};
use revm::{
primitives::{Account, AccountInfo, Bytecode, EvmStorageSlot},
primitives::{Account, AccountInfo, Bytecode, EvmState, EvmStorageSlot},
Database, DatabaseCommit,
};

Expand Down Expand Up @@ -48,28 +48,29 @@ pub trait EvmExtUnchecked<Db: Database> {
{
let mut state = HashMap::default();
let mut old = HashMap::default();
for account in changes.into_iter() {
let mut acct = self.account(account)?;
old.insert(account, acct.info.clone());
for addr in changes.into_iter() {
let mut acct = self.account(addr)?;
old.insert(addr, acct.info.clone());
f(&mut acct.info);
acct.mark_touch();
state.insert(account, acct);
state.insert(addr, acct);
}
self.db_mut_ext().commit(state);
Ok(old)
}

/// Modify an account with a closure and commit the modified account.
fn modify_account<F>(&mut self, address: Address, f: F) -> Result<AccountInfo, Db::Error>
fn modify_account<F>(&mut self, addr: Address, f: F) -> Result<AccountInfo, Db::Error>
where
F: FnOnce(&mut AccountInfo),
Db: DatabaseCommit,
{
let mut acct = self.account(address)?;
let mut acct = self.account(addr)?;
let old = acct.info.clone();
f(&mut acct.info);
acct.mark_touch();
let changes = [(address, acct)].into_iter().collect();

let changes: EvmState = [(addr, acct)].into_iter().collect();
self.db_mut_ext().commit(changes);
Ok(old)
}
Expand Down
3 changes: 0 additions & 3 deletions src/system/eip2935.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsTx<'a, Ext, Db> {
.block_hash(prev_block)
.map_err(EVMError::Database)?;

dbg!(slot);
dbg!(parent_block_hash);

self.try_set_storage_unchecked(HISTORY_STORAGE_ADDRESS, slot, parent_block_hash.into())
.map_err(EVMError::Database)?;

Expand Down
7 changes: 6 additions & 1 deletion src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{EvmNeedsCfg, Trevm, TrevmBuilder};
use alloy_primitives::{Address, U256};
use revm::{
db::{CacheDB, EmptyDB, InMemoryDB},
db::{CacheDB, EmptyDB, InMemoryDB, State},
inspector_handle_register,
inspectors::TracerEip3155,
primitives::{AccountInfo, Bytecode},
Expand Down Expand Up @@ -106,6 +106,11 @@ pub fn test_trevm() -> EvmNeedsCfg<'static, (), CacheDB<EmptyDB>> {
EvmBuilder::default().with_db(CacheDB::new(EmptyDB::default())).build_trevm()
}

/// Make a new [`Trevm`] with an in-memory database wrapped in a [`State`].
pub fn test_state_trevm() -> EvmNeedsCfg<'static, (), State<EmptyDB>> {
EvmBuilder::default().with_db(State::builder().with_bundle_update().build()).build_trevm()
}

/// Make a new [`Trevm`] with an in-memory database and a tracer inspector.
/// The tracer will print all EVM instructions to stdout.
pub fn test_trevm_tracing() -> EvmNeedsCfg<'static, TracerEip3155, CacheDB<EmptyDB>> {
Expand Down

0 comments on commit 375459f

Please sign in to comment.