diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 9fa7f92a..2baa1fc0 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -12,9 +12,9 @@ use crate::transaction::Transaction; /// /// This is useful when one block header is pointing to its parent /// block header in the block chain. ⛓️ -pub struct BlockHash([u8; 32]); +pub struct BlockHeaderHash([u8; 32]); -impl From for BlockHash { +impl From for BlockHeaderHash { fn from(block_header: BlockHeader) -> Self { let mut hash_writer = Sha256dWriter::default(); block_header @@ -54,8 +54,15 @@ impl From> for MerkleRootHash { pub struct BlockHeader { /// A SHA-256d hash in internal byte order of the previous block’s /// header. This ensures no previous block can be changed without - /// also changing this block’s header . - previous_block_hash: BlockHash, + /// also changing this block’s header. + // This is usually called a 'block hash', as it is frequently used + // to identify the entire block, since the hash preimage includes + // the merkle root of the transactions in this block. But + // _technically_, this is just a hash of the block _header_, not + // 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. + previous_block_hash: BlockHeaderHash, /// A SHA-256d hash in internal byte order. The merkle root is /// derived from the SHA256d hashes of all transactions included @@ -67,8 +74,8 @@ pub struct BlockHeader { /// [Sapling onward] The root LEBS2OSP256(rt) of the Sapling note /// commitment tree corresponding to the nal Sapling treestate of /// this block. - // TODO: replace type with custom SaplingRoot or similar type - // hash_final_sapling_root: SaplingRootHash, + // TODO: replace type with custom SaplingRootHash or similar type + hash_final_sapling_root: [u8; 32], /// The block timestamp is a Unix epoch time (UTC) when the miner /// started hashing the header (according to the miner). @@ -121,6 +128,6 @@ pub struct Block { /// "block" messages. pub header: BlockHeader, - /// Block transactions. + /// The block transactions. pub transactions: Vec, } diff --git a/zebra-network/src/protocol/message.rs b/zebra-network/src/protocol/message.rs index 220e7808..1725f12d 100644 --- a/zebra-network/src/protocol/message.rs +++ b/zebra-network/src/protocol/message.rs @@ -4,6 +4,7 @@ use std::net; use chrono::{DateTime, Utc}; +use zebra_chain::block::{BlockHeaderHash, MerkleRootHash}; use zebra_chain::{transaction::Transaction, types::BlockHeight}; use crate::meta_addr::MetaAddr; @@ -134,7 +135,40 @@ pub enum Message { /// A `block` message. /// /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#block) - Block {/* XXX add fields */}, + Block { + /// Block version information (note, this is signed). + version: Version, + + /// The hash value of the previous block (header) this + /// particular block references. + prev_block: BlockHeaderHash, + + /// The reference to a Merkle tree collection which is a hash + /// of all transactions related to this block. + merkle_root: MerkleRootHash, + + /// The root of the Sapling note commitment tree corresponding + /// to the final Sapling treestate of this block. + // TODO: more than just an array of bytes. + final_sapling_root: [u8; 32], + + /// A Unix timestamp recording when this block was created. + time: DateTime, + + /// The calculated difficulty target being used for this + /// block. + bits: u32, + + /// The nonce used to generate this block, to allow variations + /// of the header and compute different hashes. + nonce: [u8; 32], + + /// The Equihash solution. + solution: [u8; 1344], + + /// Transactions. + txns: Vec, + }, /// A `getblocks` message. ///