From c75026153cc1598e30fcd3992a6a64cdf2dbbe2a Mon Sep 17 00:00:00 2001 From: Antioch Peverell <30642645+antiochp@users.noreply.github.com> Date: Wed, 31 Jan 2018 10:23:42 -0500 Subject: [PATCH] only include kern_ids in compact block (we can safely omit input and outputs ids) (#670) --- api/src/types.rs | 8 +------ core/src/core/block.rs | 49 ++++-------------------------------------- 2 files changed, 5 insertions(+), 52 deletions(-) diff --git a/api/src/types.rs b/api/src/types.rs index 12958d961..78c4d13aa 100644 --- a/api/src/types.rs +++ b/api/src/types.rs @@ -531,10 +531,6 @@ pub struct CompactBlockPrintable { pub out_full: Vec, /// Full kernels, specifically coinbase kernel(s) pub kern_full: Vec, - /// Inputs (hex short_ids) - pub in_ids: Vec, - /// Outputs (hex short_ids) - pub out_ids: Vec, /// Kernels (hex short_ids) pub kern_ids: Vec, } @@ -559,8 +555,6 @@ impl CompactBlockPrintable { header: BlockHeaderPrintable::from_header(&cb.header), out_full, kern_full, - in_ids: cb.in_ids.iter().map(|x| x.to_hex()).collect(), - out_ids: cb.out_ids.iter().map(|x| x.to_hex()).collect(), kern_ids: cb.kern_ids.iter().map(|x| x.to_hex()).collect(), } } @@ -607,4 +601,4 @@ fn serialize_utxo() { let deserialized: Utxo = serde_json::from_str(&hex_commit).unwrap(); let serialized = serde_json::to_string(&deserialized).unwrap(); assert_eq!(serialized, hex_commit); -} \ No newline at end of file +} diff --git a/core/src/core/block.rs b/core/src/core/block.rs index ee327f34e..356e9efac 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -222,10 +222,6 @@ pub struct CompactBlock { pub out_full: Vec, /// List of full kernels - specifically the coinbase kernel(s) pub kern_full: Vec, - /// List of transaction inputs (short_ids) - pub in_ids: Vec, - /// List of transaction outputs, excluding those in the full list (short_ids) - pub out_ids: Vec, /// List of transaction kernels, excluding those in the full list (short_ids) pub kern_ids: Vec, } @@ -246,23 +242,16 @@ impl Writeable for CompactBlock { writer, [write_u8, self.out_full.len() as u8], [write_u8, self.kern_full.len() as u8], - [write_u64, self.in_ids.len() as u64], - [write_u64, self.out_ids.len() as u64], [write_u64, self.kern_ids.len() as u64] ); let mut out_full = self.out_full.clone(); let mut kern_full = self.kern_full.clone(); - - let mut in_ids = self.in_ids.clone(); - let mut out_ids = self.out_ids.clone(); let mut kern_ids = self.kern_ids.clone(); // Consensus rule that everything is sorted in lexicographical order on the wire. try!(out_full.write_sorted(writer)); try!(kern_full.write_sorted(writer)); - try!(in_ids.write_sorted(writer)); - try!(out_ids.write_sorted(writer)); try!(kern_ids.write_sorted(writer)); } Ok(()) @@ -275,21 +264,17 @@ impl Readable for CompactBlock { fn read(reader: &mut Reader) -> Result { let header = try!(BlockHeader::read(reader)); - let (out_full_len, kern_full_len, in_id_len, out_id_len, kern_id_len) = - ser_multiread!(reader, read_u8, read_u8, read_u64, read_u64, read_u64); + let (out_full_len, kern_full_len, kern_id_len) = + ser_multiread!(reader, read_u8, read_u8, read_u64); let out_full = read_and_verify_sorted(reader, out_full_len as u64)?; let kern_full = read_and_verify_sorted(reader, kern_full_len as u64)?; - let in_ids = read_and_verify_sorted(reader, in_id_len)?; - let out_ids = read_and_verify_sorted(reader, out_id_len)?; let kern_ids = read_and_verify_sorted(reader, kern_id_len)?; Ok(CompactBlock { header, out_full, kern_full, - in_ids, - out_ids, kern_ids, }) } @@ -429,15 +414,6 @@ impl Block { .cloned() .collect::>(); - let mut in_ids = self.inputs - .iter() - .map(|x| x.short_id(&block_hash)) - .collect::>(); - let mut out_ids = self.outputs - .iter() - .filter(|x| !x.features.contains(COINBASE_OUTPUT)) - .map(|x| x.short_id(&block_hash)) - .collect::>(); let mut kern_ids = self.kernels .iter() .filter(|x| !x.features.contains(COINBASE_KERNEL)) @@ -447,16 +423,12 @@ impl Block { // sort all the lists out_full.sort(); kern_full.sort(); - in_ids.sort(); - out_ids.sort(); kern_ids.sort(); CompactBlock { header, out_full, kern_full, - in_ids, - out_ids, kern_ids, } } @@ -1080,19 +1052,10 @@ mod test { let cb = b.as_compact_block(); + assert_eq!(cb.out_full.len(), 1); assert_eq!(cb.kern_full.len(), 1); assert_eq!(cb.kern_ids.len(), 1); - assert_eq!(cb.out_full.len(), 1); - assert_eq!(cb.out_ids.len(), 1); - assert_eq!(cb.in_ids.len(), 2); - assert_eq!( - cb.out_ids[0], - b.outputs - .iter() - .find(|x| !x.features.contains(COINBASE_OUTPUT)) - .unwrap() - .short_id(&b.hash()) - ); + assert_eq!( cb.kern_ids[0], b.kernels @@ -1109,8 +1072,6 @@ mod test { header: BlockHeader::default(), out_full: vec![], kern_full: vec![], - in_ids: vec![ShortId::zero(), ShortId::zero()], - out_ids: vec![ShortId::zero(), ShortId::zero(), ShortId::zero()], kern_ids: vec![ShortId::zero()], }; @@ -1119,8 +1080,6 @@ mod test { let b2: CompactBlock = ser::deserialize(&mut &vec[..]).unwrap(); assert_eq!(b.header, b2.header); - assert_eq!(b.in_ids, b2.in_ids); - assert_eq!(b.out_ids, b2.out_ids); assert_eq!(b.kern_ids, b2.kern_ids); } }