Skip to content

Commit e2088b9

Browse files
authored
[breaking-change] Improve ping/pong logic (#422)
* v1 impl * v1 impl * Fix backoff reset * fmt * Add cleaning up * add unit test * add unit test * add unit test * Use LRU cache * Use LRU cache * unwraps -> expect
1 parent dd12e8e commit e2088b9

File tree

8 files changed

+336
-62
lines changed

8 files changed

+336
-62
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ tokio = { version = "1", features = ["full"] }
2323
eyre = "0.6.12"
2424
url = "2.2.0"
2525
sha2 = { version = "0.10", default-features = false }
26+
backoff = "0.4.0"
2627

2728
# Reth deps
2829
reth-optimism-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.3" }

crates/rollup-boost/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ paste = "1.0.15"
6464
parking_lot = "0.12.3"
6565
tokio-util = { version = "0.7.13" }
6666
dashmap = "6.1.0"
67+
backoff.workspace = true
68+
uuid = { version = "1.17.0", features = ["v4", "v7"] }
69+
bytes = "1.10.1"
70+
lru = "0.16"
6771

6872
[dev-dependencies]
6973
rand = "0.9.0"

crates/rollup-boost/src/flashblocks/args.rs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
12
use clap::Parser;
3+
use std::time::Duration;
24
use url::Url;
35

46
#[derive(Parser, Clone, Debug)]
@@ -19,7 +21,59 @@ pub struct FlashblocksArgs {
1921
#[arg(long, env, default_value = "1112")]
2022
pub flashblocks_port: u16,
2123

22-
/// Time used for timeout if builder disconnected
24+
/// Websocket connection configuration
25+
#[command(flatten)]
26+
pub flashblocks_ws_config: FlashblocksWebsocketConfig,
27+
}
28+
29+
#[derive(Parser, Debug, Clone, Copy)]
30+
pub struct FlashblocksWebsocketConfig {
31+
/// Minimum time for exponential backoff for timeout if builder disconnected
32+
#[arg(long, env, default_value = "10")]
33+
pub flashblock_builder_ws_initial_reconnect_ms: u64,
34+
35+
/// Maximum time for exponential backoff for timeout if builder disconnected
2336
#[arg(long, env, default_value = "5000")]
24-
pub flashblock_builder_ws_reconnect_ms: u64,
37+
pub flashblock_builder_ws_max_reconnect_ms: u64,
38+
39+
/// Interval in milliseconds between ping messages sent to upstream servers to detect unresponsive connections
40+
#[arg(long, env, default_value = "500")]
41+
pub flashblock_builder_ws_ping_interval_ms: u64,
42+
43+
/// Timeout in milliseconds to wait for pong responses from upstream servers before considering the connection dead
44+
#[arg(long, env, default_value = "1500")]
45+
pub flashblock_builder_ws_pong_timeout_ms: u64,
46+
}
47+
48+
impl FlashblocksWebsocketConfig {
49+
/// Creates `ExponentialBackoff` use to control builder websocket reconnection time
50+
pub fn backoff(&self) -> ExponentialBackoff {
51+
ExponentialBackoffBuilder::default()
52+
.with_initial_interval(self.initial_interval())
53+
.with_max_interval(self.max_interval())
54+
.with_randomization_factor(0 as f64)
55+
.with_max_elapsed_time(None)
56+
.with_multiplier(2.0)
57+
.build()
58+
}
59+
60+
/// Returns initial time for exponential backoff
61+
pub fn initial_interval(&self) -> Duration {
62+
Duration::from_millis(self.flashblock_builder_ws_initial_reconnect_ms)
63+
}
64+
65+
/// Returns maximal time for exponential backoff
66+
pub fn max_interval(&self) -> Duration {
67+
Duration::from_millis(self.flashblock_builder_ws_max_reconnect_ms)
68+
}
69+
70+
/// Returns ping interval
71+
pub fn ping_interval(&self) -> Duration {
72+
Duration::from_millis(self.flashblock_builder_ws_ping_interval_ms)
73+
}
74+
75+
/// Returns pong interval
76+
pub fn pong_interval(&self) -> Duration {
77+
Duration::from_millis(self.flashblock_builder_ws_pong_timeout_ms)
78+
}
2579
}

0 commit comments

Comments
 (0)