Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

versionbits.h
Go to the documentation of this file.
1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_CONSENSUS_VERSIONBITS
6 #define BITCOIN_CONSENSUS_VERSIONBITS
7 
8 #include <chain.h>
9 #include <map>
10 
12 static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
14 static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
16 static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
18 static const int32_t VERSIONBITS_NUM_BITS = 29;
19 
26 };
27 
28 // A map that gives the state for blocks whose height is a multiple of Period().
29 // The map is indexed by the block's parent, however, so all keys in the map
30 // will either be nullptr or a block with (height + 1) % Period() == 0.
31 typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
32 
35  const char *name;
37  bool gbt_force;
40 };
41 
42 struct BIP9Stats {
43  int period;
44  int threshold;
45  int elapsed;
46  int count;
47  bool possible;
48 };
49 
50 extern const struct VBDeploymentInfo VersionBitsDeploymentInfo[];
51 
56 protected:
57  virtual bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const =0;
58  virtual int64_t BeginTime(const Consensus::Params& params) const =0;
59  virtual int64_t EndTime(const Consensus::Params& params) const =0;
60  virtual int Period(const Consensus::Params& params) const =0;
61  virtual int Threshold(const Consensus::Params& params, int nAttempt) const =0;
62 
63 public:
64  BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params, ThresholdConditionCache& cache) const;
65  // Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
66  ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
67  int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
68 };
69 
71 {
73 
74  void Clear();
75 };
76 
81 
82 #endif
virtual int64_t EndTime(const Consensus::Params &params) const =0
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, const Consensus::Params &params, ThresholdConditionCache &cache) const
bool gbt_force
Whether GBT clients can safely ignore this rule in simplified usage.
Definition: versionbits.h:37
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
Definition: versionbits.h:16
const struct VBDeploymentInfo VersionBitsDeploymentInfo[]
Definition: versionbits.cpp:8
virtual bool Condition(const CBlockIndex *pindex, const Consensus::Params &params) const =0
virtual int Threshold(const Consensus::Params &params, int nAttempt) const =0
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
Definition: versionbits.h:72
bool check_mn_protocol
Whether to check current MN protocol or not.
Definition: versionbits.h:39
ThresholdState
Definition: versionbits.h:20
BIP9Stats GetStateStatisticsFor(const CBlockIndex *pindex, const Consensus::Params &params, ThresholdConditionCache &cache) const
int threshold
Definition: versionbits.h:44
BIP9Stats VersionBitsStatistics(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos, VersionBitsCache &cache)
DeploymentPos
Definition: params.h:15
int period
Definition: versionbits.h:43
ThresholdState VersionBitsState(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos, VersionBitsCache &cache)
Abstract class that implements BIP9-style threshold logic, and caches results.
Definition: versionbits.h:55
Parameters that influence chain consensus.
Definition: params.h:130
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
Definition: versionbits.h:31
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, const Consensus::Params &params, ThresholdConditionCache &cache) const
Definition: versionbits.cpp:46
int VersionBitsStateSinceHeight(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos, VersionBitsCache &cache)
const char * name
Deployment name.
Definition: versionbits.h:35
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
Definition: versionbits.h:12
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
Definition: versionbits.h:14
virtual int64_t BeginTime(const Consensus::Params &params) const =0
int elapsed
Definition: versionbits.h:45
bool possible
Definition: versionbits.h:47
virtual int Period(const Consensus::Params &params) const =0
uint32_t VersionBitsMask(const Consensus::Params &params, Consensus::DeploymentPos pos)
static const int32_t VERSIONBITS_NUM_BITS
Total bits available for versionbits.
Definition: versionbits.h:18
Released under the MIT license