refactor(prune): impl Segment for other prune segments#4899
Conversation
…to alexey/pruner-part-trait
…to alexey/pruner-part-trait
Codecov Report
... and 4 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…to alexey/pruner-part-trait
…lexey/pruner-part-trait-impls
crates/prune/src/pruner.rs
Outdated
| #[allow(clippy::type_complexity)] | ||
| let segments: [( | ||
| Box<dyn Segment<DB>>, | ||
| Box< | ||
| dyn Fn( | ||
| &PruneModes, | ||
| BlockNumber, | ||
| ) | ||
| -> Result<Option<(BlockNumber, PruneMode)>, PruneSegmentError>, | ||
| >, | ||
| ); 5] = [ |
There was a problem hiding this comment.
is the issue here that we want to combine the segment and the handler into a simple array over which we can loop?
There was a problem hiding this comment.
I think we can at least add a helper type for this, with the segment and the handler as field,
or maybe the fn can even be made part of the segment trait?
There was a problem hiding this comment.
I think we can at least add a helper type for this, with the segment and the handler as field,
Yep, introduced a helper type. Couldn't make it more succinct because of Fn definition.
or maybe the fn can even be made part of the segment trait?
I think it can be, but it would also require touching PruneModes, and I rather keep this PR only to refactoring the pruner, because it's already large.
Continued work started for
Receiptssegment in #4887, but for other prune segments too. Most of the changes are copy-paste frompruner.rsinto dedicatedsegments/segment.rsfiles.Pruner::runwas also refactored to make use of a generic interface across segments:reth/crates/prune/src/pruner.rs
Lines 122 to 184 in b1d0d2b
There are two main TODOs now:
Pruner, but instead they're initialized in-place as an array ofBox<dyn Segment>and the correspondingPruneModes::prune_target_block_*function. We need to refactor it by:Pruner::new.PruneModes::prune_target_block_*functions and putting this responsibility onSegment.ReceiptsByLogssegment doesn't implement theSegmenttrait, because itsprunemethod signature differs. We need to make it work the same way as other segments.