1a445343f6
-BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
80 lines
3.2 KiB
C++
80 lines
3.2 KiB
C++
// Copyright (c) 2016 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_CONSENSUS_VERSIONBITS
|
|
#define BITCOIN_CONSENSUS_VERSIONBITS
|
|
|
|
#include <chain.h>
|
|
#include <map>
|
|
|
|
/** What block version to use for new blocks (pre versionbits) */
|
|
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
|
|
/** What bits to set in version for versionbits blocks */
|
|
static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
|
|
/** What bitmask determines whether versionbits is in use */
|
|
static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
|
|
/** Total bits available for versionbits */
|
|
static const int32_t VERSIONBITS_NUM_BITS = 29;
|
|
|
|
enum ThresholdState {
|
|
THRESHOLD_DEFINED,
|
|
THRESHOLD_STARTED,
|
|
THRESHOLD_LOCKED_IN,
|
|
THRESHOLD_ACTIVE,
|
|
THRESHOLD_FAILED,
|
|
};
|
|
|
|
// A map that gives the state for blocks whose height is a multiple of Period().
|
|
// The map is indexed by the block's parent, however, so all keys in the map
|
|
// will either be nullptr or a block with (height + 1) % Period() == 0.
|
|
typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
|
|
|
|
struct VBDeploymentInfo {
|
|
/** Deployment name */
|
|
const char *name;
|
|
/** Whether GBT clients can safely ignore this rule in simplified usage */
|
|
bool gbt_force;
|
|
};
|
|
|
|
struct BIP9Stats {
|
|
int period;
|
|
int threshold;
|
|
int elapsed;
|
|
int count;
|
|
bool possible;
|
|
};
|
|
|
|
extern const struct VBDeploymentInfo VersionBitsDeploymentInfo[];
|
|
|
|
/**
|
|
* Abstract class that implements BIP9-style threshold logic, and caches results.
|
|
*/
|
|
class AbstractThresholdConditionChecker {
|
|
protected:
|
|
virtual bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const =0;
|
|
virtual int64_t BeginTime(const Consensus::Params& params) const =0;
|
|
virtual int64_t EndTime(const Consensus::Params& params) const =0;
|
|
virtual int Period(const Consensus::Params& params) const =0;
|
|
virtual int Threshold(const Consensus::Params& params) const =0;
|
|
|
|
public:
|
|
BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const;
|
|
// Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
|
|
ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
|
|
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
|
|
};
|
|
|
|
struct VersionBitsCache
|
|
{
|
|
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS];
|
|
|
|
void Clear();
|
|
};
|
|
|
|
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
|
|
BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos);
|
|
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
|
|
uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
|
|
|
#endif
|