forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
versionbits: Split out internal details into impl header
- Loading branch information
Showing
6 changed files
with
58 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2016-2022 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_VERSIONBITS_IMPL_H | ||
#define BITCOIN_VERSIONBITS_IMPL_H | ||
|
||
#include <chain.h> | ||
#include <sync.h> | ||
#include <versionbits.h> | ||
|
||
#include <array> | ||
#include <map> | ||
|
||
/** BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages. | ||
* State transitions happen during retarget period if conditions are met | ||
* In case of reorg, transitions can go backward. Without transition, state is | ||
* inherited between periods. All blocks of a period share the same state. | ||
*/ | ||
enum class ThresholdState : uint8_t { | ||
DEFINED, // First state that each softfork starts out as. The genesis block is by definition in this state for each deployment. | ||
STARTED, // For blocks past the starttime. | ||
LOCKED_IN, // For at least one retarget period after the first retarget period with STARTED blocks of which at least threshold have the associated bit set in nVersion, until min_activation_height is reached. | ||
ACTIVE, // For all blocks after the LOCKED_IN retarget period (final state) | ||
FAILED, // For all blocks once the first retarget period after the timeout time is hit, if LOCKED_IN wasn't already reached (final state) | ||
}; | ||
|
||
/** | ||
* Abstract class that implements BIP9-style threshold logic, and caches results. | ||
*/ | ||
class AbstractThresholdConditionChecker { | ||
protected: | ||
virtual bool Condition(const CBlockIndex* pindex) const =0; | ||
virtual int64_t BeginTime() const =0; | ||
virtual int64_t EndTime() const =0; | ||
virtual int MinActivationHeight() const { return 0; } | ||
virtual int Period() const =0; | ||
virtual int Threshold() const =0; | ||
|
||
public: | ||
/** Returns the numerical statistics of an in-progress BIP9 softfork in the period including pindex | ||
* If provided, signalling_blocks is set to true/false based on whether each block in the period signalled | ||
*/ | ||
BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, std::vector<bool>* signalling_blocks = nullptr) const; | ||
/** Returns the state for pindex A based on parent pindexPrev B. Applies any state transition if conditions are present. | ||
* Caches state from first block of period. */ | ||
ThresholdState GetStateFor(const CBlockIndex* pindexPrev, ThresholdConditionCache& cache) const; | ||
/** 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 */ | ||
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, ThresholdConditionCache& cache) const; | ||
}; | ||
|
||
#endif // BITCOIN_VERSIONBITS_IMPL_H |