Raven Core  3.0.0
P2P Digital Currency
versionbits.h
Go to the documentation of this file.
1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef RAVEN_CONSENSUS_VERSIONBITS
7 #define RAVEN_CONSENSUS_VERSIONBITS
8 
9 #include "chain.h"
10 #include <map>
11 
13 static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 5;
15 static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
17 static const int32_t VERSIONBITS_TOP_BITS_ASSETS = 0x30000000UL;
19 static const int32_t VERSIONBITS_TOP_BITS_MESSAGING = 0x40000000UL;
21 static const int32_t VERSIONBITS_TOP_BITS_RESTRICTED = 0x50000000UL;
23 static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
25 static const int32_t VERSIONBITS_NUM_BITS = 29;
26 
33 };
34 
35 // A map that gives the state for blocks whose height is a multiple of Period().
36 // The map is indexed by the block's parent, however, so all keys in the map
37 // will either be nullptr or a block with (height + 1) % Period() == 0.
38 typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
39 
42  const char *name;
44  bool gbt_force;
45 };
46 
47 struct BIP9Stats {
48  int period;
49  int threshold;
50  int elapsed;
51  int count;
52  bool possible;
53 };
54 
55 extern const struct VBDeploymentInfo VersionBitsDeploymentInfo[];
56 
61 protected:
62  virtual bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const =0;
63  virtual int64_t BeginTime(const Consensus::Params& params) const =0;
64  virtual int64_t EndTime(const Consensus::Params& params) const =0;
65  virtual int Period(const Consensus::Params& params) const =0;
66  virtual int Threshold(const Consensus::Params& params) const =0;
67 
68 public:
69  BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const;
70  // Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
71  ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
72  int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
73 };
74 
76 {
78 
79  void Clear();
80 };
81 
86 
87 #endif
bool gbt_force
Whether GBT clients can safely ignore this rule in simplified usage.
Definition: versionbits.h:44
const struct VBDeploymentInfo VersionBitsDeploymentInfo[]
Definition: versionbits.cpp:9
ThresholdState
Definition: versionbits.h:27
int threshold
Definition: versionbits.h:49
BIP9Stats VersionBitsStatistics(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos)
DeploymentPos
Definition: params.h:16
int period
Definition: versionbits.h:48
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:60
Parameters that influence chain consensus.
Definition: params.h:47
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
Definition: versionbits.h:38
int VersionBitsStateSinceHeight(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos, VersionBitsCache &cache)
const char * name
Deployment name.
Definition: versionbits.h:42
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:172
int elapsed
Definition: versionbits.h:50
bool possible
Definition: versionbits.h:52
uint32_t VersionBitsMask(const Consensus::Params &params, Consensus::DeploymentPos pos)