-
Notifications
You must be signed in to change notification settings - Fork 4.7k
shred: expose merkle root for use in blockstore #34063
Conversation
0a32372
to
b741505
Compare
ledger/src/blockstore_meta.rs
Outdated
impl MerkleRootMeta { | ||
pub(crate) fn from_shred(shred: &Shred) -> Self { | ||
Self { | ||
merkle_root: shred.merkle_root().unwrap_or_default(), |
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.
Now I am thinking that MerkleRootMeta.merkle_root
should have been Option<Hash>
to explicitly distinguish legacy shreds.
This unwrap_or_default
here is a bit hacky, and it seems like we will have to special case merkle_root_meta.merkle_root == Hash::default()
later.
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.
definitely possible, however I was under the impression that legacy shreds are no longer being broadcasted.
I assume at some point you will delete shred/legacy.rs
at which point I can remove unwrap_or_default()
and any Hash::default()
checks, and return Option<Self>
for legitimate errors
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.
They are no longer broadcasted but still totally valid to send legacy shreds.
We might also need to keep shred/legacy.rs
for backward compatibility.
I am not sure for how long we will need to preserve legacy shreds, so I am leaning to use Option<Hash>
to be consistent with current state of the code.
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.
Got it. Is it supported to send a mixture of legacy and merkle shreds in a single FEC set?
If not I think we can just avoid storing the merkle root meta for legacy FEC sets. There's no benefit to inserting the meta into blockstore if the FEC set only has legacy shreds. For the next pr that writes this column, I can filter out FEC sets that are legacy.
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.
no, but if you receive two shreds with the same fec_set_index
and one is merkle and the other legacy, then that is a proof of duplicate block.
So I think we need to record that we have received a legacy shred for this fec_set_index
, and I guess the easiest way to do that is to set merkle_root
to None
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.
makes sense i'll do that first.
ledger/src/shred.rs
Outdated
@@ -337,6 +337,8 @@ impl Shred { | |||
dispatch!(pub fn payload(&self) -> &Vec<u8>); | |||
dispatch!(pub fn sanitize(&self) -> Result<(), Error>); | |||
|
|||
dispatch!(pub fn merkle_root(&self) -> Option<Hash>); |
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.
Can you please keep lines 336-340 alphabetically sorted?
also, the blank like 339 is not needed.
also, the return type should be Result<Hash, Error>
to preserve the error.
ledger/src/shred/shred_code.rs
Outdated
@@ -47,6 +47,13 @@ impl ShredCode { | |||
} | |||
} | |||
|
|||
pub(super) fn merkle_root(&self) -> Option<Hash> { |
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.
Can we return -> Result<Hash, Error>
to preserve the error?
Self::Legacy(_)
case would then return Err(Error::InvalidShredType)
.
ledger/src/shred/shred_data.rs
Outdated
pub(super) fn merkle_root(&self) -> Option<Hash> { | ||
match self { | ||
Self::Legacy(_) => None, |
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.
same here, about preserving the Error
.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #34063 +/- ##
==========================================
Coverage 81.8% 81.9%
==========================================
Files 766 812 +46
Lines 209154 219707 +10553
==========================================
+ Hits 171206 180014 +8808
- Misses 37948 39693 +1745 |
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.
lgtm, but can we first update MerkleRootMeta.merkle_root
to an explicit Option<Hash>
.
that might need to be done in a separate PR because that needs to be backported.
cfa7bc1
to
28b6626
Compare
// legacy or malformed shreds. We should still store | ||
// `None` for those cases in blockstore, as a later | ||
// shred that contains a proper merkle root would constitute | ||
// a valid duplicate shred proof. |
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.
duplicate "block" proof, no?
we might not actually observe any duplicate shreds.
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.
not sure about the terminology. We're still calling them duplicate shred proofs in gossip even though it has evolved beyond shreds with the same index. If you prefer I can do a separate refactor PR afterwards renaming all instances of "duplicate shred proof" to "duplicate block proof"?
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.
never mind then,
we can revisit once the code is shipped and stable.
Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis. |
* shred: expose merkle root for use in blockstore * pr feedback: sorted, keep Result return type * convert Result<Hash> -> Option<Hash> (cherry picked from commit 6a5b8e8)
* shred: expose merkle root for use in blockstore * pr feedback: sorted, keep Result return type * convert Result<Hash> -> Option<Hash> (cherry picked from commit 6a5b8e8)
* shred: expose merkle root for use in blockstore * pr feedback: sorted, keep Result return type * convert Result<Hash> -> Option<Hash> (cherry picked from commit 6a5b8e8)
…34063) (#34291) shred: expose merkle root for use in blockstore (#34063) * shred: expose merkle root for use in blockstore * pr feedback: sorted, keep Result return type * convert Result<Hash> -> Option<Hash> (cherry picked from commit 6a5b8e8) Co-authored-by: Ashwin Sekar <[email protected]>
Problem
We need to access the
merkle_root
for merkle shreds in blockstore.Summary of Changes
Dispatch to it, return
None
for legacy shreds.Split from #33889
Contributes to #33644