Replace CConnman global pointer with local member

This commit is contained in:
Kittywhiskers Van Gogh 2022-01-09 17:08:21 +05:30
parent 12d6597aa7
commit f90cd9fe37
10 changed files with 38 additions and 38 deletions

View File

@ -194,7 +194,7 @@ void CMNAuth::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList&
return; return;
} }
g_connman->ForEachNode([&](CNode* pnode) { connman.ForEachNode([&](CNode* pnode) {
const auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash(); const auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
if (verifiedProRegTxHash.IsNull()) { if (verifiedProRegTxHash.IsNull()) {
return; return;

View File

@ -693,7 +693,7 @@ void CQuorumBlockProcessor::AddMineableCommitment(const CFinalCommitment& fqc)
// We only relay the new commitment if it's new or better then the old one // We only relay the new commitment if it's new or better then the old one
if (relay) { if (relay) {
CInv inv(MSG_QUORUM_FINAL_COMMITMENT, commitmentHash); CInv inv(MSG_QUORUM_FINAL_COMMITMENT, commitmentHash);
g_connman->RelayInv(inv); connman.RelayInv(inv);
} }
} }

View File

@ -151,7 +151,7 @@ void CChainLocksHandler::ProcessNewChainLock(const NodeId from, const llmq::CCha
// Note: do not hold cs while calling RelayInv // Note: do not hold cs while calling RelayInv
AssertLockNotHeld(cs); AssertLockNotHeld(cs);
g_connman->RelayInv(clsigInv); connman.RelayInv(clsigInv);
if (pindex == nullptr) { if (pindex == nullptr) {
// we don't know the block/header for this CLSIG yet, so bail out for now // we don't know the block/header for this CLSIG yet, so bail out for now

View File

@ -451,7 +451,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const
CDKGLogger logger(*this, __func__); CDKGLogger logger(*this, __func__);
std::unordered_map<uint256, int, StaticSaltedHasher> protoMap; std::unordered_map<uint256, int, StaticSaltedHasher> protoMap;
g_connman->ForEachNode([&](const CNode* pnode) { connman.ForEachNode([&](const CNode* pnode) {
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash(); auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
if (verifiedProRegTxHash.IsNull()) { if (verifiedProRegTxHash.IsNull()) {
return; return;
@ -1311,14 +1311,14 @@ void CDKGSession::RelayInvToParticipants(const CInv& inv) const
logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]", logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]",
inv.ToString(), inv.ToString(),
relayMembers.size(), relayMembers.size(),
g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL), connman.GetNodeCount(CConnman::CONNECTIONS_ALL),
g_connman->GetNetworkActive(), connman.GetNetworkActive(),
g_connman->HasMasternodeQuorumNodes(params.type, m_quorum_base_block_index->GetBlockHash()), connman.HasMasternodeQuorumNodes(params.type, m_quorum_base_block_index->GetBlockHash()),
m_quorum_base_block_index->GetBlockHash().ToString(), m_quorum_base_block_index->GetBlockHash().ToString(),
myProTxHash.ToString().substr(0, 4), ss.str()); myProTxHash.ToString().substr(0, 4), ss.str());
std::stringstream ss2; std::stringstream ss2;
g_connman->ForEachNode([&](CNode* pnode) { connman.ForEachNode([&](CNode* pnode) {
if (pnode->qwatch || if (pnode->qwatch ||
(!pnode->GetVerifiedProRegTxHash().IsNull() && relayMembers.count(pnode->GetVerifiedProRegTxHash()))) { (!pnode->GetVerifiedProRegTxHash().IsNull() && relayMembers.count(pnode->GetVerifiedProRegTxHash()))) {
pnode->PushInventory(inv); pnode->PushInventory(inv);

View File

@ -1112,11 +1112,11 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& has
const auto is_det = islock->IsDeterministic(); const auto is_det = islock->IsDeterministic();
CInv inv(is_det ? MSG_ISDLOCK : MSG_ISLOCK, hash); CInv inv(is_det ? MSG_ISDLOCK : MSG_ISLOCK, hash);
if (tx != nullptr) { if (tx != nullptr) {
g_connman->RelayInvFiltered(inv, *tx, is_det ? ISDLOCK_PROTO_VERSION : MIN_PEER_PROTO_VERSION); connman.RelayInvFiltered(inv, *tx, is_det ? ISDLOCK_PROTO_VERSION : MIN_PEER_PROTO_VERSION);
} else { } else {
// we don't have the TX yet, so we only filter based on txid. Later when that TX arrives, we will re-announce // we don't have the TX yet, so we only filter based on txid. Later when that TX arrives, we will re-announce
// with the TX taken into account. // with the TX taken into account.
g_connman->RelayInvFiltered(inv, islock->txid, is_det ? ISDLOCK_PROTO_VERSION : MIN_PEER_PROTO_VERSION); connman.RelayInvFiltered(inv, islock->txid, is_det ? ISDLOCK_PROTO_VERSION : MIN_PEER_PROTO_VERSION);
} }
ResolveBlockConflicts(hash, *islock); ResolveBlockConflicts(hash, *islock);
@ -1542,11 +1542,11 @@ void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnma
} }
}; };
g_connman->ForEachNode([&](CNode* pnode) { connman.ForEachNode([&](CNode* pnode) {
// Check masternodes first // Check masternodes first
if (pnode->m_masternode_connection) maybe_add_to_nodesToAskFor(pnode); if (pnode->m_masternode_connection) maybe_add_to_nodesToAskFor(pnode);
}); });
g_connman->ForEachNode([&](CNode* pnode) { connman.ForEachNode([&](CNode* pnode) {
// Check non-masternodes next // Check non-masternodes next
if (!pnode->m_masternode_connection) maybe_add_to_nodesToAskFor(pnode); if (!pnode->m_masternode_connection) maybe_add_to_nodesToAskFor(pnode);
}); });

View File

@ -267,7 +267,7 @@ void CQuorumManager::EnsureQuorumConnections(const Consensus::LLMQParams& llmqPa
{ {
auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections); auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections);
auto connmanQuorumsToDelete = g_connman->GetMasternodeQuorums(llmqParams.type); auto connmanQuorumsToDelete = connman.GetMasternodeQuorums(llmqParams.type);
// don't remove connections for the currently in-progress DKG round // don't remove connections for the currently in-progress DKG round
if (CLLMQUtils::IsQuorumRotationEnabled(llmqParams.type, pindexNew)) { if (CLLMQUtils::IsQuorumRotationEnabled(llmqParams.type, pindexNew)) {
@ -296,7 +296,7 @@ void CQuorumManager::EnsureQuorumConnections(const Consensus::LLMQParams& llmqPa
} }
if (connmanQuorumsToDelete.count(quorum->qc->quorumHash) > 0) { if (connmanQuorumsToDelete.count(quorum->qc->quorumHash) > 0) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- removing masternodes quorum connections for quorum %s:\n", __func__, quorum->qc->quorumHash.ToString()); LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- removing masternodes quorum connections for quorum %s:\n", __func__, quorum->qc->quorumHash.ToString());
g_connman->RemoveMasternodeQuorumNodes(llmqParams.type, quorum->qc->quorumHash); connman.RemoveMasternodeQuorumNodes(llmqParams.type, quorum->qc->quorumHash);
} }
} }
} }
@ -416,7 +416,7 @@ bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqTyp
} }
CNetMsgMaker msgMaker(pFrom->GetSendVersion()); CNetMsgMaker msgMaker(pFrom->GetSendVersion());
g_connman->PushMessage(pFrom, msgMaker.Make(NetMsgType::QGETDATA, it.first->second)); connman.PushMessage(pFrom, msgMaker.Make(NetMsgType::QGETDATA, it.first->second));
return true; return true;
} }
@ -554,7 +554,7 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C
const CDataStream& body = CDataStream(SER_NETWORK, PROTOCOL_VERSION)) { const CDataStream& body = CDataStream(SER_NETWORK, PROTOCOL_VERSION)) {
request.SetError(nError); request.SetError(nError);
CDataStream ssResponse(SER_NETWORK, pFrom->GetSendVersion(), request, body); CDataStream ssResponse(SER_NETWORK, pFrom->GetSendVersion(), request, body);
g_connman->PushMessage(pFrom, CNetMsgMaker(pFrom->GetSendVersion()).Make(NetMsgType::QDATA, ssResponse)); connman.PushMessage(pFrom, CNetMsgMaker(pFrom->GetSendVersion()).Make(NetMsgType::QDATA, ssResponse));
}; };
{ {
@ -813,12 +813,12 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
// Sleep a bit depending on the start offset to balance out multiple requests to same masternode // Sleep a bit depending on the start offset to balance out multiple requests to same masternode
quorumThreadInterrupt.sleep_for(std::chrono::milliseconds(nMyStartOffset * 100)); quorumThreadInterrupt.sleep_for(std::chrono::milliseconds(nMyStartOffset * 100));
nTimeLastSuccess = GetAdjustedTime(); nTimeLastSuccess = GetAdjustedTime();
g_connman->AddPendingMasternode(*pCurrentMemberHash); connman.AddPendingMasternode(*pCurrentMemberHash);
printLog("Connect"); printLog("Connect");
} }
auto proTxHash = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash); auto proTxHash = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash);
g_connman->ForEachNode([&](CNode* pNode) { connman.ForEachNode([&](CNode* pNode) {
auto verifiedProRegTxHash = pNode->GetVerifiedProRegTxHash(); auto verifiedProRegTxHash = pNode->GetVerifiedProRegTxHash();
if (pCurrentMemberHash == nullptr || verifiedProRegTxHash != *pCurrentMemberHash) { if (pCurrentMemberHash == nullptr || verifiedProRegTxHash != *pCurrentMemberHash) {
return; return;

View File

@ -827,7 +827,7 @@ void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecovered
if (fMasternodeMode) { if (fMasternodeMode) {
CInv inv(MSG_QUORUM_RECOVERED_SIG, recoveredSig->GetHash()); CInv inv(MSG_QUORUM_RECOVERED_SIG, recoveredSig->GetHash());
g_connman->ForEachNode([&](CNode* pnode) { connman.ForEachNode([&](CNode* pnode) {
if (pnode->fSendRecSigs) { if (pnode->fSendRecSigs) {
pnode->PushInventory(inv); pnode->PushInventory(inv);
} }

View File

@ -1033,7 +1033,7 @@ void CSigSharesManager::CollectSigSharesToAnnounce(std::unordered_map<NodeId, st
auto quorumKey = std::make_pair(sigShare->llmqType, sigShare->quorumHash); auto quorumKey = std::make_pair(sigShare->llmqType, sigShare->quorumHash);
auto it = quorumNodesMap.find(quorumKey); auto it = quorumNodesMap.find(quorumKey);
if (it == quorumNodesMap.end()) { if (it == quorumNodesMap.end()) {
auto nodeIds = g_connman->GetMasternodeQuorumNodes(quorumKey.first, quorumKey.second); auto nodeIds = connman.GetMasternodeQuorumNodes(quorumKey.first, quorumKey.second);
it = quorumNodesMap.emplace(std::piecewise_construct, std::forward_as_tuple(quorumKey), std::forward_as_tuple(nodeIds.begin(), nodeIds.end())).first; it = quorumNodesMap.emplace(std::piecewise_construct, std::forward_as_tuple(quorumKey), std::forward_as_tuple(nodeIds.begin(), nodeIds.end())).first;
} }
@ -1094,7 +1094,7 @@ bool CSigSharesManager::SendMessages()
return session->sendSessionId; return session->sendSessionId;
}; };
std::vector<CNode*> vNodesCopy = g_connman->CopyNodeVector(CConnman::FullyConnectedOnly); std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);
{ {
LOCK(cs); LOCK(cs);
@ -1133,13 +1133,13 @@ bool CSigSharesManager::SendMessages()
CLLMQUtils::BuildSignHash(sigSesAnn).ToString(), sigSesAnn.sessionId, pnode->GetId()); CLLMQUtils::BuildSignHash(sigSesAnn).ToString(), sigSesAnn.sessionId, pnode->GetId());
msgs.emplace_back(sigSesAnn); msgs.emplace_back(sigSesAnn);
if (msgs.size() == MAX_MSGS_CNT_QSIGSESANN) { if (msgs.size() == MAX_MSGS_CNT_QSIGSESANN) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSESANN, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSESANN, msgs));
msgs.clear(); msgs.clear();
didSend = true; didSend = true;
} }
} }
if (!msgs.empty()) { if (!msgs.empty()) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSESANN, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSESANN, msgs));
didSend = true; didSend = true;
} }
} }
@ -1152,13 +1152,13 @@ bool CSigSharesManager::SendMessages()
signHash.ToString(), inv.ToString(), pnode->GetId()); signHash.ToString(), inv.ToString(), pnode->GetId());
msgs.emplace_back(inv); msgs.emplace_back(inv);
if (msgs.size() == MAX_MSGS_CNT_QGETSIGSHARES) { if (msgs.size() == MAX_MSGS_CNT_QGETSIGSHARES) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QGETSIGSHARES, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QGETSIGSHARES, msgs));
msgs.clear(); msgs.clear();
didSend = true; didSend = true;
} }
} }
if (!msgs.empty()) { if (!msgs.empty()) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QGETSIGSHARES, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QGETSIGSHARES, msgs));
didSend = true; didSend = true;
} }
} }
@ -1171,7 +1171,7 @@ bool CSigSharesManager::SendMessages()
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::SendMessages -- QBSIGSHARES signHash=%s, inv={%s}, node=%d\n", LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::SendMessages -- QBSIGSHARES signHash=%s, inv={%s}, node=%d\n",
signHash.ToString(), inv.ToInvString(), pnode->GetId()); signHash.ToString(), inv.ToInvString(), pnode->GetId());
if (totalSigsCount + inv.sigShares.size() > MAX_MSGS_TOTAL_BATCHED_SIGS) { if (totalSigsCount + inv.sigShares.size() > MAX_MSGS_TOTAL_BATCHED_SIGS) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QBSIGSHARES, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QBSIGSHARES, msgs));
msgs.clear(); msgs.clear();
totalSigsCount = 0; totalSigsCount = 0;
didSend = true; didSend = true;
@ -1181,7 +1181,7 @@ bool CSigSharesManager::SendMessages()
} }
if (!msgs.empty()) { if (!msgs.empty()) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QBSIGSHARES, std::move(msgs))); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QBSIGSHARES, std::move(msgs)));
didSend = true; didSend = true;
} }
} }
@ -1194,13 +1194,13 @@ bool CSigSharesManager::SendMessages()
signHash.ToString(), inv.ToString(), pnode->GetId()); signHash.ToString(), inv.ToString(), pnode->GetId());
msgs.emplace_back(inv); msgs.emplace_back(inv);
if (msgs.size() == MAX_MSGS_CNT_QSIGSHARESINV) { if (msgs.size() == MAX_MSGS_CNT_QSIGSHARESINV) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARESINV, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARESINV, msgs));
msgs.clear(); msgs.clear();
didSend = true; didSend = true;
} }
} }
if (!msgs.empty()) { if (!msgs.empty()) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARESINV, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARESINV, msgs));
didSend = true; didSend = true;
} }
} }
@ -1213,20 +1213,20 @@ bool CSigSharesManager::SendMessages()
sigShare.GetSignHash().ToString(), pnode->GetId()); sigShare.GetSignHash().ToString(), pnode->GetId());
msgs.emplace_back(std::move(sigShare)); msgs.emplace_back(std::move(sigShare));
if (msgs.size() == MAX_MSGS_SIG_SHARES) { if (msgs.size() == MAX_MSGS_SIG_SHARES) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARE, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARE, msgs));
msgs.clear(); msgs.clear();
didSend = true; didSend = true;
} }
} }
if (!msgs.empty()) { if (!msgs.empty()) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARE, msgs)); connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSHARE, msgs));
didSend = true; didSend = true;
} }
} }
} }
// looped through all nodes, release them // looped through all nodes, release them
g_connman->ReleaseNodeVector(vNodesCopy); connman.ReleaseNodeVector(vNodesCopy);
return didSend; return didSend;
} }
@ -1358,7 +1358,7 @@ void CSigSharesManager::Cleanup()
nodeStatesToDelete.emplace(nodeId); nodeStatesToDelete.emplace(nodeId);
} }
} }
g_connman->ForEachNode([&nodeStatesToDelete](const CNode* pnode) { connman.ForEachNode([&nodeStatesToDelete](const CNode* pnode) {
nodeStatesToDelete.erase(pnode->GetId()); nodeStatesToDelete.erase(pnode->GetId());
}); });

View File

@ -657,7 +657,7 @@ bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams
relayMembers = connections; relayMembers = connections;
} }
if (!connections.empty()) { if (!connections.empty()) {
if (!g_connman->HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) { if (!connman.HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) {
auto mnList = deterministicMNManager->GetListAtChainTip(); auto mnList = deterministicMNManager->GetListAtChainTip();
std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString()); std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
for (auto& c : connections) { for (auto& c : connections) {
@ -670,10 +670,10 @@ bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams
} }
LogPrint(BCLog::NET_NETCONN, debugMsg.c_str()); /* Continued */ LogPrint(BCLog::NET_NETCONN, debugMsg.c_str()); /* Continued */
} }
g_connman->SetMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), connections); connman.SetMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), connections);
} }
if (!relayMembers.empty()) { if (!relayMembers.empty()) {
g_connman->SetMasternodeQuorumRelayMembers(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), relayMembers); connman.SetMasternodeQuorumRelayMembers(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), relayMembers);
} }
return true; return true;
} }
@ -714,7 +714,7 @@ void CLLMQUtils::AddQuorumProbeConnections(const Consensus::LLMQParams& llmqPara
} }
LogPrint(BCLog::NET_NETCONN, debugMsg.c_str()); /* Continued */ LogPrint(BCLog::NET_NETCONN, debugMsg.c_str()); /* Continued */
} }
g_connman->AddPendingProbeConnections(probeConnections); connman.AddPendingProbeConnections(probeConnections);
} }
} }

View File

@ -202,7 +202,7 @@ bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
bool empty = true; bool empty = true;
// If we have some peers, let's try to find our local address from one of them // If we have some peers, let's try to find our local address from one of them
auto service = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.service); auto service = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.service);
g_connman->ForEachNodeContinueIf(CConnman::AllNodes, [&](CNode* pnode) { connman.ForEachNodeContinueIf(CConnman::AllNodes, [&](CNode* pnode) {
empty = false; empty = false;
if (pnode->addr.IsIPv4()) if (pnode->addr.IsIPv4())
fFoundLocal = GetLocal(service, &pnode->addr) && IsValidNetAddr(service); fFoundLocal = GetLocal(service, &pnode->addr) && IsValidNetAddr(service);