Skip to content
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

v1.18: blockstore: store first received coding shred index in ErasureMeta (backport of #961) #981

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 61 additions & 6 deletions ledger/src/blockstore_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ pub struct ErasureMeta {
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,
/// Index of the first received coding shred in the FEC set
first_received_coding_index: u64,
/// Erasure configuration for this erasure set
config: ErasureConfig,
}
Expand Down Expand Up @@ -348,11 +347,12 @@ 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 erasure_meta = ErasureMeta {
set_index: u64::from(shred.fec_set_index()),
config,
first_coding_index,
__unused_size: 0,
first_received_coding_index,
};
Some(erasure_meta)
}
Expand All @@ -365,7 +365,7 @@ impl ErasureMeta {
let Some(mut other) = Self::from_coding_shred(shred) else {
return false;
};
other.__unused_size = self.__unused_size;
other.first_received_coding_index = self.first_received_coding_index;
self == &other
}

Expand All @@ -392,6 +392,11 @@ impl ErasureMeta {
self.first_coding_index..self.first_coding_index + num_coding
}

#[allow(dead_code)]
pub(crate) fn first_received_coding_shred_index(&self) -> Option<u32> {
u32::try_from(self.first_received_coding_index).ok()
}

pub(crate) fn status(&self, index: &Index) -> ErasureMetaStatus {
use ErasureMetaStatus::*;

Expand Down Expand Up @@ -560,7 +565,7 @@ mod test {
set_index,
first_coding_index: set_index,
config: erasure_config,
__unused_size: 0,
first_received_coding_index: 0,
};
let mut rng = thread_rng();
let mut index = Index::new(0);
Expand Down Expand Up @@ -713,4 +718,54 @@ mod test {

assert_eq!(actual, expected);
}

#[test]
fn test_erasure_meta_transition() {
#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct OldErasureMeta {
set_index: u64,
first_coding_index: u64,
#[serde(rename = "size")]
__unused_size: usize,
config: ErasureConfig,
}

let set_index = 64;
let erasure_config = ErasureConfig {
num_data: 8,
num_coding: 16,
};
let mut old_erasure_meta = OldErasureMeta {
set_index,
first_coding_index: set_index,
__unused_size: 0,
config: erasure_config,
};
let mut new_erasure_meta = ErasureMeta {
set_index,
first_coding_index: set_index,
first_received_coding_index: 0,
config: erasure_config,
};

assert_eq!(
bincode::serialized_size(&old_erasure_meta).unwrap(),
bincode::serialized_size(&new_erasure_meta).unwrap(),
);

assert_eq!(
bincode::deserialize::<ErasureMeta>(&bincode::serialize(&old_erasure_meta).unwrap())
.unwrap(),
new_erasure_meta
);

new_erasure_meta.first_received_coding_index = u64::from(u32::max_value());
old_erasure_meta.__unused_size = usize::try_from(u32::max_value()).unwrap();

assert_eq!(
bincode::deserialize::<OldErasureMeta>(&bincode::serialize(&new_erasure_meta).unwrap())
.unwrap(),
old_erasure_meta
);
}
}
Loading