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
|
|
|
|
|
2015-07-17 12:26:24 +02:00
|
|
|
#define MASTERNODE_SYNC_INITIAL 0
|
|
|
|
#define MASTERNODE_SYNC_SPORKS 1
|
2015-07-17 05:03:42 +02:00
|
|
|
#define MASTERNODE_SYNC_LIST 2
|
|
|
|
#define MASTERNODE_SYNC_MNW 3
|
2016-06-08 08:57:16 +02:00
|
|
|
#define MASTERNODE_SYNC_GOVERNANCE 4
|
|
|
|
#define MASTERNODE_SYNC_GOVOBJ 10
|
|
|
|
#define MASTERNODE_SYNC_GOVERNANCE_FIN 11
|
2015-07-25 18:29:29 +02:00
|
|
|
#define MASTERNODE_SYNC_FAILED 998
|
2015-07-17 12:26:24 +02:00
|
|
|
#define MASTERNODE_SYNC_FINISHED 999
|
2015-07-15 04:44:58 +02:00
|
|
|
|
2016-03-08 12:15:22 +01:00
|
|
|
#define MASTERNODE_SYNC_TIMEOUT 30 // our blocks are 2.5 minutes so 30 seconds should be fine
|
2015-07-17 11:17:15 +02:00
|
|
|
|
2015-07-15 04:44:58 +02:00
|
|
|
class CMasternodeSync;
|
|
|
|
extern CMasternodeSync masternodeSync;
|
|
|
|
|
|
|
|
//
|
|
|
|
// CMasternodeSync : Sync masternode assets in stages
|
|
|
|
//
|
|
|
|
|
|
|
|
class CMasternodeSync
|
|
|
|
{
|
|
|
|
public:
|
2015-08-05 02:54:02 +02:00
|
|
|
std::map<uint256, int> mapSeenSyncMNB;
|
|
|
|
std::map<uint256, int> mapSeenSyncMNW;
|
|
|
|
std::map<uint256, int> mapSeenSyncBudget;
|
|
|
|
|
2015-07-15 04:44:58 +02:00
|
|
|
int64_t lastMasternodeList;
|
|
|
|
int64_t lastMasternodeWinner;
|
|
|
|
int64_t lastBudgetItem;
|
2015-07-25 18:29:29 +02:00
|
|
|
int64_t lastFailure;
|
2015-07-29 06:16:11 +02:00
|
|
|
int nCountFailures;
|
|
|
|
|
|
|
|
// sum of all counts
|
|
|
|
int sumMasternodeList;
|
|
|
|
int sumMasternodeWinner;
|
|
|
|
int sumBudgetItemProp;
|
|
|
|
int sumBudgetItemFin;
|
|
|
|
// peers that reported counts
|
|
|
|
int countMasternodeList;
|
|
|
|
int countMasternodeWinner;
|
|
|
|
int countBudgetItemProp;
|
|
|
|
int countBudgetItemFin;
|
2015-07-15 04:44:58 +02:00
|
|
|
|
|
|
|
// Count peers we've requested the list from
|
|
|
|
int RequestedMasternodeAssets;
|
|
|
|
int RequestedMasternodeAttempt;
|
|
|
|
|
2015-08-15 15:27:26 +02:00
|
|
|
// Time when current masternode asset sync started
|
|
|
|
int64_t nAssetSyncStarted;
|
|
|
|
|
2016-03-02 22:20:04 +01:00
|
|
|
// Keep track of current block index
|
|
|
|
const CBlockIndex *pCurrentBlockIndex;
|
|
|
|
|
2015-07-15 04:44:58 +02:00
|
|
|
CMasternodeSync();
|
|
|
|
|
2015-08-05 02:54:02 +02:00
|
|
|
void AddedMasternodeList(uint256 hash);
|
|
|
|
void AddedMasternodeWinner(uint256 hash);
|
|
|
|
void AddedBudgetItem(uint256 hash);
|
2015-07-15 04:44:58 +02:00
|
|
|
void GetNextAsset();
|
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 06:16:11 +02:00
|
|
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
2015-07-29 10:06:30 +02:00
|
|
|
bool IsBudgetFinEmpty();
|
2015-07-29 10:08:15 +02:00
|
|
|
bool IsBudgetPropEmpty();
|
|
|
|
|
2015-08-04 20:21:27 +02:00
|
|
|
void Reset();
|
2015-07-15 04:44:58 +02:00
|
|
|
void Process();
|
|
|
|
bool IsSynced();
|
2015-07-26 22:04:17 +02:00
|
|
|
bool IsBlockchainSynced();
|
2015-07-30 10:51:48 +02:00
|
|
|
void ClearFulfilledRequest();
|
2016-03-02 22:20:04 +01:00
|
|
|
|
|
|
|
void UpdatedBlockTip(const CBlockIndex *pindex);
|
2015-07-15 04:44:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|