adds back position field to coding-shred-header (#21600)

https://github.com/solana-labs/solana/pull/17004
removed position field from coding-shred-header because as it stands the
field is redundant and unused.
However, with the upcoming changes to erasure coding schema this field
will no longer be redundant and needs to be populated.
This commit is contained in:
behzad nouri
2021-12-05 14:42:09 +00:00
committed by GitHub
parent 3e5a5a834f
commit cd17f63d81
4 changed files with 69 additions and 18 deletions

View File

@ -5554,7 +5554,14 @@ pub mod tests {
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
let slot = 1;
let (shred, coding) = Shredder::new_coding_shred_header(slot, 11, 11, 11, 11, 0);
let (shred, coding) = Shredder::new_coding_shred_header(
slot, 11, // index
11, // fec_set_index
11, // num_data_shreds
11, // num_coding_shreds
8, // position
0, // version
);
let coding_shred = Shred::new_empty_from_header(shred, DataShredHeader::default(), coding);
let mut erasure_metas = HashMap::new();
@ -5604,7 +5611,14 @@ pub mod tests {
let last_root = RwLock::new(0);
let slot = 1;
let (mut shred, coding) = Shredder::new_coding_shred_header(slot, 11, 11, 11, 11, 0);
let (mut shred, coding) = Shredder::new_coding_shred_header(
slot, 11, // index
11, // fec_set_index
11, // num_data_shreds
11, // num_coding_shreds
8, // position
0, // version
);
let coding_shred =
Shred::new_empty_from_header(shred.clone(), DataShredHeader::default(), coding.clone());

View File

@ -222,8 +222,7 @@ pub struct DataShredHeader {
pub struct CodingShredHeader {
pub num_data_shreds: u16,
pub num_coding_shreds: u16,
#[serde(rename = "position")]
__unused: u16,
pub position: u16,
}
#[derive(Clone, Debug, PartialEq)]
@ -382,8 +381,9 @@ impl Shred {
slot: Slot,
index: u32,
fec_set_index: u32,
num_data: usize,
num_code: usize,
num_data: u16,
num_code: u16,
position: u16,
version: u16,
) -> Self {
let (header, coding_header) = Shredder::new_coding_shred_header(
@ -392,6 +392,7 @@ impl Shred {
fec_set_index,
num_data,
num_code,
position,
version,
);
Shred::new_empty_from_header(header, DataShredHeader::default(), coding_header)
@ -812,8 +813,9 @@ impl Shredder {
slot: Slot,
index: u32,
fec_set_index: u32,
num_data: usize,
num_code: usize,
num_data_shreds: u16,
num_coding_shreds: u16,
position: u16,
version: u16,
) -> (ShredCommonHeader, CodingShredHeader) {
let header = ShredCommonHeader {
@ -827,9 +829,9 @@ impl Shredder {
(
header,
CodingShredHeader {
num_data_shreds: num_data as u16,
num_coding_shreds: num_code as u16,
..CodingShredHeader::default()
num_data_shreds,
num_coding_shreds,
position,
},
)
}
@ -865,6 +867,8 @@ impl Shredder {
.unwrap()
.encode(&data, &mut parity[..])
.unwrap();
let num_data = u16::try_from(num_data).unwrap();
let num_coding = u16::try_from(num_coding).unwrap();
parity
.iter()
.enumerate()
@ -875,6 +879,7 @@ impl Shredder {
fec_set_index,
num_data,
num_coding,
u16::try_from(i).unwrap(), // position
version,
);
shred.payload[SIZE_OF_CODING_SHRED_HEADERS..].copy_from_slice(parity);
@ -1882,7 +1887,15 @@ pub mod tests {
);
assert_eq!(stats.index_overrun, 4);
let shred = Shred::new_empty_coding(8, 2, 10, 30, 4, 200);
let shred = Shred::new_empty_coding(
8, // slot
2, // index
10, // fec_set_index
30, // num_data
4, // num_code
1, // position
200, // version
);
shred.copy_to_packet(&mut packet);
assert_eq!(
Some((8, 2, ShredType::Code)),
@ -1894,7 +1907,15 @@ pub mod tests {
assert_eq!(None, get_shred_slot_index_type(&packet, &mut stats));
assert_eq!(1, stats.index_out_of_bounds);
let (header, coding_header) = Shredder::new_coding_shred_header(8, 2, 10, 30, 4, 200);
let (header, coding_header) = Shredder::new_coding_shred_header(
8, // slot
2, // index
10, // fec_set_index
30, // num_data_shreds
4, // num_coding_shreds
3, // position
200, // version
);
let shred = Shred::new_empty_from_header(header, DataShredHeader::default(), coding_header);
shred.copy_to_packet(&mut packet);
packet.data[OFFSET_OF_SHRED_TYPE] = u8::MAX;