Skip to content

Commit

Permalink
fix: only update account tables when actually needed (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw authored May 23, 2024
1 parent acaaba7 commit 2fe0093
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/eth/primitives/execution_account_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,9 @@ impl ExecutionAccountChanges {
pub fn is_account_update(&self) -> bool {
not(self.new_account)
}

/// Checks if the Nonce, Balance or Bytecode are modified
pub fn is_account_change(&self) -> bool {
self.nonce.is_modified() || self.balance.is_modified() || self.bytecode.is_modified()
}
}
28 changes: 15 additions & 13 deletions src/eth/storage/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,22 @@ impl RocksStorageState {

let account_changes_future = tokio::task::spawn_blocking(move || {
for change in changes_clone_for_accounts {
let address: AddressRocksdb = change.address.into();
let mut account_info_entry = accounts.entry_or_insert_with(address, AccountRocksdb::default);
if let Some(nonce) = change.nonce.clone().take_modified() {
account_info_entry.nonce = nonce.into();
}
if let Some(balance) = change.balance.clone().take_modified() {
account_info_entry.balance = balance.into();
}
if let Some(bytecode) = change.bytecode.clone().take_modified() {
account_info_entry.bytecode = bytecode.map_into();
}
if change.is_account_change() {
let address: AddressRocksdb = change.address.into();
let mut account_info_entry = accounts.entry_or_insert_with(address, AccountRocksdb::default);
if let Some(nonce) = change.nonce.clone().take_modified() {
account_info_entry.nonce = nonce.into();
}
if let Some(balance) = change.balance.clone().take_modified() {
account_info_entry.balance = balance.into();
}
if let Some(bytecode) = change.bytecode.clone().take_modified() {
account_info_entry.bytecode = bytecode.map_into();
}

account_changes.push((address, account_info_entry.clone()));
account_history_changes.push(((address, block_number.into()), account_info_entry));
account_changes.push((address, account_info_entry.clone()));
account_history_changes.push(((address, block_number.into()), account_info_entry));
}
}

accounts.insert_batch(account_changes, Some(block_number.into()));
Expand Down

0 comments on commit 2fe0093

Please sign in to comment.