fix(dkg/net): Drop outdated connections to nodes that became masternodes recently (#4934)

* feat: switch nTimeFirstMessageReceived from microseconds to seconds

Was acting more like a bool until now, so nothing should change really. Align it with nTimeConnected.

* fix(dkg/net): Drop outdated connections to nodes that became masternodes recently

Such nodes won't be seen as masternodes by RelayInvToParticipants otherwise so no contributions will be sent to them when they are picked as relay members which in its turn may result in other nodes PoSe-punishing us.
This commit is contained in:
UdjinM6 2022-07-26 00:36:17 +03:00 committed by pasta
parent f7427d9c13
commit b9dbd6da02
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 18 additions and 1 deletions

View File

@ -2379,6 +2379,7 @@ void CConnman::ThreadOpenMasternodeConnections()
return;
int64_t nANow = GetAdjustedTime();
constexpr const auto &_func_ = __func__;
// NOTE: Process only one pending masternode at a time
@ -2405,6 +2406,22 @@ void CConnman::ThreadOpenMasternodeConnections()
continue;
}
const auto& addr2 = dmn->pdmnState->addr;
if (connectedNodes.count(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
// we probably connected to it before it became a masternode
// or maybe we are still waiting for mnauth
(void)ForNode(addr2, [&](CNode* pnode) {
if (pnode->nTimeFirstMessageReceived != 0 && GetSystemTimeInSeconds() - pnode->nTimeFirstMessageReceived > 5) {
// clearly not expecting mnauth to take that long even if it wasn't the first message
// we received (as it should normally), disconnect
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- dropping non-mnauth connection to %s, service=%s\n", _func_, proRegTxHash.ToString(), addr2.ToString(false));
pnode->fDisconnect = true;
return true;
}
return false;
});
// either way - it's not ready, skip it for now
continue;
}
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
int64_t lastAttempt = mmetaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundAttempt();
// back off trying connecting to an address if we already tried recently

View File

@ -2748,7 +2748,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStrea
if (pfrom->nTimeFirstMessageReceived == 0) {
// First message after VERSION/VERACK
pfrom->nTimeFirstMessageReceived = GetTimeMicros();
pfrom->nTimeFirstMessageReceived = GetSystemTimeInSeconds();
pfrom->fFirstMessageIsMNAUTH = msg_type == NetMsgType::MNAUTH;
// Note: do not break the flow here