This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
adds back ErasureMeta::first_coding_index field #21623
Merged
behzadnouri
merged 1 commit into
solana-labs:master
from
behzadnouri:first-coding-index
Dec 10, 2021
Merged
Changes from all commits
Commits
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 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 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
use { | ||
crate::erasure::ErasureConfig, | ||
crate::{ | ||
erasure::ErasureConfig, | ||
shred::{Shred, ShredType}, | ||
}, | ||
serde::{Deserialize, Serialize}, | ||
solana_sdk::{clock::Slot, hash::Hash}, | ||
std::{ | ||
|
@@ -56,9 +59,8 @@ pub struct ShredIndex { | |
pub struct ErasureMeta { | ||
/// Which erasure set in the slot this is | ||
set_index: u64, | ||
/// Deprecated field. | ||
#[serde(rename = "first_coding_index")] | ||
__unused_first_coding_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, | ||
|
@@ -226,15 +228,41 @@ impl SlotMeta { | |
} | ||
|
||
impl ErasureMeta { | ||
pub(crate) fn new(set_index: u64, config: ErasureConfig) -> ErasureMeta { | ||
ErasureMeta { | ||
set_index, | ||
config, | ||
__unused_first_coding_index: 0, | ||
__unused_size: 0, | ||
pub(crate) fn from_coding_shred(shred: &Shred) -> Option<Self> { | ||
match shred.shred_type() { | ||
ShredType::Data => None, | ||
ShredType::Code => { | ||
let config = ErasureConfig::new( | ||
usize::from(shred.coding_header.num_data_shreds), | ||
usize::from(shred.coding_header.num_coding_shreds), | ||
); | ||
let first_coding_index = u64::from(shred.first_coding_index()?); | ||
let erasure_meta = ErasureMeta { | ||
set_index: u64::from(shred.fec_set_index()), | ||
config, | ||
first_coding_index, | ||
__unused_size: 0, | ||
}; | ||
Some(erasure_meta) | ||
} | ||
} | ||
} | ||
|
||
// Returns true if the erasure fields on the shred | ||
// are consistent with the erasure-meta. | ||
pub(crate) fn check_coding_shred(&self, shred: &Shred) -> bool { | ||
let mut other = match Self::from_coding_shred(shred) { | ||
Some(erasure_meta) => erasure_meta, | ||
None => return false, | ||
}; | ||
other.__unused_size = self.__unused_size; | ||
// Ignore first_coding_index field for now to be backward compatible. | ||
// TODO remove this once cluster is upgraded to always populate | ||
// first_coding_index field. | ||
other.first_coding_index = self.first_coding_index; | ||
self == &other | ||
} | ||
|
||
pub(crate) fn config(&self) -> ErasureConfig { | ||
self.config | ||
} | ||
|
@@ -246,7 +274,16 @@ impl ErasureMeta { | |
|
||
pub(crate) fn coding_shreds_indices(&self) -> Range<u64> { | ||
let num_coding = self.config.num_coding() as u64; | ||
self.set_index..self.set_index + num_coding | ||
// first_coding_index == 0 may imply that the field is not populated. | ||
// self.set_index to be backward compatible. | ||
// TODO remove this once cluster is upgraded to always populate | ||
// first_coding_index field. | ||
let first_coding_index = if self.first_coding_index == 0 { | ||
self.set_index | ||
} else { | ||
self.first_coding_index | ||
}; | ||
Comment on lines
+281
to
+285
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. nice, this was pretty subtle to maintain backwards compatibility |
||
first_coding_index..first_coding_index + num_coding | ||
} | ||
|
||
pub(crate) fn status(&self, index: &Index) -> ErasureMetaStatus { | ||
|
@@ -316,7 +353,12 @@ mod test { | |
let set_index = 0; | ||
let erasure_config = ErasureConfig::new(8, 16); | ||
|
||
let e_meta = ErasureMeta::new(set_index, erasure_config); | ||
let e_meta = ErasureMeta { | ||
set_index, | ||
first_coding_index: set_index, | ||
config: erasure_config, | ||
__unused_size: 0, | ||
}; | ||
let mut rng = thread_rng(); | ||
let mut index = Index::new(0); | ||
|
||
|
This file contains 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 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.
Might be good to create an issue as a reminder to track this and other TODOs
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.
Yeah, already have draft follow up changes.
There is no harm in keeping this code as is, until those upcoming changes are ready to go.
I just need to merge this commit in an earlier release to avoid any compatibility issues.