find oldest legit masternode to pay / naming "now" -> "sigTime"

This commit is contained in:
UdjinM6 2015-03-01 18:38:53 +03:00
parent 2d3426755c
commit b2017ebefa
5 changed files with 27 additions and 22 deletions

View File

@ -133,7 +133,7 @@ CMasternode::CMasternode()
pubkey2 = CPubKey();
sig = std::vector<unsigned char>();
activeState = MASTERNODE_ENABLED;
now = GetTime();
sigTime = GetAdjustedTime();
lastDseep = 0;
lastTimeSeen = 0;
cacheInputAge = 0;
@ -153,7 +153,7 @@ CMasternode::CMasternode(const CMasternode& other)
pubkey2 = other.pubkey2;
sig = other.sig;
activeState = other.activeState;
now = other.now;
sigTime = other.sigTime;
lastDseep = other.lastDseep;
lastTimeSeen = other.lastTimeSeen;
cacheInputAge = other.cacheInputAge;
@ -164,7 +164,7 @@ CMasternode::CMasternode(const CMasternode& other)
nLastDsq = other.nLastDsq;
}
CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newNow, CPubKey newPubkey2, int protocolVersionIn)
CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newSigTime, CPubKey newPubkey2, int protocolVersionIn)
{
LOCK(cs);
vin = newVin;
@ -173,7 +173,7 @@ CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std:
pubkey2 = newPubkey2;
sig = newSig;
activeState = MASTERNODE_ENABLED;
now = newNow;
sigTime = newSigTime;
lastDseep = 0;
lastTimeSeen = 0;
cacheInputAge = 0;
@ -373,6 +373,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
{
if(!enabled) return false;
CMasternodePaymentWinner newWinner;
int nEnabled = mnodeman.CountEnabled();
std::vector<CTxIn> vecLastPayments;
BOOST_REVERSE_FOREACH(CMasternodePaymentWinner& winner, vWinning)
@ -383,8 +384,9 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
vecLastPayments.push_back(winner.vin);
}
CMasternode *pmn = mnodeman.FindNotInVec(vecLastPayments);
if(pmn != NULL)
// 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.FindOldestNotInVec(vecLastPayments);
if(pmn != NULL && pmn->GetMasternodeInputAge() > nEnabled && pmn->lastTimeSeen - pmn->sigTime > nEnabled * 2.5 * 60)
{
newWinner.score = 0;
newWinner.nBlockHeight = nBlockHeight;
@ -393,7 +395,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
}
//if we can't find new MN to get paid, pick first active MN counting back from the end of vecLastPayments list
if(newWinner.nBlockHeight == 0 && mnodeman.CountEnabled() > 0)
if(newWinner.nBlockHeight == 0 && nEnabled > 0)
{
BOOST_REVERSE_FOREACH(CTxIn& vinLP, vecLastPayments)
{

View File

@ -69,7 +69,7 @@ public:
CPubKey pubkey2;
std::vector<unsigned char> sig;
int activeState;
int64_t now; //dsee message times
int64_t sigTime; //dsee message times
int64_t lastDseep;
int64_t lastTimeSeen;
int cacheInputAge;
@ -81,7 +81,7 @@ public:
CMasternode();
CMasternode(const CMasternode& other);
CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newNow, CPubKey newPubkey2, int protocolVersionIn);
CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newSigTime, CPubKey newPubkey2, int protocolVersionIn);
void swap(CMasternode& first, CMasternode& second) // nothrow
{
@ -96,7 +96,7 @@ public:
swap(first.pubkey2, second.pubkey2);
swap(first.sig, second.sig);
swap(first.activeState, second.activeState);
swap(first.now, second.now);
swap(first.sigTime, second.sigTime);
swap(first.lastDseep, second.lastDseep);
swap(first.lastTimeSeen, second.lastTimeSeen);
swap(first.cacheInputAge, second.cacheInputAge);
@ -138,7 +138,7 @@ public:
READWRITE(pubkey2);
READWRITE(sig);
READWRITE(activeState);
READWRITE(now);
READWRITE(sigTime);
READWRITE(lastDseep);
READWRITE(lastTimeSeen);
READWRITE(cacheInputAge);

View File

@ -258,10 +258,12 @@ CMasternode *CMasternodeMan::Find(const CTxIn &vin)
return NULL;
}
CMasternode *CMasternodeMan::FindNotInVec(const std::vector<CTxIn> &vVins)
CMasternode* CMasternodeMan::FindOldestNotInVec(const std::vector<CTxIn> &vVins)
{
LOCK(cs);
CMasternode *pOldestMasternode = NULL;
BOOST_FOREACH(CMasternode &mn, vMasternodes)
{
mn.Check();
@ -277,10 +279,11 @@ CMasternode *CMasternodeMan::FindNotInVec(const std::vector<CTxIn> &vVins)
if(found) continue;
return &mn;
if(pOldestMasternode == NULL || pOldestMasternode->GetMasternodeInputAge() < mn.GetMasternodeInputAge())
pOldestMasternode = &mn;
}
return NULL;
return pOldestMasternode;
}
CMasternode *CMasternodeMan::FindRandom()
@ -435,10 +438,10 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(count == -1 && pmn->pubkey == pubkey && !pmn->UpdatedWithin(MASTERNODE_MIN_DSEE_SECONDS)){
pmn->UpdateLastSeen();
if(pmn->now < sigTime){ //take the newest entry
if(pmn->sigTime < sigTime){ //take the newest entry
LogPrintf("dsee - Got updated entry for %s\n", addr.ToString().c_str());
pmn->pubkey2 = pubkey2;
pmn->now = sigTime;
pmn->sigTime = sigTime;
pmn->sig = vchSig;
pmn->protocolVersion = protocolVersion;
pmn->addr = addr;
@ -614,9 +617,9 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
{
if(fDebug) LogPrintf("dseg - Sending masternode entry - %s \n", mn.addr.ToString().c_str());
if(vin == CTxIn()){
pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.sigTime, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
} else if (vin == mn.vin) {
pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.sigTime, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
LogPrintf("dseg - Sent 1 masternode entries to %s\n", pfrom->addr.ToString().c_str());
return;
}

View File

@ -96,7 +96,7 @@ public:
CMasternode* Find(const CTxIn& vin);
//Find an entry thta do not match every entry provided vector
CMasternode* FindNotInVec(const std::vector<CTxIn> &vVins);
CMasternode* FindOldestNotInVec(const std::vector<CTxIn> &vVins);
// Find a random entry
CMasternode* FindRandom();

View File

@ -468,7 +468,7 @@ Value masternode(const Array& params, bool fHelp)
obj.push_back(Pair("vin", winner->vin.prevout.hash.ToString().c_str()));
obj.push_back(Pair("pubkey", address2.ToString().c_str()));
obj.push_back(Pair("lastseen", (int64_t)winner->lastTimeSeen));
obj.push_back(Pair("activeseconds", (int64_t)(winner->lastTimeSeen - winner->now)));
obj.push_back(Pair("activeseconds", (int64_t)(winner->lastTimeSeen - winner->sigTime)));
return obj;
}
@ -627,7 +627,7 @@ Value masternodelist(const Array& params, bool fHelp)
} else if (strMode == "activeseconds") {
if(strFilter !="" && mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int64_t)(mn.lastTimeSeen - mn.now)));
obj.push_back(Pair(strAddr, (int64_t)(mn.lastTimeSeen - mn.sigTime)));
} else if (strMode == "rank") {
if(strFilter !="" && mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int)(mnodeman.GetMasternodeRank(mn.vin, chainActive.Tip()->nHeight))));
@ -644,7 +644,7 @@ Value masternodelist(const Array& params, bool fHelp)
address2.ToString() << " | " <<
mn.vin.prevout.hash.ToString() << " | " <<
mn.lastTimeSeen << " | " <<
(mn.lastTimeSeen - mn.now);
(mn.lastTimeSeen - mn.sigTime);
std::string output = stringStream.str();
stringStream << " " << strAddr;
if(strFilter !="" && stringStream.str().find(strFilter) == string::npos) continue;