Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: Remove DatabaseRef bound on CacheDB #1113

Merged
merged 1 commit into from Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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