Skip to content

Commit

Permalink
reset the account storage when it does not exist in the world state
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmlm committed Apr 26, 2023
1 parent d9b4053 commit 71f35e6
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions crates/executor/src/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ impl<'a> ApplyBackend for RTEvmExecutorAdapter<'a> {
let is_empty =
self.apply(address, basic, code, storage, reset_storage);
if is_empty && delete_empty {
pnk!(self.state.remove(address.as_bytes()));
self.trie_db.trie_remove(address.as_bytes());
pnk!(self.state.remove(address.as_bytes()));
}
}
Apply::Delete { address } => {
let _ = self.state.remove(address.as_bytes());
self.trie_db.trie_remove(address.as_bytes());
pnk!(self.state.remove(address.as_bytes()));
}
}
}
Expand Down Expand Up @@ -275,22 +275,24 @@ impl<'a> RTEvmExecutorAdapter<'a> {
),
};

let mut storage_trie = if reset_storage {
pnk!(self.trie_db.trie_create(address.as_bytes(), None, true))
let storage_trie = if reset_storage {
self.trie_db
.trie_create(address.as_bytes(), None, true)
.c(d!())
} else if existing {
pnk!(self.trie_db.trie_restore(
address.as_bytes(),
None,
old_account.storage_root.into()
))
self.trie_db
.trie_restore(address.as_bytes(), None, old_account.storage_root.into())
.c(d!())
} else {
pnk!(
self.trie_db
.trie_create(address.as_bytes(), None, false)
.c(d!("{}, {:?}", address, address.as_bytes()))
)
// this address does not exist in the world state,
// so we reset it in the trie backend db also.
self.trie_db
.trie_create(address.as_bytes(), None, true)
.c(d!("{}, {:?}", address, address.as_bytes()))
};

let mut storage_trie = pnk!(storage_trie);

storage.into_iter().for_each(|(k, v)| {
let _ = storage_trie.insert(k.as_bytes(), v.as_bytes());
});
Expand Down

0 comments on commit 71f35e6

Please sign in to comment.