Skip to content
Merged
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
10 changes: 6 additions & 4 deletions crates/revm/src/db/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub type InMemoryDB = CacheDB<EmptyDB>;
/// The [DbAccount] holds the code hash of the contract, which is used to look up the contract in the `contracts` map.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CacheDB<ExtDB: DatabaseRef> {
pub struct CacheDB<ExtDB> {
/// Account info where None means it is not existing. Not existing state is needed for Pre TANGERINE forks.
/// `code` is always `None`, and bytecode can be found in `contracts`.
pub accounts: HashMap<Address, DbAccount>,
Expand All @@ -35,13 +35,13 @@ pub struct CacheDB<ExtDB: DatabaseRef> {
pub db: ExtDB,
}

impl<ExtDB: DatabaseRef + Default> Default for CacheDB<ExtDB> {
impl<ExtDB: Default> Default for CacheDB<ExtDB> {
fn default() -> Self {
Self::new(ExtDB::default())
}
}

impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
impl<ExtDB> CacheDB<ExtDB> {
pub fn new(db: ExtDB) -> Self {
let mut contracts = HashMap::new();
contracts.insert(KECCAK_EMPTY, Bytecode::new());
Expand Down Expand Up @@ -81,7 +81,9 @@ impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
self.insert_contract(&mut info);
self.accounts.entry(address).or_default().info = info;
}
}

impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
/// Returns the account for the given address.
///
/// If the account was not found in the cache, it will be loaded from the underlying database.
Expand Down Expand Up @@ -125,7 +127,7 @@ impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
}
}

impl<ExtDB: DatabaseRef> DatabaseCommit for CacheDB<ExtDB> {
impl<ExtDB> DatabaseCommit for CacheDB<ExtDB> {
fn commit(&mut self, changes: HashMap<Address, Account>) {
for (address, mut account) in changes {
if !account.is_touched() {
Expand Down