Skip to content

P2P: fix address book panic when banning a peer - #668

Open
thomasbuilds wants to merge 1 commit into
Cuprate:mainfrom
thomasbuilds:fix-address-book-ban-id
Open

P2P: fix address book panic when banning a peer#668
thomasbuilds wants to merge 1 commit into
Cuprate:mainfrom
thomasbuilds:fix-address-book-ban-id

Conversation

@thomasbuilds

@thomasbuilds thomasbuilds commented Aug 6, 2026

Copy link
Copy Markdown

handle_new_connection inserted into connected_peers_ban_id before update_white_list_peer_entry, which fails when a peer already in the white list connects advertising a different pruning seed. The index then kept an entry for a connection never added to connected_peers, and eviction only walks connected_peers, so it stayed.

ban_peer looked those entries back up in connected_peers and expected them to be there, so banning any peer sharing that ban ID ended the process, as the workspace sets panic = "abort".

Remove connected_peers_ban_id rather than reorder the insert: it only answered which connected peers share a ban ID, which is a filter over connected_peers that cannot disagree with it. This also drops the two lookups in the disconnect handling that assumed they agreed.

Anchor removal was wrong in three ways. ban_peer bound the iterated address inside a closure, so the removal in the loop body used the banned address instead of each closed peer's. Both it and the disconnect path keyed off the connection address, while the anchor list is keyed by the address the peer is reachable on, which differs for inbound peers. And the disconnect path dropped the entry even when another connection to that address was still open. Both now key off the reachable address, and the disconnect path waits for the last connection to close.

@github-actions github-actions Bot added the A-p2p Area: Related to P2P. label Aug 7, 2026
`handle_new_connection` inserted into `connected_peers_ban_id` before
`update_white_list_peer_entry`, which fails when a peer already in the
white list connects advertising a different pruning seed. The index then
kept an entry for a connection never added to `connected_peers`, and
eviction only walks `connected_peers`, so it stayed.

`ban_peer` looked those entries back up in `connected_peers` and
`expect`ed them to be there, so banning any peer sharing that ban ID
ended the process, as the workspace sets `panic = "abort"`.

Remove `connected_peers_ban_id` rather than reorder the insert: it only
answered which connected peers share a ban ID, which is a filter over
`connected_peers` that cannot disagree with it. This also drops the two
lookups in the disconnect handling that assumed they agreed.

Anchor removal was wrong in three ways. `ban_peer` bound the iterated
address inside a closure, so the removal in the loop body used the
banned address instead of each closed peer's. Both it and the disconnect
path keyed off the connection address, while the anchor list is keyed by
the address the peer is reachable on, which differs for inbound peers.
And the disconnect path dropped the entry even when another connection
to that address was still open. Both now key off the reachable address,
and the disconnect path waits for the last connection to close.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-p2p Area: Related to P2P.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants