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 committed by GitHub
parent 320edd5575
commit 58cfeaf321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -10,7 +10,7 @@
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
{
@ -20,6 +20,7 @@ UniValue CMasternodeMetaInfo::ToJson() const
ret.pushKV("lastDSQ", nLastDsq);
ret.pushKV("mixingTxCount", nMixingTxCount);
ret.pushKV("outboundAttemptCount", outboundAttemptCount);
ret.pushKV("lastOutboundAttempt", lastOutboundAttempt);
ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt);
ret.pushKV("lastOutboundSuccess", lastOutboundSuccess);

View File

@ -16,6 +16,7 @@
class CConnman;
static constexpr int MASTERNODE_MAX_MIXING_TXES{5};
static constexpr int MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS{5};
// Holds extra (non-deterministic) information about masternodes
// 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
std::map<uint256, int> mapGovernanceObjectsVotedOn GUARDED_BY(cs);
std::atomic<int> outboundAttemptCount{0};
std::atomic<int64_t> lastOutboundAttempt{0};
std::atomic<int64_t> lastOutboundSuccess{0};
@ -59,6 +61,7 @@ public:
obj.nLastDsq,
obj.nMixingTxCount,
obj.mapGovernanceObjectsVotedOn,
obj.outboundAttemptCount,
obj.lastOutboundAttempt,
obj.lastOutboundSuccess
);
@ -78,9 +81,10 @@ public:
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; }
void SetLastOutboundSuccess(int64_t t) { lastOutboundSuccess = t; }
void SetLastOutboundSuccess(int64_t t) { lastOutboundSuccess = t; outboundAttemptCount = 0; }
int64_t GetLastOutboundSuccess() const { return lastOutboundSuccess; }
};
using CMasternodeMetaInfoPtr = std::shared_ptr<CMasternodeMetaInfo>;

View File

@ -2515,8 +2515,11 @@ void CConnman::ThreadOpenMasternodeConnections()
});
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));
// reset last outbound success
mmetaman.GetMetaInfo(connectToDmn->proTxHash)->SetLastOutboundSuccess(0);
// Will take a few consequent failed attempts to PoSe-punish a MN.
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);
}
}
}
}