Skip to content

Commit

Permalink
renames size_of_erasure_encoded_slice to ShredCode::capacity (backport
Browse files Browse the repository at this point in the history
…solana-labs#27157) (solana-labs#27180)

renames size_of_erasure_encoded_slice to ShredCode::capacity (solana-labs#27157)

Maintain symmetry between code and data shreds:
* ShredData::capacity -> data buffer capacity
* ShredCode::capacity -> erasure code capacity

(cherry picked from commit c813d75)

Co-authored-by: behzad nouri <[email protected]>
  • Loading branch information
mergify[bot] and behzadnouri authored Aug 16, 2022
1 parent 1797e90 commit c00adba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use {
clock::Slot,
hash::{hashv, Hash},
pubkey::Pubkey,
signature::{Keypair, Signature, Signer},
signature::{Keypair, Signature, Signer, SIGNATURE_BYTES},
},
static_assertions::const_assert_eq,
std::fmt::Debug,
Expand All @@ -92,7 +92,7 @@ pub const SIZE_OF_NONCE: usize = 4;
const SIZE_OF_COMMON_SHRED_HEADER: usize = 83;
const SIZE_OF_DATA_SHRED_HEADERS: usize = 88;
const SIZE_OF_CODING_SHRED_HEADERS: usize = 89;
const SIZE_OF_SIGNATURE: usize = 64;
const SIZE_OF_SIGNATURE: usize = SIGNATURE_BYTES;
const SIZE_OF_SHRED_VARIANT: usize = 1;
const SIZE_OF_SHRED_SLOT: usize = 8;
const SIZE_OF_SHRED_INDEX: usize = 4;
Expand Down
24 changes: 11 additions & 13 deletions ledger/src/shred/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl ShredData {

// Maximum size of ledger data that can be embedded in a data-shred.
// Also equal to:
// ShredCode::size_of_erasure_encoded_slice(proof_size).unwrap()
// ShredCode::capacity(proof_size).unwrap()
// - ShredData::SIZE_OF_HEADERS
// + SIZE_OF_SIGNATURE
pub(super) fn capacity(proof_size: u8) -> Result<usize, Error> {
Expand Down Expand Up @@ -115,8 +115,8 @@ impl ShredCode {
}
}

// Size of the chunk of payload which will be erasure coded.
fn size_of_erasure_encoded_slice(proof_size: u8) -> Result<usize, Error> {
// Size of buffer embedding erasure codes.
fn capacity(proof_size: u8) -> Result<usize, Error> {
// Merkle branch is generated and signed after coding shreds are
// generated. Coding shred headers cannot be erasure coded either.
Self::SIZE_OF_PAYLOAD
Expand All @@ -130,7 +130,7 @@ impl ShredCode {

fn merkle_tree_node(&self) -> Result<Hash, Error> {
let proof_size = self.proof_size()?;
let shard_size = Self::size_of_erasure_encoded_slice(proof_size)?;
let shard_size = Self::capacity(proof_size)?;
let chunk = self
.payload
.get(SIZE_OF_SIGNATURE..Self::SIZE_OF_HEADERS + shard_size)
Expand All @@ -145,8 +145,7 @@ impl ShredCode {
}

pub(super) fn get_signed_message_range(proof_size: u8) -> Option<Range<usize>> {
let offset =
Self::SIZE_OF_HEADERS + Self::size_of_erasure_encoded_slice(proof_size).ok()?;
let offset = Self::SIZE_OF_HEADERS + Self::capacity(proof_size).ok()?;
Some(offset..offset + SIZE_OF_MERKLE_ROOT)
}

Expand Down Expand Up @@ -264,7 +263,7 @@ impl Shred for ShredCode {
};
let coding_header = deserialize_from_with_limit(&mut cursor)?;
// Skip erasure code shard.
let shard_size = Self::size_of_erasure_encoded_slice(proof_size)?;
let shard_size = Self::capacity(proof_size)?;
let shard_size = i64::try_from(shard_size).unwrap();
cursor.seek(SeekFrom::Current(shard_size))?;
// Deserialize merkle branch.
Expand Down Expand Up @@ -296,7 +295,7 @@ impl Shred for ShredCode {
return Err(Error::InvalidPayloadSize(self.payload.len()));
}
let proof_size = self.proof_size()?;
let shard_size = Self::size_of_erasure_encoded_slice(proof_size)?;
let shard_size = Self::capacity(proof_size)?;
let mut shard = self.payload;
shard.drain(..Self::SIZE_OF_HEADERS);
shard.truncate(shard_size);
Expand All @@ -308,7 +307,7 @@ impl Shred for ShredCode {
return Err(Error::InvalidPayloadSize(self.payload.len()));
}
let proof_size = self.proof_size()?;
let shard_size = Self::size_of_erasure_encoded_slice(proof_size)?;
let shard_size = Self::capacity(proof_size)?;
self.payload
.get(Self::SIZE_OF_HEADERS..Self::SIZE_OF_HEADERS + shard_size)
.ok_or(Error::InvalidPayloadSize(self.payload.len()))
Expand Down Expand Up @@ -454,8 +453,7 @@ mod test {
fn shred_data_capacity(proof_size: u8) -> usize {
const SIZE_OF_ERASURE_ENCODED_HEADER: usize =
ShredData::SIZE_OF_HEADERS - SIZE_OF_SIGNATURE;
ShredCode::size_of_erasure_encoded_slice(proof_size).unwrap()
- SIZE_OF_ERASURE_ENCODED_HEADER
ShredCode::capacity(proof_size).unwrap() - SIZE_OF_ERASURE_ENCODED_HEADER
}

fn shred_data_size_of_erasure_encoded_slice(proof_size: u8) -> usize {
Expand Down Expand Up @@ -486,10 +484,10 @@ mod test {
}

#[test]
fn test_size_of_erasure_encoded_slice() {
fn test_shred_code_capacity() {
for proof_size in 0..0x15 {
assert_eq!(
ShredCode::size_of_erasure_encoded_slice(proof_size).unwrap(),
ShredCode::capacity(proof_size).unwrap(),
shred_data_size_of_erasure_encoded_slice(proof_size),
);
}
Expand Down

0 comments on commit c00adba

Please sign in to comment.