Skip to content

Commit

Permalink
fix(db): preserve existing account state (#414)
Browse files Browse the repository at this point in the history
* fix(db): preserve existing account state

* clone existing account state

* preserve only storage cleared
rkrasiuk authored Mar 9, 2023
1 parent dd0e227 commit afc3066
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/revm/src/db/in_memory_db.rs
Original file line number Diff line number Diff line change
@@ -91,6 +91,13 @@ pub enum AccountState {
None,
}

impl AccountState {
/// Returns `true` if EVM cleared storage of this account
pub fn is_storage_cleared(&self) -> bool {
matches!(self, AccountState::StorageCleared)
}
}

impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
pub fn new(db: ExtDB) -> Self {
let mut contracts = HashMap::new();
@@ -183,6 +190,9 @@ impl<ExtDB: DatabaseRef> DatabaseCommit for CacheDB<ExtDB> {
db_account.account_state = if account.storage_cleared {
db_account.storage.clear();
AccountState::StorageCleared
} else if db_account.account_state.is_storage_cleared() {
// Preserve old account state if it already exists
AccountState::StorageCleared
} else {
AccountState::Touched
};

0 comments on commit afc3066

Please sign in to comment.