From 29591df47e761fd8a95c7474abc885edb08682d2 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 27 Sep 2019 21:06:22 -0400 Subject: [PATCH] Use the BlockHeaderHash from zebra-chain in the Inv message parsing --- zebra-chain/src/block.rs | 4 ++-- zebra-network/src/protocol/inv.rs | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index e0e29ddb..d0481986 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -21,8 +21,8 @@ use crate::transaction::Transaction; /// the direct bytes of the transactions as well as the header. So /// for now I want to call it a `BlockHeaderHash` because that's /// more explicit. -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct BlockHeaderHash([u8; 32]); +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct BlockHeaderHash(pub [u8; 32]); impl From for BlockHeaderHash { fn from(block_header: BlockHeader) -> Self { diff --git a/zebra-network/src/protocol/inv.rs b/zebra-network/src/protocol/inv.rs index 65d46acb..5e169311 100644 --- a/zebra-network/src/protocol/inv.rs +++ b/zebra-network/src/protocol/inv.rs @@ -8,6 +8,7 @@ use std::io::{Read, Write}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use zebra_chain::block::BlockHeaderHash; use zebra_chain::serialization::{ ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize, }; @@ -15,9 +16,6 @@ use zebra_chain::serialization::{ /// Stub-- delete later. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct TxHash(pub [u8; 32]); -/// Stub-- delete later. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct BlockHash(pub [u8; 32]); /// An inventory hash which refers to some advertised or requested data. /// @@ -35,14 +33,14 @@ pub enum InventoryHash { /// A hash of a transaction. Tx(TxHash), /// A hash of a block. - Block(BlockHash), + Block(BlockHeaderHash), /// A hash of a filtered block. /// /// The Bitcoin wiki says: Hash of a block header, but only to be used in /// getdata message. Indicates the reply should be a merkleblock message /// rather than a block message; this only works if a bloom filter has been /// set. - FilteredBlock(BlockHash), + FilteredBlock(BlockHeaderHash), } impl ZcashSerialize for InventoryHash { @@ -66,8 +64,8 @@ impl ZcashDeserialize for InventoryHash { match code { 0 => Ok(InventoryHash::Error), 1 => Ok(InventoryHash::Tx(TxHash(bytes))), - 2 => Ok(InventoryHash::Block(BlockHash(bytes))), - 3 => Ok(InventoryHash::FilteredBlock(BlockHash(bytes))), + 2 => Ok(InventoryHash::Block(BlockHeaderHash(bytes))), + 3 => Ok(InventoryHash::FilteredBlock(BlockHeaderHash(bytes))), _ => Err(SerializationError::ParseError("invalid inventory code")), } }