diff --git a/src/eth/evm/revm.rs b/src/eth/evm/revm.rs index 343587c27..3202d21ee 100644 --- a/src/eth/evm/revm.rs +++ b/src/eth/evm/revm.rs @@ -373,7 +373,7 @@ fn parse_revm_state(revm_state: RevmState, mut execution_changes: ExecutionChang ); let (account_created, account_touched) = (revm_account.is_created(), revm_account.is_touched()); - // parse revm to internal representation + // parse revm types to stratus primitives let mut account: Account = (revm_address, revm_account.info).into(); let account_modified_slots: Vec = revm_account .storage @@ -384,7 +384,7 @@ fn parse_revm_state(revm_state: RevmState, mut execution_changes: ExecutionChang }) .collect(); - // status: created + // handle created accounts (contracts) if account_created { // parse bytecode slots let slot_indexes: HashSet = match account.bytecode { @@ -395,16 +395,17 @@ fn parse_revm_state(revm_state: RevmState, mut execution_changes: ExecutionChang account.add_bytecode_slot_index(index); } - execution_changes.insert(account.address, ExecutionAccountChanges::from_modified_values(account, account_modified_slots)); + // track account + let account_changes = ExecutionAccountChanges::from_modified_values(account, account_modified_slots); + execution_changes.insert(account_changes.address, account_changes); } - // status: touched + // handle touched accounts (everything else that is not a contract) else if account_touched { - let Some(touched_account) = execution_changes.get_mut(&address) else { + let Some(account_changes) = execution_changes.get_mut(&address) else { tracing::error!(keys = ?execution_changes.keys(), %address, "account touched, but not loaded by evm"); - // TODO: panic! only when in dev-mode or try to refactor to avoid panic! panic!("Account '{}' was expected to be loaded by EVM, but it was not", address); }; - touched_account.apply_modifications(account, account_modified_slots); + account_changes.apply_modifications(account, account_modified_slots); } } execution_changes diff --git a/src/eth/primitives/execution_account_changes.rs b/src/eth/primitives/execution_account_changes.rs index 936d902f8..f0a6eb4ce 100644 --- a/src/eth/primitives/execution_account_changes.rs +++ b/src/eth/primitives/execution_account_changes.rs @@ -10,7 +10,6 @@ use crate::eth::primitives::Slot; use crate::eth::primitives::SlotIndex; use crate::eth::primitives::SlotIndexes; use crate::eth::primitives::Wei; -use crate::ext::not; /// Changes that happened to an account during a transaction. #[derive(Debug, Clone, PartialEq, Eq, fake::Dummy, serde::Serialize, serde::Deserialize)] @@ -74,20 +73,20 @@ impl ExecutionAccountChanges { /// Updates an existing account state with changes that happened during the transaction. pub fn apply_modifications(&mut self, modified_account: Account, modified_slots: Vec) { // update nonce if modified - let nonce_modified = match self.nonce.take_original_ref() { - Some(nonce) => *nonce != modified_account.nonce, + let is_nonce_modified = match self.nonce.take_original_ref() { + Some(original_nonce) => *original_nonce != modified_account.nonce, None => true, }; - if nonce_modified { + if is_nonce_modified { self.nonce.set_modified(modified_account.nonce); } // update balance if modified - let balance_modified = match self.balance.take_modified_ref() { - Some(balance) => *balance != modified_account.balance, + let is_balance_modified = match self.balance.take_original_ref() { + Some(original_balance) => *original_balance != modified_account.balance, None => true, }; - if balance_modified { + if is_balance_modified { self.balance.set_modified(modified_account.balance); } @@ -105,17 +104,12 @@ impl ExecutionAccountChanges { } /// Checks if the account was created by this transaction. - pub fn is_account_creation(&self) -> bool { + pub fn is_creation(&self) -> bool { self.new_account } - /// Checks if the account was updated by this transaction (it must already exist). - 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 { + /// Checks if nonce, balance or bytecode were modified. + pub fn is_changed(&self) -> bool { self.nonce.is_modified() || self.balance.is_modified() || self.bytecode.is_modified() } } diff --git a/src/eth/storage/csv/csv_exporter.rs b/src/eth/storage/csv/csv_exporter.rs index 91ac996dd..8f42faa4e 100644 --- a/src/eth/storage/csv/csv_exporter.rs +++ b/src/eth/storage/csv/csv_exporter.rs @@ -364,7 +364,7 @@ impl CsvExporter { fn export_account_changes(&mut self, now: String, number: BlockNumber, changes: Vec) -> anyhow::Result<()> { for change in changes { - if change.is_account_creation() { + if change.is_creation() { self.accounts_id.value += 1; let change_bytecode = change.bytecode.take_ref().and_then(|x| x.clone().map(to_bytea)).unwrap_or(NULL.to_string()); let row = [ diff --git a/src/eth/storage/rocks/rocks_state.rs b/src/eth/storage/rocks/rocks_state.rs index a8041b832..4bfd9b102 100644 --- a/src/eth/storage/rocks/rocks_state.rs +++ b/src/eth/storage/rocks/rocks_state.rs @@ -398,7 +398,7 @@ impl RocksStorageState { let account_changes_future = tokio::task::spawn_blocking(move || { for change in changes_clone_for_accounts { - if change.is_account_change() { + if change.is_changed() { 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() {