Skip to content

Commit

Permalink
do not include updated nodes in removed
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jan 10, 2025
1 parent 9da36e7 commit 8d4e441
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2381,8 +2381,8 @@ where
let provider = self.provider.database_provider_ro()?;
compare_trie_updates(
provider.tx_ref(),
&task_trie_updates,
&regular_updates,
task_trie_updates.clone(),
regular_updates,
)
.map_err(ProviderError::from)?;
} else {
Expand Down
37 changes: 35 additions & 2 deletions crates/engine/tree/src/tree/trie_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ impl StorageTrieUpdatesDiff {
/// the differences if there's any.
pub(super) fn compare_trie_updates(
tx: &impl DbTx,
task: &TrieUpdates,
regular: &TrieUpdates,
task: TrieUpdates,
regular: TrieUpdates,
) -> Result<(), DatabaseError> {
let trie_cursor_factory = DatabaseTrieCursorFactory::new(tx);

let task = adjust_trie_updates(task);
let regular = adjust_trie_updates(regular);

let mut diff = TrieUpdatesDiff::default();

// compare account nodes
Expand Down Expand Up @@ -204,6 +207,36 @@ fn compare_storage_trie_updates(
Ok(diff)
}

/// Filters the removed nodes of both account trie updates and storage trie updates, so that they
/// don't include those nodes that were also updated.
fn adjust_trie_updates(trie_updates: TrieUpdates) -> TrieUpdates {
TrieUpdates {
removed_nodes: trie_updates
.removed_nodes
.into_iter()
.filter(|key| !trie_updates.account_nodes.contains_key(key))
.collect(),
storage_tries: trie_updates
.storage_tries
.into_iter()
.map(|(address, updates)| {
(
address,
StorageTrieUpdates {
removed_nodes: updates
.removed_nodes
.into_iter()
.filter(|key| !updates.storage_nodes.contains_key(key))
.collect(),
..updates
},
)
})
.collect(),
..trie_updates
}
}

/// Compares the branch nodes from state root task and regular state root calculation.
///
/// If one of the branch nodes is [`None`], it means it's not updated and the other is compared to
Expand Down

0 comments on commit 8d4e441

Please sign in to comment.