2016-02-02 16:28:56 +01:00
|
|
|
// Copyright (c) 2014-2016 The Dash Core developers
|
2015-02-24 15:02:22 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
#include "masternodeman.h"
|
|
|
|
#include "activemasternode.h"
|
|
|
|
#include "darksend.h"
|
2016-01-24 20:05:31 +01:00
|
|
|
#include "masternode.h"
|
|
|
|
#include "masternode-payments.h"
|
|
|
|
#include "masternode-sync.h"
|
2015-02-23 21:01:21 +01:00
|
|
|
#include "util.h"
|
|
|
|
#include "addrman.h"
|
2015-06-25 21:59:11 +02:00
|
|
|
#include "spork.h"
|
2015-02-23 21:01:21 +01:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
/** Masternode manager */
|
|
|
|
CMasternodeMan mnodeman;
|
|
|
|
|
2015-07-30 18:00:28 +02:00
|
|
|
struct CompareLastPaid
|
2015-02-23 21:01:21 +01:00
|
|
|
{
|
|
|
|
bool operator()(const pair<int64_t, CTxIn>& t1,
|
|
|
|
const pair<int64_t, CTxIn>& t2) const
|
|
|
|
{
|
|
|
|
return t1.first < t2.first;
|
|
|
|
}
|
|
|
|
};
|
2015-07-22 05:07:23 +02:00
|
|
|
|
2015-07-30 18:00:28 +02:00
|
|
|
struct CompareScoreTxIn
|
|
|
|
{
|
|
|
|
bool operator()(const pair<int64_t, CTxIn>& t1,
|
|
|
|
const pair<int64_t, CTxIn>& t2) const
|
|
|
|
{
|
|
|
|
return t1.first < t2.first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompareScoreMN
|
2015-03-14 19:34:51 +01:00
|
|
|
{
|
|
|
|
bool operator()(const pair<int64_t, CMasternode>& t1,
|
|
|
|
const pair<int64_t, CMasternode>& t2) const
|
|
|
|
{
|
|
|
|
return t1.first < t2.first;
|
|
|
|
}
|
|
|
|
};
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-03-06 18:25:48 +01:00
|
|
|
CMasternodeMan::CMasternodeMan() {
|
|
|
|
nDsqCount = 0;
|
|
|
|
}
|
2015-02-23 21:01:21 +01:00
|
|
|
|
|
|
|
bool CMasternodeMan::Add(CMasternode &mn)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
2015-08-05 05:16:29 +02:00
|
|
|
if (!mn.IsEnabled() && !mn.IsPreEnabled())
|
2015-02-23 21:01:21 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
CMasternode *pmn = Find(mn.vin);
|
2015-02-25 12:54:03 +01:00
|
|
|
if (pmn == NULL)
|
2015-02-23 21:01:21 +01:00
|
|
|
{
|
2015-08-28 22:04:14 +02:00
|
|
|
LogPrint("masternode", "CMasternodeMan: Adding new Masternode %s - %i now\n", mn.addr.ToString(), size() + 1);
|
2015-02-23 21:01:21 +01:00
|
|
|
vMasternodes.push_back(mn);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-07 05:07:40 +02:00
|
|
|
void CMasternodeMan::AskForMN(CNode* pnode, CTxIn &vin)
|
|
|
|
{
|
|
|
|
std::map<COutPoint, int64_t>::iterator i = mWeAskedForMasternodeListEntry.find(vin.prevout);
|
|
|
|
if (i != mWeAskedForMasternodeListEntry.end())
|
|
|
|
{
|
|
|
|
int64_t t = (*i).second;
|
|
|
|
if (GetTime() < t) return; // we've asked recently
|
|
|
|
}
|
|
|
|
|
|
|
|
// ask for the mnb info once from the node that sent mnp
|
|
|
|
|
|
|
|
LogPrintf("CMasternodeMan::AskForMN - Asking node for missing entry, vin: %s\n", vin.ToString());
|
2016-02-17 23:18:57 +01:00
|
|
|
pnode->PushMessage(NetMsgType::DSEG, vin);
|
2015-08-07 05:07:40 +02:00
|
|
|
int64_t askAgain = GetTime() + MASTERNODE_MIN_MNP_SECONDS;
|
|
|
|
mWeAskedForMasternodeListEntry[vin.prevout] = askAgain;
|
|
|
|
}
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
void CMasternodeMan::Check()
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
2015-06-24 18:41:03 +02:00
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
2015-02-23 21:01:21 +01:00
|
|
|
mn.Check();
|
2015-06-24 18:41:03 +02:00
|
|
|
}
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
2015-07-14 07:25:07 +02:00
|
|
|
void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval)
|
2015-02-23 21:01:21 +01:00
|
|
|
{
|
2016-05-30 08:22:30 +02:00
|
|
|
LogPrintf("CMasternodeMan::CheckAndRemove\n");
|
|
|
|
|
2015-02-24 11:39:29 +01:00
|
|
|
Check();
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-07-30 15:44:18 +02:00
|
|
|
LOCK(cs);
|
|
|
|
|
2015-07-14 07:25:07 +02:00
|
|
|
//remove inactive and outdated
|
2015-02-24 11:39:29 +01:00
|
|
|
vector<CMasternode>::iterator it = vMasternodes.begin();
|
2015-02-23 21:01:21 +01:00
|
|
|
while(it != vMasternodes.end()){
|
2015-07-14 07:25:07 +02:00
|
|
|
if((*it).activeState == CMasternode::MASTERNODE_REMOVE ||
|
|
|
|
(*it).activeState == CMasternode::MASTERNODE_VIN_SPENT ||
|
2016-05-27 08:24:44 +02:00
|
|
|
(forceExpiredRemoval && (*it).activeState == CMasternode::MASTERNODE_EXPIRED)) {
|
2016-05-30 08:22:30 +02:00
|
|
|
LogPrint("masternode", "CMasternodeMan::CheckAndRemove - Removing %s Masternode %s - %i now\n", (*it).Status(), (*it).addr.ToString(), size() - 1);
|
2015-07-21 01:48:57 +02:00
|
|
|
|
|
|
|
//erase all of the broadcasts we've seen from this vin
|
|
|
|
// -- if we missed a few pings and the node was removed, this will allow is to get it back without them
|
|
|
|
// sending a brand new mnb
|
|
|
|
map<uint256, CMasternodeBroadcast>::iterator it3 = mapSeenMasternodeBroadcast.begin();
|
|
|
|
while(it3 != mapSeenMasternodeBroadcast.end()){
|
|
|
|
if((*it3).second.vin == (*it).vin){
|
2015-08-05 02:54:02 +02:00
|
|
|
masternodeSync.mapSeenSyncMNB.erase((*it3).first);
|
2015-07-21 01:48:57 +02:00
|
|
|
mapSeenMasternodeBroadcast.erase(it3++);
|
|
|
|
} else {
|
|
|
|
++it3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow us to ask for this masternode again if we see another ping
|
|
|
|
map<COutPoint, int64_t>::iterator it2 = mWeAskedForMasternodeListEntry.begin();
|
|
|
|
while(it2 != mWeAskedForMasternodeListEntry.end()){
|
|
|
|
if((*it2).first == (*it).vin.prevout){
|
|
|
|
mWeAskedForMasternodeListEntry.erase(it2++);
|
|
|
|
} else {
|
|
|
|
++it2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:12:43 +01:00
|
|
|
it = vMasternodes.erase(it);
|
2015-02-23 21:01:21 +01:00
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 00:21:28 +01:00
|
|
|
|
2015-03-05 09:10:15 +01:00
|
|
|
// check who's asked for the Masternode list
|
2015-02-26 00:21:28 +01:00
|
|
|
map<CNetAddr, int64_t>::iterator it1 = mAskedUsForMasternodeList.begin();
|
|
|
|
while(it1 != mAskedUsForMasternodeList.end()){
|
2015-02-26 15:02:39 +01:00
|
|
|
if((*it1).second < GetTime()) {
|
|
|
|
mAskedUsForMasternodeList.erase(it1++);
|
|
|
|
} else {
|
2015-02-27 00:12:43 +01:00
|
|
|
++it1;
|
2015-02-26 15:02:39 +01:00
|
|
|
}
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 09:10:15 +01:00
|
|
|
// check who we asked for the Masternode list
|
2015-02-26 00:21:28 +01:00
|
|
|
it1 = mWeAskedForMasternodeList.begin();
|
|
|
|
while(it1 != mWeAskedForMasternodeList.end()){
|
2015-02-26 15:02:39 +01:00
|
|
|
if((*it1).second < GetTime()){
|
|
|
|
mWeAskedForMasternodeList.erase(it1++);
|
|
|
|
} else {
|
2015-02-27 00:12:43 +01:00
|
|
|
++it1;
|
2015-02-26 15:02:39 +01:00
|
|
|
}
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 09:10:15 +01:00
|
|
|
// check which Masternodes we've asked for
|
2015-02-26 00:21:28 +01:00
|
|
|
map<COutPoint, int64_t>::iterator it2 = mWeAskedForMasternodeListEntry.begin();
|
|
|
|
while(it2 != mWeAskedForMasternodeListEntry.end()){
|
2015-02-26 15:02:39 +01:00
|
|
|
if((*it2).second < GetTime()){
|
|
|
|
mWeAskedForMasternodeListEntry.erase(it2++);
|
|
|
|
} else {
|
2015-02-27 00:12:43 +01:00
|
|
|
++it2;
|
2015-02-26 15:02:39 +01:00
|
|
|
}
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
2015-08-29 05:25:55 +02:00
|
|
|
|
2016-03-14 13:17:23 +01:00
|
|
|
// remove expired mapSeenMasternodeBroadcast
|
|
|
|
map<uint256, CMasternodeBroadcast>::iterator it3 = mapSeenMasternodeBroadcast.begin();
|
|
|
|
while(it3 != mapSeenMasternodeBroadcast.end()){
|
|
|
|
if((*it3).second.lastPing.sigTime < GetTime() - MASTERNODE_REMOVAL_SECONDS*2){
|
|
|
|
LogPrint("masternode", "CMasternodeMan::CheckAndRemove - Removing expired Masternode broadcast %s\n", (*it3).second.GetHash().ToString());
|
|
|
|
masternodeSync.mapSeenSyncMNB.erase((*it3).second.GetHash());
|
|
|
|
mapSeenMasternodeBroadcast.erase(it3++);
|
|
|
|
} else {
|
|
|
|
++it3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 04:24:30 +02:00
|
|
|
// remove expired mapSeenMasternodePing
|
|
|
|
map<uint256, CMasternodePing>::iterator it4 = mapSeenMasternodePing.begin();
|
|
|
|
while(it4 != mapSeenMasternodePing.end()){
|
2016-03-14 13:17:23 +01:00
|
|
|
if((*it4).second.sigTime < GetTime() - MASTERNODE_REMOVAL_SECONDS*2){
|
2016-03-25 00:15:03 +01:00
|
|
|
LogPrint("masternode", "CMasternodeMan::CheckAndRemove - Removing expired Masternode ping %s\n", (*it4).second.GetHash().ToString());
|
2015-08-25 04:24:30 +02:00
|
|
|
mapSeenMasternodePing.erase(it4++);
|
|
|
|
} else {
|
|
|
|
++it4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 01:04:17 +01:00
|
|
|
void CMasternodeMan::Clear()
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
vMasternodes.clear();
|
|
|
|
mAskedUsForMasternodeList.clear();
|
|
|
|
mWeAskedForMasternodeList.clear();
|
|
|
|
mWeAskedForMasternodeListEntry.clear();
|
2015-09-30 03:24:29 +02:00
|
|
|
mapSeenMasternodeBroadcast.clear();
|
|
|
|
mapSeenMasternodePing.clear();
|
2015-03-06 18:25:48 +01:00
|
|
|
nDsqCount = 0;
|
2015-03-01 01:04:17 +01:00
|
|
|
}
|
|
|
|
|
2015-07-19 01:20:48 +02:00
|
|
|
int CMasternodeMan::CountEnabled(int protocolVersion)
|
2015-02-23 21:01:21 +01:00
|
|
|
{
|
|
|
|
int i = 0;
|
2016-02-04 20:29:09 +01:00
|
|
|
protocolVersion = protocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : protocolVersion;
|
2015-02-23 21:01:21 +01:00
|
|
|
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
2015-02-24 11:39:29 +01:00
|
|
|
mn.Check();
|
2015-02-26 00:21:28 +01:00
|
|
|
if(mn.protocolVersion < protocolVersion || !mn.IsEnabled()) continue;
|
|
|
|
i++;
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
2016-08-06 22:52:01 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 07:58:55 +02:00
|
|
|
int CMasternodeMan::CountByIP(int nNetworkType)
|
2016-08-06 22:52:01 +02:00
|
|
|
{
|
2016-08-12 07:58:55 +02:00
|
|
|
int nNodeCount = 0;
|
2016-08-06 22:52:01 +02:00
|
|
|
|
2016-08-12 07:58:55 +02:00
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes)
|
|
|
|
if( (nNetworkType == NET_IPV4 && mn.addr.IsIPv4()) ||
|
|
|
|
(nNetworkType == NET_TOR && mn.addr.IsTor()) ||
|
|
|
|
(nNetworkType == NET_IPV6 && mn.addr.IsIPv6())) {
|
|
|
|
nNodeCount++;
|
2016-08-06 22:52:01 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 07:58:55 +02:00
|
|
|
return nNodeCount;
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 00:21:28 +01:00
|
|
|
void CMasternodeMan::DsegUpdate(CNode* pnode)
|
|
|
|
{
|
2015-02-27 00:12:43 +01:00
|
|
|
LOCK(cs);
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
if(Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
2015-07-29 10:06:30 +02:00
|
|
|
if(!(pnode->addr.IsRFC1918() || pnode->addr.IsLocal())){
|
|
|
|
std::map<CNetAddr, int64_t>::iterator it = mWeAskedForMasternodeList.find(pnode->addr);
|
|
|
|
if (it != mWeAskedForMasternodeList.end())
|
|
|
|
{
|
|
|
|
if (GetTime() < (*it).second) {
|
|
|
|
LogPrintf("dseg - we already asked %s for the list; skipping...\n", pnode->addr.ToString());
|
|
|
|
return;
|
|
|
|
}
|
2015-07-02 17:07:30 +02:00
|
|
|
}
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 10:06:30 +02:00
|
|
|
|
2016-02-17 23:18:57 +01:00
|
|
|
pnode->PushMessage(NetMsgType::DSEG, CTxIn());
|
2015-02-26 00:21:28 +01:00
|
|
|
int64_t askAgain = GetTime() + MASTERNODES_DSEG_SECONDS;
|
|
|
|
mWeAskedForMasternodeList[pnode->addr] = askAgain;
|
|
|
|
}
|
|
|
|
|
2015-05-28 19:45:31 +02:00
|
|
|
CMasternode *CMasternodeMan::Find(const CScript &payee)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
CScript payee2;
|
|
|
|
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes)
|
|
|
|
{
|
|
|
|
payee2 = GetScriptForDestination(mn.pubkey.GetID());
|
|
|
|
if(payee2 == payee)
|
|
|
|
return &mn;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-26 00:21:28 +01:00
|
|
|
CMasternode *CMasternodeMan::Find(const CTxIn &vin)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes)
|
|
|
|
{
|
2015-04-09 21:17:32 +02:00
|
|
|
if(mn.vin.prevout == vin.prevout)
|
2015-02-26 00:21:28 +01:00
|
|
|
return &mn;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:59:30 +02:00
|
|
|
|
|
|
|
CMasternode *CMasternodeMan::Find(const CPubKey &pubKeyMasternode)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes)
|
|
|
|
{
|
|
|
|
if(mn.pubkey2 == pubKeyMasternode)
|
|
|
|
return &mn;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-22 05:07:23 +02:00
|
|
|
//
|
|
|
|
// Deterministically select the oldest/best masternode to pay on the network
|
|
|
|
//
|
2015-08-20 17:36:44 +02:00
|
|
|
CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount)
|
2015-02-26 00:21:28 +01:00
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
2015-07-22 05:07:23 +02:00
|
|
|
CMasternode *pBestMasternode = NULL;
|
|
|
|
std::vector<pair<int64_t, CTxIn> > vecMasternodeLastPaid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Make a vector with all of the last paid times
|
|
|
|
*/
|
2015-03-01 16:38:53 +01:00
|
|
|
|
2015-07-23 16:16:55 +02:00
|
|
|
int nMnCount = CountEnabled();
|
2015-02-26 00:21:28 +01:00
|
|
|
BOOST_FOREACH(CMasternode &mn, vMasternodes)
|
|
|
|
{
|
|
|
|
mn.Check();
|
|
|
|
if(!mn.IsEnabled()) continue;
|
|
|
|
|
2015-06-25 21:59:11 +02:00
|
|
|
// //check protocol version
|
2016-02-04 20:29:09 +01:00
|
|
|
if(mn.protocolVersion < mnpayments.GetMinMasternodePaymentsProto()) continue;
|
2015-06-25 21:59:11 +02:00
|
|
|
|
2015-07-23 15:45:43 +02:00
|
|
|
//it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it
|
2016-02-04 20:29:09 +01:00
|
|
|
if(mnpayments.IsScheduled(mn, nBlockHeight)) continue;
|
2015-05-27 21:47:01 +02:00
|
|
|
|
2015-07-23 16:16:55 +02:00
|
|
|
//it's too new, wait for a cycle
|
2015-07-25 01:10:44 +02:00
|
|
|
if(fFilterSigTime && mn.sigTime + (nMnCount*2.6*60) > GetAdjustedTime()) continue;
|
2015-07-23 16:16:55 +02:00
|
|
|
|
2015-05-30 19:27:51 +02:00
|
|
|
//make sure it has as many confirmations as there are masternodes
|
2015-07-23 16:16:55 +02:00
|
|
|
if(mn.GetMasternodeInputAge() < nMnCount) continue;
|
2015-05-30 19:27:51 +02:00
|
|
|
|
2015-07-22 05:07:23 +02:00
|
|
|
vecMasternodeLastPaid.push_back(make_pair(mn.SecondsSincePayment(), mn.vin));
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2015-08-20 18:27:34 +02:00
|
|
|
nCount = (int)vecMasternodeLastPaid.size();
|
|
|
|
|
2015-08-20 17:36:44 +02:00
|
|
|
//when the network is in the process of upgrading, don't penalize nodes that recently restarted
|
|
|
|
if(fFilterSigTime && nCount < nMnCount/3) return GetNextMasternodeInQueueForPayment(nBlockHeight, false, nCount);
|
|
|
|
|
2015-08-28 22:04:14 +02:00
|
|
|
// Sort them high to low
|
2015-07-30 18:00:28 +02:00
|
|
|
sort(vecMasternodeLastPaid.rbegin(), vecMasternodeLastPaid.rend(), CompareLastPaid());
|
2015-07-22 05:07:23 +02:00
|
|
|
|
|
|
|
// Look at 1/10 of the oldest nodes (by last payment), calculate their scores and pay the best one
|
2015-07-23 15:45:43 +02:00
|
|
|
// -- This doesn't look at who is being paid in the +8-10 blocks, allowing for double payments very rarely
|
2015-07-30 18:00:28 +02:00
|
|
|
// -- 1/100 payments should be a double payment on mainnet - (1/(3000/10))*2
|
|
|
|
// -- (chance per block * chances before IsScheduled will fire)
|
2015-08-11 21:43:05 +02:00
|
|
|
int nTenthNetwork = CountEnabled()/10;
|
2015-08-20 17:36:44 +02:00
|
|
|
int nCountTenth = 0;
|
2016-02-02 16:28:56 +01:00
|
|
|
arith_uint256 nHigh = 0;
|
2015-07-22 05:07:23 +02:00
|
|
|
BOOST_FOREACH (PAIRTYPE(int64_t, CTxIn)& s, vecMasternodeLastPaid){
|
2015-08-11 21:43:05 +02:00
|
|
|
CMasternode* pmn = Find(s.second);
|
2015-07-22 05:07:23 +02:00
|
|
|
if(!pmn) break;
|
|
|
|
|
2016-08-06 16:31:51 +02:00
|
|
|
arith_uint256 n = UintToArith256(pmn->CalculateScore(1, nBlockHeight - 101));
|
2015-07-22 05:07:23 +02:00
|
|
|
if(n > nHigh){
|
|
|
|
nHigh = n;
|
|
|
|
pBestMasternode = pmn;
|
|
|
|
}
|
2015-08-20 17:36:44 +02:00
|
|
|
nCountTenth++;
|
2015-08-20 17:50:29 +02:00
|
|
|
if(nCountTenth >= nTenthNetwork) break;
|
2015-07-22 05:07:23 +02:00
|
|
|
}
|
|
|
|
return pBestMasternode;
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 07:29:41 +02:00
|
|
|
CMasternode *CMasternodeMan::FindRandomNotInVec(std::vector<CTxIn> &vecToExclude, int nProtocolVersion)
|
2015-02-26 00:21:28 +01:00
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
2016-07-29 07:29:41 +02:00
|
|
|
nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion;
|
2015-07-29 17:11:43 +02:00
|
|
|
|
2016-07-29 07:29:41 +02:00
|
|
|
int nCountEnabled = CountEnabled(nProtocolVersion);
|
|
|
|
int nCountNotExcluded = nCountEnabled - vecToExclude.size();
|
2015-07-29 17:11:43 +02:00
|
|
|
|
2016-07-29 07:29:41 +02:00
|
|
|
LogPrintf("CMasternodeMan::FindRandomNotInVec -- %d enabled masternodes, %d masternodes aren't yet exluded\n", nCountEnabled, nCountNotExcluded);
|
|
|
|
if(nCountNotExcluded < 1) return NULL;
|
2015-02-26 00:21:28 +01:00
|
|
|
|
2016-07-29 07:29:41 +02:00
|
|
|
std::vector<CMasternode> vMasternodesShuffled = vMasternodes;
|
|
|
|
std::random_shuffle(vMasternodesShuffled.begin(), vMasternodesShuffled.end(), GetRandInt);
|
|
|
|
bool fExclude;
|
|
|
|
|
|
|
|
BOOST_FOREACH(CMasternode &mn, vMasternodesShuffled) {
|
|
|
|
if(mn.protocolVersion < nProtocolVersion || !mn.IsEnabled()) continue;
|
|
|
|
fExclude = false;
|
|
|
|
BOOST_FOREACH(CTxIn &txinToExclude, vecToExclude) {
|
|
|
|
if(mn.vin.prevout == txinToExclude.prevout) {
|
|
|
|
fExclude = true;
|
2015-07-29 17:11:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-29 07:29:41 +02:00
|
|
|
if(fExclude) continue;
|
|
|
|
// found the one not in vecToExclude
|
2016-07-30 13:34:48 +02:00
|
|
|
return Find(mn.vin);
|
2015-07-29 17:11:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2015-02-26 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
CMasternode* CMasternodeMan::GetCurrentMasterNode(int mod, int64_t nBlockHeight, int minProtocol)
|
|
|
|
{
|
2015-07-24 18:44:46 +02:00
|
|
|
int64_t score = 0;
|
2015-02-23 21:01:21 +01:00
|
|
|
CMasternode* winner = NULL;
|
|
|
|
|
|
|
|
// scan for winner
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
|
|
|
mn.Check();
|
|
|
|
if(mn.protocolVersion < minProtocol || !mn.IsEnabled()) continue;
|
|
|
|
|
2015-03-05 09:10:15 +01:00
|
|
|
// calculate the score for each Masternode
|
2015-02-23 21:01:21 +01:00
|
|
|
uint256 n = mn.CalculateScore(mod, nBlockHeight);
|
2016-02-02 16:28:56 +01:00
|
|
|
int64_t n2 = UintToArith256(n).GetCompact(false);
|
2015-02-23 21:01:21 +01:00
|
|
|
|
|
|
|
// determine the winner
|
|
|
|
if(n2 > score){
|
|
|
|
score = n2;
|
|
|
|
winner = &mn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return winner;
|
|
|
|
}
|
|
|
|
|
2015-03-13 10:28:20 +01:00
|
|
|
int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, int minProtocol, bool fOnlyActive)
|
2015-02-23 21:01:21 +01:00
|
|
|
{
|
2015-07-24 18:44:46 +02:00
|
|
|
std::vector<pair<int64_t, CTxIn> > vecMasternodeScores;
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-03-23 13:59:22 +01:00
|
|
|
//make sure we know about this block
|
2016-02-02 16:28:56 +01:00
|
|
|
uint256 hash = uint256();
|
2015-03-23 13:59:22 +01:00
|
|
|
if(!GetBlockHash(hash, nBlockHeight)) return -1;
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
// scan for winner
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
|
|
|
if(mn.protocolVersion < minProtocol) continue;
|
2015-03-24 03:02:22 +01:00
|
|
|
if(fOnlyActive) {
|
|
|
|
mn.Check();
|
|
|
|
if(!mn.IsEnabled()) continue;
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
uint256 n = mn.CalculateScore(1, nBlockHeight);
|
2016-02-02 16:28:56 +01:00
|
|
|
int64_t n2 = UintToArith256(n).GetCompact(false);
|
2015-02-23 21:01:21 +01:00
|
|
|
|
|
|
|
vecMasternodeScores.push_back(make_pair(n2, mn.vin));
|
|
|
|
}
|
|
|
|
|
2015-07-30 18:00:28 +02:00
|
|
|
sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(), CompareScoreTxIn());
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-03-02 00:09:33 +01:00
|
|
|
int rank = 0;
|
2015-07-24 18:44:46 +02:00
|
|
|
BOOST_FOREACH (PAIRTYPE(int64_t, CTxIn)& s, vecMasternodeScores){
|
2015-02-23 21:01:21 +01:00
|
|
|
rank++;
|
2015-06-15 02:05:51 +02:00
|
|
|
if(s.second.prevout == vin.prevout) {
|
2015-02-23 21:01:21 +01:00
|
|
|
return rank;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-14 19:34:51 +01:00
|
|
|
std::vector<pair<int, CMasternode> > CMasternodeMan::GetMasternodeRanks(int64_t nBlockHeight, int minProtocol)
|
|
|
|
{
|
2015-07-24 18:44:46 +02:00
|
|
|
std::vector<pair<int64_t, CMasternode> > vecMasternodeScores;
|
2015-03-14 19:34:51 +01:00
|
|
|
std::vector<pair<int, CMasternode> > vecMasternodeRanks;
|
|
|
|
|
2015-03-23 13:59:22 +01:00
|
|
|
//make sure we know about this block
|
2016-02-02 16:28:56 +01:00
|
|
|
uint256 hash = uint256();
|
2015-03-23 13:59:22 +01:00
|
|
|
if(!GetBlockHash(hash, nBlockHeight)) return vecMasternodeRanks;
|
|
|
|
|
2015-03-14 19:34:51 +01:00
|
|
|
// scan for winner
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
|
|
|
|
|
|
|
mn.Check();
|
|
|
|
|
|
|
|
if(mn.protocolVersion < minProtocol) continue;
|
|
|
|
if(!mn.IsEnabled()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 n = mn.CalculateScore(1, nBlockHeight);
|
2016-02-02 16:28:56 +01:00
|
|
|
int64_t n2 = UintToArith256(n).GetCompact(false);
|
2015-03-14 19:34:51 +01:00
|
|
|
|
|
|
|
vecMasternodeScores.push_back(make_pair(n2, mn));
|
|
|
|
}
|
|
|
|
|
2015-07-30 18:00:28 +02:00
|
|
|
sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(), CompareScoreMN());
|
2015-03-14 19:34:51 +01:00
|
|
|
|
|
|
|
int rank = 0;
|
2015-07-24 18:44:46 +02:00
|
|
|
BOOST_FOREACH (PAIRTYPE(int64_t, CMasternode)& s, vecMasternodeScores){
|
2015-03-14 19:34:51 +01:00
|
|
|
rank++;
|
|
|
|
vecMasternodeRanks.push_back(make_pair(rank, s.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vecMasternodeRanks;
|
|
|
|
}
|
|
|
|
|
2015-03-13 10:28:20 +01:00
|
|
|
CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int64_t nBlockHeight, int minProtocol, bool fOnlyActive)
|
2015-03-02 00:09:33 +01:00
|
|
|
{
|
2015-07-24 18:44:46 +02:00
|
|
|
std::vector<pair<int64_t, CTxIn> > vecMasternodeScores;
|
2015-03-02 00:09:33 +01:00
|
|
|
|
|
|
|
// scan for winner
|
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
|
|
|
|
|
|
|
if(mn.protocolVersion < minProtocol) continue;
|
2015-03-24 03:02:22 +01:00
|
|
|
if(fOnlyActive) {
|
|
|
|
mn.Check();
|
|
|
|
if(!mn.IsEnabled()) continue;
|
2015-03-02 00:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint256 n = mn.CalculateScore(1, nBlockHeight);
|
2016-02-02 16:28:56 +01:00
|
|
|
int64_t n2 = UintToArith256(n).GetCompact(false);
|
2015-03-02 00:09:33 +01:00
|
|
|
|
|
|
|
vecMasternodeScores.push_back(make_pair(n2, mn.vin));
|
|
|
|
}
|
|
|
|
|
2015-07-30 18:00:28 +02:00
|
|
|
sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(), CompareScoreTxIn());
|
2015-03-02 00:09:33 +01:00
|
|
|
|
|
|
|
int rank = 0;
|
2015-07-24 18:44:46 +02:00
|
|
|
BOOST_FOREACH (PAIRTYPE(int64_t, CTxIn)& s, vecMasternodeScores){
|
2015-03-02 00:09:33 +01:00
|
|
|
rank++;
|
|
|
|
if(rank == nRank) {
|
|
|
|
return Find(s.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:22:08 +02:00
|
|
|
void CMasternodeMan::InitDummyScriptPubkey() {
|
|
|
|
CKey secret;
|
|
|
|
secret.MakeNewKey(true);
|
|
|
|
|
|
|
|
CPubKey pubkey = secret.GetPubKey();
|
|
|
|
assert(secret.VerifyPubKey(pubkey));
|
|
|
|
|
|
|
|
if (pubkey.IsValid()) {
|
|
|
|
CKeyID keyID = pubkey.GetID();
|
|
|
|
LogPrintf("Generated dummyScriptPubkey: address %s privkey %s\n", CBitcoinAddress(keyID).ToString(), CBitcoinSecret(secret).ToString());
|
|
|
|
dummyScriptPubkey = GetScriptForDestination(keyID);
|
|
|
|
} else {
|
|
|
|
LogPrintf("CMasternodeMan::InitDummyScriptPubkey - ERROR: can't assign dummyScriptPubkey\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 00:09:33 +01:00
|
|
|
void CMasternodeMan::ProcessMasternodeConnections()
|
|
|
|
{
|
2015-03-24 03:03:34 +01:00
|
|
|
//we don't care about this for regtest
|
2016-02-02 16:28:56 +01:00
|
|
|
if(Params().NetworkIDString() == CBaseChainParams::REGTEST) return;
|
2015-03-06 23:17:51 +01:00
|
|
|
|
2015-08-11 08:00:46 +02:00
|
|
|
LOCK(cs_vNodes);
|
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) {
|
2016-07-30 13:05:41 +02:00
|
|
|
if(pnode->fMasternode) {
|
2015-08-11 08:00:46 +02:00
|
|
|
if(darkSendPool.pSubmittedToMasternode != NULL && pnode->addr == darkSendPool.pSubmittedToMasternode->addr) continue;
|
2015-07-31 17:46:47 +02:00
|
|
|
LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString());
|
2016-07-30 13:05:41 +02:00
|
|
|
pnode->fDisconnect = true;
|
2015-03-02 00:09:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
|
|
|
|
{
|
|
|
|
|
2015-03-05 09:10:15 +01:00
|
|
|
if(fLiteMode) return; //disable all Darksend/Masternode related functionality
|
2015-08-07 06:48:55 +02:00
|
|
|
if(!masternodeSync.IsBlockchainSynced()) return;
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-03-31 23:21:59 +02:00
|
|
|
LOCK(cs_process_message);
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-02-17 23:18:57 +01:00
|
|
|
if (strCommand == NetMsgType::MNANNOUNCE) { //Masternode Broadcast
|
2015-04-17 17:10:38 +02:00
|
|
|
CMasternodeBroadcast mnb;
|
2015-07-14 07:25:07 +02:00
|
|
|
vRecv >> mnb;
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-03-15 00:16:29 +01:00
|
|
|
int nDos = 0;
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-03-18 00:37:48 +01:00
|
|
|
if (CheckMnbAndUpdateMasternodeList(mnb, nDos)) {
|
|
|
|
// use announced Masternode as a peer
|
2015-04-17 17:10:38 +02:00
|
|
|
addrman.Add(CAddress(mnb.addr), pfrom->addr, 2*60*60);
|
2015-02-23 21:01:21 +01:00
|
|
|
} else {
|
2016-03-18 00:37:48 +01:00
|
|
|
if(nDos > 0) Misbehaving(pfrom->GetId(), nDos);
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-29 21:11:34 +02:00
|
|
|
} else if (strCommand == NetMsgType::MNPING) { //Masternode Ping
|
|
|
|
|
|
|
|
// ignore masternode pings until masternode list is synced
|
|
|
|
if (!masternodeSync.IsMasternodeListSynced()) return;
|
|
|
|
|
2015-04-17 17:10:38 +02:00
|
|
|
CMasternodePing mnp;
|
|
|
|
vRecv >> mnp;
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-08-28 22:04:14 +02:00
|
|
|
LogPrint("masternode", "mnp - Masternode ping, vin: %s\n", mnp.vin.ToString());
|
2015-07-14 07:25:07 +02:00
|
|
|
|
2015-08-11 21:43:05 +02:00
|
|
|
if(mapSeenMasternodePing.count(mnp.GetHash())) return; //seen
|
|
|
|
mapSeenMasternodePing.insert(make_pair(mnp.GetHash(), mnp));
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-03-15 00:16:29 +01:00
|
|
|
LogPrint("masternode", "mnp - Masternode ping, vin: %s new\n", mnp.vin.ToString());
|
2016-02-17 19:53:55 +01:00
|
|
|
|
2016-03-15 00:16:29 +01:00
|
|
|
int nDos = 0;
|
|
|
|
if(mnp.CheckAndUpdate(nDos)) return;
|
2015-07-14 07:25:07 +02:00
|
|
|
|
2016-03-15 00:16:29 +01:00
|
|
|
if(nDos > 0) {
|
2015-08-07 05:07:40 +02:00
|
|
|
// if anything significant failed, mark that node
|
2016-03-15 00:16:29 +01:00
|
|
|
Misbehaving(pfrom->GetId(), nDos);
|
2015-08-07 05:07:40 +02:00
|
|
|
} else {
|
|
|
|
// if nothing significant failed, search existing Masternode list
|
2015-08-11 21:43:05 +02:00
|
|
|
CMasternode* pmn = Find(mnp.vin);
|
2015-08-07 05:07:40 +02:00
|
|
|
// if it's known, don't ask for the mnb, just return
|
|
|
|
if(pmn != NULL) return;
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
2015-08-07 05:07:40 +02:00
|
|
|
// something significant is broken or mn is unknown,
|
|
|
|
// we might have to ask for a masternode entry once
|
|
|
|
AskForMN(pfrom, mnp.vin);
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-02-17 23:18:57 +01:00
|
|
|
} else if (strCommand == NetMsgType::DSEG) { //Get Masternode list or specific entry
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-08-29 21:11:34 +02:00
|
|
|
// Ignore such requests until we are fully synced.
|
|
|
|
// We could start processing this after masternode list is synced
|
|
|
|
// but this is a heavy one so it's better to finish sync first.
|
2016-08-05 18:25:03 +02:00
|
|
|
if (!masternodeSync.IsSynced()) return;
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
CTxIn vin;
|
|
|
|
vRecv >> vin;
|
|
|
|
|
2016-02-17 19:53:55 +01:00
|
|
|
LogPrint("masternode", "dseg - Masternode list, vin: %s\n", vin.ToString());
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
if(vin == CTxIn()) { //only should ask for this once
|
|
|
|
//local network
|
2015-07-02 17:07:30 +02:00
|
|
|
bool isLocal = (pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal());
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
if(!isLocal && Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
2015-02-26 00:21:28 +01:00
|
|
|
std::map<CNetAddr, int64_t>::iterator i = mAskedUsForMasternodeList.find(pfrom->addr);
|
2015-04-03 00:51:08 +02:00
|
|
|
if (i != mAskedUsForMasternodeList.end()){
|
2015-02-23 21:01:21 +01:00
|
|
|
int64_t t = (*i).second;
|
|
|
|
if (GetTime() < t) {
|
|
|
|
Misbehaving(pfrom->GetId(), 34);
|
|
|
|
LogPrintf("dseg - peer already asked me for the list\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 00:21:28 +01:00
|
|
|
int64_t askAgain = GetTime() + MASTERNODES_DSEG_SECONDS;
|
|
|
|
mAskedUsForMasternodeList[pfrom->addr] = askAgain;
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
} //else, asking for a specific node which is ok
|
|
|
|
|
2015-07-29 06:16:11 +02:00
|
|
|
|
2015-08-31 06:05:10 +02:00
|
|
|
int nInvCount = 0;
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
2016-02-14 13:09:45 +01:00
|
|
|
if(mn.addr.IsRFC1918() || mn.addr.IsLocal()) continue; //local network
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
if(mn.IsEnabled()) {
|
2015-07-26 06:13:17 +02:00
|
|
|
if(vin == CTxIn() || vin == mn.vin){
|
2016-05-30 08:22:30 +02:00
|
|
|
LogPrint("masternode", "dseg - Sending Masternode entry - %s \n", mn.addr.ToString());
|
2015-08-26 02:18:01 +02:00
|
|
|
CMasternodeBroadcast mnb = CMasternodeBroadcast(mn);
|
|
|
|
uint256 hash = mnb.GetHash();
|
2015-08-31 06:05:10 +02:00
|
|
|
pfrom->PushInventory(CInv(MSG_MASTERNODE_ANNOUNCE, hash));
|
|
|
|
nInvCount++;
|
2015-05-04 17:04:09 +02:00
|
|
|
|
2015-08-26 02:18:01 +02:00
|
|
|
if(!mapSeenMasternodeBroadcast.count(hash)) mapSeenMasternodeBroadcast.insert(make_pair(hash, mnb));
|
|
|
|
|
2015-07-26 06:13:17 +02:00
|
|
|
if(vin == mn.vin) {
|
2015-07-31 17:46:47 +02:00
|
|
|
LogPrintf("dseg - Sent 1 Masternode entries to %s\n", pfrom->addr.ToString());
|
2015-08-31 06:05:10 +02:00
|
|
|
return;
|
2015-07-26 06:13:17 +02:00
|
|
|
}
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-29 06:16:11 +02:00
|
|
|
|
2015-08-31 06:05:10 +02:00
|
|
|
if(vin == CTxIn()) {
|
2016-02-17 23:18:57 +01:00
|
|
|
pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_LIST, nInvCount);
|
2015-08-31 06:05:10 +02:00
|
|
|
LogPrintf("dseg - Sent %d Masternode entries to %s\n", nInvCount, pfrom->addr.ToString());
|
|
|
|
}
|
2015-08-09 15:06:54 +02:00
|
|
|
}
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
2015-03-01 00:56:52 +01:00
|
|
|
|
2015-04-08 04:07:25 +02:00
|
|
|
void CMasternodeMan::Remove(CTxIn vin)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
|
|
|
|
vector<CMasternode>::iterator it = vMasternodes.begin();
|
|
|
|
while(it != vMasternodes.end()){
|
|
|
|
if((*it).vin == vin){
|
2015-08-28 22:04:14 +02:00
|
|
|
LogPrint("masternode", "CMasternodeMan: Removing Masternode %s - %i now\n", (*it).addr.ToString(), size() - 1);
|
2015-04-08 04:07:25 +02:00
|
|
|
vMasternodes.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
2015-05-04 17:04:09 +02:00
|
|
|
++it;
|
2015-04-08 04:07:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-05 00:46:50 +01:00
|
|
|
std::string CMasternodeMan::ToString() const
|
2015-03-01 00:56:52 +01:00
|
|
|
{
|
|
|
|
std::ostringstream info;
|
|
|
|
|
2015-03-05 09:10:15 +01:00
|
|
|
info << "Masternodes: " << (int)vMasternodes.size() <<
|
|
|
|
", peers who asked us for Masternode list: " << (int)mAskedUsForMasternodeList.size() <<
|
|
|
|
", peers we asked for Masternode list: " << (int)mWeAskedForMasternodeList.size() <<
|
2015-03-06 18:25:48 +01:00
|
|
|
", entries in Masternode list we asked for: " << (int)mWeAskedForMasternodeListEntry.size() <<
|
|
|
|
", nDsqCount: " << (int)nDsqCount;
|
2015-03-01 00:56:52 +01:00
|
|
|
|
|
|
|
return info.str();
|
|
|
|
}
|
2016-02-04 20:29:09 +01:00
|
|
|
|
|
|
|
int CMasternodeMan::GetEstimatedMasternodes(int nBlock)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Masternodes = (Coins/1000)*X on average
|
|
|
|
|
|
|
|
*X = nPercentage, starting at 0.52
|
|
|
|
nPercentage goes up 0.01 each period
|
|
|
|
Period starts at 35040, which has exponential slowing growth
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int nPercentage = 52; //0.52
|
|
|
|
int nPeriod = 35040;
|
|
|
|
int nCollateral = 1000;
|
|
|
|
|
|
|
|
for(int i = nPeriod; i <= nBlock; i += nPeriod)
|
|
|
|
{
|
|
|
|
nPercentage++;
|
|
|
|
nPeriod*=2;
|
|
|
|
}
|
|
|
|
return (GetTotalCoinEstimate(nBlock)/100*nPercentage/nCollateral);
|
|
|
|
}
|
2016-03-16 16:30:22 +01:00
|
|
|
|
|
|
|
void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb) {
|
|
|
|
mapSeenMasternodePing.insert(make_pair(mnb.lastPing.GetHash(), mnb.lastPing));
|
|
|
|
mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb));
|
|
|
|
masternodeSync.AddedMasternodeList(mnb.GetHash());
|
|
|
|
|
|
|
|
LogPrintf("CMasternodeMan::UpdateMasternodeList() - addr: %s\n vin: %s\n", mnb.addr.ToString(), mnb.vin.ToString());
|
|
|
|
|
|
|
|
CMasternode* pmn = Find(mnb.vin);
|
|
|
|
if(pmn == NULL)
|
|
|
|
{
|
|
|
|
CMasternode mn(mnb);
|
|
|
|
Add(mn);
|
|
|
|
} else {
|
|
|
|
pmn->UpdateFromNewBroadcast(mnb);
|
|
|
|
}
|
|
|
|
}
|
2016-03-18 00:37:48 +01:00
|
|
|
|
|
|
|
bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CMasternodeBroadcast mnb, int& nDos) {
|
|
|
|
nDos = 0;
|
|
|
|
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList - Masternode broadcast, vin: %s\n", mnb.vin.ToString());
|
|
|
|
|
|
|
|
if(mapSeenMasternodeBroadcast.count(mnb.GetHash())) { //seen
|
|
|
|
masternodeSync.AddedMasternodeList(mnb.GetHash());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb));
|
|
|
|
|
|
|
|
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList - Masternode broadcast, vin: %s new\n", mnb.vin.ToString());
|
|
|
|
|
|
|
|
if(!mnb.CheckAndUpdate(nDos)){
|
|
|
|
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList - Masternode broadcast, vin: %s CheckAndUpdate failed\n", mnb.vin.ToString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure it's still unspent
|
|
|
|
// - this is checked later by .check() in many places and by ThreadCheckDarkSendPool()
|
|
|
|
if(mnb.CheckInputsAndAdd(nDos)) {
|
|
|
|
masternodeSync.AddedMasternodeList(mnb.GetHash());
|
|
|
|
} else {
|
|
|
|
LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList - Rejected Masternode entry %s\n", mnb.addr.ToString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|