@@ -81,7 +81,7 @@ pub enum AddressState {
8181#[ strum_discriminants( name( AddressStateTransitionToTag ) , derive( strum:: EnumIter ) ) ]
8282pub enum AddressStateTransitionTo {
8383 Connected { peer_role : OutboundPeerRole } ,
84- HasActivity ,
84+ HadActivity ,
8585 Disconnected ,
8686 ConnectionFailed ,
8787 SetReserved ,
@@ -239,7 +239,7 @@ impl AddressData {
239239 }
240240 } ,
241241
242- AddressStateTransitionTo :: HasActivity => match self . state {
242+ AddressStateTransitionTo :: HadActivity => match self . state {
243243 AddressState :: Connected {
244244 had_activity : _,
245245 peer_role,
@@ -253,13 +253,13 @@ impl AddressData {
253253 was_reachable : _,
254254 } => {
255255 debug_panic_or_log ! (
256- "Unexpected address state transition: Disconnected -> HasActivity "
256+ "Unexpected address state transition: Disconnected -> HadActivity "
257257 ) ;
258258 self . state . clone ( )
259259 }
260260 AddressState :: Unreachable { erase_after : _ } => {
261261 debug_panic_or_log ! (
262- "Unexpected address state transition: Unreachable -> HasActivity "
262+ "Unexpected address state transition: Unreachable -> HadActivity "
263263 ) ;
264264 self . state . clone ( )
265265 }
@@ -273,19 +273,20 @@ impl AddressData {
273273 if had_activity {
274274 self . connections_without_activity_count = 0 ;
275275 } else {
276- // We don't increase the counter for:
277- // 1) feeler connections (because it gets disconnected immediately, so the peer may
278- // not have the chance to send us anything);
279- // 2) manual connections;
280- let is_regular_auto_connection = match peer_role {
281- OutboundPeerRole :: OutboundFullRelay
282- | OutboundPeerRole :: OutboundBlockRelay
283- | OutboundPeerRole :: OutboundReserved => true ,
284-
285- OutboundPeerRole :: Feeler | OutboundPeerRole :: OutboundManual => false ,
286- } ;
287-
288- if is_regular_auto_connection {
276+ // Note:
277+ // 1) We don't increase the counter for manual connections.
278+ // 2) Since `is_message_exchange_expected` doesn't know the actual services
279+ // that the peer provides, it's technically possible to punish an
280+ // "innocent" peer here, e.g. when the connection type is supposed to involve
281+ // block exchange, but the peer's actual services don't include Blocks.
282+ // However:
283+ // a) The worst punishment it can get is that the next connection will be
284+ // postponed for (roughly) MAX_DELAY_REACHABLE, which is currently 1 hour.
285+ // b) Such a peer will be rather useless anyway.
286+ // c) The connection has to be short enough, so that even a single PingRequest message
287+ // (which requires a response) could not be sent.
288+ // So it's not a big deal.
289+ if peer_role. is_message_exchange_expected ( ) && !peer_role. is_manual ( ) {
289290 self . connections_without_activity_count += 1 ;
290291 }
291292 }
0 commit comments