mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
blockchain/Block: moved producer tx at last position of blocks' txs vec
This commit is contained in:
@@ -128,8 +128,11 @@ impl Consensus {
|
||||
}
|
||||
let fork = &self.forks[fork_index];
|
||||
|
||||
// Grab forks' unproposed transactions and their root
|
||||
let unproposed_txs = fork.unproposed_txs(&self.blockchain, &time_keeper).await?;
|
||||
// Grab forks' unproposed transactions
|
||||
let mut unproposed_txs = fork.unproposed_txs(&self.blockchain, &time_keeper).await?;
|
||||
unproposed_txs.push(proposal_tx);
|
||||
|
||||
// Calculate transactions tree root
|
||||
let mut tree = MerkleTree::new(100);
|
||||
// The following is pretty weird, so something better should be done.
|
||||
for tx in &unproposed_txs {
|
||||
@@ -158,14 +161,8 @@ impl Consensus {
|
||||
let signature = secret_key.sign(&mut OsRng, &header.headerhash()?.as_bytes()[..]);
|
||||
|
||||
// Generate the block and its proposal
|
||||
let block = BlockInfo::new(
|
||||
header,
|
||||
unproposed_txs,
|
||||
signature,
|
||||
proposal_tx,
|
||||
slot.last_eta,
|
||||
fork.slots.clone(),
|
||||
);
|
||||
let block =
|
||||
BlockInfo::new(header, unproposed_txs, signature, slot.last_eta, fork.slots.clone());
|
||||
let proposal = Proposal::new(block);
|
||||
|
||||
Ok(proposal)
|
||||
|
||||
@@ -70,19 +70,26 @@ pub async fn verify_genesis_block(
|
||||
return Err(Error::SlotIsInvalid(genesis_slot.id))
|
||||
}
|
||||
|
||||
// Verify there is not reward
|
||||
// Verify there is no reward
|
||||
if genesis_slot.reward != 0 {
|
||||
return Err(Error::SlotIsInvalid(genesis_slot.id))
|
||||
}
|
||||
|
||||
// Genesis transaction must be the Transaction::default() one (empty)
|
||||
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.proposal.clone()]).into())
|
||||
// Verify transactions vector contains at least one(producers) transaction
|
||||
if block.txs.is_empty() {
|
||||
return Err(Error::BlockContainsNoTransactions(block_hash))
|
||||
}
|
||||
|
||||
// Verify transactions
|
||||
let erroneous_txs = verify_transactions(overlay, time_keeper, &block.txs).await?;
|
||||
// Genesis transaction must be the Transaction::default() one(empty)
|
||||
let tx = block.txs.last().unwrap();
|
||||
if tx != &Transaction::default() {
|
||||
error!(target: "validator::verification::verify_genesis_block", "Genesis proposal transaction is not default one");
|
||||
return Err(TxVerifyFailed::ErroneousTxs(vec![tx.clone()]).into())
|
||||
}
|
||||
|
||||
// Verify transactions, exluding producer(last) one
|
||||
let txs = &block.txs[..block.txs.len() - 1];
|
||||
let erroneous_txs = verify_transactions(overlay, time_keeper, txs).await?;
|
||||
if !erroneous_txs.is_empty() {
|
||||
warn!(target: "validator::verification::verify_genesis_block", "Erroneous transactions found in set");
|
||||
overlay.lock().unwrap().overlay.lock().unwrap().purge_new_trees()?;
|
||||
@@ -121,14 +128,21 @@ pub async fn verify_block(
|
||||
// Validate block, using its previous
|
||||
validate_block(block, previous, expected_reward)?;
|
||||
|
||||
// Verify transactions vector contains at least one(producers) transaction
|
||||
if block.txs.is_empty() {
|
||||
return Err(Error::BlockContainsNoTransactions(block_hash))
|
||||
}
|
||||
|
||||
// Validate proposal transaction if not in testing mode
|
||||
if !testing_mode {
|
||||
verify_proposal_transaction(overlay, time_keeper, &block.proposal).await?;
|
||||
let tx = block.txs.last().unwrap();
|
||||
verify_proposal_transaction(overlay, time_keeper, tx).await?;
|
||||
verify_producer_signature(block)?;
|
||||
}
|
||||
|
||||
// Verify transactions
|
||||
let erroneous_txs = verify_transactions(overlay, time_keeper, &block.txs).await?;
|
||||
// Verify transactions, exluding producer(last) one
|
||||
let txs = &block.txs[..block.txs.len() - 1];
|
||||
let erroneous_txs = verify_transactions(overlay, time_keeper, txs).await?;
|
||||
if !erroneous_txs.is_empty() {
|
||||
warn!(target: "validator::verification::verify_block", "Erroneous transactions found in set");
|
||||
overlay.lock().unwrap().overlay.lock().unwrap().purge_new_trees()?;
|
||||
|
||||
Reference in New Issue
Block a user