diff --git a/crates/net/network/src/peers/manager.rs b/crates/net/network/src/peers/manager.rs index 57159cb19e..4210cb029e 100644 --- a/crates/net/network/src/peers/manager.rs +++ b/crates/net/network/src/peers/manager.rs @@ -114,7 +114,7 @@ pub struct PeersManager { /// Timestamp of the last time [Self::tick] was called. last_tick: Instant, /// Maximum number of backoff attempts before we give up on a peer and dropping. - max_backoff_count: u32, + max_backoff_count: u8, /// Tracks the connection state of the node net_connection_state: NetworkConnectionState, } @@ -489,7 +489,7 @@ impl PeersManager { if let Some(kind) = err.should_backoff() { // Increment peer.backoff_counter if kind.is_severe() { - peer.severe_backoff_counter += 1; + peer.severe_backoff_counter = peer.severe_backoff_counter.saturating_add(1); } let backoff_time = @@ -902,7 +902,7 @@ pub struct Peer { /// Whether the peer is currently backed off. backed_off: bool, /// Counts number of times the peer was backed off due to a severe [BackoffKind]. - severe_backoff_counter: u32, + severe_backoff_counter: u8, } // === impl Peer === @@ -1143,7 +1143,7 @@ pub struct PeersConfig { /// peer in the table is the sum of all backoffs (1h + 2h + 3h + 4h + 5h = 15h). /// /// Note: this does not apply to trusted peers. - pub max_backoff_count: u32, + pub max_backoff_count: u8, /// Basic nodes to connect to. #[cfg_attr(feature = "serde", serde(skip))] pub basic_nodes: HashSet, @@ -1260,7 +1260,7 @@ impl PeersConfig { } /// Configures the max allowed backoff count. - pub fn with_max_backoff_count(mut self, max_backoff_count: u32) -> Self { + pub fn with_max_backoff_count(mut self, max_backoff_count: u8) -> Self { self.max_backoff_count = max_backoff_count; self } @@ -1329,9 +1329,9 @@ impl PeerBackoffDurations { /// Returns the timestamp until which we should backoff. /// /// The Backoff duration is capped by the configured maximum backoff duration. - pub fn backoff_until(&self, kind: BackoffKind, backoff_counter: u32) -> std::time::Instant { + pub fn backoff_until(&self, kind: BackoffKind, backoff_counter: u8) -> std::time::Instant { let backoff_time = self.backoff(kind); - let backoff_time = backoff_time + backoff_time * backoff_counter; + let backoff_time = backoff_time + backoff_time * backoff_counter as u32; let now = std::time::Instant::now(); now + backoff_time.min(self.max) }