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

fix: only update account databases when actually needed #908

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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