Skip to content

Commit

Permalink
[refactor]: Custom genesis wait time for tps benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Mar 19, 2024
1 parent 7b39854 commit 4b364c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion client/benches/tps/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"interval_us_per_tx": 0,
"max_txs_per_block": 1024,
"blocks": 15,
"sample_size": 10
"sample_size": 10,
"genesis_max_retries": 30
}
3 changes: 2 additions & 1 deletion client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Config {
pub max_txs_per_block: u32,
pub blocks: u32,
pub sample_size: u32,
pub genesis_max_retries: u32,
}

impl fmt::Display for Config {
Expand Down Expand Up @@ -58,7 +59,7 @@ impl Config {
// READY
let (_rt, network, client) = Network::start_test_with_runtime(self.peers, None);
let clients = network.clients();
wait_for_genesis_committed(&clients, 0);
wait_for_genesis_committed_with_max_retries(&clients, 0, self.genesis_max_retries);

client.submit_all_blocking(
ParametersBuilder::new()
Expand Down
19 changes: 16 additions & 3 deletions core/test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,23 @@ impl Network {
/// # Panics
/// When unsuccessful after `MAX_RETRIES`.
pub fn wait_for_genesis_committed(clients: &[Client], offline_peers: u32) {
const POLL_PERIOD: Duration = Duration::from_millis(1000);
const MAX_RETRIES: u32 = 40;
wait_for_genesis_committed_with_max_retries(clients, offline_peers, MAX_RETRIES)
}

/// Wait for peers to have committed genesis block for specified amount of retries.
/// Each retry once per second.
///
/// # Panics
/// When unsuccessful after `max_retries`.
pub fn wait_for_genesis_committed_with_max_retries(
clients: &[Client],
offline_peers: u32,
max_retries: u32,
) {
const POLL_PERIOD: Duration = Duration::from_millis(1000);

for _ in 0..MAX_RETRIES {
for _ in 0..max_retries {
let without_genesis_peers = clients.iter().fold(0_u32, |acc, client| {
client.get_status().map_or(
acc + 1,
Expand All @@ -344,7 +357,7 @@ pub fn wait_for_genesis_committed(clients: &[Client], offline_peers: u32) {
}
panic!(
"Failed to wait for online peers to commit genesis block. Total wait time: {:?}",
POLL_PERIOD * MAX_RETRIES
POLL_PERIOD * max_retries
);
}

Expand Down

0 comments on commit 4b364c6

Please sign in to comment.