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

blockstore: store first received coding shred index in ErasureMeta #961

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from 1 commit
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
17 changes: 11 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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is safe to change type from usize to u64 for consistency and fewer type-casts.
usize is serialized as u64 anyways:
https://github.com/serde-rs/serde/blob/f6623a365/serde/src/ser/impls.rs#L28

/// Index of the first received coding shred in the FEC set
first_received_coding_index: usize,
steviez marked this conversation as resolved.
Show resolved Hide resolved
/// 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 = usize::try_from(shred.index()).ok()?;
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 next_fec_set_index(&self) -> Option<u32> {
let num_data = u64::try_from(self.config.num_data).ok()?;
self.set_index
Expand Down Expand Up @@ -568,7 +573,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
Loading