Skip to content

Commit 7f4c8a7

Browse files
committed
Remove with_retry for port collisions.
1 parent 431e61a commit 7f4c8a7

File tree

9 files changed

+53
-104
lines changed

9 files changed

+53
-104
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/src/tests/timeboost.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
1111

1212
use alloy::eips::{BlockNumberOrTag, Encodable2718};
1313
use bytes::Bytes;
14-
use cliquenet::{Address, AddressableCommittee, Network, NetworkMetrics};
14+
use cliquenet::{Address, AddressableCommittee};
1515
use metrics::NoMetrics;
1616
use multisig::Keypair;
1717
use multisig::{Committee, x25519};
@@ -23,7 +23,6 @@ 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;
2726
use tokio::sync::broadcast;
2827
use tokio::time::{Duration, sleep};
2928
use tracing::warn;
@@ -194,41 +193,3 @@ impl Round2Block {
194193
.or_insert_with(|| self.counter.fetch_add(1, Ordering::Relaxed).into())
195194
}
196195
}
197-
198-
async fn start_sequencer_with_retry(seq_conf: SequencerConfig) -> Sequencer {
199-
with_retry(
200-
|| async { Sequencer::new(seq_conf.clone(), &NoMetrics).await },
201-
|e| format!("failed to create sequencer: {e}"),
202-
)
203-
.await
204-
}
205-
206-
async fn start_certifier_with_retry(cert_conf: CertifierConfig) -> Certifier {
207-
with_retry(
208-
|| async { Certifier::new(cert_conf.clone(), &NoMetrics).await },
209-
|e| format!("failed to create certifer: {e}"),
210-
)
211-
.await
212-
}
213-
214-
async fn start_network_with_retry(cfg: &SequencerConfig) -> Network {
215-
with_retry(
216-
|| async {
217-
Network::create(
218-
"sailfish",
219-
cfg.sailfish_address().clone(),
220-
cfg.sign_keypair().public_key(),
221-
cfg.dh_keypair().clone(),
222-
cfg.sailfish_committee().entries(),
223-
NetworkMetrics::new(
224-
"sailfish",
225-
&NoMetrics,
226-
cfg.sailfish_committee().parties().copied(),
227-
),
228-
)
229-
.await
230-
},
231-
|e| format!("Network::create failed: {e}"),
232-
)
233-
.await
234-
}

tests/src/tests/timeboost/block_order.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use std::num::NonZeroUsize;
44
use std::sync::Arc;
55
use std::time::Duration;
66

7+
use metrics::NoMetrics;
78
use multisig::Certificate;
8-
use timeboost::sequencer::Output;
9+
use timeboost::builder::Certifier;
10+
use timeboost::sequencer::{Output, Sequencer};
911
use timeboost::types::{Block, BlockInfo};
1012
use timeboost_utils::types::logging::init_logging;
1113
use tokio::select;
@@ -16,9 +18,7 @@ use tokio_util::sync::CancellationToken;
1618
use tokio_util::task::TaskTracker;
1719
use tracing::{debug, error, info};
1820

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

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

@@ -50,9 +50,14 @@ async fn block_order() {
5050
// delay start of a recovering node:
5151
sleep(Duration::from_secs(5)).await
5252
}
53-
let mut s = start_sequencer_with_retry(c).await;
54-
let mut p = start_certifier_with_retry(b).await;
53+
let mut s = Sequencer::new(c.clone(), &NoMetrics)
54+
.await
55+
.unwrap_or_else(|e| panic!("failed to create sequencer: {e}"));
56+
let mut p = Certifier::new(b.clone(), &NoMetrics)
57+
.await
58+
.unwrap_or_else(|e| panic!("failed to create certifer: {e}"));
5559
let mut r = None;
60+
5661
let handle = p.handle();
5762
loop {
5863
select! {

tests/src/tests/timeboost/handover.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use std::num::NonZeroUsize;
55
use std::time::Duration;
66

77
use alloy::eips::BlockNumberOrTag;
8-
use cliquenet::{Address, AddressableCommittee, Overlay};
8+
use cliquenet::{Address, AddressableCommittee, Network, NetworkMetrics, Overlay};
99
use futures::FutureExt;
1010
use futures::stream::{self, StreamExt};
11+
use metrics::NoMetrics;
1112
use multisig::{Committee, CommitteeId, Keypair, x25519};
1213
use sailfish::consensus::Consensus;
1314
use sailfish::rbc::Rbc;
1415
use sailfish::types::{ConsensusTime, RoundNumber, Timestamp};
1516
use sailfish::{Coordinator, Event};
16-
use timeboost::config::{ChainConfig, ParentChain};
17+
use timeboost::config::{ChainConfig, DECRYPTER_PORT_OFFSET, ParentChain};
1718
use timeboost::crypto::prelude::DkgDecKey;
1819
use timeboost::sequencer::SequencerConfig;
1920
use timeboost::types::{DecryptionKeyCell, KeyStore};
@@ -26,8 +27,6 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
2627
use tracing::info;
2728
use url::Url;
2829

29-
use super::start_network_with_retry;
30-
3130
#[derive(Debug, Clone)]
3231
enum Cmd {
3332
NextCommittee(ConsensusTime, AddressableCommittee),
@@ -80,7 +79,7 @@ where
8079

8180
let de_addrs = sf_addrs
8281
.iter()
83-
.map(|addr| Address::from((Ipv4Addr::LOCALHOST, addr.port() + 1000)))
82+
.map(|addr| Address::from((Ipv4Addr::LOCALHOST, addr.port() + DECRYPTER_PORT_OFFSET)))
8483
.collect::<Vec<_>>();
8584

8685
let committee = Committee::new(
@@ -173,7 +172,20 @@ where
173172
///
174173
/// NB that the decryption parts of the config are not used yet.
175174
async fn mk_node(cfg: &SequencerConfig) -> Coordinator<Timestamp, Rbc<Timestamp>> {
176-
let mut net = start_network_with_retry(cfg).await;
175+
let mut net = Network::create(
176+
"sailfish",
177+
cfg.sailfish_address().clone(),
178+
cfg.sign_keypair().public_key(),
179+
cfg.dh_keypair().clone(),
180+
cfg.sailfish_committee().entries(),
181+
NetworkMetrics::new(
182+
"sailfish",
183+
&NoMetrics,
184+
cfg.sailfish_committee().parties().copied(),
185+
),
186+
)
187+
.await
188+
.unwrap();
177189

178190
if let Some(prev) = &cfg.previous_sailfish_committee() {
179191
let old = prev.diff(cfg.sailfish_committee());

tests/src/tests/timeboost/timeboost_handover.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ async fn run_handover(
7171
let r2b = round2block.clone();
7272

7373
tasks.spawn(async move {
74-
let mut s = start_sequencer_with_retry(seq_conf).await;
75-
let mut c = start_certifier_with_retry(cert_conf).await;
74+
let mut s = Sequencer::new(seq_conf.clone(), &NoMetrics).await.unwrap();
75+
let mut c = Certifier::new(cert_conf.clone(), &NoMetrics).await.unwrap();
7676
let mut r: Option<RoundNumber> = None;
7777
let c_handle = c.handle();
7878

@@ -179,8 +179,12 @@ async fn run_handover(
179179
let r2b = round2block.clone();
180180

181181
tasks.spawn(async move {
182-
let mut s = start_sequencer_with_retry(seq_conf).await;
183-
let mut c = start_certifier_with_retry(cert_conf).await;
182+
let mut s = Sequencer::new(seq_conf, &NoMetrics)
183+
.await
184+
.unwrap_or_else(|e| panic!("failed to create sequencer: {e}"));
185+
let mut c = Certifier::new(cert_conf, &NoMetrics)
186+
.await
187+
.unwrap_or_else(|e| panic!("failed to create certifer: {e}"));
184188
let mut r: Option<sailfish_types::RoundNumber> = None;
185189
let c_handle = c.handle();
186190

tests/src/tests/timeboost/transaction_order.rs

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

66
use alloy::primitives::B256;
7+
use metrics::NoMetrics;
78
use sailfish_types::RoundNumber;
8-
use timeboost::sequencer::Output;
9+
use timeboost::sequencer::{Output, Sequencer};
910
use timeboost_utils::types::logging::init_logging;
1011
use tokio::select;
1112
use tokio::sync::broadcast::error::RecvError;
@@ -15,8 +16,6 @@ use tokio_util::sync::CancellationToken;
1516
use tokio_util::task::TaskTracker;
1617
use tracing::{debug, info};
1718

18-
use crate::tests::timeboost::start_sequencer_with_retry;
19-
2019
use super::{gen_bundles, make_configs};
2120

2221
const NUM_OF_TRANSACTIONS: usize = 500;
@@ -53,7 +52,9 @@ async fn transaction_order() {
5352
// delay start of a recovering node:
5453
sleep(Duration::from_secs(5)).await
5554
}
56-
let mut s = start_sequencer_with_retry(c).await;
55+
let mut s = Sequencer::new(c.clone(), &NoMetrics)
56+
.await
57+
.unwrap_or_else(|e| panic!("failed to create sequencer: {e}"));
5758
loop {
5859
select! {
5960
trx = brx.recv() => match trx {

timeboost-builder/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ smallvec = { workspace = true }
2323
thiserror = { workspace = true }
2424
timeboost-config = { path = "../timeboost-config" }
2525
timeboost-types = { path = "../timeboost-types" }
26-
timeboost-utils = { path = "../timeboost-utils" }
2726
tokio = { workspace = true }
2827
tokio-util = { workspace = true }
2928
tracing = { workspace = true }

timeboost-sequencer/src/decrypt.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,8 +1479,7 @@ mod tests {
14791479
sync::Arc,
14801480
time::Instant,
14811481
};
1482-
1483-
use timeboost_utils::{types::logging, with_retry};
1482+
use timeboost_utils::types::logging;
14841483

14851484
use cliquenet::AddressableCommittee;
14861485
use multisig::{Committee, KeyId, Keypair, SecretKey, Signed, VoteAccumulator, x25519};
@@ -2445,7 +2444,13 @@ mod tests {
24452444
.threshold_dec_key(encryption_key_cell.clone())
24462445
.build();
24472446

2448-
let decrypter = start_decrypter_with_retry(decrypter_config).await;
2447+
let decrypter = Decrypter::new(
2448+
decrypter_config.clone(),
2449+
&NoMetrics,
2450+
Arc::new(SequencerMetrics::default()),
2451+
)
2452+
.await
2453+
.unwrap_or_else(|e| panic!("failed to create decrypter: {e}"));
24492454
decrypters.push(decrypter);
24502455
encryption_key_cells.push(encryption_key_cell);
24512456
}
@@ -2460,19 +2465,4 @@ mod tests {
24602465
),
24612466
)
24622467
}
2463-
2464-
async fn start_decrypter_with_retry(dec_config: DecrypterConfig) -> Decrypter {
2465-
with_retry(
2466-
|| async {
2467-
Decrypter::new(
2468-
dec_config.clone(),
2469-
&NoMetrics,
2470-
Arc::new(SequencerMetrics::default()),
2471-
)
2472-
.await
2473-
},
2474-
|e| format!("failed to create decrypter: {e}"),
2475-
)
2476-
.await
2477-
}
24782468
}

timeboost-utils/src/lib.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ pub mod load_generation;
22
pub mod types;
33
pub mod until;
44

5-
use std::{fmt::Display, time::Duration};
5+
use std::time::Duration;
66

77
use cliquenet::Address;
88
use multisig::x25519;
99
use tokio::time::sleep;
10-
use tracing::{error, info, warn};
10+
use tracing::{error, info};
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,25 +68,3 @@ pub async fn wait_for_live_peer(host: &Address) -> anyhow::Result<()> {
6868
sleep(Duration::from_secs(3)).await;
6969
}
7070
}
71-
72-
/// Retries an async operation with exponential backoff until it succeeds.
73-
pub async fn with_retry<T, E, F, Fut>(op: F, err: impl Fn(&E) -> String) -> T
74-
where
75-
E: Display,
76-
F: Fn() -> Fut,
77-
Fut: Future<Output = Result<T, E>>,
78-
{
79-
let mut delay = Duration::from_millis(100);
80-
const MAX_DELAY: Duration = Duration::from_secs(5);
81-
82-
loop {
83-
match op().await {
84-
Ok(result) => return result,
85-
Err(e) => {
86-
warn!("{}: {e}, retrying in {:?}...", err(&e), delay);
87-
sleep(delay).await;
88-
delay = (delay * 2).min(MAX_DELAY);
89-
}
90-
}
91-
}
92-
}

0 commit comments

Comments
 (0)