Skip to content

Commit 4af2d23

Browse files
authored
Check transaction number on total chains (#4325)
## Motivation Right now we're checking just the number of chains in a wallet, but if we're using cross wallet transfers, we need to take all chains from all wallets into consideration. ## Proposal Take all chains from all wallets used in the benchmark into consideration ## Test Plan Ran this against a deployed network ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent ef57829 commit 4af2d23

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

linera-client/src/benchmark.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,16 @@ impl<Env: Environment> Benchmark<Env> {
643643
Ok(all_chains)
644644
}
645645

646-
/// Generates information related to one block per chain.
647646
pub fn make_benchmark_block_info(
648647
benchmark_chains: Vec<(ChainId, AccountOwner)>,
649648
transactions_per_block: usize,
650649
fungible_application_id: Option<ApplicationId>,
651650
all_chains: Vec<ChainId>,
652651
) -> Result<Vec<Vec<Operation>>, BenchmarkError> {
653652
let mut blocks_infos = Vec::new();
653+
let amount = Amount::from_attos(1);
654+
654655
for (current_chain_id, owner) in benchmark_chains.iter() {
655-
let amount = Amount::from(1);
656656
let mut operations = Vec::new();
657657

658658
let mut other_chains: Vec<_> = if all_chains.len() == 1 {
@@ -669,6 +669,22 @@ impl<Env: Environment> Benchmark<Env> {
669669
};
670670

671671
other_chains.shuffle(&mut thread_rng());
672+
673+
// Calculate adjusted transactions_per_block to ensure even distribution
674+
let num_destinations = other_chains.len();
675+
let adjusted_transactions_per_block = if transactions_per_block % num_destinations != 0
676+
{
677+
let adjusted = transactions_per_block.div_ceil(num_destinations) * num_destinations;
678+
warn!(
679+
"Requested transactions_per_block ({}) is not evenly divisible by number of destination chains ({}). \
680+
Adjusting to {} transactions per block to ensure transfers cancel each other out.",
681+
transactions_per_block, num_destinations, adjusted
682+
);
683+
adjusted
684+
} else {
685+
transactions_per_block
686+
};
687+
672688
for recipient_chain_id in other_chains {
673689
let operation = match fungible_application_id {
674690
Some(application_id) => Self::fungible_transfer(
@@ -690,7 +706,7 @@ impl<Env: Environment> Benchmark<Env> {
690706
let operations = operations
691707
.into_iter()
692708
.cycle()
693-
.take(transactions_per_block)
709+
.take(adjusted_transactions_per_block)
694710
.collect();
695711
blocks_infos.push(operations);
696712
}

linera-service/src/cli/main.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -829,22 +829,12 @@ impl Runnable for Job {
829829
"max_pending_message_bundles must be set to at least the same as the \
830830
number of transactions per block ({transactions_per_block}) for benchmarking",
831831
);
832-
assert!(
833-
num_chains > 0,
834-
"Number of chain groups must be greater than 0"
835-
);
832+
assert!(num_chains > 0, "Number of chains must be greater than 0");
836833
assert!(
837834
transactions_per_block > 0,
838835
"Number of transactions per block must be greater than 0"
839836
);
840837
assert!(bps > 0, "BPS must be greater than 0");
841-
if num_chains > 1 {
842-
assert!(
843-
transactions_per_block % (num_chains - 1) == 0,
844-
"Number of transactions per block must be a multiple of the number of \
845-
chains minus 1, to make sure transactions always cancel each other out"
846-
);
847-
}
848838

849839
let listener_config = ChainListenerConfig {
850840
skip_process_inbox: true,

0 commit comments

Comments
 (0)