test: addrman: successive failures in the last week for IsTerrible
What changed, and why it matters
This commit only adds a new unit test for Bitcoin Core's address manager. It checks that an address with many recent connection failures is correctly marked as 'terrible' and filtered out when peers are returned, while still remaining in the unfiltered list. There is no change to production code.
No security action required; this is a test-only addition. Reviewers may optionally confirm the test accurately reflects the intended IsTerrible semantics.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures) to src/test/addrman_tests.cpp. The test exercises AddrMan::IsTerrible behavior by simulating ADDRMAN_MAX_FAILURES failed attempts spread over more than ADDRMAN_MIN_FAIL + 24h, then verifying that GetAddr() with default filtering excludes the terrible address but GetAddr(filtered=false) still includes it. No source or header files are modified.
Changed components
src/test/addrman_tests.cppInspect captured patch +36 / −0
diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp
index a085c1f5..e9069079 100644
--- a/src/test/addrman_tests.cpp
+++ b/src/test/addrman_tests.cpp
@@ -93,6 +93,42 @@ BOOST_AUTO_TEST_CASE(addrman_simple)
BOOST_CHECK(addrman->Size() >= 1);
}
+
+BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)
+{
+ auto now = Now<NodeSeconds>();
+ SetMockTime(now - (ADDRMAN_MIN_FAIL + 24h));
+
+ auto addrman{std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node))};
+
+ CNetAddr source{ResolveIP("250.1.2.1")};
+ CAddress addr{CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE)};
+ addr.nTime = Now<NodeSeconds>();
+
+ BOOST_CHECK(addrman->Add({addr}, source));
+ BOOST_CHECK(addrman->Good(addr));
+
+ SetMockTime(now);
+
+ CAddress addr_helper{CAddress(ResolveService("251.252.2.3", 8333), NODE_NONE)};
+ addr_helper.nTime = Now<NodeSeconds>();
+ BOOST_CHECK(addrman->Add({addr_helper}, source));
+ BOOST_CHECK(addrman->Good(addr_helper));
+
+ for (int i = 0; i < ADDRMAN_MAX_FAILURES; ++i) {
+ // Use a time > 60s ago so IsTerrible doesn't bail out at the "tried in the last minute" check
+ addrman->Attempt(addr, /*fCountFailure=*/true, Now<NodeSeconds>() - 61s);
+ }
+
+ std::vector<CAddress> filtered{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)};
+ BOOST_CHECK_EQUAL(filtered.size(), 1U);
+ BOOST_CHECK_EQUAL(filtered[0].ToStringAddrPort(), "251.252.2.3:8333");
+
+ std::vector<CAddress> unfiltered{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false)};
+ BOOST_CHECK_EQUAL(unfiltered.size(), 2U);
+}
+
+
BOOST_AUTO_TEST_CASE(addrman_penalty_self_announcement)
{
SetMockTime(Now<NodeSeconds>());
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.