Skip to content

Commit

Permalink
Temporarily ban peers after failing to connect to them (#2747)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored Sep 15, 2022
1 parent 047371f commit c660afd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/full-node/src/run/network_service/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions bin/light-base/src/network_service/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ pub(super) async fn connection_task<TPlat: Platform>(
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);
Expand Down
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit c660afd

Please sign in to comment.