From c501c197508f12c91cba08f766a2274315e24f93 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 12 Jul 2019 14:38:32 -0700 Subject: [PATCH] Add a version field to blobs (bp #5057) (#5068) automerge --- core/src/chacha.rs | 2 +- core/src/erasure.rs | 2 ++ core/src/packet.rs | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/chacha.rs b/core/src/chacha.rs index 6ad2a948d1..0b42d0f048 100644 --- a/core/src/chacha.rs +++ b/core/src/chacha.rs @@ -133,7 +133,7 @@ mod tests { hasher.hash(&buf[..size]); // golden needs to be updated if blob stuff changes.... - let golden: Hash = "E2HZjSC6VgH4nmEiTbMDATTeBcFjwSYz7QYvU7doGNhD" + let golden: Hash = "37YzrTgiFRGQG1EoMZVecnGqxEK7UGxEQeBSdGMJcKqp" .parse() .unwrap(); diff --git a/core/src/erasure.rs b/core/src/erasure.rs index 99784fa053..34edccbbba 100644 --- a/core/src/erasure.rs +++ b/core/src/erasure.rs @@ -226,11 +226,13 @@ impl CodingGenerator { let index = data_blob.index(); let slot = data_blob.slot(); let id = data_blob.id(); + let version = data_blob.version(); let mut coding_blob = Blob::default(); coding_blob.set_index(index); coding_blob.set_slot(slot); coding_blob.set_id(&id); + coding_blob.set_version(version); coding_blob.set_size(max_data_size); coding_blob.set_coding(); diff --git a/core/src/packet.rs b/core/src/packet.rs index 61b701fb82..2806837292 100644 --- a/core/src/packet.rs +++ b/core/src/packet.rs @@ -341,7 +341,8 @@ macro_rules! range { const SIGNATURE_RANGE: std::ops::Range = range!(0, Signature); const FORWARDED_RANGE: std::ops::Range = range!(SIGNATURE_RANGE.end, bool); const PARENT_RANGE: std::ops::Range = range!(FORWARDED_RANGE.end, u64); -const SLOT_RANGE: std::ops::Range = range!(PARENT_RANGE.end, u64); +const VERSION_RANGE: std::ops::Range = range!(PARENT_RANGE.end, u64); +const SLOT_RANGE: std::ops::Range = range!(VERSION_RANGE.end, u64); const INDEX_RANGE: std::ops::Range = range!(SLOT_RANGE.end, u64); const ID_RANGE: std::ops::Range = range!(INDEX_RANGE.end, Pubkey); const FLAGS_RANGE: std::ops::Range = range!(ID_RANGE.end, u32); @@ -391,6 +392,12 @@ impl Blob { pub fn set_parent(&mut self, ix: u64) { LittleEndian::write_u64(&mut self.data[PARENT_RANGE], ix); } + pub fn version(&self) -> u64 { + LittleEndian::read_u64(&self.data[VERSION_RANGE]) + } + pub fn set_version(&mut self, version: u64) { + LittleEndian::write_u64(&mut self.data[VERSION_RANGE], version); + } pub fn slot(&self) -> u64 { LittleEndian::read_u64(&self.data[SLOT_RANGE]) } @@ -862,4 +869,12 @@ mod tests { b.sign(&k); assert!(b.verify()); } + + #[test] + fn test_version() { + let mut b = Blob::default(); + assert_eq!(b.version(), 0); + b.set_version(1); + assert_eq!(b.version(), 1); + } }