|
|
@@ -16,10 +16,10 @@ pub struct SlotWorkspace {
|
|
|
pub txs: Vec<Transaction>, // unpublished block transactions
|
|
|
pub root: MerkleNode,
|
|
|
/// merkle root of txs
|
|
|
- pub m: Metadata,
|
|
|
- pub is_leader: bool,
|
|
|
- pub proof: Proof,
|
|
|
+ pub m: Vec<Metadata>,
|
|
|
+ pub is_leader: Vec<bool>,
|
|
|
pub block: BlockInfo,
|
|
|
+ pub idx: usize, // index of the highest winning coin
|
|
|
}
|
|
|
|
|
|
impl Default for SlotWorkspace {
|
|
|
@@ -30,22 +30,32 @@ impl Default for SlotWorkspace {
|
|
|
sl: 0,
|
|
|
txs: vec![],
|
|
|
root: MerkleNode::from(pallas::Base::zero()),
|
|
|
- is_leader: false,
|
|
|
- m: Metadata::default(),
|
|
|
- proof: Proof::default(),
|
|
|
+ is_leader: vec![],
|
|
|
+ m: vec![],
|
|
|
block: BlockInfo::default(),
|
|
|
+ idx: 0,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
impl SlotWorkspace {
|
|
|
+ /// create new block from the workspace
|
|
|
+ /// if there are multiple winning coins (owned by the same stakeholder)
|
|
|
+ /// then pick the highest winning coin.
|
|
|
+ /// returns tuple of blockinfo, hash of that block
|
|
|
pub fn new_block(&self) -> (BlockInfo, blake3::Hash) {
|
|
|
let header = Header::new(self.st, self.e, self.sl, Timestamp::current_time(), self.root);
|
|
|
- let block = BlockInfo::new(header, self.txs.clone(), self.m.clone());
|
|
|
+ let block = BlockInfo::new(header, self.txs.clone(), self.m[self.idx].clone());
|
|
|
let hash = block.blockhash();
|
|
|
(block, hash)
|
|
|
}
|
|
|
|
|
|
+ // each opoch research the worksapce
|
|
|
+ fn reset(&mut self) {
|
|
|
+ self.is_leader = vec![];
|
|
|
+ self.m = vec![];
|
|
|
+ }
|
|
|
+
|
|
|
pub fn add_tx(&mut self, tx: Transaction) {
|
|
|
self.txs.push(tx);
|
|
|
}
|
|
|
@@ -54,12 +64,13 @@ impl SlotWorkspace {
|
|
|
self.root = root;
|
|
|
}
|
|
|
|
|
|
- pub fn set_metadata(&mut self, meta: Metadata) {
|
|
|
- self.m = meta;
|
|
|
+ pub fn add_metadata(&mut self, meta: Metadata) {
|
|
|
+ self.m.push(meta);
|
|
|
}
|
|
|
|
|
|
pub fn set_sl(&mut self, sl: u64) {
|
|
|
self.sl = sl;
|
|
|
+ self.reset();
|
|
|
}
|
|
|
|
|
|
pub fn set_st(&mut self, st: blake3::Hash) {
|
|
|
@@ -70,11 +81,15 @@ impl SlotWorkspace {
|
|
|
self.e = e;
|
|
|
}
|
|
|
|
|
|
- pub fn set_proof(&mut self, proof: Proof) {
|
|
|
- self.proof = proof;
|
|
|
+ pub fn add_leader(&mut self, alead: bool) {
|
|
|
+ self.is_leader.push(alead);
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn has_leader(&self) -> bool {
|
|
|
+ self.is_leader.iter().any(|&x| x)
|
|
|
}
|
|
|
|
|
|
- pub fn set_leader(&mut self, alead: bool) {
|
|
|
- self.is_leader = alead;
|
|
|
+ pub fn set_idx(&mut self, idx: usize) {
|
|
|
+ self.idx = idx;
|
|
|
}
|
|
|
}
|