fix(dkg): let masternodes miss few connection attempts before considering them "bad" (#4907)

* fix(dkg): let masternodes miss few connection attempts before considering them "bad"

Should help with dashd updates/restarts for nodes that were successfully probed recently.

* fix
This commit is contained in:
UdjinM6 2022-07-07 10:49:34 +03:00
parent 61c6f60ac5
commit 394bf42fef
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
3 changed files with 13 additions and 5 deletions

View File

@ -8,7 +8,7 @@
CMasternodeMetaMan mmetaman; CMasternodeMetaMan mmetaman;
const std::string CMasternodeMetaMan::SERIALIZATION_VERSION_STRING = "CMasternodeMetaMan-Version-2"; const std::string CMasternodeMetaMan::SERIALIZATION_VERSION_STRING = "CMasternodeMetaMan-Version-3";
UniValue CMasternodeMetaInfo::ToJson() const UniValue CMasternodeMetaInfo::ToJson() const
{ {
@ -18,6 +18,7 @@ UniValue CMasternodeMetaInfo::ToJson() const
ret.pushKV("lastDSQ", nLastDsq); ret.pushKV("lastDSQ", nLastDsq);
ret.pushKV("mixingTxCount", nMixingTxCount); ret.pushKV("mixingTxCount", nMixingTxCount);
ret.pushKV("outboundAttemptCount", outboundAttemptCount);
ret.pushKV("lastOutboundAttempt", lastOutboundAttempt); ret.pushKV("lastOutboundAttempt", lastOutboundAttempt);
ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt); ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt);
ret.pushKV("lastOutboundSuccess", lastOutboundSuccess); ret.pushKV("lastOutboundSuccess", lastOutboundSuccess);

View File

@ -16,6 +16,7 @@
class CConnman; class CConnman;
static constexpr int MASTERNODE_MAX_MIXING_TXES{5}; static constexpr int MASTERNODE_MAX_MIXING_TXES{5};
static constexpr int MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS{5};
// Holds extra (non-deterministic) information about masternodes // Holds extra (non-deterministic) information about masternodes
// This is mostly local information, e.g. about mixing and governance // This is mostly local information, e.g. about mixing and governance
@ -35,6 +36,7 @@ private:
// KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION // KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION
std::map<uint256, int> mapGovernanceObjectsVotedOn GUARDED_BY(cs); std::map<uint256, int> mapGovernanceObjectsVotedOn GUARDED_BY(cs);
std::atomic<int> outboundAttemptCount{0};
std::atomic<int64_t> lastOutboundAttempt{0}; std::atomic<int64_t> lastOutboundAttempt{0};
std::atomic<int64_t> lastOutboundSuccess{0}; std::atomic<int64_t> lastOutboundSuccess{0};
@ -59,6 +61,7 @@ public:
obj.nLastDsq, obj.nLastDsq,
obj.nMixingTxCount, obj.nMixingTxCount,
obj.mapGovernanceObjectsVotedOn, obj.mapGovernanceObjectsVotedOn,
obj.outboundAttemptCount,
obj.lastOutboundAttempt, obj.lastOutboundAttempt,
obj.lastOutboundSuccess obj.lastOutboundSuccess
); );
@ -78,9 +81,10 @@ public:
void RemoveGovernanceObject(const uint256& nGovernanceObjectHash); void RemoveGovernanceObject(const uint256& nGovernanceObjectHash);
void SetLastOutboundAttempt(int64_t t) { lastOutboundAttempt = t; } bool OutboundFailedTooManyTimes() const { return outboundAttemptCount > MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS; }
void SetLastOutboundAttempt(int64_t t) { lastOutboundAttempt = t; ++outboundAttemptCount; }
int64_t GetLastOutboundAttempt() const { return lastOutboundAttempt; } int64_t GetLastOutboundAttempt() const { return lastOutboundAttempt; }
void SetLastOutboundSuccess(int64_t t) { lastOutboundSuccess = t; } void SetLastOutboundSuccess(int64_t t) { lastOutboundSuccess = t; outboundAttemptCount = 0; }
int64_t GetLastOutboundSuccess() const { return lastOutboundSuccess; } int64_t GetLastOutboundSuccess() const { return lastOutboundSuccess; }
}; };
using CMasternodeMetaInfoPtr = std::shared_ptr<CMasternodeMetaInfo>; using CMasternodeMetaInfoPtr = std::shared_ptr<CMasternodeMetaInfo>;

View File

@ -2476,8 +2476,11 @@ void CConnman::ThreadOpenMasternodeConnections()
}); });
if (!connected) { if (!connected) {
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- connection failed for masternode %s, service=%s\n", __func__, connectToDmn->proTxHash.ToString(), connectToDmn->pdmnState->addr.ToString(false)); LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- connection failed for masternode %s, service=%s\n", __func__, connectToDmn->proTxHash.ToString(), connectToDmn->pdmnState->addr.ToString(false));
// reset last outbound success // Will take a few consequent failed attempts to PoSe-punish a MN.
mmetaman.GetMetaInfo(connectToDmn->proTxHash)->SetLastOutboundSuccess(0); if (mmetaman.GetMetaInfo(connectToDmn->proTxHash)->OutboundFailedTooManyTimes()) {
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- failed to connect to masternode %s too many times, resetting outbound success time\n", __func__, connectToDmn->proTxHash.ToString());
mmetaman.GetMetaInfo(connectToDmn->proTxHash)->SetLastOutboundSuccess(0);
}
} }
} }
} }