Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

masternode-sync.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2019 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 class CMasternodeSync;
11 
12 static const int MASTERNODE_SYNC_BLOCKCHAIN = 1;
13 static const int MASTERNODE_SYNC_GOVERNANCE = 4;
14 static const int MASTERNODE_SYNC_GOVOBJ = 10;
15 static const int MASTERNODE_SYNC_GOVOBJ_VOTE = 11;
16 static const int MASTERNODE_SYNC_FINISHED = 999;
17 
18 static const int MASTERNODE_SYNC_TICK_SECONDS = 6;
19 static const int MASTERNODE_SYNC_TIMEOUT_SECONDS = 30; // our blocks are 2.5 minutes so 30 seconds should be fine
20 static const int MASTERNODE_SYNC_RESET_SECONDS = 600; // Reset fReachedBestHeader in CMasternodeSync::Reset if UpdateBlockTip hasn't been called for this seconds
21 
23 
24 //
25 // CMasternodeSync : Sync masternode assets in stages
26 //
27 
29 {
30 private:
31  // Keep track of current asset
33  // Count peers we've requested the asset from
35 
36  // Time when current masternode asset sync started
38  // ... last bumped
39  int64_t nTimeLastBumped;
40 
42  bool fReachedBestHeader{false};
45 
46 public:
47  CMasternodeSync() { Reset(true, false); }
48 
49 
50  void SendGovernanceSyncRequest(CNode* pnode, CConnman& connman);
51 
54 
55  int GetAssetID() { return nCurrentAsset; }
56  int GetAttempt() { return nTriedPeerCount; }
57  void BumpAssetLastTime(const std::string& strFuncName);
59  std::string GetAssetName();
60  std::string GetSyncStatus();
61 
62  void Reset(bool fForce = false, bool fNotifyReset = true);
63  void SwitchToNextAsset(CConnman& connman);
64 
65  void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv);
66  void ProcessTick(CConnman& connman);
67 
68  void AcceptedBlockHeader(const CBlockIndex *pindexNew);
69  void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman);
70  void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman);
71 
72  void DoMaintenance(CConnman &connman);
73 };
74 
75 #endif
void SwitchToNextAsset(CConnman &connman)
static const int MASTERNODE_SYNC_GOVOBJ_VOTE
int64_t nTimeLastUpdateBlockTip
Last time UpdateBlockTip has been called.
static const int MASTERNODE_SYNC_RESET_SECONDS
void ProcessTick(CConnman &connman)
void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman &connman)
static const int MASTERNODE_SYNC_BLOCKCHAIN
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
int64_t GetAssetStartTime()
bool IsBlockchainSynced()
static const int MASTERNODE_SYNC_FINISHED
static const int MASTERNODE_SYNC_GOVERNANCE
int64_t nTimeAssetSyncStarted
static const int MASTERNODE_SYNC_TIMEOUT_SECONDS
void BumpAssetLastTime(const std::string &strFuncName)
std::string GetSyncStatus()
void AcceptedBlockHeader(const CBlockIndex *pindexNew)
std::string GetAssetName()
static const int MASTERNODE_SYNC_GOVOBJ
int64_t nTimeLastBumped
Definition: net.h:136
CMasternodeSync masternodeSync
void DoMaintenance(CConnman &connman)
static const int MASTERNODE_SYNC_TICK_SECONDS
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv)
bool fReachedBestHeader
Set to true if best header is reached in CMasternodeSync::UpdatedBlockTip.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman &connman)
Information about a peer.
Definition: net.h:800
void SendGovernanceSyncRequest(CNode *pnode, CConnman &connman)
void Reset(bool fForce=false, bool fNotifyReset=true)
Released under the MIT license