Check vote time internally

Closes #721
This commit is contained in:
UdjinM6 2016-03-06 18:44:58 +03:00 committed by Holger Schinzel
parent a2c6140cb1
commit 18afe88401
3 changed files with 29 additions and 32 deletions

View File

@ -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<uint256, CBudgetVote>::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<std::string>(nVote) + boost::lexical_cast<std::string>(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<std::string>(nVote) + boost::lexical_cast<std::string>(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<uint256, CFinalizedBudgetVote>::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<std::string>(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<std::string>(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;
}

View File

@ -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() {

View File

@ -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 = "";