mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge bitcoin/bitcoin#22179: Torv2 removal followups
00b875ba94addrman: remove invalid addresses when unserializing (Vasil Dimov)bdb62096f0fuzz: reduce possible networks check (Vasil Dimov)a164cd3ba6net: simplify CNetAddr::IsRoutable() (Vasil Dimov) Pull request description: * Simplify some code, now that we know `CNetAddr::IsRFC4193()` and `CNetAddr::IsTor()` cannot be `true` at the same time. * Drop Tor v2 addresses when loading addrman from `peers.dat` - they would have been loaded as dummy-all-zeros IPv6 addresses and linger in addrman, wasting space. ACKs for top commit: sipa: ACK00b875ba94. Reviewed the code, and tested with -DDEBUG_ADDRMAN (unit tests + mainnet run with peers.dat that contained v2 onions). laanwj: Code review and lightly tested ACK00b875ba94jonatack: ACK00b875ba94reviewed, debug-built with -DEBUG_ADDRMAN rebased to current master, restarted node on mainnet/signet/testnet and verified that on each chain -addrinfo shows no change in address counts (as expected). Added some sanity check asserts, rebuilt/re-ran test. Checked that the new test fails on master with "test/addrman_tests.cpp(824): error: in "addrman_tests/remove_invalid": check addrman.size() == 2 has failed [4 != 2]" jarolrod: ACK00b875ba94Tree-SHA512: 6ed8e6745134b1b94fffaba28482de909ea39483b46b7f57bda61cdbae7a51251d15cb674de3631772fbeabe153d77a19269f96e62a89102a2d5c01e48f0ba06
This commit is contained in:
@@ -77,6 +77,38 @@ double CAddrInfo::GetChance(int64_t nNow) const
|
||||
return fChance;
|
||||
}
|
||||
|
||||
void CAddrMan::RemoveInvalid()
|
||||
{
|
||||
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; ++bucket) {
|
||||
for (size_t i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
|
||||
const auto id = vvNew[bucket][i];
|
||||
if (id != -1 && !mapInfo[id].IsValid()) {
|
||||
ClearNew(bucket, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; ++bucket) {
|
||||
for (size_t i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
|
||||
const auto id = vvTried[bucket][i];
|
||||
if (id == -1) {
|
||||
continue;
|
||||
}
|
||||
const auto& addr_info = mapInfo[id];
|
||||
if (addr_info.IsValid()) {
|
||||
continue;
|
||||
}
|
||||
vvTried[bucket][i] = -1;
|
||||
--nTried;
|
||||
SwapRandom(addr_info.nRandomPos, vRandom.size() - 1);
|
||||
vRandom.pop_back();
|
||||
mapAddr.erase(addr_info);
|
||||
mapInfo.erase(id);
|
||||
m_tried_collisions.erase(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
|
||||
Reference in New Issue
Block a user