Skip to content

Commit

Permalink
litep2p: Increase keep-alive to 10 seconds to mirror libp2p (#7488)
Browse files Browse the repository at this point in the history
This PR ensures that litep2p will keep an idle connection alive for 10
seconds.

The bump from 5 seconds is done to mirror the libp2p behavior and
potentially improve connection stability:

https://github.com/paritytech/polkadot-sdk/blob/a07fb323bc0cfb5c2fb4c8fbe9d20e344cc8eeaf/substrate/client/network/src/service.rs#L542-L549

cc @paritytech/networking

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
  • Loading branch information
lexnv authored Feb 6, 2025
1 parent 87f4f3f commit 2f44779
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions prdoc/pr_7488.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Increase litep2p keep-alive to 10 seconds to mirror libp2p

doc:
- audience: [Node Dev, Node Operator]
description: |
Increase litep2p keep-alive to 10 seconds to mirror libp2p behavior.

crates:
- name: sc-network
bump: patch
6 changes: 6 additions & 0 deletions substrate/client/network/src/litep2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ mod peerstore;
mod service;
mod shim;

/// Timeout for connection waiting new substreams.
const KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(10);

/// Litep2p bandwidth sink.
struct Litep2pBandwidthSink {
sink: litep2p::BandwidthSink,
Expand Down Expand Up @@ -566,6 +569,9 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkBackend<B, H> for Litep2pNetworkBac
.with_connection_limits(ConnectionLimitsConfig::default().max_incoming_connections(
Some(crate::MAX_CONNECTIONS_ESTABLISHED_INCOMING as usize),
))
// This has the same effect as `libp2p::Swarm::with_idle_connection_timeout` which is
// set to 10 seconds as well.
.with_keep_alive_timeout(KEEP_ALIVE_TIMEOUT)
.with_executor(executor);

if let Some(config) = maybe_mdns_config {
Expand Down

0 comments on commit 2f44779

Please sign in to comment.