Fill out the Block Message type
Should we serialize out `Block` or leave explicit like so? ¯\_(ツ)_/¯
This commit is contained in:
parent
d77dfb2344
commit
cecbb1cc0a
|
|
@ -12,9 +12,9 @@ use crate::transaction::Transaction;
|
||||||
///
|
///
|
||||||
/// This is useful when one block header is pointing to its parent
|
/// This is useful when one block header is pointing to its parent
|
||||||
/// block header in the block chain. ⛓️
|
/// block header in the block chain. ⛓️
|
||||||
pub struct BlockHash([u8; 32]);
|
pub struct BlockHeaderHash([u8; 32]);
|
||||||
|
|
||||||
impl From<BlockHeader> for BlockHash {
|
impl From<BlockHeader> for BlockHeaderHash {
|
||||||
fn from(block_header: BlockHeader) -> Self {
|
fn from(block_header: BlockHeader) -> Self {
|
||||||
let mut hash_writer = Sha256dWriter::default();
|
let mut hash_writer = Sha256dWriter::default();
|
||||||
block_header
|
block_header
|
||||||
|
|
@ -54,8 +54,15 @@ impl From<MerkleTree<Transaction>> for MerkleRootHash {
|
||||||
pub struct BlockHeader {
|
pub struct BlockHeader {
|
||||||
/// A SHA-256d hash in internal byte order of the previous block’s
|
/// A SHA-256d hash in internal byte order of the previous block’s
|
||||||
/// header. This ensures no previous block can be changed without
|
/// header. This ensures no previous block can be changed without
|
||||||
/// also changing this block’s header .
|
/// also changing this block’s header.
|
||||||
previous_block_hash: BlockHash,
|
// 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
|
/// A SHA-256d hash in internal byte order. The merkle root is
|
||||||
/// derived from the SHA256d hashes of all transactions included
|
/// 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
|
/// [Sapling onward] The root LEBS2OSP256(rt) of the Sapling note
|
||||||
/// commitment tree corresponding to the nal Sapling treestate of
|
/// commitment tree corresponding to the nal Sapling treestate of
|
||||||
/// this block.
|
/// this block.
|
||||||
// TODO: replace type with custom SaplingRoot or similar type
|
// TODO: replace type with custom SaplingRootHash or similar type
|
||||||
// hash_final_sapling_root: SaplingRootHash,
|
hash_final_sapling_root: [u8; 32],
|
||||||
|
|
||||||
/// The block timestamp is a Unix epoch time (UTC) when the miner
|
/// The block timestamp is a Unix epoch time (UTC) when the miner
|
||||||
/// started hashing the header (according to the miner).
|
/// started hashing the header (according to the miner).
|
||||||
|
|
@ -121,6 +128,6 @@ pub struct Block {
|
||||||
/// "block" messages.
|
/// "block" messages.
|
||||||
pub header: BlockHeader,
|
pub header: BlockHeader,
|
||||||
|
|
||||||
/// Block transactions.
|
/// The block transactions.
|
||||||
pub transactions: Vec<Transaction>,
|
pub transactions: Vec<Transaction>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use std::net;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
use zebra_chain::block::{BlockHeaderHash, MerkleRootHash};
|
||||||
use zebra_chain::{transaction::Transaction, types::BlockHeight};
|
use zebra_chain::{transaction::Transaction, types::BlockHeight};
|
||||||
|
|
||||||
use crate::meta_addr::MetaAddr;
|
use crate::meta_addr::MetaAddr;
|
||||||
|
|
@ -134,7 +135,40 @@ pub enum Message {
|
||||||
/// A `block` message.
|
/// A `block` message.
|
||||||
///
|
///
|
||||||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#block)
|
/// [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<Utc>,
|
||||||
|
|
||||||
|
/// 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<Transaction>,
|
||||||
|
},
|
||||||
|
|
||||||
/// A `getblocks` message.
|
/// A `getblocks` message.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue