From d1cb33b1d27ba8fa61aac0c471967da5a9e49383 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Thu, 26 Sep 2024 20:01:29 +0200 Subject: [PATCH] fix sort --- crates/trie/trie/src/witness.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/crates/trie/trie/src/witness.rs b/crates/trie/trie/src/witness.rs index fae424356b3d..bac0cbfa38ba 100644 --- a/crates/trie/trie/src/witness.rs +++ b/crates/trie/trie/src/witness.rs @@ -10,7 +10,7 @@ use alloy_primitives::{ Bytes, B256, }; use alloy_rlp::{BufMut, Decodable, Encodable}; -use itertools::Either; +use itertools::{Either, Itertools}; use reth_execution_errors::TrieWitnessError; use reth_primitives::constants::EMPTY_ROOT_HASH; use reth_trie_common::{ @@ -120,11 +120,16 @@ where None }; let key = Nibbles::unpack(hashed_address); - account_trie_nodes.extend(self.target_nodes( - key.clone(), - value, - account_multiproof.account_subtree.matching_nodes_iter(&key), - )?); + account_trie_nodes.extend( + self.target_nodes( + key.clone(), + value, + account_multiproof + .account_subtree + .matching_nodes_iter(&key) + .sorted_by(|a, b| a.0.cmp(&b.0)), + )?, + ); // Gather and record storage trie nodes for this account. let mut storage_trie_nodes = BTreeMap::default(); @@ -135,11 +140,16 @@ where .and_then(|s| s.storage.get(&hashed_slot)) .filter(|v| !v.is_zero()) .map(|v| alloy_rlp::encode_fixed_size(v).to_vec()); - storage_trie_nodes.extend(self.target_nodes( - slot_nibbles.clone(), - slot_value, - storage_multiproof.subtree.matching_nodes_iter(&slot_nibbles), - )?); + storage_trie_nodes.extend( + self.target_nodes( + slot_nibbles.clone(), + slot_value, + storage_multiproof + .subtree + .matching_nodes_iter(&slot_nibbles) + .sorted_by(|a, b| a.0.cmp(&b.0)), + )?, + ); } Self::next_root_from_proofs(storage_trie_nodes, |key: Nibbles| {