Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 1,675 Lines • ▼ Show 20 Lines | m_connman.ForEachNode([](CNode *pnode) { | ||||
pnode->m_avalanche_state->updateAvailabilityScore(); | pnode->m_avalanche_state->updateAvailabilityScore(); | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
void PeerManagerImpl::AvalanchePeriodicNetworking(CScheduler &scheduler) const { | void PeerManagerImpl::AvalanchePeriodicNetworking(CScheduler &scheduler) const { | ||||
const auto now = GetTime<std::chrono::seconds>(); | const auto now = GetTime<std::chrono::seconds>(); | ||||
std::vector<NodeId> avanode_ids; | std::vector<NodeId> avanode_ids; | ||||
bool fQuorumEstablished; | |||||
const bool fQuorumEstablished = | bool fShouldRequestMoreNodes; | ||||
g_avalanche && g_avalanche->isQuorumEstablished(); | |||||
if (!g_avalanche) { | if (!g_avalanche) { | ||||
// Not enabled or not ready yet, retry later | // Not enabled or not ready yet, retry later | ||||
goto scheduleLater; | goto scheduleLater; | ||||
} | } | ||||
fQuorumEstablished = g_avalanche->isQuorumEstablished(); | |||||
fShouldRequestMoreNodes = | |||||
g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | |||||
return pm.shouldRequestMoreNodes(); | |||||
}); | |||||
m_connman.ForEachNode([&](CNode *pnode) { | m_connman.ForEachNode([&](CNode *pnode) { | ||||
// Build a list of the avalanche peers nodeids | // Build a list of the avalanche peers nodeids | ||||
if (pnode->m_avalanche_state && | if (pnode->m_avalanche_state && | ||||
(!fQuorumEstablished || !pnode->IsInboundConn())) { | (!fQuorumEstablished || !pnode->IsInboundConn())) { | ||||
avanode_ids.push_back(pnode->GetId()); | avanode_ids.push_back(pnode->GetId()); | ||||
} | } | ||||
// If a proof radix tree timed out, cleanup | // If a proof radix tree timed out, cleanup | ||||
if (pnode->m_proof_relay && | if (pnode->m_proof_relay && | ||||
now > (pnode->m_proof_relay->lastSharedProofsUpdate.load() + | now > (pnode->m_proof_relay->lastSharedProofsUpdate.load() + | ||||
AVALANCHE_AVAPROOFS_TIMEOUT)) { | AVALANCHE_AVAPROOFS_TIMEOUT)) { | ||||
pnode->m_proof_relay->sharedProofs = {}; | pnode->m_proof_relay->sharedProofs = {}; | ||||
} | } | ||||
}); | }); | ||||
if (avanode_ids.empty()) { | if (avanode_ids.empty()) { | ||||
// No node is available for messaging, retry later | // No node is available for messaging, retry later | ||||
goto scheduleLater; | goto scheduleLater; | ||||
} | } | ||||
Shuffle(avanode_ids.begin(), avanode_ids.end(), FastRandomContext()); | Shuffle(avanode_ids.begin(), avanode_ids.end(), FastRandomContext()); | ||||
if (!fQuorumEstablished || | // Request avalanche addresses from our peers | ||||
g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | for (NodeId avanodeId : avanode_ids) { | ||||
return pm.shouldRequestMoreNodes(); | |||||
})) { | |||||
// Randomly select an avalanche peer to send the getavaaddr message to | |||||
const NodeId avanodeId = avanode_ids.front(); | |||||
m_connman.ForNode(avanodeId, [&](CNode *pavanode) { | m_connman.ForNode(avanodeId, [&](CNode *pavanode) { | ||||
LogPrint(BCLog::AVALANCHE, | LogPrint(BCLog::AVALANCHE, | ||||
"Requesting more avalanche addresses from peer %d\n", | "Requesting more avalanche addresses from peer %d\n", | ||||
avanodeId); | avanodeId); | ||||
m_connman.PushMessage(pavanode, | m_connman.PushMessage(pavanode, | ||||
CNetMsgMaker(pavanode->GetCommonVersion()) | CNetMsgMaker(pavanode->GetCommonVersion()) | ||||
.Make(NetMsgType::GETAVAADDR)); | .Make(NetMsgType::GETAVAADDR)); | ||||
PeerRef peer = GetPeerRef(avanodeId); | PeerRef peer = GetPeerRef(avanodeId); | ||||
WITH_LOCK(peer->m_addr_token_bucket_mutex, | WITH_LOCK(peer->m_addr_token_bucket_mutex, | ||||
peer->m_addr_token_bucket += GetMaxAddrToSend()); | peer->m_addr_token_bucket += GetMaxAddrToSend()); | ||||
return true; | return true; | ||||
}); | }); | ||||
// If we have no reason to believe that we need more nodes, only request | |||||
// addresses from one of our peers. | |||||
if (fQuorumEstablished && !fShouldRequestMoreNodes) { | |||||
break; | |||||
} | |||||
} | } | ||||
if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) { | if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) { | ||||
// Don't request proofs while in IBD. We're likely to orphan them | // Don't request proofs while in IBD. We're likely to orphan them | ||||
// because we don't have the UTXOs. | // because we don't have the UTXOs. | ||||
goto scheduleLater; | goto scheduleLater; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 5,391 Lines • Show Last 20 Lines |