فهرست منبع

blockchain/Block: removed producer structure

aggstam 2 سال پیش
والد
کامیت
dba13ebef6

+ 8 - 1
bin/darkfid2/src/tests/harness.rs

@@ -199,7 +199,14 @@ impl Harness {
         );
         );
 
 
         // Generate block
         // 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)
         Ok(block)
     }
     }

+ 26 - 36
src/blockchain/block_store.rs

@@ -47,8 +47,12 @@ pub struct Block {
     pub header: blake3::Hash,
     pub header: blake3::Hash,
     /// Trasaction hashes
     /// Trasaction hashes
     pub txs: Vec<blake3::Hash>,
     pub txs: Vec<blake3::Hash>,
-    /// 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
     /// Slots up until this block
     pub slots: Vec<u64>,
     pub slots: Vec<u64>,
 }
 }
@@ -57,11 +61,13 @@ impl Block {
     pub fn new(
     pub fn new(
         header: blake3::Hash,
         header: blake3::Hash,
         txs: Vec<blake3::Hash>,
         txs: Vec<blake3::Hash>,
-        producer: BlockProducer,
+        signature: Signature,
+        proposal: Transaction,
+        eta: pallas::Base,
         slots: Vec<u64>,
         slots: Vec<u64>,
     ) -> Self {
     ) -> Self {
         let magic = BLOCK_MAGIC_BYTES;
         let magic = BLOCK_MAGIC_BYTES;
-        Self { magic, header, txs, producer, slots }
+        Self { magic, header, txs, signature, proposal, eta, slots }
     }
     }
 
 
     /// Calculate the block hash
     /// Calculate the block hash
@@ -79,8 +85,12 @@ pub struct BlockInfo {
     pub header: Header,
     pub header: Header,
     /// Transactions payload
     /// Transactions payload
     pub txs: Vec<Transaction>,
     pub txs: Vec<Transaction>,
-    /// 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
     /// Slots payload
     pub slots: Vec<Slot>,
     pub slots: Vec<Slot>,
 }
 }
@@ -93,7 +103,9 @@ impl Default for BlockInfo {
             magic,
             magic,
             header: Header::default(),
             header: Header::default(),
             txs: vec![],
             txs: vec![],
-            producer: BlockProducer::default(),
+            signature: Signature::dummy(),
+            proposal: Transaction::default(),
+            eta: pallas::Base::ZERO,
             slots: vec![Slot::default()],
             slots: vec![Slot::default()],
         }
         }
     }
     }
@@ -103,11 +115,13 @@ impl BlockInfo {
     pub fn new(
     pub fn new(
         header: Header,
         header: Header,
         txs: Vec<Transaction>,
         txs: Vec<Transaction>,
-        producer: BlockProducer,
+        signature: Signature,
+        proposal: Transaction,
+        eta: pallas::Base,
         slots: Vec<Slot>,
         slots: Vec<Slot>,
     ) -> Self {
     ) -> Self {
         let magic = BLOCK_MAGIC_BYTES;
         let magic = BLOCK_MAGIC_BYTES;
-        Self { magic, header, txs, producer, slots }
+        Self { magic, header, txs, signature, proposal, eta, slots }
     }
     }
 
 
     /// Calculate the block hash
     /// Calculate the block hash
@@ -125,7 +139,9 @@ impl From<BlockInfo> for Block {
             magic: block_info.magic,
             magic: block_info.magic,
             header: block_info.header.headerhash().unwrap(),
             header: block_info.header.headerhash().unwrap(),
             txs,
             txs,
-            producer: block_info.producer,
+            signature: block_info.signature,
+            proposal: block_info.proposal,
+            eta: block_info.eta,
             slots,
             slots,
         }
         }
     }
     }
@@ -476,29 +492,3 @@ impl BlockOrderStoreOverlay {
         Ok(self.0.lock().unwrap().is_empty(SLED_BLOCK_ORDER_TREE)?)
         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 }
-    }
-}

+ 17 - 4
src/blockchain/mod.rs

@@ -29,8 +29,7 @@ use crate::{tx::Transaction, Error, Result};
 /// Block related definitions and storage implementations
 /// Block related definitions and storage implementations
 pub mod block_store;
 pub mod block_store;
 pub use block_store::{
 pub use block_store::{
-    Block, BlockInfo, BlockOrderStore, BlockOrderStoreOverlay, BlockProducer, BlockStore,
-    BlockStoreOverlay,
+    Block, BlockInfo, BlockOrderStore, BlockOrderStoreOverlay, BlockStore, BlockStoreOverlay,
 };
 };
 
 
 /// Header definition and storage implementation
 /// Header definition and storage implementation
@@ -193,7 +192,14 @@ impl Blockchain {
             let slots = self.slots.get(&block.slots, true)?;
             let slots = self.slots.get(&block.slots, true)?;
             let slots = slots.iter().map(|x| x.clone().unwrap()).collect();
             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);
             ret.push(info);
         }
         }
 
 
@@ -508,7 +514,14 @@ impl BlockchainOverlay {
             let slots = self.slots.get(&block.slots, true)?;
             let slots = self.slots.get(&block.slots, true)?;
             let slots = slots.iter().map(|x| x.clone().unwrap()).collect();
             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);
             ret.push(info);
         }
         }
 
 

+ 9 - 7
src/validator/consensus.rs

@@ -26,9 +26,7 @@ use log::{error, info, warn};
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
 use crate::{
 use crate::{
-    blockchain::{
-        BlockInfo, BlockProducer, Blockchain, BlockchainOverlay, BlockchainOverlayPtr, Header,
-    },
+    blockchain::{BlockInfo, Blockchain, BlockchainOverlay, BlockchainOverlayPtr, Header},
     tx::Transaction,
     tx::Transaction,
     util::time::{TimeKeeper, Timestamp},
     util::time::{TimeKeeper, Timestamp},
     validator::{pid::slot_pid_output, verify_block, verify_transactions},
     validator::{pid::slot_pid_output, verify_block, verify_transactions},
@@ -159,11 +157,15 @@ impl Consensus {
         // Sign block header using provided secret key
         // Sign block header using provided secret key
         let signature = secret_key.sign(&mut OsRng, &header.headerhash()?.as_bytes()[..]);
         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
         // 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);
         let proposal = Proposal::new(block);
 
 
         Ok(proposal)
         Ok(proposal)

+ 2 - 2
src/validator/validation.rs

@@ -71,7 +71,7 @@ pub fn validate_block(block: &BlockInfo, previous: &BlockInfo, expected_reward:
                 previous_slot,
                 previous_slot,
                 &previous_hash,
                 &previous_hash,
                 &previous.header.previous,
                 &previous.header.previous,
-                &previous.producer.eta,
+                &previous.eta,
                 0,
                 0,
             )?;
             )?;
             previous_slot = slot;
             previous_slot = slot;
@@ -83,7 +83,7 @@ pub fn validate_block(block: &BlockInfo, previous: &BlockInfo, expected_reward:
         previous_slot,
         previous_slot,
         &previous_hash,
         &previous_hash,
         &previous.header.previous,
         &previous.header.previous,
-        &previous.producer.eta,
+        &previous.eta,
         expected_reward,
         expected_reward,
     )?;
     )?;
 
 

+ 3 - 3
src/validator/verification.rs

@@ -76,9 +76,9 @@ pub async fn verify_genesis_block(
     }
     }
 
 
     // Genesis transaction must be the Transaction::default() one (empty)
     // 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");
         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
     // Verify transactions
@@ -123,7 +123,7 @@ pub async fn verify_block(
 
 
     // Validate proposal transaction if not in testing mode
     // Validate proposal transaction if not in testing mode
     if !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)?;
         verify_producer_signature(block)?;
     }
     }
 
 

+ 8 - 1
tests/blockchain.rs

@@ -82,7 +82,14 @@ impl Harness {
         let header =
         let header =
             Header::new(previous_hash, previous.header.epoch, id, timestamp, previous.header.root);
             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<()> {
     fn add_blocks(&self, blocks: &[BlockInfo]) -> Result<()> {