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,674 Lines • ▼ Show 20 Lines | m_connman.ForEachNode([](CNode *pnode) { | ||||
if (pnode->m_avalanche_state) { | if (pnode->m_avalanche_state) { | ||||
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_outbound_ids; | std::vector<NodeId> avanode_ids; | ||||
const bool fQuorumEstablished = | |||||
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; | ||||
} | } | ||||
m_connman.ForEachNode([&](CNode *pnode) { | m_connman.ForEachNode([&](CNode *pnode) { | ||||
// Build a list of the avalanche manual or outbound peers nodeids | // Build a list of the avalanche peers nodeids | ||||
if (pnode->m_avalanche_state && !pnode->IsInboundConn()) { | if (pnode->m_avalanche_state && | ||||
avanode_outbound_ids.push_back(pnode->GetId()); | (!fQuorumEstablished || !pnode->IsInboundConn())) { | ||||
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_outbound_ids.empty()) { | if (avanode_ids.empty()) { | ||||
// Not node is available for messaging, retry later | // No node is available for messaging, retry later | ||||
goto scheduleLater; | goto scheduleLater; | ||||
} | } | ||||
Shuffle(avanode_outbound_ids.begin(), avanode_outbound_ids.end(), | Shuffle(avanode_ids.begin(), avanode_ids.end(), FastRandomContext()); | ||||
FastRandomContext()); | |||||
if (!g_avalanche->isQuorumEstablished() || | if (!fQuorumEstablished || | ||||
g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | ||||
return pm.shouldRequestMoreNodes(); | return pm.shouldRequestMoreNodes(); | ||||
})) { | })) { | ||||
// Randomly select an avalanche outbound peer to send the getavaaddr | // Randomly select an avalanche peer to send the getavaaddr message to | ||||
// message to | const NodeId avanodeId = avanode_ids.front(); | ||||
const NodeId avanodeId = avanode_outbound_ids.front(); | |||||
m_connman.ForNode(avanodeId, [&](CNode *pavanode) { | m_connman.ForNode(avanodeId, [&](CNode *pavanode) { | ||||
LogPrint(BCLog::AVALANCHE, | LogPrint(BCLog::AVALANCHE, | ||||
"Requesting more avalanche addresses to peer %d\n", | "Requesting more avalanche addresses to 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)); | ||||
Show All 9 Lines | if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) { | ||||
// because we don't have the UTXOs. | // because we don't have the UTXOs. | ||||
goto scheduleLater; | goto scheduleLater; | ||||
} | } | ||||
// If we never had an avaproofs message yet, be kind and only request to a | // If we never had an avaproofs message yet, be kind and only request to a | ||||
// subset of our peers as we expect a ton of avaproofs message in the | // subset of our peers as we expect a ton of avaproofs message in the | ||||
// process. | // process. | ||||
if (g_avalanche->getAvaproofsNodeCounter() == 0) { | if (g_avalanche->getAvaproofsNodeCounter() == 0) { | ||||
avanode_outbound_ids.resize( | avanode_ids.resize(std::min<size_t>(avanode_ids.size(), 3)); | ||||
std::min<size_t>(avanode_outbound_ids.size(), 3)); | |||||
} | } | ||||
for (NodeId nodeid : avanode_outbound_ids) { | for (NodeId nodeid : avanode_ids) { | ||||
// Send a getavaproofs to one of our peers | // Send a getavaproofs to one of our peers | ||||
m_connman.ForNode(nodeid, [&](CNode *pavanode) { | m_connman.ForNode(nodeid, [&](CNode *pavanode) { | ||||
LogPrint(BCLog::AVALANCHE, | LogPrint(BCLog::AVALANCHE, | ||||
"Requesting compact proofs from peer %d\n", | "Requesting compact proofs from peer %d\n", | ||||
pavanode->GetId()); | pavanode->GetId()); | ||||
if (pavanode->m_proof_relay) { | if (pavanode->m_proof_relay) { | ||||
m_connman.PushMessage(pavanode, | m_connman.PushMessage(pavanode, | ||||
CNetMsgMaker(pavanode->GetCommonVersion()) | CNetMsgMaker(pavanode->GetCommonVersion()) | ||||
▲ Show 20 Lines • Show All 5,366 Lines • Show Last 20 Lines |