diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 95945bbee..809ffbb43 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -226,7 +226,6 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste } bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, CScript donationAddress, int donationPercentage, std::string &retErrorMessage) { - CMasternode* pmn = mnodeman.Find(vin); if(pmn == NULL) { @@ -239,6 +238,7 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral } CMasternode mn(mnb); + mn.UpdateLastSeen(); mnodeman.Add(mn); } diff --git a/src/main.cpp b/src/main.cpp index f2fda2c39..1a3de9909 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3240,7 +3240,7 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis //UPDATE MASTERNODE LAST PAID TIME CMasternode* pmn = mnodeman.Find(payee); if(pmn != NULL) { - pmn->nLastPaid = GetAdjustedTime(); + pmn->nLastPaid = chainActive.Tip()->nTime; } LogPrintf("%s : Update Masternode Last Paid Time - %d\n", __func__, chainActive.Tip()->nHeight); } diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 0003a0037..488f9a925 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -230,7 +230,7 @@ bool CMasternodePayments::GetBlockPayee(int nBlockHeight, CScript& payee) return false; } -bool CMasternodePayments::IsScheduled(CMasternode& mn) +bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight) { CBlockIndex* pindexPrev = chainActive.Tip(); if(pindexPrev == NULL) return false; @@ -240,6 +240,7 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn) CScript payee; for(int64_t h = pindexPrev->nHeight; h <= pindexPrev->nHeight+10; h++){ + if(h == nNotBlockHeight) continue; if(mapMasternodeBlocks.count(h)){ if(mapMasternodeBlocks[h].GetPayee(payee)){ if(mnpayee == payee || mn.donationAddress == payee) { @@ -450,6 +451,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) } else { CScript payeeSource; uint256 hash; + if(!GetBlockHash(hash, nBlockHeight-100)) return false; unsigned int nHash; memcpy(&nHash, &hash, 2); @@ -457,7 +459,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) LogPrintf(" ProcessBlock Start nHeight %d. \n", nBlockHeight); // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough - CMasternode *pmn = mnodeman.GetNextMasternodeInQueueForPayment(); + CMasternode *pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight); if(pmn != NULL) { LogPrintf(" Found by FindOldestNotInVec \n"); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 07086dd8f..f5d15e5d0 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -192,7 +192,7 @@ public: bool GetBlockPayee(int nBlockHeight, CScript& payee); bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); - bool IsScheduled(CMasternode& mn); + bool IsScheduled(CMasternode& mn, int nNotBlockHeight); void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); std::string GetRequiredPaymentsString(int nBlockHeight); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index a4decb0af..c29298b0d 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -206,7 +206,6 @@ bool CMasternodeMan::Add(CMasternode &mn) return false; CMasternode *pmn = Find(mn.vin); - if (pmn == NULL) { if(fDebug) LogPrintf("CMasternodeMan: Adding new Masternode %s - %i now\n", mn.addr.ToString().c_str(), size() + 1); @@ -365,7 +364,7 @@ CMasternode *CMasternodeMan::Find(const CPubKey &pubKeyMasternode) return NULL; } -CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment() +CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight) { LOCK(cs); @@ -377,7 +376,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment() if(!mn.IsEnabled()) continue; //it's in the list -- so let's skip it - if(masternodePayments.IsScheduled(mn)) continue; + if(masternodePayments.IsScheduled(mn, nBlockHeight)) continue; //make sure it has as many confirmations as there are masternodes if(mn.GetMasternodeInputAge() < CountEnabled()) continue; @@ -440,13 +439,11 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in // scan for winner BOOST_FOREACH(CMasternode& mn, vMasternodes) { - if(mn.protocolVersion < minProtocol) continue; if(fOnlyActive) { mn.Check(); if(!mn.IsEnabled()) continue; } - uint256 n = mn.CalculateScore(1, nBlockHeight); unsigned int n2 = 0; memcpy(&n2, &n, sizeof(n2)); @@ -459,7 +456,7 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in int rank = 0; BOOST_FOREACH (PAIRTYPE(unsigned int, CTxIn)& s, vecMasternodeScores){ rank++; - if(s.second == vin) { + if(s.second.prevout == vin.prevout) { return rank; } } diff --git a/src/masternodeman.h b/src/masternodeman.h index 64cfcc52f..9a52d87d7 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -110,7 +110,7 @@ public: CMasternode* Find(const CPubKey& pubKeyMasternode); /// Find an entry in the masternode list that is next to be paid - CMasternode* GetNextMasternodeInQueueForPayment(); + CMasternode* GetNextMasternodeInQueueForPayment(int nBlockHeight); /// Find a random entry CMasternode* FindRandom();