Ensure forwarded Blobs don't break Erasure (#3907)

This commit is contained in:
Sagar Dhawan
2019-04-20 16:44:06 -07:00
committed by GitHub
parent c0bffb56df
commit 349e8a9462
8 changed files with 35 additions and 48 deletions

View File

@@ -31,7 +31,7 @@ pub const NUM_BLOBS: usize = (NUM_PACKETS * PACKET_DATA_SIZE) / BLOB_SIZE;
#[repr(C)]
pub struct Meta {
pub size: usize,
pub num_retransmits: u64,
pub forward: bool,
pub addr: [u16; 8],
pub port: u16,
pub v6: bool,
@@ -353,8 +353,8 @@ const PARENT_RANGE: std::ops::Range<usize> = range!(0, u64);
const SLOT_RANGE: std::ops::Range<usize> = range!(PARENT_RANGE.end, u64);
const INDEX_RANGE: std::ops::Range<usize> = range!(SLOT_RANGE.end, u64);
const ID_RANGE: std::ops::Range<usize> = range!(INDEX_RANGE.end, Pubkey);
const FORWARD_RANGE: std::ops::Range<usize> = range!(ID_RANGE.end, bool);
const FLAGS_RANGE: std::ops::Range<usize> = range!(FORWARD_RANGE.end, u32);
const FORWARDED_RANGE: std::ops::Range<usize> = range!(ID_RANGE.end, bool);
const FLAGS_RANGE: std::ops::Range<usize> = range!(FORWARDED_RANGE.end, u32);
const SIZE_RANGE: std::ops::Range<usize> = range!(FLAGS_RANGE.end, u64);
macro_rules! align {
@@ -427,11 +427,12 @@ impl Blob {
/// A bool is used here instead of a flag because this item is not intended to be signed when
/// blob signatures are introduced
pub fn should_forward(&self) -> bool {
self.data[FORWARD_RANGE][0] & 0x1 == 1
self.data[FORWARDED_RANGE][0] & 0x1 == 0
}
pub fn forward(&mut self, forward: bool) {
self.data[FORWARD_RANGE][0] = u8::from(forward)
/// Mark this blob's forwarded status
pub fn set_forwarded(&mut self, forward: bool) {
self.data[FORWARDED_RANGE][0] = u8::from(forward)
}
pub fn flags(&self) -> u32 {
@@ -581,7 +582,6 @@ pub fn index_blobs(blobs: &[SharedBlob], id: &Pubkey, mut blob_index: u64, slot:
blob.set_slot(slot);
blob.set_parent(parent);
blob.set_id(id);
blob.forward(true);
blob_index += 1;
}
}
@@ -708,9 +708,9 @@ mod tests {
#[test]
fn test_blob_forward() {
let mut b = Blob::default();
assert!(!b.should_forward());
b.forward(true);
assert!(b.should_forward());
b.set_forwarded(true);
assert!(!b.should_forward());
}
#[test]