Skip to content

Commit 19bb4e9

Browse files
committed
Reduce number of blocks (duration)
1 parent be5fa41 commit 19bb4e9

File tree

7 files changed

+59
-41
lines changed

7 files changed

+59
-41
lines changed

.config/nextest.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[profile.default]
22
slow-timeout = { period = "60s", terminate-after = 2 }
3+
4+
[[profile.default.overrides]]
5+
filter = 'test(/^tests::timeboost::timeboost_handover::/)'
6+
threads-required = 2
7+
slow-timeout = { period = "300s", terminate-after = 1 }

tests/src/tests/timeboost.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use timeboost::crypto::prelude::DkgDecKey;
2323
use timeboost::sequencer::{Sequencer, SequencerConfig};
2424
use timeboost::types::{BlockNumber, BundleVariant, DecryptionKeyCell, KeyStore, Transaction};
2525
use timeboost_utils::load_generation::make_bundle;
26+
use timeboost_utils::with_retry;
2627
use tokio::sync::broadcast;
2728
use tokio::time::{Duration, sleep};
2829
use tracing::warn;
@@ -194,27 +195,6 @@ impl Round2Block {
194195
}
195196
}
196197

197-
async fn with_retry<T, E, F, Fut>(operation: F, error_message: impl Fn(&E) -> String) -> T
198-
where
199-
E: std::fmt::Display,
200-
F: Fn() -> Fut,
201-
Fut: std::future::Future<Output = Result<T, E>>,
202-
{
203-
let mut delay = Duration::from_millis(100);
204-
const MAX_DELAY: Duration = Duration::from_secs(5);
205-
206-
loop {
207-
match operation().await {
208-
Ok(result) => return result,
209-
Err(e) => {
210-
warn!("{}: {e}, retrying in {:?}...", error_message(&e), delay);
211-
sleep(delay).await;
212-
delay = (delay * 2).min(MAX_DELAY);
213-
}
214-
}
215-
}
216-
}
217-
218198
async fn start_sequencer_with_retry(seq_conf: SequencerConfig) -> Sequencer {
219199
with_retry(
220200
|| async { Sequencer::new(seq_conf.clone(), &NoMetrics).await },

tests/src/tests/timeboost/block_order.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use metrics::NoMetrics;
21
use multisig::Certificate;
32
use std::collections::HashMap;
43
use std::iter::once;
54
use std::num::NonZeroUsize;
65
use std::sync::Arc;
76
use std::time::Duration;
8-
use timeboost::builder::Certifier;
9-
use timeboost::sequencer::{Output, Sequencer};
7+
use timeboost::sequencer::Output;
108
use timeboost::types::{Block, BlockInfo};
119
use timeboost_utils::types::logging::init_logging;
1210
use tokio::select;
@@ -17,7 +15,9 @@ use tokio_util::sync::CancellationToken;
1715
use tokio_util::task::TaskTracker;
1816
use tracing::{debug, error, info};
1917

20-
use crate::tests::timeboost::{Round2Block, hash};
18+
use crate::tests::timeboost::{
19+
Round2Block, hash, start_certifier_with_retry, start_sequencer_with_retry,
20+
};
2121

2222
use super::{gen_bundles, make_configs};
2323

@@ -49,8 +49,8 @@ async fn block_order() {
4949
// delay start of a recovering node:
5050
sleep(Duration::from_secs(5)).await
5151
}
52-
let mut s = Sequencer::new(c, &NoMetrics).await.unwrap();
53-
let mut p = Certifier::new(b, &NoMetrics).await.unwrap();
52+
let mut s = start_sequencer_with_retry(c).await;
53+
let mut p = start_certifier_with_retry(b).await;
5454
let mut r = None;
5555
let handle = p.handle();
5656
loop {

tests/src/tests/timeboost/timeboost_handover.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ async fn run_handover(
3636
curr: Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)>,
3737
next: Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)>,
3838
) {
39-
const NEXT_COMMITTEE_DELAY: u64 = 10;
39+
const NEXT_COMMITTEE_DELAY: u64 = 15;
4040
const NUM_OF_BLOCKS: usize = 50;
4141

4242
let mut out1 = Vec::new();
4343
let tasks = TaskTracker::new();
44-
let (bcast, _) = broadcast::channel(200);
44+
let (bcast, _) = broadcast::channel(500);
4545
let finish = CancellationToken::new();
4646
let round2block = Arc::new(Round2Block::new());
4747

@@ -130,6 +130,8 @@ async fn run_handover(
130130
key.read().await;
131131
}
132132

133+
tokio::time::sleep(Duration::from_secs(5)).await;
134+
133135
tasks.spawn({
134136
let (key, _, _) = &curr[0];
135137
let key = key.clone();

tests/src/tests/timeboost/transaction_order.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use std::num::NonZeroUsize;
44
use std::time::Duration;
55

66
use alloy::primitives::B256;
7-
use metrics::NoMetrics;
87
use sailfish_types::RoundNumber;
9-
use timeboost::sequencer::{Output, Sequencer};
8+
use timeboost::sequencer::Output;
109
use timeboost_utils::types::logging::init_logging;
1110
use tokio::select;
1211
use tokio::sync::broadcast::error::RecvError;
@@ -16,6 +15,8 @@ use tokio_util::sync::CancellationToken;
1615
use tokio_util::task::TaskTracker;
1716
use tracing::{debug, info};
1817

18+
use crate::tests::timeboost::start_sequencer_with_retry;
19+
1920
use super::{gen_bundles, make_configs};
2021

2122
const NUM_OF_TRANSACTIONS: usize = 500;
@@ -52,7 +53,7 @@ async fn transaction_order() {
5253
// delay start of a recovering node:
5354
sleep(Duration::from_secs(5)).await
5455
}
55-
let mut s = Sequencer::new(c, &NoMetrics).await.unwrap();
56+
let mut s = start_sequencer_with_retry(c).await;
5657
loop {
5758
select! {
5859
trx = brx.recv() => match trx {

timeboost-sequencer/src/decrypt.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ mod tests {
14081408
time::Instant,
14091409
};
14101410

1411-
use timeboost_utils::types::logging;
1411+
use timeboost_utils::{types::logging, with_retry};
14121412

14131413
use cliquenet::AddressableCommittee;
14141414
use multisig::{Committee, KeyId, Keypair, SecretKey, Signed, VoteAccumulator, x25519};
@@ -2373,13 +2373,7 @@ mod tests {
23732373
.threshold_dec_key(encryption_key_cell.clone())
23742374
.build();
23752375

2376-
let decrypter = Decrypter::new(
2377-
decrypter_config,
2378-
&NoMetrics,
2379-
Arc::new(SequencerMetrics::default()),
2380-
)
2381-
.await
2382-
.expect("Decrypter creation should succeed");
2376+
let decrypter = start_decrypter_with_retry(decrypter_config).await;
23832377
decrypters.push(decrypter);
23842378
encryption_key_cells.push(encryption_key_cell);
23852379
}
@@ -2394,4 +2388,19 @@ mod tests {
23942388
),
23952389
)
23962390
}
2391+
2392+
async fn start_decrypter_with_retry(dec_config: DecrypterConfig) -> Decrypter {
2393+
with_retry(
2394+
|| async {
2395+
Decrypter::new(
2396+
dec_config.clone(),
2397+
&NoMetrics,
2398+
Arc::new(SequencerMetrics::default()),
2399+
)
2400+
.await
2401+
},
2402+
|e| format!("failed to create decrypter: {e}"),
2403+
)
2404+
.await
2405+
}
23972406
}

timeboost-utils/src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77
use cliquenet::Address;
88
use multisig::x25519;
99
use tokio::time::sleep;
10-
use tracing::{error, info};
10+
use tracing::{error, info, warn};
1111

1212
pub fn unsafe_zero_keypair<N: Into<u64>>(i: N) -> multisig::Keypair {
1313
sig_keypair_from_seed_indexed([0u8; 32], i.into())
@@ -68,3 +68,24 @@ pub async fn wait_for_live_peer(host: &Address) -> anyhow::Result<()> {
6868
sleep(Duration::from_secs(3)).await;
6969
}
7070
}
71+
72+
pub async fn with_retry<T, E, F, Fut>(operation: F, error_message: impl Fn(&E) -> String) -> T
73+
where
74+
E: std::fmt::Display,
75+
F: Fn() -> Fut,
76+
Fut: std::future::Future<Output = Result<T, E>>,
77+
{
78+
let mut delay = Duration::from_millis(100);
79+
const MAX_DELAY: Duration = Duration::from_secs(5);
80+
81+
loop {
82+
match operation().await {
83+
Ok(result) => return result,
84+
Err(e) => {
85+
warn!("{}: {e}, retrying in {:?}...", error_message(&e), delay);
86+
sleep(delay).await;
87+
delay = (delay * 2).min(MAX_DELAY);
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)