From c660afd51a6bec6e8269294dd013f763abc530e0 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 15 Sep 2022 17:53:19 +0200 Subject: [PATCH] Temporarily ban peers after failing to connect to them (#2747) --- bin/full-node/src/run/network_service/tasks.rs | 9 +++++++++ bin/light-base/src/network_service/tasks.rs | 5 +++++ bin/wasm-node/CHANGELOG.md | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/bin/full-node/src/run/network_service/tasks.rs b/bin/full-node/src/run/network_service/tasks.rs index 1408e23dce..53ecce0cca 100644 --- a/bin/full-node/src/run/network_service/tasks.rs +++ b/bin/full-node/src/run/network_service/tasks.rs @@ -60,6 +60,9 @@ pub(super) async fn opening_connection_task( let mut guarded = inner.guarded.lock().await; guarded.num_pending_out_attempts -= 1; guarded.network.pending_outcome_err(start_connect.id, true); + for chain_index in 0..guarded.network.num_chains() { + guarded.unassign_slot_and_ban(chain_index, start_connect.expected_peer_id.clone()); + } inner.wake_up_main_background_task.notify(1); return; } @@ -83,6 +86,9 @@ pub(super) async fn opening_connection_task( let mut guarded = inner.guarded.lock().await; guarded.num_pending_out_attempts -= 1; guarded.network.pending_outcome_err(start_connect.id, false); + for chain_index in 0..guarded.network.num_chains() { + guarded.unassign_slot_and_ban(chain_index, start_connect.expected_peer_id.clone()); + } inner.wake_up_main_background_task.notify(1); return; } @@ -93,6 +99,9 @@ pub(super) async fn opening_connection_task( let mut guarded = inner.guarded.lock().await; guarded.num_pending_out_attempts -= 1; guarded.network.pending_outcome_err(start_connect.id, true); + for chain_index in 0..guarded.network.num_chains() { + guarded.unassign_slot_and_ban(chain_index, start_connect.expected_peer_id.clone()); + } inner.wake_up_main_background_task.notify(1); return; } diff --git a/bin/light-base/src/network_service/tasks.rs b/bin/light-base/src/network_service/tasks.rs index 6cafc4e2d4..0a0837306e 100644 --- a/bin/light-base/src/network_service/tasks.rs +++ b/bin/light-base/src/network_service/tasks.rs @@ -100,6 +100,11 @@ pub(super) async fn connection_task( err.map_or(false, |err| err.is_bad_addr), ); // TODO: should pass a proper value for `is_unreachable`, but an error is sometimes returned despite a timeout https://github.com/paritytech/smoldot/issues/1531 + for chain_index in 0..guarded.network.num_chains() { + guarded + .unassign_slot_and_ban(chain_index, start_connect.expected_peer_id.clone()); + } + // We wake up the background task so that the slot can potentially be // assigned to a different peer. shared.wake_up_main_background_task.notify(1); diff --git a/bin/wasm-node/CHANGELOG.md b/bin/wasm-node/CHANGELOG.md index 9b219c61f3..4f955243d2 100644 --- a/bin/wasm-node/CHANGELOG.md +++ b/bin/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Changed + +- No longer try to connect to a peer for 20 seconds after failing to connect to it. This prevents loops where we keep trying to connect to the same address(es) over and over again ([#2747](https://github.com/paritytech/smoldot/pull/2747)). + ### Added - Add support for the `chainHead_unstable_finalizedDatabase` JSON-RPC method. This JSON-RPC method aims to be a replacement for the `databaseContent` method of the `Chain` and is expected to remain a permanently unstable smoldot-specific function. ([#2749](https://github.com/paritytech/smoldot/pull/2749))