Merge bitcoin/bitcoin#30445: test: addrman: tried 3 times and never a success so isTerrible=true
Some checks are pending
CI / Win64 native, VS 2022 (push) Waiting to run
CI / Win64 native fuzz, VS 2022 (push) Waiting to run
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Waiting to run
CI / test each commit (push) Waiting to run
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Waiting to run
CI / macOS 14 native, arm64, fuzz (push) Waiting to run

1807df3d9f 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 054a9bee32..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 1807df3d9f
  naumenkogs:
    ACK 1807df3d9f
  achow101:
    ACK 1807df3d9f

Tree-SHA512: e3cc43c98bddfe90f585d5b4bd00543be443b77ecaf038615261aa8cc4d14fc2f1006d0b00c04188040eaace455c5c6dbb3bb200a2c0f29c3b4ef5128bf0973a
This commit is contained in:
Ava Chow 2024-12-04 15:34:59 -05:00
commit e8cc790fe2
No known key found for this signature in database
GPG key ID: 17565732E08E5E41

View file

@ -448,10 +448,21 @@ BOOST_AUTO_TEST_CASE(getaddr_unfiltered)
CNetAddr source = ResolveIP("250.1.2.1");
BOOST_CHECK(addrman->Add({addr1, addr2}, source));
// Filtered GetAddr should only return addr1
// Set time on this addr so isTerrible = false
CAddress addr3 = CAddress(ResolveService("250.251.2.3", 9998), NODE_NONE);
addr3.nTime = Now<NodeSeconds>();
addrman->Good(addr3, /*time=*/Now<NodeSeconds>());
BOOST_CHECK(addrman->Add({addr3}, source));
// The time is set, but after ADDRMAN_RETRIES unsuccessful attempts not
// retried in the last minute, this addr should be isTerrible = true
for (size_t i = 0; i < 3; ++i) {
addrman->Attempt(addr3, /*fCountFailure=*/true, /*time=*/Now<NodeSeconds>() - 61s);
}
// GetAddr filtered by quality (i.e. not IsTerrible) should only return addr1
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size(), 1U);
// Unfiltered GetAddr should return addr1 and addr2
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size(), 2U);
// Unfiltered GetAddr should return all addrs
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size(), 3U);
}
BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy)