Skip to content

Commit

Permalink
fix: do not disconnect inbound nodes when processing mnauth, postpone…
Browse files Browse the repository at this point in the history
… it for later
  • Loading branch information
UdjinM6 committed Oct 31, 2023
1 parent c7ea030 commit ae50962
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode %s has already verified as peer %d, deterministicOutbound=%s. peer=%d\n",
mnauth.proRegTxHash.ToString(), pnode2->GetId(), deterministicOutbound.ToString(), peer.GetId());
if (deterministicOutbound == myProTxHash) {
// NOTE: do not drop inbound nodes here, mark them as probes so that
// they would be disconnected later in CMasternodeUtils::DoMaintenance
if (pnode2->fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping old inbound, peer=%d\n", pnode2->GetId());
pnode2->fDisconnect = true;
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- marking old inbound for dropping it later, peer=%d\n", pnode2->GetId());
pnode2->m_masternode_probe_connection = true;
} else if (peer.fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping new inbound, peer=%d\n", peer.GetId());
peer.fDisconnect = true;
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- marking new inbound for dropping it later, peer=%d\n", peer.GetId());
peer.m_masternode_probe_connection = true;
}
} else {
if (!pnode2->fInbound) {
Expand Down
43 changes: 23 additions & 20 deletions src/masternode/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,33 @@ void CMasternodeUtils::DoMaintenance(CConnman& connman, const CMasternodeSync& m
}

connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) {
// we're only disconnecting m_masternode_connection connections
if (!pnode->m_masternode_connection) return;
if (!pnode->GetVerifiedProRegTxHash().IsNull()) {
// keep _verified_ LLMQ connections
if (connman.IsMasternodeQuorumNode(pnode)) {
return;
}
// keep _verified_ LLMQ relay connections
if (connman.IsMasternodeQuorumRelayMember(pnode->GetVerifiedProRegTxHash())) {
if (pnode->m_masternode_probe_connection) {
// we're not disconnecting masternode probes for at least a few seconds
if (GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) return;
} else {
// we're only disconnecting m_masternode_connection connections
if (!pnode->m_masternode_connection) return;
if (!pnode->GetVerifiedProRegTxHash().IsNull()) {
// keep _verified_ LLMQ connections
if (connman.IsMasternodeQuorumNode(pnode)) {
return;
}
// keep _verified_ LLMQ relay connections
if (connman.IsMasternodeQuorumRelayMember(pnode->GetVerifiedProRegTxHash())) {
return;
}
// keep _verified_ inbound connections
if (pnode->fInbound) {
return;
}
} else if (GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) {
// non-verified, give it some time to verify itself
return;
}
// keep _verified_ inbound connections
if (pnode->fInbound) {
} else if (pnode->qwatch) {
// keep watching nodes
return;
}
} else if (GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) {
// non-verified, give it some time to verify itself
return;
} else if (pnode->qwatch) {
// keep watching nodes
return;
}
// we're not disconnecting masternode probes for at least a few seconds
if (pnode->m_masternode_probe_connection && GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) return;

#ifdef ENABLE_WALLET
bool fFound = ranges::any_of(vecDmns, [&pnode](const auto& dmn){ return pnode->addr == dmn->pdmnState->addr; });
Expand Down

0 comments on commit ae50962

Please sign in to comment.