diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index d29f1fc8a..18107be1f 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -378,6 +378,11 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st return; } + if(!masternodePayments.CanVote(winner.vinMasternode.prevout, winner.nBlockHeight)){ + LogPrintf("mnw - masternode already voted - %s\n", winner.vinMasternode.prevout.ToStringShort()); + return; + } + if(!winner.SignatureValid()){ LogPrintf("mnw - invalid signature\n"); Misbehaving(pfrom->GetId(), 100); @@ -388,7 +393,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st ExtractDestination(winner.payee, address1); CBitcoinAddress address2(address1); - if(fDebug) LogPrintf("mnw - winning vote - Addr %s Height %d bestHeight %d\n", address2.ToString().c_str(), winner.nBlockHeight, chainActive.Tip()->nHeight); + if(fDebug) LogPrintf("mnw - winning vote - Addr %s Height %d bestHeight %d - %s\n", address2.ToString().c_str(), winner.nBlockHeight, chainActive.Tip()->nHeight, winner.vinMasternode.prevout.ToStringShort()); if(masternodePayments.AddWinningMasternode(winner)){ winner.Relay(); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 7afb0472a..f7939c7ca 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -181,6 +181,7 @@ public: payee = payeeIn; } + ADD_SERIALIZE_METHODS; template @@ -216,6 +217,7 @@ private: public: std::map mapMasternodePayeeVotes; std::map mapMasternodeBlocks; + std::map mapMasternodesLastVote; //prevout.hash + prevout.n, nBlockHeight CMasternodePayments() { nSyncedFromPeer = 0; @@ -238,6 +240,18 @@ public: bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); bool IsScheduled(CMasternode& mn, int nNotBlockHeight); + bool CanVote(COutPoint outMasternode, int nBlockHeight) { + if(mapMasternodesLastVote.count(outMasternode.hash + outMasternode.n)) { + if(mapMasternodesLastVote[outMasternode.hash + outMasternode.n] == nBlockHeight) { + return false; + } + } + + //record this masternode voted + mapMasternodesLastVote[outMasternode.hash + outMasternode.n] = nBlockHeight; + return true; + } + int GetMinMasternodePaymentsProto(); void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); std::string GetRequiredPaymentsString(int nBlockHeight);