-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
add merkle root meta column to blockstore #33979
add merkle root meta column to blockstore #33979
Conversation
5b62f50
to
01f3c9f
Compare
01f3c9f
to
29fae8d
Compare
Codecov Report
@@ Coverage Diff @@
## master #33979 +/- ##
=======================================
Coverage 81.9% 81.9%
=======================================
Files 811 811
Lines 219424 219452 +28
=======================================
+ Hits 179761 179797 +36
+ Misses 39663 39655 -8 |
|
This PR only adds the new column, and writes to it. The next change will actually utilize the column
Correct, this behavior is not currently caught, but it is next on my list! #33037 |
don't we need to backport the new column to v1.17, v1.16 for forward compatibility? |
Yes, the idea would be to backport some minimal PR to the older versions. Since we're adding a new column, the old branches only need to know about the existence of the columns (Rocksdb has a requirement that all present columns must be opened in order to open the DB). I think we could considerably slim down what we backport from this PR. Namely, we don't need any code that interacts with the column, like the stuff in We would definitely want the BP for v1.17, probably v1.16 as well but we'll likely have to do some convincing given where v1.16 is at in its' release cycle |
ledger/src/shred.rs
Outdated
pub fn merkle_root(&self) -> Option<Hash> { | ||
layout::get_merkle_root(self.payload()) | ||
} |
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.
Instead of using raw layout, this probably should dispatch to merkle_root
methods:
https://github.com/solana-labs/solana/blob/a9509f56b/ledger/src/shred/merkle.rs#L157
https://github.com/solana-labs/solana/blob/a9509f56b/ledger/src/shred/merkle.rs#L269
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.
noted, will do this in the following PR
29fae8d
to
eba1089
Compare
good to know, I was unaware of the rocksdb requirement. I've slimmed down this PR to just the addition of the new column. |
eba1089
to
1fdfed7
Compare
ledger/src/blockstore_db.rs
Outdated
} | ||
|
||
fn key((slot, fec_set_index): Self::Index) -> Vec<u8> { | ||
let mut key = vec![0; 16]; |
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 not 16 bytes anymore.
It is 8 + 4 = 12 bytes.
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.
good catch
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 add a test for this part? The mismatch isn't caught by any test sounds scary.
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.
unable to create a test that would fail.
assert_eq!(MerkleRootMeta::index(&MerkleRootMeta::key((slot, fec_set_index)), (slot, fec_set_index))
will pass with both 12
and 16
.
only way would be to check the length of MerkleRootMeta::key
which requires hardcoding the 16
or 12
in the unit test. this approach would not have caught the oversight.
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.
a round-trip test might still be useful to assert that what is written is read back the same.
asserting manually in the test that the key size is 12 is also fine (agreed that it wouldn't have caught this though, but nonetheless)
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 hit submit but was chatting with Ashwin and agreed with others that a unit test would have been unlikely to catch this.
There is a key_size()
field on the Column
trait that I thought about suggesting; however, this method is flawed in that it calls std::mem::size_of
on Self::Index
. The result is that the calculated key size from this call will include any alignment bytes that would be present in Self::Index
. But, we manually pack the keys end-to-end, so the actual keys do not contain alignment bytes. Have a PR to rip that out / maybe re-implement on each column individually.
Will think on this one a little more to see if there is some way to make this a little more full-proof.
1fdfed7
to
a5dd204
Compare
We always want to be Nonetheless, my preference would be to backport to v1.16 anyways. It would be a pita if we need to do some debugging on mainnet and then we hit this incompatibility issue. |
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) # Conflicts: # ledger/src/blockstore.rs
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) # Conflicts: # ledger/src/blockstore.rs
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) # Conflicts: # ledger/src/blockstore.rs
Backports to the stable 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. |
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. |
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. |
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) # Conflicts: # ledger/src/blockstore.rs
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02)
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02)
…#34028) * add merkle root meta column to blockstore (#33979) * add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) * blockstore: make merkle root Optional in MerkleRootMeta column (#34091) --------- Co-authored-by: Ashwin Sekar <[email protected]>
Backports to the stable 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. |
* add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) # Conflicts: # ledger/src/blockstore.rs
…#34665) * add merkle root meta column to blockstore (#33979) * add merkle root meta column to blockstore * pr feedback: remove write/reads to column * pr feedback: u64 -> u32 + revert * pr feedback: fec_set_index u32, use Self::Index * pr feedback: key size 16 -> 12 (cherry picked from commit e457c02) # Conflicts: # ledger/src/blockstore.rs * fix conflicts * blockstore: make merkle root Optional in MerkleRootMeta column (#34091) --------- Co-authored-by: Ashwin Sekar <[email protected]>
Problem
In order to detect duplicate blocks with conflicting merkle roots we need to be able to access the merkle root for each FEC set. We would like to store the merkle root and relevant meta information for easy access in blockstore.
Summary of Changes
Add new merkle root meta column
Contributes to #33644