From 3028bbd83ccd3b1a5abb1de3b7547206a10ea92d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 15 Oct 2023 21:31:30 +0200 Subject: [PATCH] fix: some trace statediff improvements (#5033) --- .../src/tracing/builder/parity.rs | 18 ++++++++++++++ crates/rpc/rpc-types/src/eth/trace/parity.rs | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/crates/revm/revm-inspectors/src/tracing/builder/parity.rs b/crates/revm/revm-inspectors/src/tracing/builder/parity.rs index 75fee4029..246f608b4 100644 --- a/crates/revm/revm-inspectors/src/tracing/builder/parity.rs +++ b/crates/revm/revm-inspectors/src/tracing/builder/parity.rs @@ -577,6 +577,11 @@ where DB: DatabaseRef, { for (addr, changed_acc) in account_diffs.into_iter() { + // if the account was selfdestructed and created during the transaction, we can ignore it + if changed_acc.is_selfdestructed() && changed_acc.is_created() { + continue + } + let addr = *addr; let entry = state_diff.entry(addr).or_default(); @@ -592,6 +597,19 @@ where } else { // account already exists, we need to fetch the account from the db let db_acc = db.basic(addr)?.unwrap_or_default(); + + // check if the account was changed at all + // NOTE: changed storage values are set by the the + // `CallTraceNode::parity_update_state_diff` + if entry.storage.is_empty() && + db_acc == changed_acc.info && + !changed_acc.is_selfdestructed() + { + // clear the entry if the account was not changed + state_diff.remove(&addr); + continue + } + entry.balance = if db_acc.balance == changed_acc.info.balance { Delta::Unchanged } else { diff --git a/crates/rpc/rpc-types/src/eth/trace/parity.rs b/crates/rpc/rpc-types/src/eth/trace/parity.rs index 175e79dc2..d9d78e1e4 100644 --- a/crates/rpc/rpc-types/src/eth/trace/parity.rs +++ b/crates/rpc/rpc-types/src/eth/trace/parity.rs @@ -82,6 +82,30 @@ pub enum Delta { Changed(ChangedType), } +// === impl Delta === + +impl Delta { + /// Returns true if the value is unchanged + pub fn is_unchanged(&self) -> bool { + matches!(self, Delta::Unchanged) + } + + /// Returns true if the value is added + pub fn is_added(&self) -> bool { + matches!(self, Delta::Added(_)) + } + + /// Returns true if the value is removed + pub fn is_removed(&self) -> bool { + matches!(self, Delta::Removed(_)) + } + + /// Returns true if the value is changed + pub fn is_changed(&self) -> bool { + matches!(self, Delta::Changed(_)) + } +} + #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct AccountDiff {