diff --git a/src/darksend-relay.cpp b/src/darksend-relay.cpp index 4c209933655c6..e0f7724315d83 100644 --- a/src/darksend-relay.cpp +++ b/src/darksend-relay.cpp @@ -85,7 +85,7 @@ bool CDarkSendRelay::VerifyMessage(std::string strSharedKey) void CDarkSendRelay::Relay() { - int nCount = std::min(mnodeman.CountEnabled(), 20); + int nCount = std::min(mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION), 20); int nRank1 = (rand() % nCount)+1; int nRank2 = (rand() % nCount)+1; diff --git a/src/darksend.cpp b/src/darksend.cpp index 6d25f53dc6cd5..2cb9557a7fb3c 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -80,7 +80,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand if(sessionUsers == 0) { if(pmn->nLastDsq != 0 && - pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){ + pmn->nLastDsq + mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){ LogPrintf("dsa -- last dsq too recent, must wait. %s \n", pfrom->addr.ToString().c_str()); errorID = ERR_RECENT; pfrom->PushMessage("dssu", sessionID, GetState(), GetEntriesCount(), MASTERNODE_REJECTED, errorID); @@ -139,7 +139,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand if(fDebug) LogPrintf("dsq last %d last2 %d count %d\n", pmn->nLastDsq, pmn->nLastDsq + mnodeman.size()/5, mnodeman.nDsqCount); //don't allow a few nodes to dominate the queuing process if(pmn->nLastDsq != 0 && - pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){ + pmn->nLastDsq + mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){ if(fDebug) LogPrintf("dsq -- Masternode sending too many dsq messages. %s \n", pmn->addr.ToString().c_str()); return; } @@ -1679,7 +1679,7 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready) } if(pmn->nLastDsq != 0 && - pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){ + pmn->nLastDsq + mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){ i++; continue; } @@ -2348,7 +2348,7 @@ void ThreadCheckDarkSendPool() CleanTransactionLocksList(); //if we've used 90% of the Masternode list then drop all the oldest. - int nThreshold = (int)(mnodeman.CountEnabled() * 0.9); + int nThreshold = (int)(mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION) * 0.9); if(fDebug) LogPrintf("Checking vecMasternodesUsed size %d threshold %d\n", (int)vecMasternodesUsed.size(), nThreshold); while((int)vecMasternodesUsed.size() > nThreshold){ vecMasternodesUsed.erase(vecMasternodesUsed.begin()); diff --git a/src/init.cpp b/src/init.cpp index a8ef742ab78de..c0cd20d163096 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -415,7 +415,6 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += " -mnconflock= " + strprintf(_("Lock masternodes from masternode configuration file (default: %u)"), 1) + "\n"; strUsage += " -masternodeprivkey= " + _("Set the masternode private key") + "\n"; strUsage += " -masternodeaddr= " + _("Set external address:port to get to this masternode (example: address:port)") + "\n"; - strUsage += " -masternodeminprotocol= " + strprintf(_("Ignore masternodes less than version (example: 70050; default: %u)"), MIN_POOL_PEER_PROTO_VERSION) + "\n"; strUsage += " -budgetvotemode= " + _("Change automatic finalized budget voting behavior. mode=auto: Vote for only exact finalized budget match to my generated budget. (string, default: auto)") + "\n"; strUsage += "\n" + _("Darksend options:") + "\n"; @@ -868,9 +867,6 @@ bool AppInit2(boost::thread_group& threadGroup) return InitError(_("Unable to sign spork message, wrong key?")); } - //ignore masternodes below protocol version - nMasternodeMinProtocol = GetArg("-masternodeminprotocol", MIN_POOL_PEER_PROTO_VERSION); - /* Start the RPC server already. It will be started in "warmup" mode * and not really process calls already (but it will signify connections * that the server is there and will be ready later). Warmup mode will diff --git a/src/main.cpp b/src/main.cpp index eb55cc15cf49b..4f8940109006f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3261,13 +3261,14 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis return error("%s : ActivateBestChain failed", __func__); if(!fLiteMode){ - if (masternodeSync.IsSynced()){ + if (masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_LIST) { CScript payee; CTxIn vin; coinbasePayee.ReprocessChain(); darkSendPool.NewBlock(); masternodePayments.ProcessBlock(GetHeight()+10); - budget.NewBlock(); + if (masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_BUDGET) + budget.NewBlock(); } } diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 26252669b404d..d0655f0463856 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -523,7 +523,7 @@ bool CBudgetManager::IsBudgetPaymentBlock(int nBlockHeight){ /* If budget doesn't have 5% of the network votes, then we should pay a masternode instead */ - if(nHighestCount > mnodeman.CountEnabled()/20) return true; + if(nHighestCount > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return true; return false; } @@ -551,7 +551,7 @@ bool CBudgetManager::IsTransactionValid(const CTransaction& txNew, int nBlockHei /* If budget doesn't have 5% of the network votes, then we should pay a masternode instead */ - if(nHighestCount < mnodeman.CountEnabled()/20) return false; + if(nHighestCount < mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return false; // check the highest finalized budgets (+/- 10% to assist in consensus) @@ -560,7 +560,7 @@ bool CBudgetManager::IsTransactionValid(const CTransaction& txNew, int nBlockHei { CFinalizedBudget* pfinalizedBudget = &((*it).second); - if(pfinalizedBudget->GetVoteCount() > nHighestCount - mnodeman.CountEnabled()/10){ + if(pfinalizedBudget->GetVoteCount() > nHighestCount - mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){ if(nBlockHeight >= pfinalizedBudget->GetBlockStart() && nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ if(pfinalizedBudget->IsTransactionValid(txNew, nBlockHeight)){ return true; @@ -636,7 +636,7 @@ std::vector CBudgetManager::GetBudget() //prop start/end should be inside this period if(pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart && pbudgetProposal->nBlockEnd >= nBlockEnd && - pbudgetProposal->GetYeas() - pbudgetProposal->GetNays() > mnodeman.CountEnabled()/10) + pbudgetProposal->GetYeas() - pbudgetProposal->GetNays() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10) { if(nTotalBudget == nBudgetAllocated){ pbudgetProposal->SetAllotted(0); @@ -1070,7 +1070,7 @@ CBudgetProposal::CBudgetProposal(const CBudgetProposal& other) bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral) { - if(GetNays() - GetYeas() > mnodeman.CountEnabled()/10){ + if(GetNays() - GetYeas() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){ strError = "Active removal"; return false; } @@ -1094,7 +1094,7 @@ bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral) //if proposal doesn't gain traction within 2 weeks, remove it // nTime not being saved correctly // if(nTime + (60*60*24*2) < GetAdjustedTime()) { - // if(GetYeas()-GetNays() < (mnodeman.CountEnabled()/10)) { + // if(GetYeas()-GetNays() < (mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10)) { // strError = "Not enough support"; // return false; // } diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 51908181db91f..44d6fb52f635c 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -4,6 +4,7 @@ #include "main.h" #include "masternode-sync.h" +#include "masternode-payments.h" #include "masternode.h" #include "masternodeman.h" #include "util.h" @@ -46,6 +47,9 @@ void CMasternodeSync::GetNextAsset() switch(RequestedMasternodeAssets) { case(MASTERNODE_SYNC_INITIAL): + lastMasternodeList = 0; + lastMasternodeWinner = 0; + lastBudgetItem = 0; RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS; break; case(MASTERNODE_SYNC_SPORKS): @@ -67,7 +71,12 @@ void CMasternodeSync::GetNextAsset() void CMasternodeSync::Process() { - static int c = 0; + static int tick = 0; + + if(tick++ % MASTERNODE_SYNC_TIMEOUT != 0) return; + + CBlockIndex* pindexPrev = chainActive.Tip(); + if(pindexPrev == NULL) return; if(IsSynced()) { /* @@ -75,49 +84,44 @@ void CMasternodeSync::Process() */ if(mnodeman.CountEnabled() == 0) { RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL; - RequestedMasternodeAttempt = 0; - } - return; + } else + return; } - if(c++ % MASTERNODE_SYNC_TIMEOUT != 0) return; + if(fDebug) LogPrintf("CMasternodeSync::Process() - tick %d RequestedMasternodeAssets %d\n", tick, RequestedMasternodeAssets); - if(fDebug) LogPrintf("CMasternodeSync::Process() - RequestedMasternodeAssets %d c %d\n", RequestedMasternodeAssets, c); - - //request full mn list only if Masternodes.dat was updated quite a long time ago if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset(); - CBlockIndex* pindexPrev = chainActive.Tip(); - if(pindexPrev == NULL) return; - LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { - if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) - { - //set to syned - if(Params().NetworkID() == CBaseChainParams::REGTEST && c >= 10) { - LogPrintf("CMasternodeSync::Process - Sync has finished\n"); - RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; - RequestedMasternodeAttempt = 0; - } - if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){ - if(pnode->HasFulfilledRequest("getspork")) continue; - pnode->FulfilledRequest("getspork"); + //set to synced + if(Params().NetworkID() == CBaseChainParams::REGTEST && tick >= 10) { + LogPrintf("CMasternodeSync::Process - Sync has finished\n"); + RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; + RequestedMasternodeAttempt = 0; + } - if(RequestedMasternodeAttempt <= 2){ - pnode->PushMessage("getsporks"); //get current network sporks - if(RequestedMasternodeAttempt == 2) GetNextAsset(); - RequestedMasternodeAttempt++; - } - return; + if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){ + if(pnode->HasFulfilledRequest("getspork")) continue; + pnode->FulfilledRequest("getspork"); + + if(RequestedMasternodeAttempt <= 2){ + pnode->PushMessage("getsporks"); //get current network sporks + if(RequestedMasternodeAttempt == 2) GetNextAsset(); + RequestedMasternodeAttempt++; } + return; + } + + //don't begin syncing until we're almost at a recent block + if(pindexPrev->nHeight + 4 < pindexBestHeader->nHeight && pindexPrev->nTime + 600 < GetTime()) return; - //don't begin syncing until we're at a recent block - if(pindexPrev->nTime + 600 < GetTime()) return; + if (pnode->nVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { - if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST){ + if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) { + if(fDebug) LogPrintf("CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT); if(lastMasternodeList > 0 && lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT){ //hasn't received a new item in the last five seconds, so we'll move to the GetNextAsset(); return; @@ -134,7 +138,7 @@ void CMasternodeSync::Process() return; } - if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW){ + if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) { if(lastMasternodeWinner > 0 && lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT){ //hasn't received a new item in the last five seconds, so we'll move to the GetNextAsset(); return; @@ -150,6 +154,9 @@ void CMasternodeSync::Process() } return; } + } + + if (pnode->nVersion >= MIN_BUDGET_PEER_PROTO_VERSION) { if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ if(lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT){ //hasn't received a new item in the last five seconds, so we'll move to the diff --git a/src/masternode.cpp b/src/masternode.cpp index a06d43de8adf2..4e97c53211ba5 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -78,7 +78,7 @@ CMasternode::CMasternode() cacheInputAgeBlock = 0; unitTest = false; allowFreeTx = true; - protocolVersion = MIN_PEER_PROTO_VERSION; + protocolVersion = PROTOCOL_VERSION; nLastDsq = 0; nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; @@ -244,7 +244,7 @@ CMasternodeBroadcast::CMasternodeBroadcast() cacheInputAgeBlock = 0; unitTest = false; allowFreeTx = true; - protocolVersion = MIN_PEER_PROTO_VERSION; + protocolVersion = PROTOCOL_VERSION; nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; } @@ -302,7 +302,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); std::string strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); - if(protocolVersion < nMasternodeMinProtocol) { + if(protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) { LogPrintf("mnb - ignoring outdated Masternode %s protocol version %d\n", vin.ToString().c_str(), protocolVersion); return false; } @@ -355,6 +355,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) pmn->UpdateFromNewBroadcast((*this)); pmn->Check(); if(pmn->IsEnabled()) Relay(); + masternodeSync.AddedMasternodeList(); } return true; @@ -515,7 +516,7 @@ bool CMasternodePing::CheckAndUpdate(int& nDos) // see if we have this Masternode CMasternode* pmn = mnodeman.Find(vin); - if(pmn != NULL && pmn->IsEnabled() && pmn->protocolVersion >= nMasternodeMinProtocol) + if(pmn != NULL && pmn->IsEnabled() && pmn->protocolVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { // LogPrintf("mnping - Found corresponding mn for vin: %s\n", vin.ToString().c_str()); // update only if there is no known ping for this masternode or diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 4c333ecf5fdc4..c25ca010d503a 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -239,7 +239,7 @@ void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval) if((*it).activeState == CMasternode::MASTERNODE_REMOVE || (*it).activeState == CMasternode::MASTERNODE_VIN_SPENT || (forceExpiredRemoval && (*it).activeState == CMasternode::MASTERNODE_EXPIRED) || - (*it).protocolVersion < nMasternodeMinProtocol) { + (*it).protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) { if(fDebug) LogPrintf("CMasternodeMan: Removing inactive Masternode %s - %i now\n", (*it).addr.ToString().c_str(), size() - 1); it = vMasternodes.erase(it); } else { @@ -289,21 +289,10 @@ void CMasternodeMan::Clear() nDsqCount = 0; } -int CMasternodeMan::CountEnabled() -{ - int i = 0; - - BOOST_FOREACH(CMasternode& mn, vMasternodes) { - mn.Check(); - if(mn.IsEnabled()) i++; - } - - return i; -} - -int CMasternodeMan::CountMasternodesAboveProtocol(int protocolVersion) +int CMasternodeMan::CountEnabled(int protocolVersion) { int i = 0; + protocolVersion = protocolVersion == -1 ? masternodePayments.GetMinMasternodePaymentsProto() : protocolVersion; BOOST_FOREACH(CMasternode& mn, vMasternodes) { mn.Check(); @@ -630,10 +619,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData return; } - // only ask for missing items after our syncing process is complete -- - // otherwise we'll think a full sync succeeded when they return a result - if(!masternodeSync.IsSynced()) return; - //search existing Masternode list, if it's known -- don't ask for the mnb CMasternode* pmn = mnodeman.Find(mnp.vin); if(pmn != NULL) return; diff --git a/src/masternodeman.h b/src/masternodeman.h index 8c7b4393531ed..8058f365b8fd5 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -101,9 +101,7 @@ class CMasternodeMan /// Clear Masternode vector void Clear(); - int CountEnabled(); - - int CountMasternodesAboveProtocol(int protocolVersion); + int CountEnabled(int protocolVersion = -1); void DsegUpdate(CNode* pnode); diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index d19e0f8042edd..2ebe471670e12 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -69,7 +69,8 @@ int ClientModel::getNumConnections(unsigned int flags) const QString ClientModel::getMasternodeCountString() const { - return QString::number((int)mnodeman.CountEnabled()) + " / " + QString::number((int)mnodeman.size()); + return QString::number((int)mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION)) + + " / " + QString::number((int)mnodeman.CountEnabled()) + " / " + QString::number((int)mnodeman.size()); } int ClientModel::getNumBlocks() const diff --git a/src/rpcmasternode.cpp b/src/rpcmasternode.cpp index c0f4a15666936..1b71d3cf97f72 100644 --- a/src/rpcmasternode.cpp +++ b/src/rpcmasternode.cpp @@ -136,7 +136,7 @@ Value masternode(const Array& params, bool fHelp) "1. \"command\" (string or set of strings, required) The command to execute\n" "2. \"passphrase\" (string, optional) The wallet passphrase\n" "\nAvailable commands:\n" - " count - Print number of all known masternodes (optional: 'enabled', 'both')\n" + " count - Print number of all known masternodes (optional: 'ds', 'enabled', 'all')\n" " current - Print info on current masternode winner\n" " debug - Print masternode status\n" " genkey - Generate new masternodeprivkey\n" @@ -190,8 +190,11 @@ Value masternode(const Array& params, bool fHelp) } if (params.size() == 2) { + if(params[1] == "ds") return mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION); if(params[1] == "enabled") return mnodeman.CountEnabled(); - if(params[1] == "both") return strprintf("%d / %d", mnodeman.CountEnabled(), mnodeman.size()); + if(params[1] == "all") return strprintf("%d / %d / %d", + mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION), + mnodeman.CountEnabled(), mnodeman.size()); } return mnodeman.size(); } diff --git a/src/util.cpp b/src/util.cpp index e98811e6c86f1..19c2db10e472a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -113,7 +113,6 @@ int nAnonymizeDarkcoinAmount = 1000; int nLiquidityProvider = 0; /** Spork enforcement enabled time */ int64_t enforceMasternodePaymentsTime = 4085657524; -int nMasternodeMinProtocol = 0; bool fSucessfullyLoaded = false; bool fEnableDarksend = false; /** All denominations used by darksend */ diff --git a/src/util.h b/src/util.h index 6ce2ed57666ec..93f6db447021b 100644 --- a/src/util.h +++ b/src/util.h @@ -39,7 +39,6 @@ extern int nLiquidityProvider; extern bool fEnableDarksend; extern int64_t enforceMasternodePaymentsTime; extern std::string strMasterNodeAddr; -extern int nMasternodeMinProtocol; extern int keysLoaded; extern bool fSucessfullyLoaded; extern std::vector darkSendDenominations;