Masternode System Bug Fixes

- Fixed a race condition with masternode node selection upon new blocks
- Using nTime for lastpaid instead of the current time for high consensus
This commit is contained in:
Evan Duffield 2015-06-14 17:05:51 -07:00
parent b2b2e12b10
commit c489574e8a
6 changed files with 11 additions and 12 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

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

View File

@ -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);

View File

@ -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;
}
}

View File

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