Skip to content

Commit 29c41f1

Browse files
authored
Fix flashblocks ping/pong intervals (#330)
1 parent cc9ad11 commit 29c41f1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/rollup-boost/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ metrics-util = "0.19.0"
6060
paste = "1.0.15"
6161
parking_lot = "0.12.3"
6262
url = "2.2.0"
63+
tokio-util = { version = "0.7.13" }
6364

6465
[dev-dependencies]
6566
rand = "0.9.0"

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::{metrics::FlashblocksWsInboundMetrics, primitives::FlashblocksPayload
44
use futures::{SinkExt, StreamExt};
55
use tokio::{sync::mpsc, time::interval};
66
use tokio_tungstenite::{connect_async, tungstenite::Message};
7+
use tokio_util::sync::CancellationToken;
78
use tracing::{error, info};
89
use url::Url;
910

@@ -68,6 +69,9 @@ impl FlashblocksReceiverService {
6869
info!("Connected to Flashblocks receiver at {}", self.url);
6970
self.metrics.connection_status.set(1);
7071

72+
let cancel_token = CancellationToken::new();
73+
let cancel_for_ping = cancel_token.clone();
74+
7175
let ping_task = tokio::spawn(async move {
7276
let mut ping_interval = interval(Duration::from_millis(500));
7377

@@ -78,14 +82,18 @@ impl FlashblocksReceiverService {
7882
return Err(FlashblocksReceiverError::PingFailed);
7983
}
8084
}
85+
_ = cancel_for_ping.cancelled() => {
86+
tracing::debug!("Ping task cancelled");
87+
return Ok(());
88+
}
8189
}
8290
}
8391
});
8492

8593
let sender = self.sender.clone();
8694
let metrics = self.metrics.clone();
8795

88-
let read_timeout = Duration::from_millis(500);
96+
let read_timeout = Duration::from_millis(1500);
8997
let message_handle = tokio::spawn(async move {
9098
loop {
9199
let result = tokio::time::timeout(read_timeout, read.next())
@@ -128,6 +136,7 @@ impl FlashblocksReceiverService {
128136
},
129137
};
130138

139+
cancel_token.cancel();
131140
result
132141
}
133142
}

0 commit comments

Comments
 (0)