Page MenuHomePhabricator

p2p: AddrFetch - don't disconnect on self-announcements
ClosedPublic

Authored by Fabien on Jan 28 2022, 11:26.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Maniphest Tasks
Restricted Maniphest Task
Commits
rABC7cb864e19430: p2p: AddrFetch - don't disconnect on self-announcements
Summary
AddrFetch connections (old name: oneshots) are intended to be short-lived connections on which we ask a peer for addresses via getaddr and disconnect after receiving them.

This is done by disconnecting after receiving the first addr. However, it is no longer working as intended, because nowadays, the first addr a typical bitcoin core node sends is its self-announcement.
So we'll disconnect before the peer gets a chance to answer our getaddr.

I checked that this affects both -seednode peers specified manually, and DNS seeds when AddrFetch is used as a fallback if DNS doesn't work for us.

The current behavior of getting peers via AddrFetch when starting with an empty addrman would be to connect to the peer, receive its self-announcement and add it to addrman, disconnect, reconnect to the same peer again as a full outbound (no other addresses in addrman) and then receive more addr. This is silly and not in line with AddrFetch peer being intended to be short-lived peers.

Fix this by only disconnecting after receiving an addr message of size > 1.

[Edit] As per review discussion, this PR now also adds a timeout after which we disconnect if we haven't received any suitable addr, and a functional test.

Backport of core#22096.

Ref T1696.

Test Plan
ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable