Skip to content

Commit

Permalink
Merge pull request #2309 from AleoHQ/bug/aborted-transaction-limit
Browse files Browse the repository at this point in the history
Increase aborted transaction limit
  • Loading branch information
howardwu authored Jan 20, 2024
2 parents 8f36036 + b8373f5 commit 62a59b9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ledger/block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ package = "snarkvm-ledger-committee"
path = "../../ledger/committee"
version = "=0.16.16"

[dependencies.ledger-narwhal-batch-header]
package = "snarkvm-ledger-narwhal-batch-header"
path = "../narwhal/batch-header"
version = "=0.16.16"

[dependencies.ledger-narwhal-subdag]
package = "snarkvm-ledger-narwhal-subdag"
path = "../narwhal/subdag"
Expand Down
2 changes: 1 addition & 1 deletion ledger/block/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<N: Network> FromBytes for Block<N> {
// Read the number of aborted transaction IDs.
let num_aborted = u32::read_le(&mut reader)?;
// Ensure the number of aborted transaction IDs is within bounds (this is an early safety check).
if num_aborted as usize > Transactions::<N>::MAX_TRANSACTIONS {
if num_aborted as usize > Transactions::<N>::MAX_ABORTED_TRANSACTIONS {
return Err(error("Invalid number of aborted transaction IDs in the block"));
}
// Read the aborted transaction IDs.
Expand Down
4 changes: 2 additions & 2 deletions ledger/block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ impl<N: Network> Block<N> {
}

// Ensure the number of aborted transaction IDs is within the allowed range.
if aborted_transaction_ids.len() > Transactions::<N>::MAX_TRANSACTIONS {
if aborted_transaction_ids.len() > Transactions::<N>::MAX_ABORTED_TRANSACTIONS {
bail!(
"Cannot initialize a block with more than {} aborted transaction IDs",
Transactions::<N>::MAX_TRANSACTIONS
Transactions::<N>::MAX_ABORTED_TRANSACTIONS
);
}

Expand Down
7 changes: 7 additions & 0 deletions ledger/block/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ use console::{
},
types::{Field, Group, U64},
};
use ledger_committee::Committee;
use ledger_narwhal_batch_header::BatchHeader;
use ledger_narwhal_subdag::Subdag;
use synthesizer_program::FinalizeOperation;

use indexmap::IndexMap;
Expand Down Expand Up @@ -166,6 +169,10 @@ impl<N: Network> Transactions<N> {
}

impl<N: Network> Transactions<N> {
/// The maximum number of aborted transactions allowed in a block.
pub const MAX_ABORTED_TRANSACTIONS: usize = Subdag::<N>::MAX_ROUNDS
* Committee::<N>::MAX_COMMITTEE_SIZE as usize
* BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH;
/// The maximum number of transactions allowed in a block.
pub const MAX_TRANSACTIONS: usize = usize::pow(2, TRANSACTIONS_DEPTH as u32);

Expand Down
4 changes: 2 additions & 2 deletions ledger/block/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ impl<N: Network> Block<N> {
}

// Ensure the number of aborted transaction IDs is within the allowed range.
if self.aborted_transaction_ids.len() > Transactions::<N>::MAX_TRANSACTIONS {
if self.aborted_transaction_ids.len() > Transactions::<N>::MAX_ABORTED_TRANSACTIONS {
bail!(
"Cannot validate a block with more than {} aborted transaction IDs",
Transactions::<N>::MAX_TRANSACTIONS
Transactions::<N>::MAX_ABORTED_TRANSACTIONS
);
}

Expand Down
5 changes: 5 additions & 0 deletions ledger/narwhal/batch-header/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl<N: Network> BatchHeader<N> {
pub const MAX_TRANSACTIONS: usize = usize::pow(2, console::program::TRANSACTIONS_DEPTH as u32);
/// The maximum number of transmissions in a batch.
pub const MAX_TRANSMISSIONS: usize = Self::MAX_SOLUTIONS + Self::MAX_TRANSACTIONS;
/// The maximum number of transmissions in a batch.
/// Note: This limit is set to 50 as part of safety measures to prevent DoS attacks.
/// This limit can be increased in the future as performance improves. Alternatively,
/// the rate of block production can be sped up to compensate for the limit set here.
pub const MAX_TRANSMISSIONS_PER_BATCH: usize = 50;
}

impl<N: Network> BatchHeader<N> {
Expand Down
4 changes: 2 additions & 2 deletions synthesizer/src/vm/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
// Perform the finalize operation on the preset finalize mode.
atomic_finalize!(self.finalize_store(), FinalizeMode::DryRun, {
// Ensure the number of transactions does not exceed the maximum.
if num_transactions > 2 * Transactions::<N>::MAX_TRANSACTIONS {
if num_transactions > Transactions::<N>::MAX_ABORTED_TRANSACTIONS {
// Note: This will abort the entire atomic batch.
return Err(format!(
"Too many transactions in the block - {num_transactions} (max: {})",
2 * Transactions::<N>::MAX_TRANSACTIONS
Transactions::<N>::MAX_ABORTED_TRANSACTIONS
));
}

Expand Down

0 comments on commit 62a59b9

Please sign in to comment.