Skip to content

Commit

Permalink
feat(chain-listener): enable ws ping (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh committed Sep 17, 2024
1 parent c48f52e commit 764f34c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/chain-listener/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use jsonrpsee::core::client::{Client as WsClient, Subscription, SubscriptionClie
use jsonrpsee::core::params::ArrayParams;
use jsonrpsee::core::{client, JsonValue};
use jsonrpsee::rpc_params;
use jsonrpsee::ws_client::WsClientBuilder;
use jsonrpsee::ws_client::{PingConfig, WsClientBuilder};
use libp2p_identity::PeerId;
use serde::de::DeserializeOwned;
use serde_json::{json, Value};
Expand Down Expand Up @@ -71,6 +71,8 @@ use crate::proof_tracker::ProofTracker;
use crate::types::{CUGroups, PhysicalCoreGroups};

const PROOF_POLL_LIMIT: usize = 50;
// TODO: move to config
const WS_PING_PERIOD_SEC: u64 = 10;

#[derive(Clone)]
struct OnChainWorker {
Expand Down Expand Up @@ -458,6 +460,9 @@ impl ChainListener {
pub async fn create_ws_client(ws_endpoint: &str) -> Result<WsClient, client::Error> {
let ws_client = retry(ExponentialBackoff::default(), || async {
let client = WsClientBuilder::default()
.enable_ws_ping(
PingConfig::new().ping_interval(Duration::from_secs(WS_PING_PERIOD_SEC)),
)
.build(ws_endpoint)
.await
.map_err(|err| {
Expand Down

0 comments on commit 764f34c

Please sign in to comment.