mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
perf(prune): sort tx hashes for efficient TransactionLookup pruning (#21297)
This commit is contained in:
committed by
GitHub
parent
492fc20fd1
commit
865f8f8951
@@ -96,12 +96,17 @@ where
|
||||
let tx_range_end = *tx_range.end();
|
||||
|
||||
// Retrieve transactions in the range and calculate their hashes in parallel
|
||||
let hashes = provider
|
||||
let mut hashes = provider
|
||||
.transactions_by_tx_range(tx_range.clone())?
|
||||
.into_par_iter()
|
||||
.map(|transaction| transaction.trie_hash())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Sort hashes to enable efficient cursor traversal through the TransactionHashNumbers
|
||||
// table, which is keyed by hash. Without sorting, each seek would be O(log n) random
|
||||
// access; with sorting, the cursor advances sequentially through the B+tree.
|
||||
hashes.sort_unstable();
|
||||
|
||||
// Number of transactions retrieved from the database should match the tx range count
|
||||
let tx_count = tx_range.count();
|
||||
if hashes.len() != tx_count {
|
||||
|
||||
Reference in New Issue
Block a user