Skip to content

Commit

Permalink
consensus: Reject candidates with txs count higher than MAX_NUMBER_OF…
Browse files Browse the repository at this point in the history
…_TRANSACTIONS
  • Loading branch information
Goshawk committed Aug 16, 2024
1 parent e3d33fc commit 90ed813
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
base64 = "0.13"
node-data = { version = "0.1", path = "../node-data", features = ["faker"]}
criterion = "0.5"

[[bench]]
name = "merkle"
harness = false
1 change: 1 addition & 0 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub enum ConsensusError {
ChildTaskTerminated,
Canceled(u64),
VoteAlreadyCollected,
TooManyTransactions(usize),
}

impl From<StepSigError> for ConsensusError {
Expand Down
1 change: 1 addition & 0 deletions consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const RATIFICATION_COMMITTEE_QUORUM: f64 =
pub const DEFAULT_BLOCK_GAS_LIMIT: u64 = 5 * 1_000_000_000;

pub const RELAX_ITERATION_THRESHOLD: u8 = 8;
pub const MAX_NUMBER_OF_TRANSACTIONS: usize = 30_000;

/// Emergency mode is enabled after 16 iterations
pub const EMERGENCY_MODE_ITERATION_THRESHOLD: u8 = 16;
Expand Down
7 changes: 7 additions & 0 deletions consensus/src/proposal/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::commons::{ConsensusError, Database, RoundUpdate};
use crate::config::MAX_NUMBER_OF_TRANSACTIONS;
use crate::merkle::merkle_root;
use crate::msg_handler::{HandleMsgOutput, MsgHandler};
use crate::user::committee::Committee;
Expand Down Expand Up @@ -95,6 +96,12 @@ impl<D: Database> ProposalHandler<D> {
return Err(ConsensusError::InvalidBlockHash);
}

if p.candidate.txs().len() >= MAX_NUMBER_OF_TRANSACTIONS {
return Err(ConsensusError::TooManyTransactions(
p.candidate.txs().len(),
));
}

let tx_hashes: Vec<_> =
p.candidate.txs().iter().map(|t| t.hash()).collect();
let tx_root = merkle_root(&tx_hashes[..]);
Expand Down

0 comments on commit 90ed813

Please sign in to comment.