Skip to content

Commit

Permalink
fix: some trace statediff improvements (#5033)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 15, 2023
1 parent 7e088da commit 3028bbd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/revm/revm-inspectors/src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions crates/rpc/rpc-types/src/eth/trace/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ pub enum Delta<T> {
Changed(ChangedType<T>),
}

// === impl Delta ===

impl<T> Delta<T> {
/// 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 {
Expand Down

0 comments on commit 3028bbd

Please sign in to comment.