Skip to content

Commit 6576a87

Browse files
author
Antoine Riard
committed
doc: Improve versionbits.h documentation
1 parent 00dad5e commit 6576a87

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/versionbits.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
9494
return state;
9595
}
9696

97-
// return the numerical statistics of blocks signalling the specified BIP9 condition in this current period
9897
BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const
9998
{
10099
BIP9Stats stats = {};

src/versionbits.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,35 @@ static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
1717
/** Total bits available for versionbits */
1818
static const int32_t VERSIONBITS_NUM_BITS = 29;
1919

20+
/** BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
21+
* State transitions happen during retarget period if conditions are met
22+
* In case of reorg, transitions can go backward. Without transition, state is
23+
* inherited between periods. All blocks of a period share the same state.
24+
*/
2025
enum class ThresholdState {
21-
DEFINED,
22-
STARTED,
23-
LOCKED_IN,
24-
ACTIVE,
25-
FAILED,
26+
DEFINED, // First state that each softfork starts out as. The genesis block is by definition in this state for each deployment.
27+
STARTED, // For blocks past the starttime.
28+
LOCKED_IN, // For one retarget period after the first retarget period with STARTED blocks of which at least threshold have the associated bit set in nVersion.
29+
ACTIVE, // For all blocks after the LOCKED_IN retarget period (final state)
30+
FAILED, // For all blocks once the first retarget period after the timeout time is hit, if LOCKED_IN wasn't already reached (final state)
2631
};
2732

2833
// A map that gives the state for blocks whose height is a multiple of Period().
2934
// The map is indexed by the block's parent, however, so all keys in the map
3035
// will either be nullptr or a block with (height + 1) % Period() == 0.
3136
typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
3237

38+
/** Display status of an in-progress BIP9 softfork */
3339
struct BIP9Stats {
40+
/** Length of blocks of the BIP9 signalling period */
3441
int period;
42+
/** Number of blocks with the version bit set required to activate the softfork */
3543
int threshold;
44+
/** Number of blocks elapsed since the beginning of the current period */
3645
int elapsed;
46+
/** Number of blocks with the version bit set since the beginning of the current period */
3747
int count;
48+
/** False if there are not enough blocks left in this period to pass activation threshold */
3849
bool possible;
3950
};
4051

@@ -50,12 +61,17 @@ class AbstractThresholdConditionChecker {
5061
virtual int Threshold(const Consensus::Params& params) const =0;
5162

5263
public:
64+
/** Returns the numerical statistics of an in-progress BIP9 softfork in the current period */
5365
BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const;
54-
// Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
66+
/** Returns the state for pindex A based on parent pindexPrev B. Applies any state transition if conditions are present.
67+
* Caches state from first block of period. */
5568
ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
69+
/** Returns the height since when the ThresholdState has started for pindex A based on parent pindexPrev B, all blocks of a period share the same */
5670
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
5771
};
5872

73+
/** BIP 9 allows multiple softforks to be deployed in parallel. We cache per-period state for every one of them
74+
* keyed by the bit position used to signal support. */
5975
struct VersionBitsCache
6076
{
6177
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS];

0 commit comments

Comments
 (0)