Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chain-listener): enable ws ping #2379

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
justprosh marked this conversation as resolved.
Show resolved Hide resolved

#[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
Loading