shredder introduce shred builder / new api#8048
shredder introduce shred builder / new api#8048puhtaytow wants to merge 1 commit intoanza-xyz:masterfrom
Conversation
|
@alexpyattaev if you could look when you have a minute and leave early comments 🙏 |
0919885 to
5919705
Compare
| where | ||
| S: ShredBuilderDataFiller, | ||
| { | ||
| pub fn with_parent_slot(&mut self, parent_slot: Slot) -> &mut Self { |
There was a problem hiding this comment.
can we add tests for these as well and/or blend them into existing tests?
| self | ||
| } | ||
|
|
||
| pub fn with_invalid_index(&mut self, index: u32) -> &mut Self { |
There was a problem hiding this comment.
especially need test for this one, as well as doc-comments explaining each
|
Overall looking really nice, thank you! |
a5ea76f to
3bc8c7c
Compare
steviez
left a comment
There was a problem hiding this comment.
Can you please update the PR description with the motivation for this PR. Namely, what is the problem with the current code and how does this PR address that problem / make things better
3bc8c7c to
50c7ea9
Compare
0cca75c to
6e84663
Compare
Sure, it wasn't there at the first point as i made the draft just so Alex could put early comments. --edit Please keep in mind as its still WiP. |
Ahh ok, I still got some notifications for it which is why I commented
Thank you !
🫡 |
| }; | ||
|
|
||
| /// Helper to construct [`ShredBuilder`] with different options | ||
| fn shred_builder_options_setter( |
There was a problem hiding this comment.
Why do we need this? Seems like the exact pattern we wanted to avoid no?
There was a problem hiding this comment.
It seemed for a moment like good way, but its clearly not. I'm workin on it 🙏
27d6dc2 to
1b5d910
Compare
steviez
left a comment
There was a problem hiding this comment.
Current Shredder API forces tests to pass all parameters explicitly, even when these are irrelevant. This makes unit tests unnecessairly verbose and harder to read/ work with.
I agree with the sentiment that having to specify all the arguments in test code where we often use defaults is annoying.
That being said, I also typically try to avoid modifying "production" code for the sake of supporting "test" code. For example,
Provides defaults: parent_slot = slot - 1, version = 0, reference_tick = 0, start_index = 0
This changes makes test more manageable at the cost of making it easier to screw up production code. As is, the verbose code requires the caller to pass those parameters which requires them to think about it. This is good for the production code
As an alternative, what if we introduced a wrapper like TestShredder that held the "extra" state and a production Shredder internally.
Semi-related - I think it probably makes sense to sense to finish other cleanup (like making merkle_root a Hash instead of Option<Hash>) first
Sure, ill switch to the cleanup and lets see what Alex think about the suggested alternative. From my perspective, any good solution is good :) Obviously thank you for the input as always 🙏 |
Cool, I imagine the cleanup should be pretty straight forward and less stuff to possibly support with whatever we land on here
🤝 |
|
As for API design we can definitely have a function that requires all arguments to be provided for prod, and only use the builder in tests. |
|
I'm also thinking if this new test api, could for example replace wrappers like this.. agave/ledger/benches/make_shreds_from_entries.rs Lines 50 to 71 in 0b83420 We could add optional Just an idea. |
Problem
Current Shredder API forces tests to pass all parameters explicitly, even when these are irrelevant. This makes unit tests unnecessairly verbose and harder to read/ work with.
ReedSolomonCacheandProcessShredsStats,Keypair, andEntrydatanext_shred_index/next_code_index, even if not neededversion,reference_tick,parent_slotin scenario where defaults would sufficeSummary of Changes
Introduce
ShredBuilder, a type-state builder with fluent api to construct shreds for tests in ergonomic and flexible way:parent_slot = slot - 1,version = 0,reference_tick = 0,start_index = 0with_parent_slot,with_version,with_reference_tick,with_start_index,with_invalid_index(specific failure tests)Keypair,ReedSolomonCacheandProcessShredsStatsout of boxNo changes to production shredding logic.