|
|
@@ -14,7 +14,7 @@ use crate::{
|
|
|
Result,
|
|
|
};
|
|
|
|
|
|
-/// This struct represents a tuple of the form ('v', `st`, `sl`, txs`, `metadata`).
|
|
|
+/// This struct represents a tuple of the form (`v`, `st`, `e`, `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)]
|
|
|
@@ -23,7 +23,9 @@ pub struct Block {
|
|
|
pub v: u8,
|
|
|
/// Previous block hash
|
|
|
pub st: blake3::Hash,
|
|
|
- /// Slot uid, generated by the beacon
|
|
|
+ /// Epoch
|
|
|
+ pub e: u64,
|
|
|
+ /// Slot uid
|
|
|
pub sl: u64,
|
|
|
/// Transaction hashes
|
|
|
pub txs: Vec<blake3::Hash>,
|
|
|
@@ -32,9 +34,15 @@ pub struct Block {
|
|
|
}
|
|
|
|
|
|
impl Block {
|
|
|
- pub fn new(st: blake3::Hash, sl: u64, txs: Vec<blake3::Hash>, metadata: Metadata) -> Self {
|
|
|
+ pub fn new(
|
|
|
+ st: blake3::Hash,
|
|
|
+ e: u64,
|
|
|
+ sl: u64,
|
|
|
+ txs: Vec<blake3::Hash>,
|
|
|
+ metadata: Metadata,
|
|
|
+ ) -> Self {
|
|
|
let v = *BLOCK_VERSION;
|
|
|
- Self { v, st, sl, txs, metadata }
|
|
|
+ Self { v, st, e, sl, txs, metadata }
|
|
|
}
|
|
|
|
|
|
/// Generate the genesis block.
|
|
|
@@ -42,7 +50,7 @@ impl Block {
|
|
|
let metadata =
|
|
|
Metadata::new(genesis_ts, String::from("proof"), String::from("r"), String::from("s"));
|
|
|
|
|
|
- Self::new(genesis_data, 0, vec![], metadata)
|
|
|
+ Self::new(genesis_data, 0, 0, vec![], metadata)
|
|
|
}
|
|
|
|
|
|
/// Calculate the block hash
|
|
|
@@ -73,7 +81,9 @@ pub struct BlockInfo {
|
|
|
pub v: u8,
|
|
|
/// Previous block hash
|
|
|
pub st: blake3::Hash,
|
|
|
- /// Slot UID, generated by the beacon
|
|
|
+ /// Epoch
|
|
|
+ pub e: u64,
|
|
|
+ /// Slot uid
|
|
|
pub sl: u64,
|
|
|
/// Transactions payload
|
|
|
pub txs: Vec<Transaction>,
|
|
|
@@ -86,13 +96,14 @@ pub struct BlockInfo {
|
|
|
impl BlockInfo {
|
|
|
pub fn new(
|
|
|
st: blake3::Hash,
|
|
|
+ e: u64,
|
|
|
sl: u64,
|
|
|
txs: Vec<Transaction>,
|
|
|
metadata: Metadata,
|
|
|
sm: StreamletMetadata,
|
|
|
) -> Self {
|
|
|
let v = *BLOCK_VERSION;
|
|
|
- Self { v, st, sl, txs, metadata, sm }
|
|
|
+ Self { v, st, e, sl, txs, metadata, sm }
|
|
|
}
|
|
|
|
|
|
/// Calculate the block hash
|
|
|
@@ -105,7 +116,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 { v: b.v, st: b.st, sl: b.sl, txs: txids, metadata: b.metadata }
|
|
|
+ Self { v: b.v, st: b.st, e: b.e, sl: b.sl, txs: txids, metadata: b.metadata }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -150,23 +161,31 @@ impl BlockProposal {
|
|
|
signature: Signature,
|
|
|
address: Address,
|
|
|
st: blake3::Hash,
|
|
|
+ e: u64,
|
|
|
sl: u64,
|
|
|
txs: Vec<Transaction>,
|
|
|
metadata: Metadata,
|
|
|
sm: StreamletMetadata,
|
|
|
) -> Self {
|
|
|
- let block = BlockInfo::new(st, sl, txs, metadata, sm);
|
|
|
+ let block = BlockInfo::new(st, e, sl, txs, metadata, sm);
|
|
|
Self { public_key, signature, address, block }
|
|
|
}
|
|
|
|
|
|
- /// Produce proposal hash using `st`, `sl`, `txs`, and `metadata`.
|
|
|
+ /// Produce proposal hash using `st`, `e`, `sl`, `txs`, and `metadata`.
|
|
|
pub fn hash(&self) -> blake3::Hash {
|
|
|
- Self::to_proposal_hash(self.block.st, self.block.sl, &self.block.txs, &self.block.metadata)
|
|
|
+ Self::to_proposal_hash(
|
|
|
+ self.block.st,
|
|
|
+ self.block.e,
|
|
|
+ self.block.sl,
|
|
|
+ &self.block.txs,
|
|
|
+ &self.block.metadata,
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
- /// Generate a proposal hash using provided `st`, `sl`, `txs`, and `metadata`.
|
|
|
+ /// Generate a proposal hash using provided `st`, `e`, `sl`, `txs`, and `metadata`.
|
|
|
pub fn to_proposal_hash(
|
|
|
st: blake3::Hash,
|
|
|
+ e: u64,
|
|
|
sl: u64,
|
|
|
transactions: &[Transaction],
|
|
|
metadata: &Metadata,
|
|
|
@@ -176,7 +195,7 @@ impl BlockProposal {
|
|
|
txs.push(blake3::hash(&serialize(tx)));
|
|
|
}
|
|
|
|
|
|
- blake3::hash(&serialize(&Block::new(st, sl, txs, metadata.clone())))
|
|
|
+ blake3::hash(&serialize(&Block::new(st, e, sl, txs, metadata.clone())))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -186,6 +205,7 @@ impl PartialEq for BlockProposal {
|
|
|
self.signature == other.signature &&
|
|
|
self.address == other.address &&
|
|
|
self.block.st == other.block.st &&
|
|
|
+ self.block.e == other.block.e &&
|
|
|
self.block.sl == other.block.sl &&
|
|
|
self.block.txs == other.block.txs &&
|
|
|
self.block.metadata == other.block.metadata
|