From bc5f29150b36c70aab66e15bc4649c1ad8d551f4 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Fri, 17 Aug 2018 11:56:32 -0700 Subject: [PATCH] fix erasure, remove Entry "pad" * fixes #997 * Entry pad is no longer required since erasure coding aligns data length --- src/entry.rs | 7 ------- src/erasure.rs | 36 +++++++++++++++++++++++------------- src/packet.rs | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/entry.rs b/src/entry.rs index df98f9a360..4741633823 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -45,9 +45,6 @@ pub struct Entry { /// 2. this Entry can be left out of the bank's entry_id cache for /// purposes of duplicate rejection pub has_more: bool, - - /// Erasure requires that Entry be a multiple of 4 bytes in size - pad: [u8; 3], } impl Entry { @@ -65,7 +62,6 @@ impl Entry { id, transactions, has_more, - pad: [0, 0, 0], }; let size = serialized_size(&entry).unwrap(); @@ -116,7 +112,6 @@ impl Entry { id: Hash::default(), transactions, has_more: false, - pad: [0, 0, 0], }).unwrap() <= BLOB_DATA_SIZE as u64 } @@ -142,7 +137,6 @@ impl Entry { id: *id, transactions: vec![], has_more: false, - pad: [0, 0, 0], } } @@ -209,7 +203,6 @@ pub fn next_entry(start_hash: &Hash, num_hashes: u64, transactions: Vec BLOB_DATA_SIZE { + trace!( + "{:x} corrupt data blob[{}] data_size: {}", + debug_id, + idx, + data_size + ); + corrupt = true; + } } else { - data_size = size as u64; + data_size = size; idx -= NUM_CODING as u64; locks[n].set_index(idx).unwrap(); + + if data_size - BLOB_HEADER_SIZE > BLOB_DATA_SIZE { + trace!( + "{:x} corrupt coding blob[{}] data_size: {}", + debug_id, + idx, + data_size + ); + corrupt = true; + } } locks[n].meta = meta.clone().unwrap(); - locks[n].set_size(data_size as usize); + locks[n].set_size(data_size); trace!( "{:x} erasures[{}] ({}) size: {:x} data[0]: {}", debug_id, @@ -602,15 +621,6 @@ pub fn recover( data_size, locks[n].data()[0] ); - if data_size > BLOB_DATA_SIZE as u64 { - trace!( - "{:x} corrupt blob[{}] data_size: {}", - debug_id, - idx, - data_size - ); - corrupt = true; - } } assert!(!corrupt, " {:x} ", debug_id); diff --git a/src/packet.rs b/src/packet.rs index 33ced51cd0..bb54b1b8be 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -22,7 +22,7 @@ pub type BlobRecycler = Recycler; pub const NUM_PACKETS: usize = 1024 * 8; pub const BLOB_SIZE: usize = (64 * 1024 - 128); // wikipedia says there should be 20b for ipv4 headers -pub const BLOB_DATA_SIZE: usize = BLOB_SIZE - BLOB_HEADER_SIZE; +pub const BLOB_DATA_SIZE: usize = BLOB_SIZE - (BLOB_HEADER_SIZE * 2); pub const PACKET_DATA_SIZE: usize = 256; pub const NUM_BLOBS: usize = (NUM_PACKETS * PACKET_DATA_SIZE) / BLOB_SIZE;