Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: send certs in batch to each connection
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberb committed Mar 27, 2024
1 parent 674c209 commit dd945f5
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions crates/topos-certificate-spammer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,22 @@ pub async fn run(
let source_subnet =
&mut source_subnets[rand::random::<usize>() % args.nb_subnets as usize];
// Randomize number of target subnets if target subnet list cli argument is provided
// let target_subnets: Vec<SubnetId> = if target_subnet_ids.is_empty() {
// // Empty list of target subnets in certificate
// Vec::new()
// } else {
// // Generate random list in size of 0..len(target_subnet_ids) as target subnets
// let number_of_target_subnets =
// rand::random::<usize>() % (target_subnet_ids.len() + 1);
// let mut target_subnets = Vec::new();
// for _ in 0..number_of_target_subnets {
// target_subnets.push(
// target_subnet_ids
// [rand::random::<usize>() % target_subnet_ids.len()],
// );
// }
// target_subnets
// };
let target_subnets: Vec<SubnetId> = if target_subnet_ids.is_empty() {
// Empty list of target subnets in certificate
Vec::new()
} else {
// Generate random list in size of 0..len(target_subnet_ids) as target subnets
let number_of_target_subnets =
rand::random::<usize>() % (target_subnet_ids.len() + 1);
let mut target_subnets = Vec::new();
for _ in 0..number_of_target_subnets {
target_subnets.push(
target_subnet_ids
[rand::random::<usize>() % target_subnet_ids.len()],
);
}
target_subnets
};

let new_cert = match generate_test_certificate(
source_subnet,
Expand All @@ -346,15 +346,21 @@ pub async fn run(
batch.push(new_cert);
}

// Dispatch certs in this batch
// Dispatch certs in this batch
for cert in batch {
// Randomly choose target tce node for every certificate from related source_subnet_id connection list
let target_node_connection = &target_node_connections[&cert.source_subnet_id]
[rand::random::<usize>() % target_nodes.len()];
dispatch(cert, target_node_connection)
.instrument(Span::current())
.with_current_context()
.await;
// let target_node_connection = &target_node_connections[&cert.source_subnet_id]
// [rand::random::<usize>() % target_nodes.len()];

for connection in &target_node_connections[&cert.source_subnet_id] {
if !connection.address.is_empty() {
dispatch(cert.clone(), connection)
.instrument(Span::current())
.with_current_context()
.await;
}
}
}
}
.instrument(span)
Expand Down

0 comments on commit dd945f5

Please sign in to comment.