This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
blockstore: add merkle root to ErasureMeta column family #33848
Closed
AshwinSekar
wants to merge
4
commits into
solana-labs:master
from
AshwinSekar:merkle-erasure-blockstore
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b34ef05
blockstore: add merkle root to ErasureMeta column family
AshwinSekar 2e35743
pr feedback: use ErasureMetaLegacy naming scheme
AshwinSekar 3196f26
pr feedback: store received coding index in erasure meta for duplicat…
AshwinSekar 9d9252a
pr feedback: add test impl for ErasureConfig
AshwinSekar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,18 +118,34 @@ pub struct ShredIndex { | |
| index: BTreeSet<u64>, | ||
| } | ||
|
|
||
| #[deprecated = "Use ErasureMeta"] | ||
| #[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)] | ||
| /// Erasure coding information | ||
| pub struct ErasureMetaLegacy { | ||
| /// Which erasure set in the slot this is | ||
| pub(crate) set_index: u64, | ||
| /// First coding index in the FEC set | ||
| pub(crate) first_coding_index: u64, | ||
| /// Size of shards in this erasure set | ||
| #[serde(rename = "size")] | ||
| pub(crate) __unused_size: usize, | ||
| /// Erasure configuration for this erasure set | ||
| pub(crate) config: ErasureConfig, | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)] | ||
| /// Erasure coding information for merkle shreds | ||
| pub struct ErasureMeta { | ||
| /// Which erasure set in the slot this is | ||
| set_index: u64, | ||
| /// First coding index in the FEC set | ||
| first_coding_index: u64, | ||
| /// Size of shards in this erasure set | ||
| #[serde(rename = "size")] | ||
| __unused_size: usize, | ||
| /// First coding shred received, from which we populated this ErasureMeta | ||
| first_received_coding_index: u64, | ||
| /// Erasure configuration for this erasure set | ||
| config: ErasureConfig, | ||
| /// Merkle root for this FEC set | ||
| merkle_root: Hash, | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
|
|
@@ -138,6 +154,16 @@ pub(crate) struct ErasureConfig { | |
| num_coding: usize, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| impl ErasureConfig { | ||
| pub(crate) fn new(num_data: usize, num_coding: usize) -> Self { | ||
| ErasureConfig { | ||
| num_data, | ||
| num_coding, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize)] | ||
| pub struct DuplicateSlotProof { | ||
| #[serde(with = "serde_bytes")] | ||
|
|
@@ -331,11 +357,14 @@ impl ErasureMeta { | |
| num_coding: usize::from(shred.num_coding_shreds().ok()?), | ||
| }; | ||
| let first_coding_index = u64::from(shred.first_coding_index()?); | ||
| let first_received_coding_index = u64::from(shred.index()); | ||
| let merkle_root = Hash::default(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. next change in master will populate this from the coding shred, but I don't think that needs to be part of this backport change. |
||
| let erasure_meta = ErasureMeta { | ||
| set_index: u64::from(shred.fec_set_index()), | ||
| config, | ||
| first_coding_index, | ||
| __unused_size: 0, | ||
| first_received_coding_index, | ||
| merkle_root, | ||
| }; | ||
| Some(erasure_meta) | ||
| } | ||
|
|
@@ -348,7 +377,8 @@ impl ErasureMeta { | |
| let Some(mut other) = Self::from_coding_shred(shred) else { | ||
| return false; | ||
| }; | ||
| other.__unused_size = self.__unused_size; | ||
| // The order of received shreds should not impact consistency | ||
| other.first_received_coding_index = self.first_received_coding_index; | ||
| self == &other | ||
| } | ||
|
|
||
|
|
@@ -394,6 +424,41 @@ impl ErasureMeta { | |
| StillNeed(num_needed) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub(crate) fn set_index(&self) -> u64 { | ||
| self.set_index | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub(crate) fn first_coding_index(&self) -> u64 { | ||
| self.first_coding_index | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub(crate) fn first_received_coding_index(&self) -> u64 { | ||
| self.first_received_coding_index | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub(crate) fn merkle_root(&self) -> Hash { | ||
| self.merkle_root | ||
| } | ||
| } | ||
|
|
||
| impl From<ErasureMetaLegacy> for ErasureMeta { | ||
| fn from(erasure_meta: ErasureMetaLegacy) -> ErasureMeta { | ||
| ErasureMeta { | ||
| set_index: erasure_meta.set_index, | ||
| first_coding_index: erasure_meta.first_coding_index, | ||
| // We only use this in the context of merkle_root duplicate shred | ||
| // proofs, so it's fine to not have the correct value here while | ||
| // merkle_root is Hash::default() | ||
| first_received_coding_index: erasure_meta.first_coding_index, | ||
| config: erasure_meta.config, | ||
| merkle_root: Hash::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl DuplicateSlotProof { | ||
|
|
@@ -514,8 +579,9 @@ mod test { | |
| let e_meta = ErasureMeta { | ||
| set_index, | ||
| first_coding_index: set_index, | ||
| first_received_coding_index: 0, | ||
| config: erasure_config, | ||
| __unused_size: 0, | ||
| merkle_root: Hash::default(), | ||
| }; | ||
| let mut rng = thread_rng(); | ||
| let mut index = Index::new(0); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
This type trait and its associated code is pretty verbose and actually adding more complexity here.
Might be simple just to do something like below:
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.
I added it to provide an easy way to transition types of already existing columns in blockstore. Similar to ColumnIndexDeprecation.
All you have to do is implement the trait and TypedColumn. And after the old type is no longer in blockstore, you can just remove the trait impl and the associated migration test.
Figured its worth adding the complexity here to make future transitions frictionless.