Skip to content

Commit d28d318

Browse files
authored
Remove logic for handling objects and votes orphaned by not-yet-known MNs (#2954)
This should no longer happen now that we use deterministic masternode list.
1 parent e02c562 commit d28d318

File tree

6 files changed

+9
-128
lines changed

6 files changed

+9
-128
lines changed

src/dsnotificationinterface.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr<const CBl
116116
void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)
117117
{
118118
CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff);
119-
governance.CheckMasternodeOrphanObjects(connman);
120-
governance.CheckMasternodeOrphanVotes(connman);
121119
governance.UpdateCachesAndClean();
122120
}
123121

src/governance/governance-object.cpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ CGovernanceObject::CGovernanceObject() :
4242
fExpired(false),
4343
fUnparsable(false),
4444
mapCurrentMNVotes(),
45-
cmmapOrphanVotes(),
4645
fileVotes()
4746
{
4847
// PARSE JSON DATA STORAGE (VCHDATA)
@@ -70,7 +69,6 @@ CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevision
7069
fExpired(false),
7170
fUnparsable(false),
7271
mapCurrentMNVotes(),
73-
cmmapOrphanVotes(),
7472
fileVotes()
7573
{
7674
// PARSE JSON DATA STORAGE (VCHDATA)
@@ -98,7 +96,6 @@ CGovernanceObject::CGovernanceObject(const CGovernanceObject& other) :
9896
fExpired(other.fExpired),
9997
fUnparsable(other.fUnparsable),
10098
mapCurrentMNVotes(other.mapCurrentMNVotes),
101-
cmmapOrphanVotes(other.cmmapOrphanVotes),
10299
fileVotes(other.fileVotes)
103100
{
104101
}
@@ -126,12 +123,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
126123
if (!dmn) {
127124
std::ostringstream ostr;
128125
ostr << "CGovernanceObject::ProcessVote -- Masternode " << vote.GetMasternodeOutpoint().ToStringShort() << " not found";
129-
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
130-
if (cmmapOrphanVotes.Insert(vote.GetMasternodeOutpoint(), vote_time_pair_t(vote, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
131-
LogPrintf("%s\n", ostr.str());
132-
} else {
133-
LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
134-
}
126+
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
135127
return false;
136128
}
137129

@@ -452,15 +444,13 @@ void CGovernanceObject::UpdateLocalValidity()
452444

453445
bool CGovernanceObject::IsValidLocally(std::string& strError, bool fCheckCollateral) const
454446
{
455-
bool fMissingMasternode = false;
456447
bool fMissingConfirmations = false;
457448

458-
return IsValidLocally(strError, fMissingMasternode, fMissingConfirmations, fCheckCollateral);
449+
return IsValidLocally(strError, fMissingConfirmations, fCheckCollateral);
459450
}
460451

461-
bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMasternode, bool& fMissingConfirmations, bool fCheckCollateral) const
452+
bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const
462453
{
463-
fMissingMasternode = false;
464454
fMissingConfirmations = false;
465455

466456
if (fUnparsable) {
@@ -718,34 +708,3 @@ void CGovernanceObject::UpdateSentinelVariables()
718708

719709
if (GetAbsoluteNoCount(VOTE_SIGNAL_VALID) >= nAbsVoteReq) fCachedValid = false;
720710
}
721-
722-
void CGovernanceObject::CheckOrphanVotes(CConnman& connman)
723-
{
724-
int64_t nNow = GetAdjustedTime();
725-
auto mnList = deterministicMNManager->GetListAtChainTip();
726-
const vote_cmm_t::list_t& listVotes = cmmapOrphanVotes.GetItemList();
727-
vote_cmm_t::list_cit it = listVotes.begin();
728-
while (it != listVotes.end()) {
729-
bool fRemove = false;
730-
const COutPoint& key = it->key;
731-
const vote_time_pair_t& pairVote = it->value;
732-
const CGovernanceVote& vote = pairVote.first;
733-
if (pairVote.second < nNow) {
734-
fRemove = true;
735-
} else if (!mnList.HasValidMNByCollateral(vote.GetMasternodeOutpoint())) {
736-
++it;
737-
continue;
738-
}
739-
CGovernanceException exception;
740-
if (!ProcessVote(nullptr, vote, exception, connman)) {
741-
LogPrintf("CGovernanceObject::CheckOrphanVotes -- Failed to add orphan vote: %s\n", exception.what());
742-
} else {
743-
vote.Relay(connman);
744-
fRemove = true;
745-
}
746-
++it;
747-
if (fRemove) {
748-
cmmapOrphanVotes.Erase(key, pairVote);
749-
}
750-
}
751-
}

src/governance/governance-object.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ class CGovernanceObject
180180

181181
vote_m_t mapCurrentMNVotes;
182182

183-
/// Limited map of votes orphaned by MN
184-
vote_cmm_t cmmapOrphanVotes;
185-
186183
CGovernanceObjectVoteFile fileVotes;
187184

188185
public:
@@ -267,7 +264,7 @@ class CGovernanceObject
267264

268265
bool IsValidLocally(std::string& strError, bool fCheckCollateral) const;
269266

270-
bool IsValidLocally(std::string& strError, bool& fMissingMasternode, bool& fMissingConfirmations, bool fCheckCollateral) const;
267+
bool IsValidLocally(std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const;
271268

272269
/// Check the collateral transaction for the budget proposal/finalized budget
273270
bool IsCollateralValid(std::string& strError, bool& fMissingConfirmations) const;
@@ -350,8 +347,6 @@ class CGovernanceObject
350347
// also for MNs that were removed from the list completely.
351348
// Returns deleted vote hashes.
352349
std::set<uint256> RemoveInvalidVotes(const COutPoint& mnOutpoint);
353-
354-
void CheckOrphanVotes(CConnman& connman);
355350
};
356351

357352

src/governance/governance.cpp

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ CGovernanceManager::CGovernanceManager() :
3333
nCachedBlockHeight(0),
3434
mapObjects(),
3535
mapErasedGovernanceObjects(),
36-
mapMasternodeOrphanObjects(),
3736
cmapVoteToObject(MAX_CACHE_SIZE),
3837
cmapInvalidVotes(MAX_CACHE_SIZE),
3938
cmmapOrphanVotes(MAX_CACHE_SIZE),
@@ -161,8 +160,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm
161160

162161
LOCK2(cs_main, cs);
163162

164-
if (mapObjects.count(nHash) || mapPostponedObjects.count(nHash) ||
165-
mapErasedGovernanceObjects.count(nHash) || mapMasternodeOrphanObjects.count(nHash)) {
163+
if (mapObjects.count(nHash) || mapPostponedObjects.count(nHash) || mapErasedGovernanceObjects.count(nHash)) {
166164
// TODO - print error code? what if it's GOVOBJ_ERROR_IMMATURE?
167165
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Received already seen object: %s\n", strHash);
168166
return;
@@ -177,33 +175,18 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm
177175
std::string strError = "";
178176
// CHECK OBJECT AGAINST LOCAL BLOCKCHAIN
179177

180-
bool fMasternodeMissing = false;
181178
bool fMissingConfirmations = false;
182-
bool fIsValid = govobj.IsValidLocally(strError, fMasternodeMissing, fMissingConfirmations, true);
179+
bool fIsValid = govobj.IsValidLocally(strError, fMissingConfirmations, true);
183180

184-
if (fRateCheckBypassed && (fIsValid || fMasternodeMissing)) {
181+
if (fRateCheckBypassed && fIsValid) {
185182
if (!MasternodeRateCheck(govobj, true)) {
186183
LogPrintf("MNGOVERNANCEOBJECT -- masternode rate check failed (after signature verification) - %s - (current block height %d)\n", strHash, nCachedBlockHeight);
187184
return;
188185
}
189186
}
190187

191188
if (!fIsValid) {
192-
if (fMasternodeMissing) {
193-
int& count = mapMasternodeOrphanCounter[govobj.GetMasternodeOutpoint()];
194-
if (count >= 10) {
195-
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Too many orphan objects, missing masternode=%s\n", govobj.GetMasternodeOutpoint().ToStringShort());
196-
// ask for this object again in 2 minutes
197-
CInv inv(MSG_GOVERNANCE_OBJECT, govobj.GetHash());
198-
pfrom->AskFor(inv);
199-
return;
200-
}
201-
202-
count++;
203-
ExpirationInfo info(pfrom->GetId(), GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME);
204-
mapMasternodeOrphanObjects.insert(std::make_pair(nHash, object_info_pair_t(govobj, info)));
205-
LogPrintf("MNGOVERNANCEOBJECT -- Missing masternode for: %s, strError = %s\n", strHash, strError);
206-
} else if (fMissingConfirmations) {
189+
if (fMissingConfirmations) {
207190
AddPostponedObject(govobj);
208191
LogPrintf("MNGOVERNANCEOBJECT -- Not enough fee confirmations for: %s, strError = %s\n", strHash, strError);
209192
} else {
@@ -863,52 +846,6 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
863846
return fOk;
864847
}
865848

866-
void CGovernanceManager::CheckMasternodeOrphanVotes(CConnman& connman)
867-
{
868-
LOCK2(cs_main, cs);
869-
870-
ScopedLockBool guard(cs, fRateChecksEnabled, false);
871-
872-
for (auto& objPair : mapObjects) {
873-
objPair.second.CheckOrphanVotes(connman);
874-
}
875-
}
876-
877-
void CGovernanceManager::CheckMasternodeOrphanObjects(CConnman& connman)
878-
{
879-
LOCK2(cs_main, cs);
880-
int64_t nNow = GetAdjustedTime();
881-
ScopedLockBool guard(cs, fRateChecksEnabled, false);
882-
object_info_m_it it = mapMasternodeOrphanObjects.begin();
883-
while (it != mapMasternodeOrphanObjects.end()) {
884-
object_info_pair_t& pair = it->second;
885-
CGovernanceObject& govobj = pair.first;
886-
887-
if (pair.second.nExpirationTime >= nNow) {
888-
std::string strError;
889-
bool fMasternodeMissing = false;
890-
bool fConfirmationsMissing = false;
891-
bool fIsValid = govobj.IsValidLocally(strError, fMasternodeMissing, fConfirmationsMissing, true);
892-
893-
if (fIsValid) {
894-
AddGovernanceObject(govobj, connman);
895-
} else if (fMasternodeMissing) {
896-
++it;
897-
continue;
898-
}
899-
} else {
900-
// apply node's ban score
901-
Misbehaving(pair.second.idFrom, 20);
902-
}
903-
904-
auto it_count = mapMasternodeOrphanCounter.find(govobj.GetMasternodeOutpoint());
905-
if (--it_count->second == 0)
906-
mapMasternodeOrphanCounter.erase(it_count);
907-
908-
mapMasternodeOrphanObjects.erase(it++);
909-
}
910-
}
911-
912849
void CGovernanceManager::CheckPostponedObjects(CConnman& connman)
913850
{
914851
if (!masternodeSync.IsSynced()) return;

src/governance/governance.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ class CGovernanceManager
241241
// value - expiration time for deleted objects
242242
hash_time_m_t mapErasedGovernanceObjects;
243243

244-
object_info_m_t mapMasternodeOrphanObjects;
245-
txout_int_m_t mapMasternodeOrphanCounter;
246-
247244
object_m_t mapPostponedObjects;
248245
hash_s_t setAdditionalRelayObjects;
249246

@@ -402,10 +399,6 @@ class CGovernanceManager
402399
return fOK;
403400
}
404401

405-
void CheckMasternodeOrphanVotes(CConnman& connman);
406-
407-
void CheckMasternodeOrphanObjects(CConnman& connman);
408-
409402
void CheckPostponedObjects(CConnman& connman);
410403

411404
bool AreRateChecksEnabled() const

src/rpc/governance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,10 @@ UniValue gobject_submit(const JSONRPCRequest& request)
308308
std::string strHash = govobj.GetHash().ToString();
309309

310310
std::string strError = "";
311-
bool fMissingMasternode;
312311
bool fMissingConfirmations;
313312
{
314313
LOCK(cs_main);
315-
if (!govobj.IsValidLocally(strError, fMissingMasternode, fMissingConfirmations, true) && !fMissingConfirmations) {
314+
if (!govobj.IsValidLocally(strError, fMissingConfirmations, true) && !fMissingConfirmations) {
316315
LogPrintf("gobject(submit) -- Object submission rejected because object is not valid - hash = %s, strError = %s\n", strHash, strError);
317316
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + strHash + " - " + strError);
318317
}

0 commit comments

Comments
 (0)