Skip to content

Commit ff404c8

Browse files
mkykadirmattsse
andauthored
feat: trigger resolution task when multiple connection failures occur for a trusted peer (#16652)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent 2fdae16 commit ff404c8

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

crates/net/network-types/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ pub use backoff::BackoffKind;
2525
pub use peers::{
2626
addr::PeerAddr,
2727
kind::PeerKind,
28-
reputation::{is_banned_reputation, ReputationChangeOutcome, DEFAULT_REPUTATION},
28+
reputation::{
29+
is_banned_reputation, is_connection_failed_reputation, ReputationChangeOutcome,
30+
DEFAULT_REPUTATION,
31+
},
2932
state::PeerConnectionState,
3033
ConnectionsConfig, Peer, PeersConfig,
3134
};

crates/net/network-types/src/peers/reputation.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub const BANNED_REPUTATION: i32 = 50 * REPUTATION_UNIT;
1313
const REMOTE_DISCONNECT_REPUTATION_CHANGE: i32 = 4 * REPUTATION_UNIT;
1414

1515
/// The reputation change to apply to a peer that we failed to connect to.
16-
const FAILED_TO_CONNECT_REPUTATION_CHANGE: i32 = 25 * REPUTATION_UNIT;
16+
pub const FAILED_TO_CONNECT_REPUTATION_CHANGE: i32 = 25 * REPUTATION_UNIT;
1717

1818
/// The reputation change to apply to a peer that failed to respond in time.
1919
const TIMEOUT_REPUTATION_CHANGE: i32 = 4 * REPUTATION_UNIT;
@@ -48,6 +48,13 @@ pub const fn is_banned_reputation(reputation: i32) -> bool {
4848
reputation < BANNED_REPUTATION
4949
}
5050

51+
/// Returns `true` if the given reputation is below the [`FAILED_TO_CONNECT_REPUTATION_CHANGE`]
52+
/// threshold
53+
#[inline]
54+
pub const fn is_connection_failed_reputation(reputation: i32) -> bool {
55+
reputation < FAILED_TO_CONNECT_REPUTATION_CHANGE
56+
}
57+
5158
/// The type that tracks the reputation score.
5259
pub type Reputation = i32;
5360

crates/net/network/src/peers.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use reth_net_banlist::BanList;
1414
use reth_network_api::test_utils::{PeerCommand, PeersHandle};
1515
use reth_network_peers::{NodeRecord, PeerId};
1616
use reth_network_types::{
17+
is_connection_failed_reputation,
1718
peers::{
1819
config::PeerBackoffDurations,
1920
reputation::{DEFAULT_REPUTATION, MAX_TRUSTED_PEER_REPUTATION_CHANGE},
@@ -583,6 +584,12 @@ impl PeersManager {
583584
// we already have an active connection to the peer, so we can ignore this error
584585
return
585586
}
587+
588+
if peer.is_trusted() && is_connection_failed_reputation(peer.reputation) {
589+
// trigger resolution task for trusted peer since multiple connection failures
590+
// occurred
591+
self.trusted_peers_resolver.interval.reset_immediately();
592+
}
586593
}
587594

588595
self.on_connection_failure(remote_addr, peer_id, err, ReputationChangeKind::FailedToConnect)

0 commit comments

Comments
 (0)