Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions bins/revme/src/cmd/blockchaintest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use revm::{
database::{states::bundle_state::BundleRetention, EmptyDB, State},
handler::EvmTr,
inspector::inspectors::TracerEip3155,
primitives::{hardfork::SpecId, hex, Address, HashMap, U256},
primitives::{hardfork::SpecId, hex, Address, AddressMap, U256Map, U256},
state::{bal::Bal, AccountInfo},
Context, Database, ExecuteCommitEvm, ExecuteEvm, InspectEvm, MainBuilder, MainContext,
};
Expand Down Expand Up @@ -272,7 +272,7 @@ fn run_test_file(
#[derive(Debug, Clone)]
struct DebugInfo {
/// Initial pre-state before any execution
pre_state: HashMap<Address, (AccountInfo, HashMap<U256, U256>)>,
pre_state: AddressMap<(AccountInfo, U256Map<U256>)>,
/// Transaction environment
tx_env: Option<revm::context::tx::TxEnv>,
/// Block environment
Expand All @@ -289,15 +289,13 @@ struct DebugInfo {

impl DebugInfo {
/// Capture current state from the State database
fn capture_committed_state(
state: &State<EmptyDB>,
) -> HashMap<Address, (AccountInfo, HashMap<U256, U256>)> {
let mut committed_state = HashMap::default();
fn capture_committed_state(state: &State<EmptyDB>) -> AddressMap<(AccountInfo, U256Map<U256>)> {
let mut committed_state = AddressMap::default();

// Access the cache state to get all accounts
for (address, cache_account) in &state.cache.accounts {
if let Some(plain_account) = &cache_account.account {
let mut storage = HashMap::default();
let mut storage = U256Map::default();
for (key, value) in &plain_account.storage {
storage.insert(*key, *value);
}
Expand Down Expand Up @@ -668,7 +666,7 @@ fn execute_blockchain_test(
let mut state = State::builder().with_bal_builder().build();

// Capture pre-state for debug info
let mut pre_state_debug = HashMap::default();
let mut pre_state_debug = AddressMap::default();

// Insert genesis state into database
let genesis_state = test_case.pre.clone().into_genesis_state();
Expand Down
9 changes: 5 additions & 4 deletions crates/context/interface/src/journaled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{
use core::ops::{Deref, DerefMut};
use database_interface::Database;
use primitives::{
hardfork::SpecId, Address, Bytes, HashMap, HashSet, Log, StorageKey, StorageValue, B256, U256,
hardfork::SpecId, Address, AddressMap, AddressSet, Bytes, HashSet, Log, StorageKey,
StorageValue, B256, U256,
};
use state::{Account, AccountInfo, Bytecode};
use std::{borrow::Cow, vec::Vec};
Expand Down Expand Up @@ -104,16 +105,16 @@ pub trait JournalTr {
) -> Result<StateLoad<SelfDestructResult>, JournalLoadError<<Self::Database as Database>::Error>>;

/// Sets access list inside journal.
fn warm_access_list(&mut self, access_list: HashMap<Address, HashSet<StorageKey>>);
fn warm_access_list(&mut self, access_list: AddressMap<HashSet<StorageKey>>);

/// Warms the coinbase account.
fn warm_coinbase_account(&mut self, address: Address);

/// Warms the precompiles.
fn warm_precompiles(&mut self, addresses: HashSet<Address>);
fn warm_precompiles(&mut self, addresses: AddressSet);

/// Returns the addresses of the precompiles.
fn precompile_addresses(&self) -> &HashSet<Address>;
fn precompile_addresses(&self) -> &AddressSet;

/// Sets the spec id.
fn set_spec_id(&mut self, spec_id: SpecId);
Expand Down
7 changes: 4 additions & 3 deletions crates/context/interface/src/journaled_state/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use super::entry::JournalEntryTr;
use auto_impl::auto_impl;
use database_interface::Database;
use primitives::{
hash_map::Entry, Address, HashMap, HashSet, StorageKey, StorageValue, B256, KECCAK_EMPTY, U256,
hash_map::Entry, Address, AddressMap, HashSet, StorageKey, StorageValue, B256, KECCAK_EMPTY,
U256,
};
use state::{Account, Bytecode, EvmStorageSlot};
use std::vec::Vec;
Expand Down Expand Up @@ -129,7 +130,7 @@ pub struct JournaledAccount<'a, DB, ENTRY: JournalEntryTr = JournalEntry> {
/// Journal entries.
journal_entries: &'a mut Vec<ENTRY>,
/// Access list.
access_list: &'a HashMap<Address, HashSet<StorageKey>>,
access_list: &'a AddressMap<HashSet<StorageKey>>,
/// Transaction ID.
transaction_id: usize,
/// Database used to load storage.
Expand All @@ -144,7 +145,7 @@ impl<'a, DB: Database, ENTRY: JournalEntryTr> JournaledAccount<'a, DB, ENTRY> {
account: &'a mut Account,
journal_entries: &'a mut Vec<ENTRY>,
db: &'a mut DB,
access_list: &'a HashMap<Address, HashSet<StorageKey>>,
access_list: &'a AddressMap<HashSet<StorageKey>>,
transaction_id: usize,
) -> Self {
Self {
Expand Down
9 changes: 5 additions & 4 deletions crates/context/src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use context_interface::{
use core::ops::{Deref, DerefMut};
use database_interface::Database;
use primitives::{
hardfork::SpecId, Address, HashMap, HashSet, Log, StorageKey, StorageValue, B256, U256,
hardfork::SpecId, Address, AddressMap, AddressSet, HashSet, Log, StorageKey, StorageValue,
B256, U256,
};
use state::{Account, EvmState};
use std::vec::Vec;
Expand Down Expand Up @@ -168,22 +169,22 @@ impl<DB: Database, ENTRY: JournalEntryTr> JournalTr for Journal<DB, ENTRY> {
}

#[inline]
fn warm_access_list(&mut self, access_list: HashMap<Address, HashSet<StorageKey>>) {
fn warm_access_list(&mut self, access_list: AddressMap<HashSet<StorageKey>>) {
self.inner.warm_addresses.set_access_list(access_list);
}

fn warm_coinbase_account(&mut self, address: Address) {
self.inner.warm_addresses.set_coinbase(address);
}

fn warm_precompiles(&mut self, precompiles: HashSet<Address>) {
fn warm_precompiles(&mut self, precompiles: AddressSet) {
self.inner
.warm_addresses
.set_precompile_addresses(precompiles);
}

#[inline]
fn precompile_addresses(&self) -> &HashSet<Address> {
fn precompile_addresses(&self) -> &AddressSet {
self.inner.warm_addresses.precompiles()
}

Expand Down
20 changes: 11 additions & 9 deletions crates/context/src/journal/warm_addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use bitvec::{bitvec, vec::BitVec};
use context_interface::journaled_state::JournalLoadError;
use primitives::{short_address, Address, HashMap, HashSet, StorageKey, SHORT_ADDRESS_CAP};
use primitives::{
short_address, Address, AddressMap, AddressSet, HashSet, StorageKey, SHORT_ADDRESS_CAP,
};

/// Stores addresses that are warm loaded. Contains precompiles and coinbase address.
///
Expand All @@ -19,7 +21,7 @@ use primitives::{short_address, Address, HashMap, HashSet, StorageKey, SHORT_ADD
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WarmAddresses {
/// Set of warm loaded precompile addresses.
precompile_set: HashSet<Address>,
precompile_set: AddressSet,
/// Bit vector of precompile short addresses. If address is shorter than [`SHORT_ADDRESS_CAP`] it
/// will be stored in this bit vector for faster access.
precompile_short_addresses: BitVec,
Expand All @@ -28,7 +30,7 @@ pub struct WarmAddresses {
/// Coinbase address.
coinbase: Option<Address>,
/// Access list
access_list: HashMap<Address, HashSet<StorageKey>>,
access_list: AddressMap<HashSet<StorageKey>>,
}

impl Default for WarmAddresses {
Expand All @@ -42,17 +44,17 @@ impl WarmAddresses {
#[inline]
pub fn new() -> Self {
Self {
precompile_set: HashSet::default(),
precompile_set: AddressSet::default(),
precompile_short_addresses: bitvec![0; SHORT_ADDRESS_CAP],
precompile_all_short_addresses: true,
coinbase: None,
access_list: HashMap::default(),
access_list: AddressMap::default(),
}
}

/// Returns the precompile addresses.
#[inline]
pub fn precompiles(&self) -> &HashSet<Address> {
pub fn precompiles(&self) -> &AddressSet {
&self.precompile_set
}

Expand All @@ -64,7 +66,7 @@ impl WarmAddresses {

/// Set the precompile addresses and short addresses.
#[inline]
pub fn set_precompile_addresses(&mut self, addresses: HashSet<Address>) {
pub fn set_precompile_addresses(&mut self, addresses: AddressSet) {
self.precompile_short_addresses.fill(false);

let mut all_short_addresses = true;
Expand All @@ -88,13 +90,13 @@ impl WarmAddresses {

/// Set the access list.
#[inline]
pub fn set_access_list(&mut self, access_list: HashMap<Address, HashSet<StorageKey>>) {
pub fn set_access_list(&mut self, access_list: AddressMap<HashSet<StorageKey>>) {
self.access_list = access_list;
}

/// Returns the access list.
#[inline]
pub fn access_list(&self) -> &HashMap<Address, HashSet<StorageKey>> {
pub fn access_list(&self) -> &AddressMap<HashSet<StorageKey>> {
&self.access_list
}

Expand Down
4 changes: 2 additions & 2 deletions crates/database/interface/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{Database, DatabaseCommit, DatabaseRef};
use either::Either;
use primitives::{Address, HashMap, StorageKey, StorageValue, B256};
use primitives::{Address, AddressMap, StorageKey, StorageValue, B256};
use state::{Account, AccountInfo, Bytecode};

impl<L, R> Database for Either<L, R>
Expand Down Expand Up @@ -62,7 +62,7 @@ where
L: DatabaseCommit,
R: DatabaseCommit,
{
fn commit(&mut self, changes: HashMap<Address, Account>) {
fn commit(&mut self, changes: AddressMap<Account>) {
match self {
Self::Left(db) => db.commit(changes),
Self::Right(db) => db.commit(changes),
Expand Down
14 changes: 7 additions & 7 deletions crates/database/interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate alloc as std;
use core::convert::Infallible;

use auto_impl::auto_impl;
use primitives::{address, Address, HashMap, StorageKey, StorageValue, B256, U256};
use primitives::{address, Address, AddressMap, StorageKey, StorageValue, B256, U256};
use state::{Account, AccountInfo, Bytecode};
use std::vec::Vec;

Expand Down Expand Up @@ -92,21 +92,21 @@ pub trait Database {
#[auto_impl(&mut, Box)]
pub trait DatabaseCommit {
/// Commit changes to the database.
fn commit(&mut self, changes: HashMap<Address, Account>);
fn commit(&mut self, changes: AddressMap<Account>);

/// Commit changes to the database with an iterator.
///
/// Implementors of [`DatabaseCommit`] should override this method when possible for efficiency.
///
/// Callers should prefer using [`DatabaseCommit::commit`] when they already have a [`HashMap`].
/// Callers should prefer using [`DatabaseCommit::commit`] when they already have a [`AddressMap`].
///
/// # Dyn Compatibility
///
/// This method uses `&mut dyn Iterator` to remain object-safe and callable on trait objects.
/// For ergonomic usage with `impl IntoIterator`, use the inherent method
/// `commit_from_iter` on `dyn DatabaseCommit`.
fn commit_iter(&mut self, changes: &mut dyn Iterator<Item = (Address, Account)>) {
let changes: HashMap<Address, Account> = changes.collect();
let changes: AddressMap<Account> = changes.collect();
self.commit(changes);
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<T: DatabaseRef> Database for WrapDatabaseRef<T> {

impl<T: DatabaseRef + DatabaseCommit> DatabaseCommit for WrapDatabaseRef<T> {
#[inline]
fn commit(&mut self, changes: HashMap<Address, Account>) {
fn commit(&mut self, changes: AddressMap<Account>) {
self.0.commit(changes)
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ mod tests {
}

impl DatabaseCommit for MockDb {
fn commit(&mut self, changes: HashMap<Address, Account>) {
fn commit(&mut self, changes: AddressMap<Account>) {
let std_map: StdHashMap<_, _> = changes.into_iter().collect();
self.commits.push(std_map);
}
Expand All @@ -337,7 +337,7 @@ mod tests {
// Test commit() on trait objects
{
let db_dyn: &mut dyn DatabaseCommit = &mut db;
db_dyn.commit(HashMap::default());
db_dyn.commit(AddressMap::default());
}
assert_eq!(db.commits.len(), 2);

Expand Down
10 changes: 5 additions & 5 deletions crates/database/interface/src/try_commit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Try database commit interface.
use crate::DatabaseCommit;
use core::{convert::Infallible, error::Error, fmt};
use primitives::{Address, HashMap};
use primitives::AddressMap;
use state::Account;
use std::sync::Arc;

Expand All @@ -15,7 +15,7 @@ pub trait TryDatabaseCommit {
type Error: Error;

/// Attempt to commit changes to the database.
fn try_commit(&mut self, changes: HashMap<Address, Account>) -> Result<(), Self::Error>;
fn try_commit(&mut self, changes: AddressMap<Account>) -> Result<(), Self::Error>;
}

impl<Db> TryDatabaseCommit for Db
Expand All @@ -25,7 +25,7 @@ where
type Error = Infallible;

#[inline]
fn try_commit(&mut self, changes: HashMap<Address, Account>) -> Result<(), Self::Error> {
fn try_commit(&mut self, changes: AddressMap<Account>) -> Result<(), Self::Error> {
self.commit(changes);
Ok(())
}
Expand All @@ -51,7 +51,7 @@ where
type Error = ArcUpgradeError;

#[inline]
fn try_commit(&mut self, changes: HashMap<Address, Account>) -> Result<(), Self::Error> {
fn try_commit(&mut self, changes: AddressMap<Account>) -> Result<(), Self::Error> {
Arc::get_mut(self)
.map(|db| db.commit(changes))
.ok_or(ArcUpgradeError)
Expand All @@ -67,7 +67,7 @@ mod test {
struct MockDb;

impl DatabaseCommit for MockDb {
fn commit(&mut self, _changes: HashMap<Address, Account>) {}
fn commit(&mut self, _changes: AddressMap<Account>) {}
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions crates/database/src/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use database_interface::{
BENCH_TARGET, BENCH_TARGET_BALANCE,
};
use primitives::{
hash_map::Entry, Address, AddressMap, B256Map, HashMap, Log, StorageKey, StorageValue, B256,
KECCAK_EMPTY, U256,
hash_map::Entry, Address, AddressMap, B256Map, HashMap, Log, StorageKey, StorageKeyMap,
StorageValue, U256Map, B256, KECCAK_EMPTY, U256,
};
use state::{Account, AccountInfo, Bytecode};
use std::vec::Vec;
Expand All @@ -29,7 +29,7 @@ pub struct Cache {
/// All logs that were committed via [DatabaseCommit::commit].
pub logs: Vec<Log>,
/// All cached block hashes from the [DatabaseRef].
pub block_hashes: HashMap<U256, B256>,
pub block_hashes: U256Map<B256>,
}

impl Default for Cache {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
pub fn replace_account_storage(
&mut self,
address: Address,
storage: HashMap<StorageKey, StorageValue>,
storage: StorageKeyMap<StorageValue>,
) -> Result<(), ExtDB::Error> {
let account = self.load_account(address)?;
account.account_state = AccountState::StorageCleared;
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
}

impl<ExtDB> DatabaseCommit for CacheDB<ExtDB> {
fn commit(&mut self, changes: HashMap<Address, Account>) {
fn commit(&mut self, changes: AddressMap<Account>) {
for (address, mut account) in changes {
if !account.is_touched() {
continue;
Expand Down Expand Up @@ -459,7 +459,7 @@ pub struct DbAccount {
/// If account is selfdestructed or newly created, storage will be cleared.
pub account_state: AccountState,
/// Storage slots
pub storage: HashMap<StorageKey, StorageValue>,
pub storage: StorageKeyMap<StorageValue>,
}

impl DbAccount {
Expand Down
Loading
Loading