diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index aaa86df85..bdfb92999 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -967,7 +967,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote)); - if(!vote.SignatureValid(true)){ + if(!vote.IsValid(true)){ LogPrintf("mvote - signature invalid\n"); if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); // it could just be a non-synced masternode @@ -1037,8 +1037,8 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData } mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); - if(!vote.SignatureValid(true)){ - LogPrintf("fbvote - signature invalid\n"); + + if(!vote.IsValid(true)){ if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); // it could just be a non-synced masternode mnodeman.AskForMN(pfrom, vote.vin); @@ -1434,12 +1434,6 @@ bool CBudgetProposal::AddOrUpdateVote(CBudgetVote& vote, std::string& strError) } } - if(vote.nTime > GetTime() + (60*60)){ - strError = strprintf("new vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", vote.GetHash().ToString(), vote.nTime, GetTime() + (60*60)); - LogPrint("mnbudget", "CBudgetProposal::AddOrUpdateVote - %s\n", strError); - return false; - } - mapVotes[hash] = vote; return true; } @@ -1450,7 +1444,7 @@ void CBudgetProposal::CleanAndRemove(bool fSignatureCheck) std::map::iterator it = mapVotes.begin(); while(it != mapVotes.end()) { - (*it).second.fValid = (*it).second.SignatureValid(fSignatureCheck); + (*it).second.fValid = (*it).second.IsValid(fSignatureCheck); ++it; } } @@ -1615,23 +1609,28 @@ bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) return true; } -bool CBudgetVote::SignatureValid(bool fSignatureCheck) +bool CBudgetVote::IsValid(bool fSignatureCheck) { - std::string errorMessage; - std::string strMessage = vin.prevout.ToStringShort() + nProposalHash.ToString() + boost::lexical_cast(nVote) + boost::lexical_cast(nTime); + if(nTime > GetTime() + (60*60)){ + LogPrint("mnbudget", "CBudgetVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60)); + return false; + } CMasternode* pmn = mnodeman.Find(vin); if(pmn == NULL) { - LogPrint("mnbudget", "CBudgetVote::SignatureValid() - Unknown Masternode - %s\n", vin.ToString()); + LogPrint("mnbudget", "CBudgetVote::IsValid() - Unknown Masternode - %s\n", vin.ToString()); return false; } if(!fSignatureCheck) return true; + std::string errorMessage; + std::string strMessage = vin.prevout.ToStringShort() + nProposalHash.ToString() + boost::lexical_cast(nVote) + boost::lexical_cast(nTime); + if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) { - LogPrintf("CBudgetVote::SignatureValid() - Verify message failed\n"); + LogPrintf("CBudgetVote::IsValid() - Verify message failed - Error: %s\n", errorMessage); return false; } @@ -1680,12 +1679,6 @@ bool CFinalizedBudget::AddOrUpdateVote(CFinalizedBudgetVote& vote, std::string& } } - if(vote.nTime > GetTime() + (60*60)){ - strError = strprintf("new vote is too far ahead of current time - %s - nTime %lli - Max Time %lli", vote.GetHash().ToString(), vote.nTime, GetTime() + (60*60)); - LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); - return false; - } - mapVotes[hash] = vote; return true; } @@ -1774,7 +1767,7 @@ void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck) std::map::iterator it = mapVotes.begin(); while(it != mapVotes.end()) { - (*it).second.fValid = (*it).second.SignatureValid(fSignatureCheck); + (*it).second.fValid = (*it).second.IsValid(fSignatureCheck); ++it; } } @@ -2019,24 +2012,28 @@ bool CFinalizedBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) return true; } -bool CFinalizedBudgetVote::SignatureValid(bool fSignatureCheck) +bool CFinalizedBudgetVote::IsValid(bool fSignatureCheck) { - std::string errorMessage; - - std::string strMessage = vin.prevout.ToStringShort() + nBudgetHash.ToString() + boost::lexical_cast(nTime); + if(nTime > GetTime() + (60*60)){ + LogPrint("mnbudget", "CFinalizedBudgetVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60)); + return false; + } CMasternode* pmn = mnodeman.Find(vin); if(pmn == NULL) { - LogPrint("mnbudget", "CFinalizedBudgetVote::SignatureValid() - Unknown Masternode\n"); + LogPrint("mnbudget", "CFinalizedBudgetVote::IsValid() - Unknown Masternode\n"); return false; } if(!fSignatureCheck) return true; + std::string errorMessage; + std::string strMessage = vin.prevout.ToStringShort() + nBudgetHash.ToString() + boost::lexical_cast(nTime); + if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) { - LogPrintf("CFinalizedBudgetVote::SignatureValid() - Verify message failed\n"); + LogPrintf("CFinalizedBudgetVote::IsValid() - Verify message failed\n"); return false; } diff --git a/src/masternode-budget.h b/src/masternode-budget.h index 1a6b4334b..d8efb994c 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -370,7 +370,7 @@ public: CFinalizedBudgetVote(CTxIn vinIn, uint256 nBudgetHashIn); bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); - bool SignatureValid(bool fSignatureCheck); + bool IsValid(bool fSignatureCheck); void Relay(); uint256 GetHash(){ @@ -560,7 +560,7 @@ public: CBudgetVote(CTxIn vin, uint256 nProposalHash, int nVoteIn); bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); - bool SignatureValid(bool fSignatureCheck); + bool IsValid(bool fSignatureCheck); void Relay(); std::string GetVoteString() { diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index e3de83dfa..55bbae4a7 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -667,8 +667,8 @@ UniValue mnbudgetvoteraw(const UniValue& params, bool fHelp) vote.nTime = nTime; vote.vchSig = vchSig; - if(!vote.SignatureValid(true)){ - return "Failure to verify signature."; + if(!vote.IsValid(true)){ + return "Failure to verify vote."; } std::string strError = "";