From 3e3f33299d8e25875b5d237ab11c1f7f11c6122e Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Thu, 22 Aug 2024 22:50:37 -0700 Subject: [PATCH] fix(trie): take earliest value in `HashedStorage::from_reverts` (#10475) --- crates/trie/db/src/storage.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/trie/db/src/storage.rs b/crates/trie/db/src/storage.rs index 896861e32..9ab2cdeda 100644 --- a/crates/trie/db/src/storage.rs +++ b/crates/trie/db/src/storage.rs @@ -1,3 +1,5 @@ +use std::collections::hash_map; + use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory}; use reth_db::{cursor::DbCursorRO, models::BlockNumberAddress, tables, DatabaseError}; use reth_db_api::transaction::DbTx; @@ -84,7 +86,9 @@ impl DatabaseHashedStorage for HashedStorage { let (BlockNumberAddress((_, storage_address)), storage_change) = entry?; if storage_address == address { let hashed_slot = keccak256(storage_change.key); - storage.storage.insert(hashed_slot, storage_change.value); + if let hash_map::Entry::Vacant(entry) = storage.storage.entry(hashed_slot) { + entry.insert(storage_change.value); + } } } Ok(storage)