Review report

core: PR #33663

2 suggestions

Optional improvements

Link

[suggestion] · Ban-list scans extend AddrMan lock hold time

Large operator-configured ban lists can make uncached address selection hold AddrMan’s lock longer, though no concrete production trigger or affected caller was identified.

Location: src/net.cpp:3765 (head).

Details and suggested fix

The policy passed to GetAddr runs while AddrManImpl::cs is held. For each candidate, it calls IsDiscouraged and IsBanned; IsBanned scans and matches every operator-configured ban entry. Thus, with a large ban list, the lock-hold time can grow with the number of candidates checked multiplied by the number of ban entries. The base revision performed these checks after GetAddr returned, on the capped result. Uncapped calls from ASMapHealthCheck and getnodeaddresses 0 can scan every address, and capped selection can also continue scanning if many candidates are rejected. Other code needing AddrMan may wait during that scan. Remote peers can add only O(1) bloom-filter discouragement entries; the linear cost comes from operator-created bans, and the uncached GETADDR path requires operator-granted Addr permission. The behavior change is established, but no concrete production trigger or affected caller was identified, and no latency was measured. State a supported ban-list size or keep BanMan lookups outside AddrManImpl::cs, for example by filtering after GetAddr and requesting more when the result is short. Also correct the policy comment: it says AddrMan::cs, which is not the lock name, and says the policy must be non-blocking without accounting for the ban-list scan.


Link

[suggestion] · Policy tests do not cover capped selection and refill

All new policy assertions request every address, so they would not catch a regression that lets rejected candidates consume a capped result.

Location: src/test/addrman_tests.cpp:480 (head).

Details and suggested fix

The four new policy calls use max_addresses=0 and max_pct=0, so filtering during selection and filtering a capped sample afterward can return the same set. These tests would not detect rejected candidates counting against the limit or filtering moving back after selection. The fuzz additions discard their results, and the functional getnodeaddresses test does not add banned or discouraged entries. Add a capped case whose policy rejects its first candidate and accepts the rest; with max_addresses=1 and filtered=false, assert that one address is returned. This tests refill without depending on shuffle order. A setban case in test_getnodeaddresses that bans most of the imported range and checks the returned count would also cover the CConnman wiring.


Coverage details