Skip to content

Commit b7f59a0

Browse files
committed
[Core] Don't log missing MNs during CBudgetProposal::CleanAndRemove
Simply remove `fSignatureCheck` argument in CheckSignature and use mnodeman
1 parent 51e7ea2 commit b7f59a0

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

src/masternode-budget.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ std::vector<CBudgetProposal*> CBudgetManager::GetAllProposals()
742742

743743
std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin();
744744
while (it != mapProposals.end()) {
745-
(*it).second.CleanAndRemove(false);
745+
(*it).second.CleanAndRemove();
746746

747747
CBudgetProposal* pbudgetProposal = &((*it).second);
748748
vBudgetProposalRet.push_back(pbudgetProposal);
@@ -776,7 +776,7 @@ std::vector<CBudgetProposal*> CBudgetManager::GetBudget()
776776

777777
std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin();
778778
while (it != mapProposals.end()) {
779-
(*it).second.CleanAndRemove(false);
779+
(*it).second.CleanAndRemove();
780780
vBudgetPorposalsSort.push_back(std::make_pair(&((*it).second), (*it).second.GetYeas() - (*it).second.GetNays()));
781781
++it;
782782
}
@@ -995,14 +995,14 @@ void CBudgetManager::NewBlock()
995995
LogPrint("mnbudget","CBudgetManager::NewBlock - mapProposals cleanup - size: %d\n", mapProposals.size());
996996
std::map<uint256, CBudgetProposal>::iterator it2 = mapProposals.begin();
997997
while (it2 != mapProposals.end()) {
998-
(*it2).second.CleanAndRemove(false);
998+
(*it2).second.CleanAndRemove();
999999
++it2;
10001000
}
10011001

10021002
LogPrint("mnbudget","CBudgetManager::NewBlock - mapFinalizedBudgets cleanup - size: %d\n", mapFinalizedBudgets.size());
10031003
std::map<uint256, CFinalizedBudget>::iterator it3 = mapFinalizedBudgets.begin();
10041004
while (it3 != mapFinalizedBudgets.end()) {
1005-
(*it3).second.CleanAndRemove(false);
1005+
(*it3).second.CleanAndRemove();
10061006
++it3;
10071007
}
10081008

@@ -1141,7 +1141,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
11411141

11421142

11431143
mapSeenMasternodeBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
1144-
if (!vote.CheckSignature(true)) {
1144+
if (!vote.CheckSignature()) {
11451145
if (masternodeSync.IsSynced()) {
11461146
LogPrintf("CBudgetManager::ProcessMessage() : mvote - signature invalid\n");
11471147
Misbehaving(pfrom->GetId(), 20);
@@ -1215,7 +1215,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
12151215
}
12161216

12171217
mapSeenFinalizedBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
1218-
if (!vote.CheckSignature(true)) {
1218+
if (!vote.CheckSignature()) {
12191219
if (masternodeSync.IsSynced()) {
12201220
LogPrintf("CBudgetManager::ProcessMessage() : fbvote - signature from masternode %s invalid\n", HexStr(pmn->pubKeyMasternode));
12211221
Misbehaving(pfrom->GetId(), 20);
@@ -1616,12 +1616,13 @@ bool CBudgetProposal::AddOrUpdateVote(CBudgetVote& vote, std::string& strError)
16161616
}
16171617

16181618
// If masternode voted for a proposal, but is now invalid -- remove the vote
1619-
void CBudgetProposal::CleanAndRemove(bool fSignatureCheck)
1619+
void CBudgetProposal::CleanAndRemove()
16201620
{
16211621
std::map<uint256, CBudgetVote>::iterator it = mapVotes.begin();
16221622

16231623
while (it != mapVotes.end()) {
1624-
(*it).second.fValid = (*it).second.CheckSignature(fSignatureCheck);
1624+
CMasternode* pmn = mnodeman.Find((*it).second.GetVin());
1625+
(*it).second.fValid = (pmn != nullptr);
16251626
++it;
16261627
}
16271628
}
@@ -1959,12 +1960,13 @@ void CFinalizedBudget::CheckAndVote()
19591960
}
19601961

19611962
// Remove votes from masternodes which are not valid/existent anymore
1962-
void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck)
1963+
void CFinalizedBudget::CleanAndRemove()
19631964
{
19641965
std::map<uint256, CFinalizedBudgetVote>::iterator it = mapVotes.begin();
19651966

19661967
while (it != mapVotes.end()) {
1967-
(*it).second.fValid = (*it).second.CheckSignature(fSignatureCheck);
1968+
CMasternode* pmn = mnodeman.Find((*it).second.GetVin());
1969+
(*it).second.fValid = (pmn != nullptr);
19681970
++it;
19691971
}
19701972
}

src/masternode-budget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class CFinalizedBudget
327327
CFinalizedBudget();
328328
CFinalizedBudget(const CFinalizedBudget& other);
329329

330-
void CleanAndRemove(bool fSignatureCheck);
330+
void CleanAndRemove();
331331
bool AddOrUpdateVote(CFinalizedBudgetVote& vote, std::string& strError);
332332
double GetScore();
333333
bool HasMinimumRequiredSupport();
@@ -509,7 +509,7 @@ class CBudgetProposal
509509
void SetAllotted(CAmount nAllotedIn) { nAlloted = nAllotedIn; }
510510
CAmount GetAllotted() { return nAlloted; }
511511

512-
void CleanAndRemove(bool fSignatureCheck);
512+
void CleanAndRemove();
513513

514514
uint256 GetHash() const
515515
{

src/messagesigner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ bool CSignedMessage::CheckSignature(const CPubKey& pubKey) const
140140
return true;
141141
}
142142

143-
bool CSignedMessage::CheckSignature(const bool fSignatureCheck) const
143+
bool CSignedMessage::CheckSignature() const
144144
{
145145
std::string strError = "";
146146

147147
const CPubKey pubkey = GetPublicKey(strError);
148148
if (pubkey == CPubKey())
149-
return error("%s : ERROR: %s", __func__, strError);
149+
return error("%s : %s", __func__, strError);
150150

151-
return !fSignatureCheck || CheckSignature(pubkey);
151+
return CheckSignature(pubkey);
152152
}
153153

154154
const CPubKey CSignedMessage::GetPublicKey(std::string& strErrorRet) const

src/messagesigner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CSignedMessage
7070
bool Sign(const CKey& key, const CPubKey& pubKey, const bool fNewSigs);
7171
bool Sign(const std::string strSignKey, const bool fNewSigs);
7272
bool CheckSignature(const CPubKey& pubKey) const;
73-
bool CheckSignature(const bool fSignatureCheck = true) const;
73+
bool CheckSignature() const;
7474

7575
// Pure virtual functions (used in Sign-Verify functions)
7676
// Must be implemented in child classes

src/rpc/budget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,10 @@ UniValue mnbudgetrawvote(const UniValue& params, bool fHelp)
732732
vote.nTime = nTime;
733733
vote.SetVchSig(vchSig);
734734

735-
if (!vote.CheckSignature(true)) {
735+
if (!vote.CheckSignature()) {
736736
// try old message version
737737
vote.nMessVersion = MessageVersion::MESS_VER_STRMESS;
738-
if (!vote.CheckSignature(true)) return "Failure to verify signature.";
738+
if (!vote.CheckSignature()) return "Failure to verify signature.";
739739
}
740740

741741
std::string strError = "";

0 commit comments

Comments
 (0)