You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There appears to be a logical inconsistency in the prune shard handling code in crates/prune/prune/src/segments/user/history.rs, specifically in the prune_shard function around lines 114-143.
Current Logic
When a shard becomes empty after pruning (i.e., higher_blocks.is_empty()), the code distinguishes between two cases:
Regular shards (highest_block_number != u64::MAX): Simply delete the shard
Last shards (highest_block_number == u64::MAX): Check for previous shard and potentially merge
if higher_blocks.is_empty(){if key.as_ref().highest_block_number == u64::MAX{// Complex logic to check previous shard and potentially mergelet prev_row = cursor.prev()?;match prev_row {Some((prev_key, prev_value))ifkey_matches(&prev_key,&key) => {
cursor.delete_current()?;
cursor.upsert(RawKey::new(key),&prev_value)?;Ok(PruneShardOutcome::Updated)}
_ => {
cursor.delete_current()?;Ok(PruneShardOutcome::Deleted)}}}else{// Simple deletion for non-u64::MAX shards
cursor.delete_current()?;Ok(PruneShardOutcome::Deleted)}}
Shard ordering: Shards are ordered by highest_block_number
Logical consequence: If the last shard (u64::MAX) is filtered empty, all previous shards should also be filtered empty
Why This Should Be True
Shards are ordered by highest_block_number
The pruning filter removes all blocks <= to_block
If the last shard (with highest highest_block_number) is empty after filtering, it means all its blocks were <= to_block
Since previous shards have lower highest_block_number, they should contain even more blocks that are <= to_block
Therefore, previous shards should also be empty after filtering
Proposed Solution
Simplify the logic by removing the special case for u64::MAX shards:
if higher_blocks.is_empty(){// Simply delete the shard regardless of whether it's u64::MAX or not
cursor.delete_current()?;Ok(PruneShardOutcome::Deleted)}
Benefits of Simplification
Consistency: All empty shards are handled the same way
Correctness: If u64::MAX shard is empty, previous shards should also be empty
Simplicity: Removes complex logic that may be unnecessary
Potentially affects account history and storage history pruning
Testing Considerations
The proposed change should be tested with:
Various pruning scenarios
Edge cases with shard boundaries
Performance comparison between current and simplified logic
Note: This analysis is based on the assumption that shards are properly ordered by highest_block_number and that the pruning logic is consistent. If there are special cases or edge conditions that justify the current logic, they should be documented and explained.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Description
There appears to be a logical inconsistency in the prune shard handling code in
crates/prune/prune/src/segments/user/history.rs, specifically in theprune_shardfunction around lines 114-143.Current Logic
When a shard becomes empty after pruning (i.e.,
higher_blocks.is_empty()), the code distinguishes between two cases:highest_block_number != u64::MAX): Simply delete the shardhighest_block_number == u64::MAX): Check for previous shard and potentially mergeThe Issue
The logic seems inconsistent because:
blocks.iter().skip_while(|block| *block <= to_block)highest_block_numberWhy This Should Be True
highest_block_number<= to_blockhighest_block_number) is empty after filtering, it means all its blocks were<= to_blockhighest_block_number, they should contain even more blocks that are<= to_blockProposed Solution
Simplify the logic by removing the special case for
u64::MAXshards:Benefits of Simplification
Questions for Discussion
Files Affected
crates/prune/prune/src/segments/user/history.rs(lines 114-143)Testing Considerations
The proposed change should be tested with:
Note: This analysis is based on the assumption that shards are properly ordered by
highest_block_numberand that the pruning logic is consistent. If there are special cases or edge conditions that justify the current logic, they should be documented and explained.Beta Was this translation helpful? Give feedback.
All reactions