mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
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:
parent
f7427d9c13
commit
b9dbd6da02
17
src/net.cpp
17
src/net.cpp
@ -2379,6 +2379,7 @@ void CConnman::ThreadOpenMasternodeConnections()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
int64_t nANow = GetAdjustedTime();
|
int64_t nANow = GetAdjustedTime();
|
||||||
|
constexpr const auto &_func_ = __func__;
|
||||||
|
|
||||||
// NOTE: Process only one pending masternode at a time
|
// NOTE: Process only one pending masternode at a time
|
||||||
|
|
||||||
@ -2405,6 +2406,22 @@ void CConnman::ThreadOpenMasternodeConnections()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& addr2 = dmn->pdmnState->addr;
|
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)) {
|
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
|
||||||
int64_t lastAttempt = mmetaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundAttempt();
|
int64_t lastAttempt = mmetaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundAttempt();
|
||||||
// back off trying connecting to an address if we already tried recently
|
// back off trying connecting to an address if we already tried recently
|
||||||
|
@ -2748,7 +2748,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStrea
|
|||||||
|
|
||||||
if (pfrom->nTimeFirstMessageReceived == 0) {
|
if (pfrom->nTimeFirstMessageReceived == 0) {
|
||||||
// First message after VERSION/VERACK
|
// First message after VERSION/VERACK
|
||||||
pfrom->nTimeFirstMessageReceived = GetTimeMicros();
|
pfrom->nTimeFirstMessageReceived = GetSystemTimeInSeconds();
|
||||||
pfrom->fFirstMessageIsMNAUTH = msg_type == NetMsgType::MNAUTH;
|
pfrom->fFirstMessageIsMNAUTH = msg_type == NetMsgType::MNAUTH;
|
||||||
// Note: do not break the flow here
|
// Note: do not break the flow here
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user