Skip to content

Commit 44b482c

Browse files
Increase idle connection timeout 10sec -> 1h (#27)
Increase idle connection timeout from default 10 seconds to 1 hour to give IPFS clients more time to query data over Bitswap. This is needed when manually adding our node to a swarm of an IPFS node, because the IPFS node doesn't keep any active substreams with us and our node closes a connection after idle_connection_timeout.
1 parent 865e7cd commit 44b482c

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ serde = { version = "1.0.126" }
1616
serde_json = { version = "1.0.132", default-features = false }
1717
static_assertions = { version = "1.1" }
1818
try-runtime-cli = { version = "0.42" }
19+
tracing = { version = "0.1.41", default-features = false }
1920

2021
[workspace]
2122
resolver = "2"

node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ name = "polkadot-bulletin-chain"
1818
[dependencies]
1919
clap = { features = ["derive"], workspace = true }
2020
futures = { features = ["thread-pool"], workspace = true }
21+
tracing = { workspace = true }
2122

2223
frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "db5e645422ccf952018a3c466a33fef477858602" }
2324
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "db5e645422ccf952018a3c466a33fef477858602" }

node/src/command.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE
88
use polkadot_bulletin_chain_runtime::Block;
99
use sc_cli::SubstrateCli;
1010
use sc_service::PartialComponents;
11-
use std::sync::Arc;
11+
use std::{sync::Arc, time::Duration};
1212

1313
#[cfg(feature = "try-runtime")]
1414
use {
1515
polkadot_bulletin_chain_runtime::SLOT_DURATION,
1616
try_runtime_cli::block_building_info::timestamp_with_babe_info,
1717
};
1818

19+
/// Log target for this file.
20+
const LOG_TARGET: &str = "command";
21+
1922
impl SubstrateCli for Cli {
2023
fn impl_name() -> String {
2124
"Polkadot Bulletin Chain Node".into()
@@ -206,7 +209,25 @@ pub fn run() -> sc_cli::Result<()> {
206209
},
207210
None => {
208211
let runner = cli.create_runner(&cli.run)?;
209-
runner.run_node_until_exit(|config| async move {
212+
runner.run_node_until_exit(|mut config| async move {
213+
// Override default idle connection timeout of 10 seconds to give IPFS clients more
214+
// time to query data over Bitswap. This is needed when manually adding our node
215+
// to a swarm of an IPFS node, because the IPFS node doesn't keep any active
216+
// substreams with us and our node closes a connection after
217+
// `idle_connection_timeout`.
218+
const IPFS_WORKAROUND_TIMEOUT: Duration = Duration::from_secs(3600);
219+
220+
if config.network.idle_connection_timeout < IPFS_WORKAROUND_TIMEOUT {
221+
tracing::info!(
222+
target: LOG_TARGET,
223+
old = ?config.network.idle_connection_timeout,
224+
overriden_with = ?IPFS_WORKAROUND_TIMEOUT,
225+
"Overriding `config.network.idle_connection_timeout` to allow long-lived connections with IPFS nodes",
226+
227+
);
228+
config.network.idle_connection_timeout = IPFS_WORKAROUND_TIMEOUT;
229+
}
230+
210231
service::new_full::<sc_network::Litep2pNetworkBackend>(config)
211232
.map_err(sc_cli::Error::Service)
212233
})

0 commit comments

Comments
 (0)