|
|
@@ -2,7 +2,7 @@ use std::io;
|
|
|
|
|
|
use log::debug;
|
|
|
|
|
|
-use super::{Metadata, StreamletMetadata, Timestamp};
|
|
|
+use super::{Metadata, StreamletMetadata, Timestamp, BLOCK_VERSION};
|
|
|
use crate::{
|
|
|
crypto::{address::Address, keypair::PublicKey, schnorr::Signature},
|
|
|
impl_vec, net,
|
|
|
@@ -11,11 +11,13 @@ use crate::{
|
|
|
Result,
|
|
|
};
|
|
|
|
|
|
-/// This struct represents a tuple of the form (`st`, `sl`, txs`, `metadata`).
|
|
|
+/// This struct represents a tuple of the form ('v', `st`, `sl`, txs`, `metadata`).
|
|
|
/// The transactions here are stored as hashes, which serve as pointers to
|
|
|
/// the actual transaction data in the blockchain database.
|
|
|
#[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
|
|
|
pub struct Block {
|
|
|
+ /// Block version
|
|
|
+ pub v: u8,
|
|
|
/// Previous block hash
|
|
|
pub st: blake3::Hash,
|
|
|
/// Slot uid, generated by the beacon
|
|
|
@@ -28,7 +30,8 @@ pub struct Block {
|
|
|
|
|
|
impl Block {
|
|
|
pub fn new(st: blake3::Hash, sl: u64, txs: Vec<blake3::Hash>, metadata: Metadata) -> Self {
|
|
|
- Self { st, sl, txs, metadata }
|
|
|
+ let v = *BLOCK_VERSION;
|
|
|
+ Self { v, st, sl, txs, metadata }
|
|
|
}
|
|
|
|
|
|
/// Generate the genesis block.
|
|
|
@@ -63,6 +66,8 @@ impl net::Message for BlockOrder {
|
|
|
/// Structure representing full block data.
|
|
|
#[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
|
|
|
pub struct BlockInfo {
|
|
|
+ /// Block version
|
|
|
+ pub v: u8,
|
|
|
/// Previous block hash
|
|
|
pub st: blake3::Hash,
|
|
|
/// Slot UID, generated by the beacon
|
|
|
@@ -83,7 +88,8 @@ impl BlockInfo {
|
|
|
metadata: Metadata,
|
|
|
sm: StreamletMetadata,
|
|
|
) -> Self {
|
|
|
- Self { st, sl, txs, metadata, sm }
|
|
|
+ let v = *BLOCK_VERSION;
|
|
|
+ Self { v, st, sl, txs, metadata, sm }
|
|
|
}
|
|
|
|
|
|
/// Calculate the block hash
|
|
|
@@ -96,7 +102,7 @@ impl BlockInfo {
|
|
|
impl From<BlockInfo> for Block {
|
|
|
fn from(b: BlockInfo) -> Self {
|
|
|
let txids = b.txs.iter().map(|x| blake3::hash(&serialize(x))).collect();
|
|
|
- Self { st: b.st, sl: b.sl, txs: txids, metadata: b.metadata }
|
|
|
+ Self { v: b.v, st: b.st, sl: b.sl, txs: txids, metadata: b.metadata }
|
|
|
}
|
|
|
}
|
|
|
|