Skip to content

Commit e8cc790

Browse files
committed
Merge bitcoin/bitcoin#30445: test: addrman: tried 3 times and never a success so isTerrible=true
1807df3 test: addrman: tried 3 times and never a success so `isTerrible=true` (brunoerg) Pull request description: This PR adds test coverage for the following verification: ```cpp if (TicksSinceEpoch<std::chrono::seconds>(m_last_success) == 0 && nAttempts >= ADDRMAN_RETRIES) { // tried N times and never a success return true; } ``` If we've tried an address for 3 or more times and were unsuccessful, this address should be pointed out as "terrible". ------- You can test this by applying: ```diff diff --git a/src/addrman.cpp b/src/addrman.cpp index 054a9be..93a9521b59 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -81,7 +81,7 @@ bool AddrInfo::IsTerrible(NodeSeconds now) const } if (TicksSinceEpoch<std::chrono::seconds>(m_last_success) == 0 && nAttempts >= ADDRMAN_RETRIES) { // tried N times and never a success - return true; + return false; } ``` ACKs for top commit: jonatack: re-ACK 1807df3 naumenkogs: ACK 1807df3 achow101: ACK 1807df3 Tree-SHA512: e3cc43c98bddfe90f585d5b4bd00543be443b77ecaf038615261aa8cc4d14fc2f1006d0b00c04188040eaace455c5c6dbb3bb200a2c0f29c3b4ef5128bf0973a
2 parents 17372d7 + 1807df3 commit e8cc790

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/test/addrman_tests.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,21 @@ BOOST_AUTO_TEST_CASE(getaddr_unfiltered)
448448
CNetAddr source = ResolveIP("250.1.2.1");
449449
BOOST_CHECK(addrman->Add({addr1, addr2}, source));
450450

451-
// Filtered GetAddr should only return addr1
451+
// Set time on this addr so isTerrible = false
452+
CAddress addr3 = CAddress(ResolveService("250.251.2.3", 9998), NODE_NONE);
453+
addr3.nTime = Now<NodeSeconds>();
454+
addrman->Good(addr3, /*time=*/Now<NodeSeconds>());
455+
BOOST_CHECK(addrman->Add({addr3}, source));
456+
// The time is set, but after ADDRMAN_RETRIES unsuccessful attempts not
457+
// retried in the last minute, this addr should be isTerrible = true
458+
for (size_t i = 0; i < 3; ++i) {
459+
addrman->Attempt(addr3, /*fCountFailure=*/true, /*time=*/Now<NodeSeconds>() - 61s);
460+
}
461+
462+
// GetAddr filtered by quality (i.e. not IsTerrible) should only return addr1
452463
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size(), 1U);
453-
// Unfiltered GetAddr should return addr1 and addr2
454-
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size(), 2U);
464+
// Unfiltered GetAddr should return all addrs
465+
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size(), 3U);
455466
}
456467

457468
BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy)

0 commit comments

Comments
 (0)