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.
|
|
|
|
#ifndef MASTERNODE_SYNC_H
|
|
|
|
#define MASTERNODE_SYNC_H
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
#include "chain.h"
|
|
|
|
#include "net.h"
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
#include <univalue.h>
|
2015-07-17 11:17:15 +02:00
|
|
|
|
2015-07-15 04:44:58 +02:00
|
|
|
class CMasternodeSync;
|
2016-08-28 12:12:14 +02:00
|
|
|
|
|
|
|
static const int MASTERNODE_SYNC_INITIAL = 0;
|
|
|
|
static const int MASTERNODE_SYNC_SPORKS = 1;
|
|
|
|
static const int MASTERNODE_SYNC_LIST = 2;
|
|
|
|
static const int MASTERNODE_SYNC_MNW = 3;
|
|
|
|
static const int MASTERNODE_SYNC_GOVERNANCE = 4;
|
|
|
|
static const int MASTERNODE_SYNC_GOVOBJ = 10;
|
|
|
|
static const int MASTERNODE_SYNC_GOVERNANCE_FIN = 11;
|
|
|
|
static const int MASTERNODE_SYNC_FAILED = 998;
|
|
|
|
static const int MASTERNODE_SYNC_FINISHED = 999;
|
|
|
|
|
|
|
|
static const int MASTERNODE_SYNC_TIMEOUT_SECONDS = 30; // our blocks are 2.5 minutes so 30 seconds should be fine
|
|
|
|
|
2015-07-15 04:44:58 +02:00
|
|
|
extern CMasternodeSync masternodeSync;
|
|
|
|
|
|
|
|
//
|
|
|
|
// CMasternodeSync : Sync masternode assets in stages
|
|
|
|
//
|
|
|
|
|
|
|
|
class CMasternodeSync
|
|
|
|
{
|
2016-08-28 12:12:14 +02:00
|
|
|
private:
|
|
|
|
// Keep track of current asset
|
|
|
|
int nRequestedMasternodeAssets;
|
|
|
|
// Count peers we've requested the asset from
|
|
|
|
int nRequestedMasternodeAttempt;
|
|
|
|
|
|
|
|
// Time when current masternode asset sync started
|
|
|
|
int64_t nTimeAssetSyncStarted;
|
|
|
|
|
|
|
|
// Last time when we received some masternode asset ...
|
|
|
|
int64_t nTimeLastMasternodeList;
|
|
|
|
int64_t nTimeLastMasternodeWinner;
|
|
|
|
int64_t nTimeLastBudgetItem;
|
|
|
|
// ... or failed
|
|
|
|
int64_t nTimeLastFailure;
|
2015-08-05 02:54:02 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
// How many times we failed
|
2015-07-29 06:16:11 +02:00
|
|
|
int nCountFailures;
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
// Sum of all data counts
|
|
|
|
int nSumMasternodeList;
|
|
|
|
int nSumMasternodeWinner;
|
|
|
|
int nSumBudgetItemProp;
|
|
|
|
int nSumBudgetItemFin;
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
// Number of peers that reported data counts
|
|
|
|
int nCountMasternodeList;
|
|
|
|
int nCountMasternodeWinner;
|
|
|
|
int nCountBudgetItemProp;
|
|
|
|
int nCountBudgetItemFin;
|
2015-08-15 15:27:26 +02:00
|
|
|
|
2016-03-02 22:20:04 +01:00
|
|
|
// Keep track of current block index
|
|
|
|
const CBlockIndex *pCurrentBlockIndex;
|
|
|
|
|
2016-08-28 12:12:14 +02:00
|
|
|
void Fail();
|
|
|
|
void ClearFulfilledRequest();
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::map<uint256, int> mapSeenSyncMNB;
|
|
|
|
std::map<uint256, int> mapSeenSyncMNW;
|
|
|
|
std::map<uint256, int> mapSeenSyncBudget;
|
|
|
|
|
|
|
|
CMasternodeSync() { Reset(); }
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2015-08-05 02:54:02 +02:00
|
|
|
void AddedMasternodeList(uint256 hash);
|
|
|
|
void AddedMasternodeWinner(uint256 hash);
|
|
|
|
void AddedBudgetItem(uint256 hash);
|
2016-08-28 12:12:14 +02:00
|
|
|
|
|
|
|
bool IsFailed() { return nRequestedMasternodeAssets == MASTERNODE_SYNC_FAILED; }
|
|
|
|
bool IsSynced() { return nRequestedMasternodeAssets == MASTERNODE_SYNC_FINISHED; }
|
|
|
|
bool IsBlockchainSynced();
|
|
|
|
|
|
|
|
int GetAssetID() { return nRequestedMasternodeAssets; }
|
|
|
|
int GetAttempt() { return nRequestedMasternodeAttempt; }
|
2016-06-08 08:57:16 +02:00
|
|
|
std::string GetAssetName();
|
2015-08-15 17:53:55 +02:00
|
|
|
std::string GetSyncStatus();
|
2015-07-29 10:08:15 +02:00
|
|
|
|
2015-08-04 20:21:27 +02:00
|
|
|
void Reset();
|
2016-08-28 12:12:14 +02:00
|
|
|
void SwitchToNextAsset();
|
|
|
|
|
|
|
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
|
|
|
void ProcessTick();
|
2016-03-02 22:20:04 +01:00
|
|
|
|
|
|
|
void UpdatedBlockTip(const CBlockIndex *pindex);
|
2015-07-15 04:44:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|