Skip to content

Ban peers after repeated invalid channel messages - #1532

Draft
quake wants to merge 4 commits into
developfrom
fix/rate-limit-invalid-channel-messages
Draft

Ban peers after repeated invalid channel messages#1532
quake wants to merge 4 commits into
developfrom
fix/rate-limit-invalid-channel-messages

Conversation

@quake

@quake quake commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • track per-peer count of messages targeting non-existent channels
  • disconnect and ban peer after 20 repeated invalid messages
  • cleanup counter on normal peer disconnect

Tests

  • cargo check -p fnn --features sqlite
  • cargo fmt --all -- --check
  • git diff --check

@quake
quake requested review from chenyukang and jjyr July 7, 2026 03:52
chenyukang

This comment was marked as duplicate.

@chenyukang chenyukang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline notes for the issues I mentioned in the earlier review summary.

Comment thread crates/fiber-lib/src/fiber/network.rs
Comment thread crates/fiber-lib/src/fiber/network.rs Outdated
Comment thread crates/fiber-lib/src/fiber/network.rs Outdated
@quake
quake requested a review from chenyukang July 21, 2026 04:50
Comment thread crates/fiber-lib/src/fiber/network.rs Outdated
}

self.peer_session_map.remove(&pubkey);
self.invalid_channel_msg_count.remove(&pubkey);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve invalid-message strikes across voluntary reconnects

This removes the per-peer counter on every normal disconnect, but the ban is only created when the counter becomes greater than 20. A peer can therefore send exactly 20 invalid-channel messages, disconnect voluntarily, reconnect with a fresh counter, and repeat indefinitely without ever entering banned_peers. Please retain the violation state across disconnects until an explicit expiry window, and add a regression test covering 20 invalid messages, disconnect, reconnect, then one more invalid message.

return;
}
// Ban expired, clean up
self.banned_peers.remove(&remote_pubkey);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Expire temporary bans independently of an inbound reconnect

Expired entries are removed only when the same peer reaches on_peer_connected. Banning also inserts the peer into requested_disconnect_peers, so all local reconnect paths skip it. If the remote peer does not initiate another connection after the ten-minute deadline, no code removes either entry or resumes local reconnects: the temporary ban effectively becomes permanent for outbound connectivity, and peers that never return leave stale entries in both maps indefinitely. Please schedule expiry or purge expired bans during maintenance, remove the requested-disconnect marker, and resume reconnect backoff where appropriate.

@quake
quake marked this pull request as draft July 27, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants