mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
blockchain/Block: removed producer structure
This commit is contained in:
@@ -47,8 +47,12 @@ pub struct Block {
|
||||
pub header: blake3::Hash,
|
||||
/// Trasaction hashes
|
||||
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
|
||||
pub slots: Vec<u64>,
|
||||
}
|
||||
@@ -57,11 +61,13 @@ impl Block {
|
||||
pub fn new(
|
||||
header: blake3::Hash,
|
||||
txs: Vec<blake3::Hash>,
|
||||
producer: BlockProducer,
|
||||
signature: Signature,
|
||||
proposal: Transaction,
|
||||
eta: pallas::Base,
|
||||
slots: Vec<u64>,
|
||||
) -> 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<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
|
||||
pub slots: Vec<Slot>,
|
||||
}
|
||||
@@ -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<Transaction>,
|
||||
producer: BlockProducer,
|
||||
signature: Signature,
|
||||
proposal: Transaction,
|
||||
eta: pallas::Base,
|
||||
slots: Vec<Slot>,
|
||||
) -> 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<BlockInfo> 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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -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)?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user