Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Aug 30, 2024
1 parent 42e2463 commit 93c36f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct ReadOnlyDB {
/// In-memory map of code hash to bytecode.
code_db: HashMap<B256, Bytecode>,
/// The initial storage roots of accounts, used for after commit.
/// Need to be updated after zkTrie commit.
prev_storage_roots: RefCell<HashMap<Address, B256>>,
/// Storage trie cache, avoid re-creating trie for the same account.
/// Need to invalidate before `update`, otherwise the trie root may be outdated.
Expand Down Expand Up @@ -81,9 +82,23 @@ impl ReadOnlyDB {
})
}

/// Get the current zkTrie root.
/// Set the previous storage root of an account.
///
/// Should be updated after commit.
#[inline]
pub fn prev_storage_root(&self, address: &Address) -> B256 {
pub(crate) fn set_prev_storage_root(
&self,
address: Address,
storage_root: B256,
) -> Option<B256> {
self.prev_storage_roots
.borrow_mut()
.insert(address, storage_root)
}

/// Get the previous storage root of an account.
#[inline]
pub(crate) fn prev_storage_root(&self, address: &Address) -> B256 {
self.prev_storage_roots
.borrow()
.get(address)
Expand Down Expand Up @@ -118,7 +133,7 @@ impl ReadOnlyDB {
}

/// Invalidate internal cache for any account touched by EVM.
pub fn invalidate_storage_root_caches(
pub(crate) fn invalidate_storage_root_caches(
&mut self,
account_states: impl Iterator<Item = (Address, AccountState)>,
) {
Expand Down
3 changes: 3 additions & 0 deletions src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ impl EvmExecutor {
}
cycle_tracker_end!("update storage_tire");
acc_data.storage_root = H256::from(storage_tire.root());
self.db
.db
.set_prev_storage_root(*addr, acc_data.storage_root.0.into());

#[cfg(feature = "debug-storage")]
{
Expand Down

0 comments on commit 93c36f6

Please sign in to comment.