feat: trigger resolution task when multiple connection failures occur for a trusted peer (#16652)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Muhammed Kadir Yücel
2025-06-04 15:32:58 +03:00
committed by GitHub
parent 2fdae16d5f
commit ff404c80e2
3 changed files with 19 additions and 2 deletions

View File

@@ -25,7 +25,10 @@ pub use backoff::BackoffKind;
pub use peers::{
addr::PeerAddr,
kind::PeerKind,
reputation::{is_banned_reputation, ReputationChangeOutcome, DEFAULT_REPUTATION},
reputation::{
is_banned_reputation, is_connection_failed_reputation, ReputationChangeOutcome,
DEFAULT_REPUTATION,
},
state::PeerConnectionState,
ConnectionsConfig, Peer, PeersConfig,
};

View File

@@ -13,7 +13,7 @@ pub const BANNED_REPUTATION: i32 = 50 * REPUTATION_UNIT;
const REMOTE_DISCONNECT_REPUTATION_CHANGE: i32 = 4 * REPUTATION_UNIT;
/// The reputation change to apply to a peer that we failed to connect to.
const FAILED_TO_CONNECT_REPUTATION_CHANGE: i32 = 25 * REPUTATION_UNIT;
pub const FAILED_TO_CONNECT_REPUTATION_CHANGE: i32 = 25 * REPUTATION_UNIT;
/// The reputation change to apply to a peer that failed to respond in time.
const TIMEOUT_REPUTATION_CHANGE: i32 = 4 * REPUTATION_UNIT;
@@ -48,6 +48,13 @@ pub const fn is_banned_reputation(reputation: i32) -> bool {
reputation < BANNED_REPUTATION
}
/// Returns `true` if the given reputation is below the [`FAILED_TO_CONNECT_REPUTATION_CHANGE`]
/// threshold
#[inline]
pub const fn is_connection_failed_reputation(reputation: i32) -> bool {
reputation < FAILED_TO_CONNECT_REPUTATION_CHANGE
}
/// The type that tracks the reputation score.
pub type Reputation = i32;

View File

@@ -14,6 +14,7 @@ use reth_net_banlist::BanList;
use reth_network_api::test_utils::{PeerCommand, PeersHandle};
use reth_network_peers::{NodeRecord, PeerId};
use reth_network_types::{
is_connection_failed_reputation,
peers::{
config::PeerBackoffDurations,
reputation::{DEFAULT_REPUTATION, MAX_TRUSTED_PEER_REPUTATION_CHANGE},
@@ -583,6 +584,12 @@ impl PeersManager {
// we already have an active connection to the peer, so we can ignore this error
return
}
if peer.is_trusted() && is_connection_failed_reputation(peer.reputation) {
// trigger resolution task for trusted peer since multiple connection failures
// occurred
self.trusted_peers_resolver.interval.reset_immediately();
}
}
self.on_connection_failure(remote_addr, peer_id, err, ReputationChangeKind::FailedToConnect)