diff --git a/bin/darkfid2/src/tests/harness.rs b/bin/darkfid2/src/tests/harness.rs index 549ad6fa4..dcaf8e929 100644 --- a/bin/darkfid2/src/tests/harness.rs +++ b/bin/darkfid2/src/tests/harness.rs @@ -199,7 +199,14 @@ impl Harness { ); // Generate block - let block = BlockInfo::new(header, vec![], previous.producer.clone(), slots); + let block = BlockInfo::new( + header, + vec![], + previous.signature, + previous.proposal.clone(), + previous.eta, + slots, + ); Ok(block) } diff --git a/src/blockchain/block_store.rs b/src/blockchain/block_store.rs index 1e9b8f8bd..52da8578f 100644 --- a/src/blockchain/block_store.rs +++ b/src/blockchain/block_store.rs @@ -47,8 +47,12 @@ pub struct Block { pub header: blake3::Hash, /// Trasaction hashes pub txs: Vec, - /// Block producer info - pub producer: BlockProducer, + /// Block producer signature + pub signature: Signature, + /// Proposal transaction + pub proposal: Transaction, + /// Block producer ETA + pub eta: pallas::Base, /// Slots up until this block pub slots: Vec, } @@ -57,11 +61,13 @@ impl Block { pub fn new( header: blake3::Hash, txs: Vec, - producer: BlockProducer, + signature: Signature, + proposal: Transaction, + eta: pallas::Base, slots: Vec, ) -> Self { let magic = BLOCK_MAGIC_BYTES; - Self { magic, header, txs, producer, slots } + Self { magic, header, txs, signature, proposal, eta, slots } } /// Calculate the block hash @@ -79,8 +85,12 @@ pub struct BlockInfo { pub header: Header, /// Transactions payload pub txs: Vec, - /// Block producer info - pub producer: BlockProducer, + /// Block producer signature + pub signature: Signature, + /// Proposal transaction + pub proposal: Transaction, + /// Block producer ETA + pub eta: pallas::Base, /// Slots payload pub slots: Vec, } @@ -93,7 +103,9 @@ impl Default for BlockInfo { magic, header: Header::default(), txs: vec![], - producer: BlockProducer::default(), + signature: Signature::dummy(), + proposal: Transaction::default(), + eta: pallas::Base::ZERO, slots: vec![Slot::default()], } } @@ -103,11 +115,13 @@ impl BlockInfo { pub fn new( header: Header, txs: Vec, - producer: BlockProducer, + signature: Signature, + proposal: Transaction, + eta: pallas::Base, slots: Vec, ) -> Self { let magic = BLOCK_MAGIC_BYTES; - Self { magic, header, txs, producer, slots } + Self { magic, header, txs, signature, proposal, eta, slots } } /// Calculate the block hash @@ -125,7 +139,9 @@ impl From for Block { magic: block_info.magic, header: block_info.header.headerhash().unwrap(), txs, - producer: block_info.producer, + signature: block_info.signature, + proposal: block_info.proposal, + eta: block_info.eta, slots, } } @@ -476,29 +492,3 @@ impl BlockOrderStoreOverlay { Ok(self.0.lock().unwrap().is_empty(SLED_BLOCK_ORDER_TREE)?) } } - -/// This struct represents [`Block`] producer information. -#[derive(Debug, Clone, SerialEncodable, SerialDecodable)] -pub struct BlockProducer { - /// Block producer signature - pub signature: Signature, - /// Proposal transaction - pub proposal: Transaction, - /// Block producer ETA - pub eta: pallas::Base, -} - -impl BlockProducer { - pub fn new(signature: Signature, proposal: Transaction, eta: pallas::Base) -> Self { - Self { signature, proposal, eta } - } -} - -impl Default for BlockProducer { - fn default() -> Self { - let signature = Signature::dummy(); - let proposal = Transaction::default(); - let eta = pallas::Base::ZERO; - Self { signature, proposal, eta } - } -} diff --git a/src/blockchain/mod.rs b/src/blockchain/mod.rs index 2b4bc28dc..454ebc006 100644 --- a/src/blockchain/mod.rs +++ b/src/blockchain/mod.rs @@ -29,8 +29,7 @@ use crate::{tx::Transaction, Error, Result}; /// Block related definitions and storage implementations pub mod block_store; pub use block_store::{ - Block, BlockInfo, BlockOrderStore, BlockOrderStoreOverlay, BlockProducer, BlockStore, - BlockStoreOverlay, + Block, BlockInfo, BlockOrderStore, BlockOrderStoreOverlay, BlockStore, BlockStoreOverlay, }; /// Header definition and storage implementation @@ -193,7 +192,14 @@ impl Blockchain { let slots = self.slots.get(&block.slots, true)?; let slots = slots.iter().map(|x| x.clone().unwrap()).collect(); - let info = BlockInfo::new(header, txs, block.producer.clone(), slots); + let info = BlockInfo::new( + header, + txs, + block.signature, + block.proposal.clone(), + block.eta, + slots, + ); ret.push(info); } @@ -508,7 +514,14 @@ impl BlockchainOverlay { let slots = self.slots.get(&block.slots, true)?; let slots = slots.iter().map(|x| x.clone().unwrap()).collect(); - let info = BlockInfo::new(header, txs, block.producer.clone(), slots); + let info = BlockInfo::new( + header, + txs, + block.signature, + block.proposal.clone(), + block.eta, + slots, + ); ret.push(info); } diff --git a/src/validator/consensus.rs b/src/validator/consensus.rs index b1a8872a7..71fa7c4fe 100644 --- a/src/validator/consensus.rs +++ b/src/validator/consensus.rs @@ -26,9 +26,7 @@ use log::{error, info, warn}; use rand::rngs::OsRng; use crate::{ - blockchain::{ - BlockInfo, BlockProducer, Blockchain, BlockchainOverlay, BlockchainOverlayPtr, Header, - }, + blockchain::{BlockInfo, Blockchain, BlockchainOverlay, BlockchainOverlayPtr, Header}, tx::Transaction, util::time::{TimeKeeper, Timestamp}, validator::{pid::slot_pid_output, verify_block, verify_transactions}, @@ -159,11 +157,15 @@ impl Consensus { // Sign block header using provided secret key let signature = secret_key.sign(&mut OsRng, &header.headerhash()?.as_bytes()[..]); - // Generate block producer info - let block_producer = BlockProducer::new(signature, proposal_tx, slot.last_eta); - // Generate the block and its proposal - let block = BlockInfo::new(header, unproposed_txs, block_producer, fork.slots.clone()); + let block = BlockInfo::new( + header, + unproposed_txs, + signature, + proposal_tx, + slot.last_eta, + fork.slots.clone(), + ); let proposal = Proposal::new(block); Ok(proposal) diff --git a/src/validator/validation.rs b/src/validator/validation.rs index 19631ae22..c28a28a4c 100644 --- a/src/validator/validation.rs +++ b/src/validator/validation.rs @@ -71,7 +71,7 @@ pub fn validate_block(block: &BlockInfo, previous: &BlockInfo, expected_reward: previous_slot, &previous_hash, &previous.header.previous, - &previous.producer.eta, + &previous.eta, 0, )?; previous_slot = slot; @@ -83,7 +83,7 @@ pub fn validate_block(block: &BlockInfo, previous: &BlockInfo, expected_reward: previous_slot, &previous_hash, &previous.header.previous, - &previous.producer.eta, + &previous.eta, expected_reward, )?; diff --git a/src/validator/verification.rs b/src/validator/verification.rs index c2c66192a..892f579c6 100644 --- a/src/validator/verification.rs +++ b/src/validator/verification.rs @@ -76,9 +76,9 @@ pub async fn verify_genesis_block( } // Genesis transaction must be the Transaction::default() one (empty) - if block.producer.proposal != Transaction::default() { + if block.proposal != Transaction::default() { error!(target: "validator::verification::verify_genesis_block", "Genesis proposal transaction is not default one"); - return Err(TxVerifyFailed::ErroneousTxs(vec![block.producer.proposal.clone()]).into()) + return Err(TxVerifyFailed::ErroneousTxs(vec![block.proposal.clone()]).into()) } // Verify transactions @@ -123,7 +123,7 @@ pub async fn verify_block( // Validate proposal transaction if not in testing mode if !testing_mode { - verify_proposal_transaction(overlay, time_keeper, &block.producer.proposal).await?; + verify_proposal_transaction(overlay, time_keeper, &block.proposal).await?; verify_producer_signature(block)?; } diff --git a/tests/blockchain.rs b/tests/blockchain.rs index 469a9fe3e..cb7ff9c48 100644 --- a/tests/blockchain.rs +++ b/tests/blockchain.rs @@ -82,7 +82,14 @@ impl Harness { let header = Header::new(previous_hash, previous.header.epoch, id, timestamp, previous.header.root); - BlockInfo::new(header, vec![], previous.producer.clone(), vec![slot]) + BlockInfo::new( + header, + vec![], + previous.signature, + previous.proposal.clone(), + previous.eta, + vec![slot], + ) } fn add_blocks(&self, blocks: &[BlockInfo]) -> Result<()> {