mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge bitcoin/bitcoin#22791: init: Fix asmap/addrman initialization order bug
724c497562[fuzz] Add ConsumeAsmap() function (John Newbery)5840476714[addrman] Make m_asmap private (John Newbery)f9002cb5db[net] Rename the copyStats arg from m_asmap to asmap (John Newbery)f572f2b204[addrman] Set m_asmap in CAddrMan initializer list (John Newbery)593247872d[net] Remove CConnMan::SetAsmap() (John Newbery)50fd77045e[init] Read/decode asmap before constructing addrman (John Newbery) Pull request description: Commit181a1207introduced an initialization order bug: CAddrMan's m_asmap must be set before deserializing peers.dat. The first commit restores the correct initialization order. The remaining commits make `CAddrMan::m_asmap` usage safer: - don't reach into `CAddrMan`'s internal data from `CConnMan` - set `m_asmap` in the initializer list and make it const - make `m_asmap` private, and access it (as a reference to const) from a getter. This ensures that peers.dat deserialization must happen after setting m_asmap, since m_asmap is set during CAddrMan construction. ACKs for top commit: mzumsande: Tested ACK724c497562amitiuttarwar: code review but utACK724c497562naumenkogs: utACK724c497562vasild: ACK724c497562MarcoFalke: review ACK724c497562👫 Tree-SHA512: 684a4cf9e3d4496c9997fb2bc4ec874809987055c157ec3fad1d2143b8223df52b5a0af787d028930b27388c8efeba0aeb2446cb35c337a5552ae76112ade726
This commit is contained in:
14
src/net.cpp
14
src/net.cpp
@@ -552,14 +552,14 @@ Network CNode::ConnectedThroughNetwork() const
|
||||
|
||||
#undef X
|
||||
#define X(name) stats.name = name
|
||||
void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
||||
void CNode::CopyStats(CNodeStats& stats, const std::vector<bool>& asmap)
|
||||
{
|
||||
stats.nodeid = this->GetId();
|
||||
X(nServices);
|
||||
X(addr);
|
||||
X(addrBind);
|
||||
stats.m_network = ConnectedThroughNetwork();
|
||||
stats.m_mapped_as = addr.GetMappedAS(m_asmap);
|
||||
stats.m_mapped_as = addr.GetMappedAS(asmap);
|
||||
if (m_tx_relay != nullptr) {
|
||||
LOCK(m_tx_relay->cs_filter);
|
||||
stats.fRelayTxes = m_tx_relay->fRelayTxes;
|
||||
@@ -1921,7 +1921,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
case ConnectionType::BLOCK_RELAY:
|
||||
case ConnectionType::ADDR_FETCH:
|
||||
case ConnectionType::FEELER:
|
||||
setConnected.insert(pnode->addr.GetGroup(addrman.m_asmap));
|
||||
setConnected.insert(pnode->addr.GetGroup(addrman.GetAsmap()));
|
||||
} // no default case, so the compiler can warn about missing cases
|
||||
}
|
||||
}
|
||||
@@ -1995,7 +1995,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
m_anchors.pop_back();
|
||||
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
|
||||
!HasAllDesirableServiceFlags(addr.nServices) ||
|
||||
setConnected.count(addr.GetGroup(addrman.m_asmap))) continue;
|
||||
setConnected.count(addr.GetGroup(addrman.GetAsmap()))) continue;
|
||||
addrConnect = addr;
|
||||
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToString());
|
||||
break;
|
||||
@@ -2035,7 +2035,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
}
|
||||
|
||||
// Require outbound connections, other than feelers, to be to distinct network groups
|
||||
if (!fFeeler && setConnected.count(addr.GetGroup(addrman.m_asmap))) {
|
||||
if (!fFeeler && setConnected.count(addr.GetGroup(addrman.GetAsmap()))) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2804,7 +2804,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
|
||||
vstats.reserve(vNodes.size());
|
||||
for (CNode* pnode : vNodes) {
|
||||
vstats.emplace_back();
|
||||
pnode->copyStats(vstats.back(), addrman.m_asmap);
|
||||
pnode->CopyStats(vstats.back(), addrman.GetAsmap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3067,7 +3067,7 @@ CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
|
||||
|
||||
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const
|
||||
{
|
||||
std::vector<unsigned char> vchNetGroup(ad.GetGroup(addrman.m_asmap));
|
||||
std::vector<unsigned char> vchNetGroup(ad.GetGroup(addrman.GetAsmap()));
|
||||
|
||||
return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup.data(), vchNetGroup.size()).Finalize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user