From effa0ab4c7ae559c06c7ecf4452d8ef8f10192e2 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Wed, 28 Jan 2026 15:52:08 +0000 Subject: [PATCH] fix(provider): read changesets from static files during unwind (#21528) Co-authored-by: Amp --- .../stages/src/stages/hashing_storage.rs | 6 ++-- .../src/stages/index_storage_history.rs | 2 +- .../src/providers/blockchain_provider.rs | 2 +- .../provider/src/providers/consistent.rs | 2 +- .../src/providers/database/provider.rs | 35 ++++++------------- .../src/providers/static_file/manager.rs | 2 +- .../storage/provider/src/test_utils/mock.rs | 2 +- crates/storage/storage-api/src/hashing.rs | 2 +- crates/storage/storage-api/src/history.rs | 2 +- crates/storage/storage-api/src/noop.rs | 2 +- crates/storage/storage-api/src/storage.rs | 6 ++-- 11 files changed, 23 insertions(+), 40 deletions(-) diff --git a/crates/stages/stages/src/stages/hashing_storage.rs b/crates/stages/stages/src/stages/hashing_storage.rs index b2b771cd9a..19e8936209 100644 --- a/crates/stages/stages/src/stages/hashing_storage.rs +++ b/crates/stages/stages/src/stages/hashing_storage.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use reth_config::config::{EtlConfig, HashingConfig}; use reth_db_api::{ cursor::{DbCursorRO, DbDupCursorRW}, - models::{BlockNumberAddress, CompactU256}, + models::CompactU256, table::Decompress, tables, transaction::{DbTx, DbTxMut}, @@ -179,7 +179,7 @@ where let (range, unwind_progress, _) = input.unwind_block_range_with_threshold(self.commit_threshold); - provider.unwind_storage_hashing_range(BlockNumberAddress::range(range))?; + provider.unwind_storage_hashing_range(range)?; let mut stage_checkpoint = input.checkpoint.storage_hashing_stage_checkpoint().unwrap_or_default(); @@ -227,7 +227,7 @@ mod tests { use rand::Rng; use reth_db_api::{ cursor::{DbCursorRW, DbDupCursorRO}, - models::StoredBlockBodyIndices, + models::{BlockNumberAddress, StoredBlockBodyIndices}, }; use reth_ethereum_primitives::Block; use reth_primitives_traits::SealedBlock; diff --git a/crates/stages/stages/src/stages/index_storage_history.rs b/crates/stages/stages/src/stages/index_storage_history.rs index 7b7d39f6d6..29eb5816d6 100644 --- a/crates/stages/stages/src/stages/index_storage_history.rs +++ b/crates/stages/stages/src/stages/index_storage_history.rs @@ -166,7 +166,7 @@ where let (range, unwind_progress, _) = input.unwind_block_range_with_threshold(self.commit_threshold); - provider.unwind_storage_history_indices_range(BlockNumberAddress::range(range))?; + provider.unwind_storage_history_indices_range(range)?; Ok(UnwindOutput { checkpoint: StageCheckpoint::new(unwind_progress) }) } diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 141a5074b6..a9cf4c38f4 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -728,7 +728,7 @@ impl StorageChangeSetReader for BlockchainProvider { fn storage_changesets_range( &self, - range: RangeInclusive, + range: impl RangeBounds, ) -> ProviderResult> { self.consistent_provider()?.storage_changesets_range(range) } diff --git a/crates/storage/provider/src/providers/consistent.rs b/crates/storage/provider/src/providers/consistent.rs index 076e0e3d1f..4963708d1b 100644 --- a/crates/storage/provider/src/providers/consistent.rs +++ b/crates/storage/provider/src/providers/consistent.rs @@ -1397,7 +1397,7 @@ impl StorageChangeSetReader for ConsistentProvider { fn storage_changesets_range( &self, - range: RangeInclusive, + range: impl RangeBounds, ) -> ProviderResult> { let range = to_range(range); let mut changesets = Vec::new(); diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 795dbc308b..89c3c65020 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -40,7 +40,8 @@ use reth_db_api::{ database::Database, models::{ sharded_key, storage_sharded_key::StorageShardedKey, AccountBeforeTx, BlockNumberAddress, - ShardedKey, StorageBeforeTx, StorageSettings, StoredBlockBodyIndices, + BlockNumberAddressRange, ShardedKey, StorageBeforeTx, StorageSettings, + StoredBlockBodyIndices, }, table::Table, tables, @@ -1384,14 +1385,14 @@ impl StorageChangeSetReader for DatabaseProvider fn storage_changesets_range( &self, - range: RangeInclusive, + range: impl RangeBounds, ) -> ProviderResult> { if self.cached_storage_settings().storage_changesets_in_static_files { self.static_file_provider.storage_changesets_range(range) } else { self.tx .cursor_dup_read::()? - .walk_range(BlockNumberAddress::range(range))? + .walk_range(BlockNumberAddressRange::from(range))? .map(|r| r.map_err(Into::into)) .collect() } @@ -2834,11 +2835,7 @@ impl HashingWriter for DatabaseProvi &self, range: impl RangeBounds, ) -> ProviderResult>> { - let changesets = self - .tx - .cursor_read::()? - .walk_range(range)? - .collect::, _>>()?; + let changesets = self.account_changesets_range(range)?; self.unwind_account_hashing(changesets.iter()) } @@ -2896,13 +2893,9 @@ impl HashingWriter for DatabaseProvi fn unwind_storage_hashing_range( &self, - range: impl RangeBounds, + range: impl RangeBounds, ) -> ProviderResult>> { - let changesets = self - .tx - .cursor_read::()? - .walk_range(range)? - .collect::, _>>()?; + let changesets = self.storage_changesets_range(range)?; self.unwind_storage_hashing(changesets.into_iter()) } @@ -2997,11 +2990,7 @@ impl HistoryWriter for DatabaseProvi &self, range: impl RangeBounds, ) -> ProviderResult { - let changesets = self - .tx - .cursor_read::()? - .walk_range(range)? - .collect::, _>>()?; + let changesets = self.account_changesets_range(range)?; self.unwind_account_history_indices(changesets.iter()) } @@ -3063,13 +3052,9 @@ impl HistoryWriter for DatabaseProvi fn unwind_storage_history_indices_range( &self, - range: impl RangeBounds, + range: impl RangeBounds, ) -> ProviderResult { - let changesets = self - .tx - .cursor_read::()? - .walk_range(range)? - .collect::, _>>()?; + let changesets = self.storage_changesets_range(range)?; self.unwind_storage_history_indices(changesets.into_iter()) } diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 14beb0a4d8..a8743f301c 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -2499,7 +2499,7 @@ impl StorageChangeSetReader for StaticFileProvider { fn storage_changesets_range( &self, - range: RangeInclusive, + range: impl RangeBounds, ) -> ProviderResult> { let range = self.bound_range(range, StaticFileSegment::StorageChangeSets); self.walk_storage_changeset_range(range).collect() diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index d54324c54c..4d6b172993 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -1025,7 +1025,7 @@ impl StorageChangeSetReader fn storage_changesets_range( &self, - _range: RangeInclusive, + _range: impl RangeBounds, ) -> ProviderResult> { Ok(Vec::default()) } diff --git a/crates/storage/storage-api/src/hashing.rs b/crates/storage/storage-api/src/hashing.rs index 7c1ced53c1..30d734d09b 100644 --- a/crates/storage/storage-api/src/hashing.rs +++ b/crates/storage/storage-api/src/hashing.rs @@ -57,7 +57,7 @@ pub trait HashingWriter: Send { /// Mapping of hashed keys of updated accounts to their respective updated hashed slots. fn unwind_storage_hashing_range( &self, - range: impl RangeBounds, + range: impl RangeBounds, ) -> ProviderResult>>; /// Iterates over storages and inserts them to hashing table. diff --git a/crates/storage/storage-api/src/history.rs b/crates/storage/storage-api/src/history.rs index d47f354ab6..a06816a170 100644 --- a/crates/storage/storage-api/src/history.rs +++ b/crates/storage/storage-api/src/history.rs @@ -44,7 +44,7 @@ pub trait HistoryWriter: Send { /// Returns number of changesets walked. fn unwind_storage_history_indices_range( &self, - range: impl RangeBounds, + range: impl RangeBounds, ) -> ProviderResult; /// Insert storage change index to database. Used inside `StorageHistoryIndex` stage diff --git a/crates/storage/storage-api/src/noop.rs b/crates/storage/storage-api/src/noop.rs index c6f0a30e08..42620d9f83 100644 --- a/crates/storage/storage-api/src/noop.rs +++ b/crates/storage/storage-api/src/noop.rs @@ -430,7 +430,7 @@ impl StorageChangeSetReader for NoopProvider< fn storage_changesets_range( &self, - _range: RangeInclusive, + _range: impl core::ops::RangeBounds, ) -> ProviderResult< Vec<(reth_db_api::models::BlockNumberAddress, reth_primitives_traits::StorageEntry)>, > { diff --git a/crates/storage/storage-api/src/storage.rs b/crates/storage/storage-api/src/storage.rs index 66f74e7f0c..ab92744970 100644 --- a/crates/storage/storage-api/src/storage.rs +++ b/crates/storage/storage-api/src/storage.rs @@ -3,7 +3,7 @@ use alloc::{ vec::Vec, }; use alloy_primitives::{Address, BlockNumber, B256}; -use core::ops::RangeInclusive; +use core::ops::{RangeBounds, RangeInclusive}; use reth_primitives_traits::StorageEntry; use reth_storage_errors::provider::ProviderResult; @@ -53,11 +53,9 @@ pub trait StorageChangeSetReader: Send { ) -> ProviderResult>; /// Get all storage changesets in a range of blocks. - /// - /// NOTE: Get inclusive range of blocks. fn storage_changesets_range( &self, - range: RangeInclusive, + range: impl RangeBounds, ) -> ProviderResult>; /// Get the total count of all storage changes.