-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: De-duplicate code to create BlockHeader for genesis and view #12109
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12109 +/- ##
==========================================
+ Coverage 71.53% 71.59% +0.06%
==========================================
Files 818 818
Lines 164494 164367 -127
Branches 164494 164367 -127
==========================================
+ Hits 117667 117679 +12
+ Misses 41688 41549 -139
Partials 5139 5139
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you!
assert_ne!( | ||
signer.is_some(), | ||
signature.is_some(), | ||
"Exactly one of signer and signature must be provided" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should replace them with a single enum then, with two variants, e.g.
enum SignatureSource<'a> {
Signer(&'a ValidatorSigner)
Signature(Signature)
}
which documents itself.
} | ||
|
||
/// Common logic for generating BlockHeader for different purposes, including new blocks, from views, and for genesis block | ||
fn new_impl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably unite arguments in BlockHeaderInnerLite, BlockHeaderInnerRestV1 (?) and the rest earlier to reduce number of arguments.
We address a TODO item to use
BlockHeader::new
when creating aBlockHeader
in two other places (today these places use similar logic to choose the rightBlockHeader
version and contruct the inner structs based on the protocol version).BlockHeader
fromBlockHeaderView
.BlockHeader
for the genesis block.For this, we add
BlockHeader::new_impl
to contain the common code and have two other wrapper functions to callnew_impl
for the use cases above:BlockHeader::from_view
andBlockHeader::genesis
.