2016-02-02 16:28:56 +01:00
|
|
|
// Copyright (c) 2014-2016 The Dash Core developers
|
2015-07-15 04:44:58 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2015-07-29 05:26:08 +02:00
|
|
|
#include "activemasternode.h"
|
2016-04-15 04:54:11 +02:00
|
|
|
#include "governance.h"
|
2016-08-28 12:12:14 +02:00
|
|
|
#include "main.h"
|
2015-07-15 04:44:58 +02:00
|
|
|
#include "masternode.h"
|
2016-08-28 12:12:14 +02:00
|
|
|
#include "masternode-payments.h"
|
|
|
|
#include "masternode-sync.h"
|
2015-07-17 11:17:15 +02:00
|
|
|
#include "masternodeman.h"
|
2015-08-15 15:27:26 +02:00
|
|
|
#include "spork.h"
|
2015-07-15 04:44:58 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
class CMasternodeSync;
|
|
|
|
CMasternodeSync masternodeSync;
|
|
|
|
|
2015-07-26 22:04:17 +02:00
|
|
|
bool CMasternodeSync::IsBlockchainSynced()
|
2015-07-26 21:37:01 +02:00
|
|
|
{
|
2015-08-04 01:23:36 +02:00
|
|
|
static bool fBlockchainSynced = false;
|
2015-08-04 23:15:24 +02:00
|
|
|
static int64_t lastProcess = GetTime();
|
|
|
|
|
2015-08-11 23:54:42 +02:00
|
|
|
// if the last call to this function was more than 60 minutes ago (client was in sleep mode) reset the sync process
|
|
|
|
if(GetTime() - lastProcess > 60*60) {
|
2015-08-04 23:15:24 +02:00
|
|
|
Reset();
|
|
|
|
fBlockchainSynced = false;
|
|
|
|
}
|
|
|
|
lastProcess = GetTime();
|
|
|
|
|
2015-08-04 01:23:36 +02:00
|
|
|
if(fBlockchainSynced) return true;
|
|
|
|
|
2015-08-03 22:42:18 +02:00
|
|
|
if (fImporting || fReindex) return false;
|
|
|
|
|
2016-03-02 22:20:04 +01:00
|
|
|
if(!pCurrentBlockIndex) return false;
|
|
|
|
if(pCurrentBlockIndex->nTime + 60*60 < GetTime()) return false;
|
2015-08-03 22:42:18 +02:00
|
|
|
|
|
|
|
fBlockchainSynced = true;
|
2015-07-26 22:04:17 +02:00
|
|
|
|
|
|
|
return true;
|
2015-07-26 21:37:01 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
void CMasternodeSync::Fail()
|
|
|
|
{
|
|
|
|
nTimeLastFailure = GetTime();
|
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_FAILED;
|
|
|
|
}
|
|
|
|
|
2015-08-04 20:21:27 +02:00
|
|
|
void CMasternodeSync::Reset()
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL;
|
|
|
|
nRequestedMasternodeAttempt = 0;
|
|
|
|
nTimeAssetSyncStarted = GetTime();
|
|
|
|
nTimeLastMasternodeList = GetTime();
|
|
|
|
nTimeLastMasternodeWinner = GetTime();
|
|
|
|
nTimeLastBudgetItem = GetTime();
|
|
|
|
nTimeLastFailure = 0;
|
|
|
|
nCountFailures = 0;
|
|
|
|
nSumMasternodeList = 0;
|
|
|
|
nSumMasternodeWinner = 0;
|
|
|
|
nSumBudgetItemProp = 0;
|
|
|
|
nSumBudgetItemFin = 0;
|
|
|
|
nCountMasternodeList = 0;
|
|
|
|
nCountMasternodeWinner = 0;
|
|
|
|
nCountBudgetItemProp = 0;
|
|
|
|
nCountBudgetItemFin = 0;
|
2015-08-05 04:10:47 +02:00
|
|
|
mapSeenSyncMNB.clear();
|
|
|
|
mapSeenSyncMNW.clear();
|
|
|
|
mapSeenSyncBudget.clear();
|
2015-08-04 20:21:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 02:54:02 +02:00
|
|
|
void CMasternodeSync::AddedMasternodeList(uint256 hash)
|
2015-07-15 04:44:58 +02:00
|
|
|
{
|
2015-08-05 02:54:02 +02:00
|
|
|
if(mnodeman.mapSeenMasternodeBroadcast.count(hash)) {
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastMasternodeList = GetTime();
|
2016-02-04 20:29:09 +01:00
|
|
|
mapSeenSyncMNB[hash]++;
|
2015-08-05 02:54:02 +02:00
|
|
|
} else {
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastMasternodeList = GetTime();
|
|
|
|
mapSeenSyncMNB.insert(std::make_pair(hash, 1));
|
2015-08-05 02:54:02 +02:00
|
|
|
}
|
2015-07-15 04:44:58 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 02:54:02 +02:00
|
|
|
void CMasternodeSync::AddedMasternodeWinner(uint256 hash)
|
2015-07-15 04:44:58 +02:00
|
|
|
{
|
2016-02-04 20:29:09 +01:00
|
|
|
if(mnpayments.mapMasternodePayeeVotes.count(hash)) {
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastMasternodeWinner = GetTime();
|
2016-02-04 20:29:09 +01:00
|
|
|
mapSeenSyncMNW[hash]++;
|
2015-08-05 02:54:02 +02:00
|
|
|
} else {
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastMasternodeWinner = GetTime();
|
|
|
|
mapSeenSyncMNW.insert(std::make_pair(hash, 1));
|
2015-08-05 02:54:02 +02:00
|
|
|
}
|
2015-07-15 04:44:58 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
std::string CMasternodeSync::GetAssetName()
|
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
switch(nRequestedMasternodeAssets)
|
2016-06-08 08:57:16 +02:00
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
case(MASTERNODE_SYNC_INITIAL): return "MASTERNODE_SYNC_INITIAL";
|
|
|
|
case(MASTERNODE_SYNC_SPORKS): return "MASTERNODE_SYNC_SPORKS";
|
|
|
|
case(MASTERNODE_SYNC_LIST): return "MASTERNODE_SYNC_LIST";
|
|
|
|
case(MASTERNODE_SYNC_MNW): return "MASTERNODE_SYNC_MNW";
|
|
|
|
case(MASTERNODE_SYNC_GOVERNANCE): return "MASTERNODE_SYNC_GOVERNANCE";
|
|
|
|
case(MASTERNODE_SYNC_FAILED): return "MASTERNODE_SYNC_FAILED";
|
|
|
|
case MASTERNODE_SYNC_FINISHED: return "MASTERNODE_SYNC_FINISHED";
|
|
|
|
default: return "UNKNOWN";
|
2016-06-08 08:57:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
void CMasternodeSync::SwitchToNextAsset()
|
2015-07-15 04:44:58 +02:00
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
switch(nRequestedMasternodeAssets)
|
2015-07-15 04:44:58 +02:00
|
|
|
{
|
2015-07-17 12:26:24 +02:00
|
|
|
case(MASTERNODE_SYNC_INITIAL):
|
2015-08-04 23:33:47 +02:00
|
|
|
case(MASTERNODE_SYNC_FAILED): // should never be used here actually, use Reset() instead
|
2015-07-30 10:51:48 +02:00
|
|
|
ClearFulfilledRequest();
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS;
|
2015-07-17 05:03:42 +02:00
|
|
|
break;
|
2015-07-17 12:26:24 +02:00
|
|
|
case(MASTERNODE_SYNC_SPORKS):
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastMasternodeList = GetTime();
|
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_LIST;
|
2015-07-15 04:44:58 +02:00
|
|
|
break;
|
|
|
|
case(MASTERNODE_SYNC_LIST):
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastMasternodeWinner = GetTime();
|
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_MNW;
|
2015-07-15 04:44:58 +02:00
|
|
|
break;
|
|
|
|
case(MASTERNODE_SYNC_MNW):
|
2016-08-28 12:12:14 +02:00
|
|
|
nTimeLastBudgetItem = GetTime();
|
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_GOVERNANCE;
|
2015-07-15 04:44:58 +02:00
|
|
|
break;
|
2016-06-08 08:57:16 +02:00
|
|
|
case(MASTERNODE_SYNC_GOVERNANCE):
|
2016-08-28 12:12:14 +02:00
|
|
|
LogPrintf("CMasternodeSync::SwitchToNextAsset -- Sync has finished\n");
|
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
|
2016-02-19 19:09:54 +01:00
|
|
|
uiInterface.NotifyAdditionalDataSyncProgressChanged(1);
|
2016-08-05 18:25:03 +02:00
|
|
|
//try to activate our masternode if possible
|
2016-08-05 21:49:45 +02:00
|
|
|
activeMasternode.ManageState();
|
2015-07-15 04:44:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAttempt = 0;
|
|
|
|
nTimeAssetSyncStarted = GetTime();
|
2015-07-15 04:44:58 +02:00
|
|
|
}
|
|
|
|
|
2015-08-15 17:53:55 +02:00
|
|
|
std::string CMasternodeSync::GetSyncStatus()
|
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
switch (masternodeSync.nRequestedMasternodeAssets) {
|
|
|
|
case MASTERNODE_SYNC_INITIAL: return _("Synchronization pending...");
|
|
|
|
case MASTERNODE_SYNC_SPORKS: return _("Synchronizing sporks...");
|
|
|
|
case MASTERNODE_SYNC_LIST: return _("Synchronizing masternodes...");
|
|
|
|
case MASTERNODE_SYNC_MNW: return _("Synchronizing masternode winners...");
|
|
|
|
case MASTERNODE_SYNC_GOVERNANCE: return _("Synchronizing governance objects...");
|
|
|
|
case MASTERNODE_SYNC_FAILED: return _("Synchronization failed");
|
|
|
|
case MASTERNODE_SYNC_FINISHED: return _("Synchronization finished");
|
|
|
|
default: return "";
|
2015-08-15 17:53:55 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 06:16:11 +02:00
|
|
|
|
|
|
|
void CMasternodeSync::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
|
|
|
|
{
|
2016-02-17 23:18:57 +01:00
|
|
|
if (strCommand == NetMsgType::SYNCSTATUSCOUNT) { //Sync status count
|
2015-07-29 06:16:11 +02:00
|
|
|
int nItemID;
|
|
|
|
int nCount;
|
|
|
|
vRecv >> nItemID >> nCount;
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets >= MASTERNODE_SYNC_FINISHED) return;
|
2015-07-29 06:16:11 +02:00
|
|
|
|
2015-07-29 10:06:30 +02:00
|
|
|
//this means we will receive no further communication
|
|
|
|
switch(nItemID)
|
|
|
|
{
|
|
|
|
case(MASTERNODE_SYNC_LIST):
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nItemID != nRequestedMasternodeAssets) return;
|
|
|
|
nSumMasternodeList += nCount;
|
|
|
|
nCountMasternodeList++;
|
2015-07-29 10:06:30 +02:00
|
|
|
break;
|
|
|
|
case(MASTERNODE_SYNC_MNW):
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nItemID != nRequestedMasternodeAssets) return;
|
|
|
|
nSumMasternodeWinner += nCount;
|
|
|
|
nCountMasternodeWinner++;
|
2015-07-29 10:06:30 +02:00
|
|
|
break;
|
2016-06-08 08:57:16 +02:00
|
|
|
case(MASTERNODE_SYNC_GOVOBJ):
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets != MASTERNODE_SYNC_GOVERNANCE) return;
|
|
|
|
nSumBudgetItemProp += nCount;
|
|
|
|
nCountBudgetItemProp++;
|
2015-07-29 10:06:30 +02:00
|
|
|
break;
|
2016-06-08 08:57:16 +02:00
|
|
|
case(MASTERNODE_SYNC_GOVERNANCE_FIN):
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets != MASTERNODE_SYNC_GOVERNANCE) return;
|
|
|
|
nSumBudgetItemFin += nCount;
|
|
|
|
nCountBudgetItemFin++;
|
2015-07-29 10:06:30 +02:00
|
|
|
break;
|
2015-07-29 06:16:11 +02:00
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
LogPrintf("CMasternodeSync::ProcessMessage -- SYNCSTATUSCOUNT -- got inventory count: nItemID=%d nCount=%d\n", nItemID, nCount);
|
2015-07-30 10:51:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMasternodeSync::ClearFulfilledRequest()
|
|
|
|
{
|
2015-07-30 15:44:18 +02:00
|
|
|
TRY_LOCK(cs_vNodes, lockRecv);
|
|
|
|
if(!lockRecv) return;
|
|
|
|
|
2015-07-30 10:51:48 +02:00
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
|
|
|
{
|
2016-05-24 22:14:47 +02:00
|
|
|
pnode->ClearFulfilledRequest("spork-sync");
|
|
|
|
pnode->ClearFulfilledRequest("masternode-winner-sync");
|
|
|
|
pnode->ClearFulfilledRequest("governance-sync");
|
|
|
|
pnode->ClearFulfilledRequest("masternode-sync");
|
2015-07-29 06:16:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
void CMasternodeSync::ProcessTick()
|
2015-07-15 04:44:58 +02:00
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
static int nTick = 0;
|
|
|
|
if(nTick++ % 6 != 0) return;
|
2016-03-02 22:20:04 +01:00
|
|
|
if(!pCurrentBlockIndex) return;
|
|
|
|
|
2016-02-04 20:29:09 +01:00
|
|
|
//the actual count of masternodes we have currently
|
2016-03-02 22:20:04 +01:00
|
|
|
int nMnCount = mnodeman.CountEnabled();
|
2015-07-19 10:19:54 +02:00
|
|
|
|
2016-02-04 20:29:09 +01:00
|
|
|
// RESET SYNCING INCASE OF FAILURE
|
|
|
|
{
|
|
|
|
if(IsSynced()) {
|
2016-08-17 09:08:25 +02:00
|
|
|
/*
|
2016-02-04 20:29:09 +01:00
|
|
|
Resync if we lose all masternodes from sleep/wake or failure to sync originally
|
|
|
|
*/
|
2016-03-08 12:15:22 +01:00
|
|
|
if(nMnCount == 0) {
|
2016-02-04 20:29:09 +01:00
|
|
|
Reset();
|
2016-06-08 08:57:16 +02:00
|
|
|
} else {
|
|
|
|
//if syncing is complete and we have masternodes, return
|
2016-08-17 09:08:25 +02:00
|
|
|
return;
|
2016-06-08 08:57:16 +02:00
|
|
|
}
|
2016-02-04 20:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//try syncing again
|
2016-08-28 12:12:14 +02:00
|
|
|
if(IsFailed()) {
|
|
|
|
if(nTimeLastFailure + (1*60) < GetTime()) // 1 minute cooldown after failed sync
|
|
|
|
Reset();
|
2015-07-19 10:19:54 +02:00
|
|
|
return;
|
2016-02-04 20:29:09 +01:00
|
|
|
}
|
2015-07-18 01:49:41 +02:00
|
|
|
}
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
// INITIAL SYNC SETUP / LOG REPORTING
|
2016-08-28 12:12:14 +02:00
|
|
|
double nSyncProgress = double(nRequestedMasternodeAttempt + (nRequestedMasternodeAssets - 1) * 8) / (8*4);
|
|
|
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d nRequestedMasternodeAttempt %d nSyncProgress %f\n", nTick, nRequestedMasternodeAssets, nRequestedMasternodeAttempt, nSyncProgress);
|
2016-08-05 18:25:03 +02:00
|
|
|
uiInterface.NotifyAdditionalDataSyncProgressChanged(nSyncProgress);
|
2015-07-17 11:17:15 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// sporks synced but blockchain is not, wait until we're almost at a recent block to continue
|
|
|
|
if(Params().NetworkIDString() != CBaseChainParams::REGTEST &&
|
2016-08-28 12:12:14 +02:00
|
|
|
!IsBlockchainSynced() && nRequestedMasternodeAssets > MASTERNODE_SYNC_SPORKS) return;
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
TRY_LOCK(cs_vNodes, lockRecv);
|
|
|
|
if(!lockRecv) return;
|
2015-08-03 22:42:18 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) SwitchToNextAsset();
|
2015-07-30 15:44:18 +02:00
|
|
|
|
2015-07-17 11:17:15 +02:00
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
|
|
|
{
|
2016-06-08 08:57:16 +02:00
|
|
|
// QUICK MODE (REGTEST ONLY!)
|
|
|
|
if(Params().NetworkIDString() == CBaseChainParams::REGTEST)
|
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAttempt <= 2) {
|
2016-02-17 23:18:57 +01:00
|
|
|
pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks
|
2016-08-28 12:12:14 +02:00
|
|
|
} else if(nRequestedMasternodeAttempt < 4) {
|
2016-08-17 09:08:25 +02:00
|
|
|
mnodeman.DsegUpdate(pnode);
|
2016-08-28 12:12:14 +02:00
|
|
|
} else if(nRequestedMasternodeAttempt < 6) {
|
2015-09-02 14:13:32 +02:00
|
|
|
int nMnCount = mnodeman.CountEnabled();
|
2016-02-17 23:18:57 +01:00
|
|
|
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees
|
2016-02-02 16:28:56 +01:00
|
|
|
uint256 n = uint256();
|
2016-06-08 08:57:16 +02:00
|
|
|
pnode->PushMessage(NetMsgType::MNGOVERNANCESYNC, n); //sync masternode votes
|
2015-07-23 23:35:14 +02:00
|
|
|
} else {
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
|
2015-07-17 11:17:15 +02:00
|
|
|
}
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAttempt++;
|
2015-07-19 01:25:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
// NORMAL NETWORK MODE - TESTNET/MAINNET
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2016-06-08 08:57:16 +02:00
|
|
|
// SPORK : ALWAYS ASK FOR SPORKS AS WE SYNC (we skip this mode now)
|
2015-07-20 20:56:02 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
if(!pnode->HasFulfilledRequest("spork-sync")) {
|
|
|
|
// only request once from each peer
|
2016-06-08 08:57:16 +02:00
|
|
|
pnode->FulfilledRequest("spork-sync");
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
// get current network sporks
|
2016-08-17 09:08:25 +02:00
|
|
|
pnode->PushMessage(NetMsgType::GETSPORKS);
|
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
// we always ask for sporks, so just skip this
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS) SwitchToNextAsset();
|
2016-08-05 18:25:03 +02:00
|
|
|
|
|
|
|
continue; // always get sporks first, switch to the next node without waiting for the next tick
|
2016-06-08 08:57:16 +02:00
|
|
|
}
|
2016-05-24 21:20:10 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// MNLIST : SYNC MASTERNODE LIST FROM OTHER CONNECTED CLIENTS
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {
|
2016-08-05 18:25:03 +02:00
|
|
|
// check for timeout first
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nTimeLastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT_SECONDS) {
|
|
|
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- timeout\n", nTick, nRequestedMasternodeAssets);
|
|
|
|
if (nRequestedMasternodeAttempt == 0) {
|
2016-08-05 18:25:03 +02:00
|
|
|
LogPrintf("CMasternodeSync::Process -- WARNING: failed to sync %s\n", GetAssetName());
|
2016-08-28 12:12:14 +02:00
|
|
|
}
|
|
|
|
SwitchToNextAsset();
|
2015-07-15 04:44:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-07-17 11:17:15 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// check for data
|
|
|
|
// if we have enough masternodes in or list, switch to the next asset
|
|
|
|
/* Note: Is this activing up? It's probably related to int CMasternodeMan::GetEstimatedMasternodes(int nBlock)
|
|
|
|
Surely doesn't work right for testnet currently */
|
2016-08-28 12:12:14 +02:00
|
|
|
// try to fetch data from at least two peers though
|
|
|
|
if(nRequestedMasternodeAttempt > 1 && nMnCount > mnodeman.GetEstimatedMasternodes(pCurrentBlockIndex->nHeight)*0.9) {
|
|
|
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- found enough data\n", nTick, nRequestedMasternodeAssets);
|
|
|
|
SwitchToNextAsset();
|
2015-08-15 15:27:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// only request once from each peer
|
2016-05-24 22:12:20 +02:00
|
|
|
if(pnode->HasFulfilledRequest("masternode-sync")) continue;
|
|
|
|
pnode->FulfilledRequest("masternode-sync");
|
2015-07-27 05:41:25 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
if (pnode->nVersion < mnpayments.GetMinMasternodePaymentsProto()) continue;
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAttempt++;
|
2015-07-21 04:24:43 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
mnodeman.DsegUpdate(pnode);
|
|
|
|
|
2016-02-04 23:48:23 +01:00
|
|
|
return; //this will cause each peer to get one request each six seconds for the various assets we need
|
|
|
|
}
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
// MNW : SYNC MASTERNODE WINNERS FROM OTHER CONNECTED CLIENTS
|
2016-05-24 21:20:10 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
|
2016-08-05 18:25:03 +02:00
|
|
|
// check for timeout first
|
2016-08-28 12:12:14 +02:00
|
|
|
// This might take a lot longer than MASTERNODE_SYNC_TIMEOUT_SECONDS minutes due to new blocks,
|
2016-08-05 18:25:03 +02:00
|
|
|
// but that should be OK and it should timeout eventually.
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nTimeLastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT_SECONDS) {
|
|
|
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- timeout\n", nTick, nRequestedMasternodeAssets);
|
|
|
|
if (nRequestedMasternodeAttempt == 0) {
|
2016-08-05 18:25:03 +02:00
|
|
|
LogPrintf("CMasternodeSync::Process -- WARNING: failed to sync %s\n", GetAssetName());
|
2016-08-28 12:12:14 +02:00
|
|
|
}
|
|
|
|
SwitchToNextAsset();
|
2015-07-15 04:44:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// check for data
|
2016-08-28 12:12:14 +02:00
|
|
|
// if mnpayments already has enough blocks and votes, switch to the next asset
|
|
|
|
// try to fetch data from at least two peers though
|
|
|
|
if(nRequestedMasternodeAttempt > 1 && mnpayments.IsEnoughData(nMnCount)) {
|
|
|
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- found enough data\n", nTick, nRequestedMasternodeAssets);
|
|
|
|
SwitchToNextAsset();
|
2016-05-29 20:35:09 +02:00
|
|
|
return;
|
2015-08-14 05:56:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// only request once from each peer
|
2016-05-24 22:12:20 +02:00
|
|
|
if(pnode->HasFulfilledRequest("masternode-winner-sync")) continue;
|
|
|
|
pnode->FulfilledRequest("masternode-winner-sync");
|
2016-02-04 20:29:09 +01:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
if(pnode->nVersion < mnpayments.GetMinMasternodePaymentsProto()) continue;
|
|
|
|
nRequestedMasternodeAttempt++;
|
2016-02-04 20:29:09 +01:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees
|
|
|
|
|
2016-02-04 20:29:09 +01:00
|
|
|
|
2016-02-04 23:48:23 +01:00
|
|
|
return; //this will cause each peer to get one request each six seconds for the various assets we need
|
|
|
|
}
|
2016-06-08 08:57:16 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// GOVOBJ : SYNC GOVERNANCE ITEMS FROM OUR PEERS
|
2016-06-08 08:57:16 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_GOVERNANCE) {
|
2016-08-05 18:25:03 +02:00
|
|
|
// check for timeout first
|
2016-08-28 12:12:14 +02:00
|
|
|
if(nTimeLastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT_SECONDS){
|
|
|
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- timeout\n", nTick, nRequestedMasternodeAssets);
|
|
|
|
if(nRequestedMasternodeAttempt == 0) {
|
2016-08-05 18:25:03 +02:00
|
|
|
LogPrintf("CMasternodeSync::Process -- WARNING: failed to sync %s\n", GetAssetName());
|
2016-08-28 12:12:14 +02:00
|
|
|
// it's kind of ok to skip this for now, hopefully we'll catch up later?
|
|
|
|
}
|
|
|
|
SwitchToNextAsset();
|
2016-08-05 18:25:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-24 21:20:10 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// check for data
|
2016-08-28 12:12:14 +02:00
|
|
|
// if(nCountBudgetItemProp > 0 && nCountBudgetItemFin)
|
2016-05-24 21:25:33 +02:00
|
|
|
// {
|
2016-08-28 12:12:14 +02:00
|
|
|
// if(governance.CountProposalInventoryItems() >= (nSumBudgetItemProp / nCountBudgetItemProp)*0.9)
|
2016-05-24 21:25:33 +02:00
|
|
|
// {
|
2016-08-28 12:12:14 +02:00
|
|
|
// if(governance.CountFinalizedInventoryItems() >= (nSumBudgetItemFin / nCountBudgetItemFin)*0.9)
|
2016-05-24 21:25:33 +02:00
|
|
|
// {
|
2016-08-28 12:12:14 +02:00
|
|
|
// SwitchToNextAsset();
|
2016-05-24 21:25:33 +02:00
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
// only request once from each peer
|
2016-05-24 22:12:20 +02:00
|
|
|
if(pnode->HasFulfilledRequest("governance-sync")) continue;
|
|
|
|
pnode->FulfilledRequest("governance-sync");
|
2016-05-24 21:25:33 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
if (pnode->nVersion < MSG_GOVERNANCE_PEER_PROTO_VERSION) continue;
|
2016-08-28 12:12:14 +02:00
|
|
|
nRequestedMasternodeAttempt++;
|
2016-05-24 21:25:33 +02:00
|
|
|
|
2016-08-05 18:25:03 +02:00
|
|
|
pnode->PushMessage(NetMsgType::MNGOVERNANCESYNC, uint256()); //sync masternode votes
|
|
|
|
|
2016-05-24 21:25:33 +02:00
|
|
|
return; //this will cause each peer to get one request each six seconds for the various assets we need
|
|
|
|
}
|
|
|
|
}
|
2015-07-15 04:44:58 +02:00
|
|
|
}
|
2015-07-17 11:17:15 +02:00
|
|
|
}
|
2016-03-02 22:20:04 +01:00
|
|
|
|
|
|
|
void CMasternodeSync::UpdatedBlockTip(const CBlockIndex *pindex)
|
|
|
|
{
|
|
|
|
pCurrentBlockIndex = pindex;
|
|
|
|
}
|
2016-05-09 18:31:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
void CMasternodeSync::AddedBudgetItem(uint256 hash)
|
|
|
|
{
|
|
|
|
// skip this for now
|
|
|
|
return;
|
|
|
|
}
|