Skip to content

Commit 05b3171

Browse files
author
Solar Mithril
authored
Add pingpong and closing frame handle (#154)
1 parent b248d3b commit 05b3171

File tree

1 file changed

+25
-0
lines changed
  • crates/op-rbuilder/src/builders/flashblocks

1 file changed

+25
-0
lines changed

crates/op-rbuilder/src/builders/flashblocks/wspub.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use core::{
66
task::{Context, Poll},
77
};
88
use futures::{Sink, SinkExt};
9+
use futures_util::StreamExt;
910
use rollup_boost::FlashblocksPayloadV1;
1011
use std::{io, net::TcpListener, sync::Arc};
1112
use tokio::{
@@ -209,6 +210,30 @@ async fn broadcast_loop(
209210
tracing::warn!("Broadcast channel lagged, some messages were dropped");
210211
}
211212
},
213+
214+
// This handles channel closing and ping-pong logic
215+
message = stream.next() => if let Some(message) = message { match message {
216+
Ok(message) => {
217+
match message {
218+
Message::Ping(data) => {
219+
if let Err(e) = stream.send(Message::Pong(data)).await {
220+
tracing::warn!("Closing flashblocks subscription for {peer_addr}: {e}");
221+
break; // Exit the loop if sending fails
222+
}
223+
}
224+
// We don't get any data from RB, so we won't handle closing frame
225+
Message::Close(_) => {
226+
tracing::info!("Closing frame received, stopping connection for {peer_addr}");
227+
break;
228+
}
229+
_ => (),
230+
}
231+
}
232+
Err(e) => {
233+
tracing::warn!("Received error. Closing flashblocks subscription for {peer_addr}: {e}");
234+
break;
235+
}
236+
} }
212237
}
213238
}
214239
}

0 commit comments

Comments
 (0)