Skip to content

Commit

Permalink
Remove DatabaseRef bound on CacheDB (#1113)
Browse files Browse the repository at this point in the history
Co-authored-by: jasalper <>
  • Loading branch information
jasalper committed Feb 21, 2024
1 parent c203f3d commit 559e096
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/revm/src/db/in_memory_db.rs
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

0 comments on commit 559e096

Please sign in to comment.