Dash Core  0.12.2.1
P2P Digital Currency
masternode-sync.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 #ifndef MASTERNODE_SYNC_H
5 #define MASTERNODE_SYNC_H
6 
7 #include "chain.h"
8 #include "net.h"
9 
10 #include <univalue.h>
11 
12 class CMasternodeSync;
13 
14 static const int MASTERNODE_SYNC_FAILED = -1;
15 static const int MASTERNODE_SYNC_INITIAL = 0; // sync just started, was reset recently or still in IDB
16 static const int MASTERNODE_SYNC_WAITING = 1; // waiting after initial to see if we can get more headers/blocks
17 static const int MASTERNODE_SYNC_LIST = 2;
18 static const int MASTERNODE_SYNC_MNW = 3;
19 static const int MASTERNODE_SYNC_GOVERNANCE = 4;
20 static const int MASTERNODE_SYNC_GOVOBJ = 10;
21 static const int MASTERNODE_SYNC_GOVOBJ_VOTE = 11;
22 static const int MASTERNODE_SYNC_FINISHED = 999;
23 
24 static const int MASTERNODE_SYNC_TICK_SECONDS = 6;
25 static const int MASTERNODE_SYNC_TIMEOUT_SECONDS = 30; // our blocks are 2.5 minutes so 30 seconds should be fine
26 
27 static const int MASTERNODE_SYNC_ENOUGH_PEERS = 6;
28 
30 
31 //
32 // CMasternodeSync : Sync masternode assets in stages
33 //
34 
36 {
37 private:
38  // Keep track of current asset
40  // Count peers we've requested the asset from
42 
43  // Time when current masternode asset sync started
45  // ... last bumped
46  int64_t nTimeLastBumped;
47  // ... or failed
49 
50  void Fail();
51  void ClearFulfilledRequests(CConnman& connman);
52 
53 public:
55 
56 
57  void SendGovernanceSyncRequest(CNode* pnode, CConnman& connman);
58 
64 
67  void BumpAssetLastTime(std::string strFuncName);
69  std::string GetAssetName();
70  std::string GetSyncStatus();
71 
72  void Reset();
73  void SwitchToNextAsset(CConnman& connman);
74 
75  void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
76  void ProcessTick(CConnman& connman);
77 
78  void AcceptedBlockHeader(const CBlockIndex *pindexNew);
79  void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman);
80  void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman);
81 };
82 
83 #endif
static const int MASTERNODE_SYNC_GOVOBJ_VOTE
void AcceptedBlockHeader(const CBlockIndex *pindexNew)
int64_t GetAssetStartTime()
void ProcessTick(CConnman &connman)
Definition: net.h:108
int nRequestedMasternodeAssets
int64_t nTimeAssetSyncStarted
bool IsWinnersListSynced()
static const int MASTERNODE_SYNC_FINISHED
static const int MASTERNODE_SYNC_GOVERNANCE
void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman &connman)
static const int MASTERNODE_SYNC_MNW
void SendGovernanceSyncRequest(CNode *pnode, CConnman &connman)
int nRequestedMasternodeAttempt
Definition: net.h:661
static const int MASTERNODE_SYNC_INITIAL
std::string GetSyncStatus()
static const int MASTERNODE_SYNC_TIMEOUT_SECONDS
std::string GetAssetName()
static const int MASTERNODE_SYNC_GOVOBJ
static const int MASTERNODE_SYNC_LIST
int64_t nTimeLastFailure
static const int MASTERNODE_SYNC_ENOUGH_PEERS
CMasternodeSync masternodeSync
static const int MASTERNODE_SYNC_WAITING
void ProcessMessage(CNode *pfrom, std::string &strCommand, CDataStream &vRecv)
static const int MASTERNODE_SYNC_TICK_SECONDS
void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman &connman)
void SwitchToNextAsset(CConnman &connman)
int64_t nTimeLastBumped
bool IsBlockchainSynced()
void ClearFulfilledRequests(CConnman &connman)
void BumpAssetLastTime(std::string strFuncName)
bool IsMasternodeListSynced()
static const int MASTERNODE_SYNC_FAILED