Skip to content

Commit 12a25f6

Browse files
committed
fix(p2p): more fault-tolerant establish_connections
1 parent 01a19e6 commit 12a25f6

File tree

10 files changed

+150
-447
lines changed

10 files changed

+150
-447
lines changed

Cargo.lock

Lines changed: 65 additions & 443 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ strata-rpc-api = { git = "https://github.com/alpenlabs/strata.git" }
7878
strata-rpc-types = { git = "https://github.com/alpenlabs/strata.git" }
7979
strata-state = { git = "https://github.com/alpenlabs/strata.git" }
8080

81-
strata-p2p = { git = "https://github.com/alpenlabs/strata-p2p.git" }
82-
strata-p2p-types = { git = "https://github.com/alpenlabs/strata-p2p.git" }
83-
strata-p2p-wire = { git = "https://github.com/alpenlabs/strata-p2p.git" }
81+
# TODO(@storopoli): remove these once the PR is ready
82+
strata-p2p = { git = "https://github.com/alpenlabs/strata-p2p.git", branch = "fix/better-retries" }
83+
strata-p2p-types = { git = "https://github.com/alpenlabs/strata-p2p.git", branch = "fix/better-retries" }
84+
strata-p2p-wire = { git = "https://github.com/alpenlabs/strata-p2p.git", branch = "fix/better-retries" }
8485

8586
zkaleido = { git = "https://github.com/alpenlabs/zkaleido", tag = "v0.1.0-alpha-rc10" }
8687
zkaleido-native-adapter = { git = "https://github.com/alpenlabs/zkaleido", tag = "v0.1.0-alpha-rc10" }

bin/alpen-bridge/src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ pub(crate) struct P2PConfig {
101101
/// Default is
102102
/// [`DEFAULT_NUM_THREADS`](strata_bridge_p2p_service::constants::DEFAULT_NUM_THREADS).
103103
pub num_threads: Option<usize>,
104+
105+
/// Dial timeout.
106+
///
107+
/// The default is [`DEFAULT_DIAL_TIMEOUT`](strata_p2p::swarm::DEFAULT_DIAL_TIMEOUT).
108+
pub dial_timeout: Option<Duration>,
109+
110+
/// General timeout for operations.
111+
///
112+
/// The default is [`DEFAULT_GENERAL_TIMEOUT`](strata_p2p::swarm::DEFAULT_GENERAL_TIMEOUT).
113+
pub general_timeout: Option<Duration>,
114+
115+
/// Connection check interval.
116+
///
117+
/// The default is
118+
/// [`DEFAULT_CONNECTION_CHECK_INTERVAL`](strata_p2p::swarm::DEFAULT_CONNECTION_CHECK_INTERVAL).
119+
pub connection_check_interval: Option<Duration>,
104120
}
105121

106122
/// Operator wallet configuration.

bin/alpen-bridge/src/mode/operator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ async fn init_p2p_handle(
247247
listening_addr,
248248
connect_to,
249249
num_threads,
250+
dial_timeout,
251+
general_timeout,
252+
connection_check_interval,
250253
} = config.p2p.clone();
251254

252255
let config = P2PConfiguration::new_with_secret_key(
@@ -257,6 +260,9 @@ async fn init_p2p_handle(
257260
connect_to,
258261
signers_allowlist,
259262
num_threads,
263+
dial_timeout,
264+
general_timeout,
265+
connection_check_interval,
260266
);
261267
let (p2p_handle, _cancel, listen_task) = p2p_bootstrap(&config).await?;
262268
Ok((p2p_handle, listen_task))

crates/p2p-service/src/bootstrap.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
33
use std::time::Duration;
44

5-
use strata_p2p::swarm::{self, handle::P2PHandle, P2PConfig, P2P};
5+
use strata_p2p::swarm::{
6+
self, handle::P2PHandle, P2PConfig, DEFAULT_CONNECTION_CHECK_INTERVAL, DEFAULT_DIAL_TIMEOUT,
7+
DEFAULT_GENERAL_TIMEOUT, P2P,
8+
};
69
use tokio::task::JoinHandle;
710
use tokio_util::sync::CancellationToken;
811
use tracing::info;
@@ -23,6 +26,13 @@ pub async fn bootstrap(
2326
allowlist: config.allowlist.clone(),
2427
connect_to: config.connect_to.clone(),
2528
signers_allowlist: config.signers_allowlist.clone(),
29+
dial_timeout: Some(config.dial_timeout.unwrap_or(DEFAULT_DIAL_TIMEOUT)),
30+
general_timeout: Some(config.general_timeout.unwrap_or(DEFAULT_GENERAL_TIMEOUT)),
31+
connection_check_interval: Some(
32+
config
33+
.connection_check_interval
34+
.unwrap_or(DEFAULT_CONNECTION_CHECK_INTERVAL),
35+
),
2636
};
2737
let cancel = CancellationToken::new();
2838

crates/p2p-service/src/config.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,27 @@ pub struct Configuration {
3434
///
3535
/// Default is [`DEFAULT_NUM_THREADS`](crate::constants::DEFAULT_NUM_THREADS).
3636
pub num_threads: Option<usize>,
37+
38+
/// Dial timeout.
39+
///
40+
/// The default is [`DEFAULT_DIAL_TIMEOUT`](strata_p2p::swarm::DEFAULT_DIAL_TIMEOUT).
41+
pub dial_timeout: Option<Duration>,
42+
43+
/// General timeout for operations.
44+
///
45+
/// The default is [`DEFAULT_GENERAL_TIMEOUT`](strata_p2p::swarm::DEFAULT_GENERAL_TIMEOUT).
46+
pub general_timeout: Option<Duration>,
47+
48+
/// Connection check interval.
49+
///
50+
/// The default is
51+
/// [`DEFAULT_CONNECTION_CHECK_INTERVAL`](strata_p2p::swarm::DEFAULT_CONNECTION_CHECK_INTERVAL).
52+
pub connection_check_interval: Option<Duration>,
3753
}
3854

3955
impl Configuration {
4056
/// Creates a new [`Configuration`] by using a [`SecretKey`].
57+
#[expect(clippy::too_many_arguments)]
4158
pub fn new_with_secret_key(
4259
sk: SecretKey,
4360
idle_connection_timeout: Option<Duration>,
@@ -46,6 +63,9 @@ impl Configuration {
4663
connect_to: Vec<Multiaddr>,
4764
signers_allowlist: Vec<P2POperatorPubKey>,
4865
num_threads: Option<usize>,
66+
dial_timeout: Option<Duration>,
67+
general_timeout: Option<Duration>,
68+
connection_check_interval: Option<Duration>,
4969
) -> Self {
5070
let sk = Libp2pSecpSecretKey::try_from_bytes(sk.secret_bytes()).expect("infallible");
5171
let keypair = Libp2pSecpKeypair::from(sk);
@@ -57,6 +77,9 @@ impl Configuration {
5777
connect_to,
5878
signers_allowlist,
5979
num_threads,
80+
dial_timeout,
81+
general_timeout,
82+
connection_check_interval,
6083
}
6184
}
6285

@@ -91,6 +114,9 @@ mod tests {
91114
vec![],
92115
vec![],
93116
None,
117+
None,
118+
None,
119+
None,
94120
);
95121
assert_eq!(config.public_key().inner, pk);
96122
assert_eq!(config.x_only_public_key(), x_only_pk);

crates/p2p-service/src/tests/common.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ pub(crate) struct Operator {
3131
}
3232

3333
impl Operator {
34+
#[expect(clippy::too_many_arguments)]
3435
pub(crate) fn new(
3536
keypair: SecpKeypair,
3637
allowlist: Vec<PeerId>,
3738
connect_to: Vec<Multiaddr>,
3839
local_addr: Multiaddr,
3940
cancel: CancellationToken,
4041
signers_allowlist: Vec<P2POperatorPubKey>,
42+
dial_timeout: Option<Duration>,
43+
general_timeout: Option<Duration>,
44+
connection_check_interval: Option<Duration>,
4145
) -> anyhow::Result<Self> {
4246
let config = P2PConfig {
4347
keypair: keypair.clone(),
@@ -47,6 +51,9 @@ impl Operator {
4751
allowlist,
4852
connect_to,
4953
signers_allowlist,
54+
dial_timeout,
55+
general_timeout,
56+
connection_check_interval,
5057
};
5158

5259
let swarm = swarm::with_inmemory_transport(&config)?;
@@ -101,6 +108,9 @@ impl Setup {
101108
addr.clone(),
102109
cancel.child_token(),
103110
signers_allowlist.clone(),
111+
None,
112+
None,
113+
None,
104114
)?;
105115

106116
operators.push(operator);
@@ -149,6 +159,9 @@ impl Setup {
149159
addr.clone(),
150160
cancel.child_token(),
151161
signers_allowlist.clone(),
162+
None,
163+
None,
164+
None,
152165
)?;
153166

154167
operators.push(operator);

docker/vol/alpen-bridge-1/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ idle_connection_timeout = { secs = 1000, nanos = 0 }
2828
listening_addr = "/ip4/172.28.0.5/tcp/5679"
2929
connect_to = ["/ip4/172.28.0.6/tcp/5679", "/ip4/172.28.0.7/tcp/5679"]
3030
num_threads = 4
31+
dial_timeout = { secs = 0, nanos = 250_000_000 }
32+
general_timeout = { secs = 0, nanos = 250_000_000 }
33+
connection_check_interval = { secs = 0, nanos = 500_000_000 }
3134

3235
[operator_wallet]
3336
stake_funding_pool_size = 32

docker/vol/alpen-bridge-2/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ idle_connection_timeout = { secs = 1000, nanos = 0 }
2828
listening_addr = "/ip4/172.28.0.6/tcp/5679"
2929
connect_to = ["/ip4/172.28.0.5/tcp/5679", "/ip4/172.28.0.7/tcp/5679"]
3030
num_threads = 4
31+
dial_timeout = { secs = 0, nanos = 250_000_000 }
32+
general_timeout = { secs = 0, nanos = 250_000_000 }
33+
connection_check_interval = { secs = 0, nanos = 500_000_000 }
3134

3235
[operator_wallet]
3336
stake_funding_pool_size = 32

docker/vol/alpen-bridge-3/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ idle_connection_timeout = { secs = 1000, nanos = 0 }
2828
listening_addr = "/ip4/172.28.0.7/tcp/5679"
2929
connect_to = ["/ip4/172.28.0.5/tcp/5679", "/ip4/172.28.0.6/tcp/5679"]
3030
num_threads = 4
31+
dial_timeout = { secs = 0, nanos = 250_000_000 }
32+
general_timeout = { secs = 0, nanos = 250_000_000 }
33+
connection_check_interval = { secs = 0, nanos = 500_000_000 }
3134

3235
[operator_wallet]
3336
stake_funding_pool_size = 32

0 commit comments

Comments
 (0)