Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CMasternode
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;
Expand All @@ -81,7 +81,7 @@ class CMasternode

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
{
Expand All @@ -96,7 +96,7 @@ class CMasternode
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);
Expand Down Expand Up @@ -138,7 +138,7 @@ class CMasternode
READWRITE(pubkey2);
READWRITE(sig);
READWRITE(activeState);
READWRITE(now);
READWRITE(sigTime);
READWRITE(lastDseep);
READWRITE(lastTimeSeen);
READWRITE(cacheInputAge);
Expand Down
35 changes: 28 additions & 7 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -478,6 +481,24 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return;
}

// verify that sig time is legit in past
// should be at least not earlier than block when 1000 DRK tx got MASTERNODE_MIN_CONFIRMATIONS
uint256 hashBlock = 0;
GetTransaction(vin.prevout.hash, tx, hashBlock, true);
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second)
{
CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DRK tx -> 1 confirmation
CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS
if(pConfIndex->GetBlockTime() > sigTime)
{
LogPrintf("dsee - Bad sigTime %d for masternode %20s %105s (%i conf block is at %d)\n",
sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime());
return;
}
}


// use this as a peer
addrman.Add(CAddress(addr), pfrom->addr, 2*60*60);

Expand Down Expand Up @@ -614,9 +635,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CMasternodeMan
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();
Expand Down
6 changes: 3 additions & 3 deletions src/rpcdarksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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))));
Expand All @@ -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;
Expand Down