From 8e2fc97ab8f85a5303b69cb27bbdf59f57ef57b6 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 27 Mar 2024 22:47:02 -0400 Subject: [PATCH] Refactor forks, incorporate bip30_deactivate/activate forks. --- include/bitcoin/system/chain/chain_state.hpp | 82 +++-- include/bitcoin/system/chain/context.hpp | 2 +- include/bitcoin/system/chain/enums/forks.hpp | 31 +- .../system/impl/machine/interpreter.ipp | 10 +- include/bitcoin/system/settings.hpp | 44 +-- src/chain/chain_state.cpp | 292 +++++++++++------- src/chain/context.cpp | 4 +- src/settings.cpp | 165 ++++++---- test/chain/chain_state.cpp | 9 +- test/settings.cpp | 22 +- 10 files changed, 384 insertions(+), 277 deletions(-) diff --git a/include/bitcoin/system/chain/chain_state.hpp b/include/bitcoin/system/chain/chain_state.hpp index d12f486de4..9e15e6b26b 100644 --- a/include/bitcoin/system/chain/chain_state.hpp +++ b/include/bitcoin/system/chain/chain_state.hpp @@ -46,9 +46,31 @@ class BC_API chain_state typedef std::deque bitss; typedef std::deque versions; typedef std::deque timestamps; - typedef struct { size_t count; size_t high; } range; - typedef std::shared_ptr ptr; + typedef struct { size_t count; size_t high; } range; + typedef struct + { + bool bip16; + bool bip30; + bool bip30_deactivate; + bool bip30_reactivate; + bool bip34; + bool bip42; + bool bip65; + bool bip66; + bool bip68; + bool bip90; + bool bip112; + bool bip113; + bool bip141; + bool bip143; + bool bip147; + bool retarget; // !regtest + bool difficult; // !testnet + bool time_warp_patch; // litecoin + bool retarget_overflow_patch; // litecoin + bool scrypt_proof_of_work; // litecoin + } forks_t; /// Heights used to identify construction requirements. /// All values are lower-bounded by the genesis block height. @@ -81,11 +103,14 @@ class BC_API chain_state /// (block - (block % 2016 == 0 ? 2016 : block % 2016)) size_t timestamp_retarget{}; + /// mainnet: 227931, testnet: 21111 (or map::unrequested) + size_t bip30_deactivate_height{ unrequested }; + /// mainnet: 419328, testnet: 770112 (or map::unrequested) - size_t bip9_bit0_height; + size_t bip9_bit0_height{ unrequested }; /// mainnet: 481824, testnet: 834624 (or map::unrequested) - size_t bip9_bit1_height; + size_t bip9_bit1_height{ unrequested }; }; /// Values used to populate chain state at the target height. @@ -97,14 +122,17 @@ class BC_API chain_state /// Hash of the candidate block or null_hash for memory pool. hash_digest hash{}; + /// Hash of the bip34 block that inactivates bip30, or null_hash. + hash_digest bip30_deactivate_hash{}; + /// Hash of the bip9_bit0 block or null_hash if unrequested. - hash_digest bip9_bit0_hash; + hash_digest bip9_bit0_hash{}; /// Hash of the bip9_bit1 block or null_hash if unrequested. - hash_digest bip9_bit1_hash; + hash_digest bip9_bit1_hash{}; /// Sum of all work from genesis to block height. - uint256_t cumulative_work; + uint256_t cumulative_work{}; /// Values must be ordered by height with high (block - 1) last. struct @@ -154,8 +182,8 @@ class BC_API chain_state static map get_map(size_t height, const system::settings& settings) NOEXCEPT; - /// The block version to signal based on active forks. - static uint32_t signal_version(uint32_t forks, + /// The block version to signal based on configured forks. + static uint32_t signal_version( const system::settings& settings) NOEXCEPT; /// Create pool state from top chain top block state. @@ -181,39 +209,42 @@ class BC_API chain_state uint32_t work_required() const NOEXCEPT; uint32_t timestamp() const NOEXCEPT; uint32_t median_time_past() const NOEXCEPT; - uint32_t forks() const NOEXCEPT; + uint32_t flags() const NOEXCEPT; size_t height() const NOEXCEPT; protected: struct activations { /// The forks that are active at this height. - uint32_t forks; + uint32_t flags; /// The minimum block version required at this height. uint32_t minimum_block_version; }; /// No failure sentinel. - static activations activation(const data& values, uint32_t forks, - const system::settings& settings) NOEXCEPT; + static activations activation(const data& values, + const forks_t& forks, const system::settings& settings) NOEXCEPT; /// Returns zero if data is invalid. static uint32_t median_time_past(const data& values, - uint32_t forks) NOEXCEPT; + const forks_t& forks) NOEXCEPT; /// Returns zero if data is invalid. - static uint32_t work_required(const data& values, uint32_t forks, - const system::settings& settings) NOEXCEPT; + static uint32_t work_required(const data& values, + const forks_t& forks, const system::settings& settings) NOEXCEPT; private: - static size_t bits_count(size_t height, uint32_t forks, + static size_t bits_count(size_t height, const forks_t& forks, size_t retargeting_interval) NOEXCEPT; - static size_t version_count(size_t height, uint32_t forks, + static size_t version_count(size_t height, const forks_t& forks, size_t bip34_activation_sample) NOEXCEPT; - static size_t timestamp_count(size_t height, uint32_t forks) NOEXCEPT; - static size_t retarget_height(size_t height, uint32_t forks, + static size_t timestamp_count(size_t height, const forks_t& forks) NOEXCEPT; + static size_t retarget_height(size_t height, const forks_t& forks, size_t retargeting_interval) NOEXCEPT; + + static size_t bip30_deactivate_height(size_t height, + const checkpoint& bip30_deactivate_checkpoint) NOEXCEPT; static size_t bip9_bit0_height(size_t height, const checkpoint& bip9_bit0_active_checkpoint) NOEXCEPT; static size_t bip9_bit1_height(size_t height, @@ -226,9 +257,10 @@ class BC_API chain_state static data to_header(const chain_state& parent, const header& header, const system::settings& settings) NOEXCEPT; - static uint32_t work_required_retarget(const data& values, uint32_t forks, - uint32_t proof_of_work_limit, uint32_t minimum_timespan, - uint32_t maximum_timespan, uint32_t retargeting_interval_seconds) NOEXCEPT; + static uint32_t work_required_retarget(const data& values, + const forks_t& forks, uint32_t proof_of_work_limit, + uint32_t minimum_timespan, uint32_t maximum_timespan, + uint32_t retargeting_interval_seconds) NOEXCEPT; static uint32_t retarget_timespan(const data& values, uint32_t minimum_timespan, uint32_t maximum_timespan) NOEXCEPT; static uint32_t easy_work_required(const data& values, @@ -237,8 +269,8 @@ class BC_API chain_state // These are thread safe. const data data_; - const uint32_t forks_; - const activations active_; + const forks_t& forks_; + const activations activations_; const uint32_t work_required_; const uint32_t median_time_past_; const uint256_t cumulative_work_; diff --git a/include/bitcoin/system/chain/context.hpp b/include/bitcoin/system/chain/context.hpp index cc394e3fb5..679b695cb5 100644 --- a/include/bitcoin/system/chain/context.hpp +++ b/include/bitcoin/system/chain/context.hpp @@ -34,7 +34,7 @@ class BC_API context final bool is_enabled(chain::forks fork) const NOEXCEPT; /// Header context within chain. - uint32_t forks; + uint32_t flags; uint32_t timestamp; uint32_t median_time_past; size_t height; diff --git a/include/bitcoin/system/chain/enums/forks.hpp b/include/bitcoin/system/chain/enums/forks.hpp index 337c08e1fe..f47c9e384b 100644 --- a/include/bitcoin/system/chain/enums/forks.hpp +++ b/include/bitcoin/system/chain/enums/forks.hpp @@ -41,7 +41,8 @@ enum forks : uint32_t /// Pay-to-script-hash enabled (soft fork, feature). bip16_rule = bit_right(2), - /// No duplicated unspent transaction ids (soft fork, deflation). + /// No duplicated unspent transaction ids (soft/hard/soft fork, deflation). + /// This (initially) soft fork rule expires and then unexpires (hard/soft). bip30_rule = bit_right(3), /// Coinbase must include height, redundant w/bip30 (soft fork, arbitrary). @@ -86,54 +87,49 @@ enum forks : uint32_t /// Finite monetary supply, effective at 13,440,000 (soft fork, inflation). bip42_rule = bit_right(17), - // TODO: + /// TODO: hardwired or obsoleted (historical). + /// ----------------------------------------------------------------------- + /// Promote nop1..nop10 [0.3.6] (hard fork, expansion). /// Combined script max 20,000 bytes, push_data 520 (soft fork, arbitrary). /// Initial script and push_data size limits (soft fork, arbitrary). /// Demote return, op_ver, verif, vernotif (soft fork, security). nops_rule = bit_right(18), - // TODO: /// Splits script evaluation, activated by [0.3.7] (hard fork, security). /// Per script max 10,000 bytes, one more total byte than prior, as the /// previous limit was imposed after concatenating with op_codeseparator. split_rule = bit_right(19), - // TODO: /// Invalidate op_cat, etc. [0.3.9] (soft fork, security). cats_rule = bit_right(20), - // TODO: /// The original rule leaked output value, was plugged here (soft fork). /// This was activated at block 74,638 [0.3.10], later to all blocks. plug_rule = bit_right(21), - // TODO: /// Limit block size to 1,000,000 bytes (soft fork, system DoS). /// Limit signature operations per block (soft fork, system DoS). /// This was activated at block 79,400 [0.3.12], and later to all blocks. size_rule = bit_right(22), - // TODO: /// Release [0.8.0] removal of hash limit, chain split at block 225,430. /// Original rule was from Berkely DB [unknown] (hard fork, determinism). unlock_rule = bit_right(23), - // TODO: /// This allowed double spends, applied and removed (hard fork, inflation). /// Activated (hard fork) in [0.15.0] deactivated (soft fork) in [0.16.3]. inflation_rule = bit_right(24), - // TODO: - /// Tx and input hashes max 4,500 per block (hard fork, determinism). + /// Tx and input hashes max 4,500 per block (soft/hard fork, determinism). /// This (initially) soft fork rule expires, which makes it a hard fork. bip50_rule = bit_right(25), - // TODO: /// Reduces threshold segregated witness signaling (soft fork, feature). bip91_rule = bit_right(26), - /// TODO: taproot rules. + /// Agregates + /// ----------------------------------------------------------------------- /// Rules that use bip34-based activation. bip34_activations = @@ -141,26 +137,21 @@ enum forks : uint32_t forks::bip65_rule | forks::bip66_rule, - /// TODO: /// Rules that use BIP9 bit 0 first time activation. bip9_bit0_group = forks::bip68_rule | forks::bip112_rule | forks::bip113_rule, - /// TODO: /// Rules that use BIP9 bit 1 first time activation. bip9_bit1_group = forks::bip141_rule | forks::bip143_rule | forks::bip147_rule, - /// TODO: - /// Rules that use BIP9 bit 4 first time activation. - bip9_bit4_group = - forks::bip91_rule, - - /// TODO: rules that use taproot-style activation. + /////// Rules that use BIP9 bit 4 first time activation. + ////bip9_bit4_group = + //// forks::bip91_rule, /// Mask to set all rule bits. all_rules = bit_all diff --git a/include/bitcoin/system/impl/machine/interpreter.ipp b/include/bitcoin/system/impl/machine/interpreter.ipp index 939030d82b..e6a692d7c8 100644 --- a/include/bitcoin/system/impl/machine/interpreter.ipp +++ b/include/bitcoin/system/impl/machine/interpreter.ipp @@ -1607,7 +1607,7 @@ connect(const context& state, const transaction& tx, return error::missing_previous_output; // Evaluate input script. - interpreter in_program(tx, it, state.forks); + interpreter in_program(tx, it, state.flags); if ((ec = in_program.run())) return ec; @@ -1622,13 +1622,13 @@ connect(const context& state, const transaction& tx, { return error::stack_false; } - else if (prevout->is_pay_to_script_hash(state.forks)) + else if (prevout->is_pay_to_script_hash(state.flags)) { // Because output script pushed script hash program (bip16). if ((ec = connect_embedded(state, tx, it, in_program))) return ec; } - else if (prevout->is_pay_to_witness(state.forks)) + else if (prevout->is_pay_to_witness(state.flags)) { // The input script must be empty (bip141). if (!input.script().ops().empty()) @@ -1674,7 +1674,7 @@ code interpreter::connect_embedded(const context& state, { return error::stack_false; } - else if (prevout->is_pay_to_witness(state.forks)) + else if (prevout->is_pay_to_witness(state.flags)) { // The input script must be a push of the embedded_script (bip141). if (input.script().ops().size() != one) @@ -1716,7 +1716,7 @@ code interpreter::connect_witness(const context&state, return error::invalid_witness; // A defined version indicates bip141 is active. - interpreter program(tx, it, script, state.forks, version, stack); + interpreter program(tx, it, script, state.flags, version, stack); if ((ec = program.run())) return ec; diff --git a/include/bitcoin/system/settings.hpp b/include/bitcoin/system/settings.hpp index d270799a3b..b6956a5cd7 100644 --- a/include/bitcoin/system/settings.hpp +++ b/include/bitcoin/system/settings.hpp @@ -43,34 +43,17 @@ class BC_API settings virtual uint64_t max_money() const NOEXCEPT; virtual uint64_t initial_subsidy() const NOEXCEPT; virtual uint64_t bitcoin_to_satoshi(uint64_t value) const NOEXCEPT; - virtual uint32_t enabled_forks() const NOEXCEPT; /// These are used internal to system. virtual uint32_t minimum_timespan() const NOEXCEPT; virtual uint32_t maximum_timespan() const NOEXCEPT; virtual size_t retargeting_interval() const NOEXCEPT; - /// Implemented chain::forks. + /// Configured forks. /// ----------------------------------------------------------------------- + /// These are not used internal to system. - bool bip16; - bool bip30; - bool bip34; - bool bip42; - bool bip65; - bool bip66; - bool bip68; - bool bip90; - bool bip112; - bool bip113; - bool bip141; - bool bip143; - bool bip147; - bool retarget; // !regtest - bool difficult; // !testnet - bool time_warp_patch; // litecoin - bool retarget_overflow_patch; // litecoin - bool scrypt_proof_of_work; // litecoin + chain::chain_state::forks_t forks{}; /// Consensus parameters. /// ----------------------------------------------------------------------- @@ -101,24 +84,23 @@ class BC_API settings uint32_t bip9_version_bit1; uint32_t bip9_version_base; + /// Block 514 is the first testnet block after date-based activation. + /// Block 173805 is the first mainnet block after date-based activation. + /// First mainnet activation window hardwired in satoshi 0.6.0rc1 failed. + uint32_t bip16_activation_time{}; + /// Activation parameters (bip34-style activations). size_t bip34_activation_threshold{}; size_t bip34_enforcement_threshold{}; size_t bip34_activation_sample{}; /// Frozen activation heights (frozen_activations). - size_t bip65_freeze{}; - size_t bip66_freeze{}; - size_t bip34_freeze{}; - - /// Block 514 is the first testnet block after date-based activation. - /// Block 173805 is the first mainnet block after date-based activation. - /// First mainnet activation window hardwired in satoshi 0.6.0rc1 failed. - uint32_t bip16_activation_time{}; + size_t bip90_bip34_height{}; + size_t bip90_bip65_height{}; + size_t bip90_bip66_height{}; - /// This is not used in consensus computations. - /// bip90 stops checking unspent duplicates above this bip34 activation. - chain::checkpoint bip34_active_checkpoint{}; + size_t bip30_reactivate_height{}; + chain::checkpoint bip30_deactivate_checkpoint{}; /// This cannot be reactivated in a future branch due to window expiration. chain::checkpoint bip9_bit0_active_checkpoint{}; diff --git a/src/chain/chain_state.cpp b/src/chain/chain_state.cpp index 43f4c4fb81..1892bad393 100644 --- a/src/chain/chain_state.cpp +++ b/src/chain/chain_state.cpp @@ -100,12 +100,63 @@ inline uint32_t bits_high(const chain_state::data& values) NOEXCEPT // ---------------------------------------------------------------------------- chain_state::activations chain_state::activation(const data& values, - uint32_t forks, const system::settings& settings) NOEXCEPT + const forks_t& forks, const system::settings& settings) NOEXCEPT { + // Initialize activation results with genesis values. + activations result{ forks::no_rules, settings.first_version }; + + // regtest is only activated via configuration. + if (forks.retarget) + { + result.flags |= forks::retarget; + } + + // testnet is activated based on configuration alone. + if (forks.difficult) + { + result.flags |= forks::difficult; + } + + // time_warp_patch is activated based on configuration alone. + if (forks.time_warp_patch) + { + result.flags |= forks::time_warp_patch; + } + + // retarget_overflow_patch is activated based on configuration alone. + if (forks.retarget_overflow_patch) + { + result.flags |= forks::retarget_overflow_patch; + } + + // scrypt_proof_of_work is activated based on configuration alone. + if (forks.scrypt_proof_of_work) + { + result.flags |= forks::scrypt_proof_of_work; + } + + // bip42 is activated based on configuration alone (soft fork). + if (forks.bip42) + { + result.flags |= forks::bip42_rule; + } + + // bip90 is activated based on configuration alone (hard fork). + if (forks.bip90) + { + result.flags |= forks::bip90_rule; + } + + // bip16 was activated by manual inspection of signal history (soft fork). + if (forks.bip16 && + (values.timestamp.self >= settings.bip16_activation_time)) + { + result.flags |= forks::bip16_rule; + } + const auto height = values.height; const auto version = values.version.self; const auto& history = values.version.ordered; - const auto bip90 = script::is_enabled(forks, forks::bip90_rule); //************************************************************************* // CONSENSUS: Though unspecified in bip34, the satoshi implementation @@ -117,12 +168,12 @@ chain_state::activations chain_state::activation(const data& values, }; // Declare bip34-based version predicates. - const auto ge_2 = [&](uint32_t value) NOEXCEPT { return ge(value, - settings.bip34_version); }; - const auto ge_3 = [&](uint32_t value) NOEXCEPT { return ge(value, - settings.bip66_version); }; - const auto ge_4 = [&](uint32_t value) NOEXCEPT { return ge(value, - settings.bip65_version); }; + const auto ge_2 = [&](uint32_t value) NOEXCEPT + { return ge(value, settings.bip34_version); }; + const auto ge_3 = [&](uint32_t value) NOEXCEPT + { return ge(value, settings.bip66_version); }; + const auto ge_4 = [&](uint32_t value) NOEXCEPT + { return ge(value, settings.bip65_version); }; // Compute bip34-based activation version summaries (empty if disabled). const auto count_2 = std::count_if(history.begin(), history.end(), ge_2); @@ -130,80 +181,49 @@ chain_state::activations chain_state::activation(const data& values, const auto count_4 = std::count_if(history.begin(), history.end(), ge_4); // Frozen activations (require version and enforce above freeze height). - const auto bip90_34 = bip90 && height >= settings.bip34_freeze; - const auto bip90_66 = bip90 && height >= settings.bip66_freeze; - const auto bip90_65 = bip90 && height >= settings.bip65_freeze; - - // Initialize activation results with genesis values. - activations result{ forks::no_rules, settings.first_version }; - - // regtest is only activated via configuration (hard fork). - result.forks |= (forks::retarget & forks); - - // testnet is activated based on configuration alone (hard fork). - result.forks |= (forks::difficult & forks); - - // bip42 is activated based on configuration alone (soft fork). - result.forks |= (forks::bip42_rule & forks); - - // bip90 is activated based on configuration alone (hard fork). - result.forks |= (forks::bip90_rule & forks); - - // time_warp_patch is activated based on configuration alone (hard fork). - result.forks |= (forks::time_warp_patch & forks); - - // retarget_overflow_patch is activated based on configuration alone (hard fork). - result.forks |= (forks::retarget_overflow_patch & forks); - - // scrypt_proof_of_work is activated based on configuration alone (hard fork). - result.forks |= (forks::scrypt_proof_of_work & forks); - - // bip16 was activated based on manual inspection of signal history (soft fork). - if (values.timestamp.self >= settings.bip16_activation_time) - { - result.forks |= (forks::bip16_rule & forks); - } + const auto bip90_bip34 = forks.bip90 && height >= settings.bip90_bip34_height; + const auto bip90_bip65 = forks.bip90 && height >= settings.bip90_bip65_height; + const auto bip90_bip66 = forks.bip90 && height >= settings.bip90_bip66_height; // bip34 activations oscillate until enforced by minimum_block_version. // bip90 does not require that the corresponding rules be defined. - // bip34 is active based on 75% of preceding 1000 mainnet blocks. - if (bip90_34 || (is_active(count_2, settings.bip34_activation_threshold) && + if (bip90_bip34 || + (is_active(count_2, settings.bip34_activation_threshold) && version >= settings.bip34_version)) { - result.forks |= (forks::bip34_rule & forks); - } - // bip30 is disabled by bip34 or unconditional activation of it by bip90. - // Otherwise if not exception, existing duplicate coinbase must be spent. - else if (!is_bip30_exception({ values.hash, height })) - { - result.forks |= (forks::bip30_rule & forks); + result.flags |= forks::bip34_rule; } // bip66 is active based on 75% of preceding 1000 mainnet blocks. - if (bip90_66 || (is_active(count_3, settings.bip34_activation_threshold) && + if (bip90_bip66 || + (is_active(count_3, settings.bip34_activation_threshold) && version >= settings.bip66_version)) { - result.forks |= (forks::bip66_rule & forks); + result.flags |= forks::bip66_rule; } // bip65 is active based on 75% of preceding 1000 mainnet blocks. - if (bip90_65 || (is_active(count_4, settings.bip34_activation_threshold) && + if (bip90_bip65 || + (is_active(count_4, settings.bip34_activation_threshold) && version >= settings.bip65_version)) { - result.forks |= (forks::bip65_rule & forks); + result.flags |= forks::bip65_rule; } // version 4/3/2 enforced based on 95% of preceding 1000 mainnet blocks. - if (bip90_65 || is_enforced(count_4, settings.bip34_enforcement_threshold)) + if (bip90_bip65 || + is_enforced(count_4, settings.bip34_enforcement_threshold)) { result.minimum_block_version = settings.bip65_version; } - else if (bip90_66 || is_enforced(count_3, settings.bip34_enforcement_threshold)) + else if (bip90_bip66 || + is_enforced(count_3, settings.bip34_enforcement_threshold)) { result.minimum_block_version = settings.bip66_version; } - else if (bip90_34 || is_enforced(count_2, settings.bip34_enforcement_threshold)) + else if (bip90_bip34 || + is_enforced(count_2, settings.bip34_enforcement_threshold)) { result.minimum_block_version = settings.bip34_version; } @@ -217,27 +237,48 @@ chain_state::activations chain_state::activation(const data& values, // bip9_bit0 forks are enforced above the bip9_bit0 checkpoint. if (values.bip9_bit0_hash == settings.bip9_bit0_active_checkpoint.hash()) { - result.forks |= (forks::bip9_bit0_group & forks); + result.flags |= forks::bip68_rule; + result.flags |= forks::bip112_rule; + result.flags |= forks::bip113_rule; } // bip9_bit1 forks are enforced above the bip9_bit1 checkpoint. if (values.bip9_bit1_hash == settings.bip9_bit1_active_checkpoint.hash()) { - result.forks |= (forks::bip9_bit1_group & forks); + result.flags |= forks::bip141_rule; + result.flags |= forks::bip143_rule; + result.flags |= forks::bip147_rule; + } + + // bip30_deactivate fork enforced above bip30_deactivate (bip34) checkpoint. + const auto bip30_deactivate = forks.bip30 && forks.bip30_deactivate && + (values.bip30_deactivate_hash == + settings.bip30_deactivate_checkpoint.hash()); + + // bip30_reactivate fork is enforced above the bip30_reactivate height. + const auto bip30_reactivate = bip30_deactivate && forks.bip30_reactivate && + (height >= settings.bip30_reactivate_height); + + // bip30 is disabled by bip30_deactivate and reenabled by bip30_reactivate. + // Otherwise if not exception, existing duplicate coinbase must be spent. + if (forks.bip30 && (!bip30_deactivate || bip30_reactivate) && + !is_bip30_exception({ values.hash, height })) + { + result.flags |= forks::bip30_rule; } return result; } -size_t chain_state::bits_count(size_t height, uint32_t forks, +size_t chain_state::bits_count(size_t height, const forks_t& forks, size_t retargeting_interval) NOEXCEPT { // Mainnet doesn't use bits in retargeting. - if (script::is_enabled(forks, forks::difficult)) + if (forks.difficult) return one; // Regtest bypasses all retargeting. - if (!script::is_enabled(forks, forks::retarget)) + if (!forks.retarget) return one; // Testnet uses mainnet retargeting on interval. @@ -248,27 +289,24 @@ size_t chain_state::bits_count(size_t height, uint32_t forks, return std::min(height, retargeting_interval); } -size_t chain_state::version_count(size_t height, uint32_t forks, +size_t chain_state::version_count(size_t height, const forks_t& forks, size_t bip34_activation_sample) NOEXCEPT { - if (script::is_enabled(forks, forks::bip90_rule) || - !script::is_enabled(forks, forks::bip34_activations)) - { + if (forks.bip90 || (!forks.bip34 && !forks.bip65 && !forks.bip66)) return zero; - } return std::min(height, bip34_activation_sample); } -size_t chain_state::timestamp_count(size_t height, uint32_t) NOEXCEPT +size_t chain_state::timestamp_count(size_t height, const forks_t&) NOEXCEPT { return std::min(height, median_time_past_interval); } -size_t chain_state::retarget_height(size_t height, uint32_t forks, +size_t chain_state::retarget_height(size_t height, const forks_t& forks, size_t retargeting_interval) NOEXCEPT { - if (!script::is_enabled(forks, forks::retarget)) + if (!forks.retarget) return map::unrequested; // Height must be a positive multiple of interval, so underflow safe. @@ -287,7 +325,8 @@ size_t chain_state::retarget_height(size_t height, uint32_t forks, // curious and confusing convention. We associate the median time past for // block N with block N. This is simple but requires care when comparing code. //***************************************************************************** -uint32_t chain_state::median_time_past(const data& values, uint32_t) NOEXCEPT +uint32_t chain_state::median_time_past(const data& values, + const forks_t&) NOEXCEPT { // Sort the times by value to obtain the median. auto times = sort_copy(values.timestamp.ordered); @@ -302,7 +341,7 @@ uint32_t chain_state::median_time_past(const data& values, uint32_t) NOEXCEPT // work_required // ---------------------------------------------------------------------------- -uint32_t chain_state::work_required(const data& values, uint32_t forks, +uint32_t chain_state::work_required(const data& values, const forks_t& forks, const system::settings& settings) NOEXCEPT { // Genesis has no preceding block data. @@ -314,7 +353,7 @@ uint32_t chain_state::work_required(const data& values, uint32_t forks, return 0; // Regtest bypasses all retargeting. - if (!script::is_enabled(forks, forks::retarget)) + if (!forks.retarget) return bits_high(values); // Mainnet and testnet retarget on interval. @@ -326,7 +365,7 @@ uint32_t chain_state::work_required(const data& values, uint32_t forks, settings.retargeting_interval_seconds); // Testnet retargets easy on inter-interval. - if (!script::is_enabled(forks, forks::difficult)) + if (!forks.difficult) return easy_work_required(values, settings.retargeting_interval(), settings.proof_of_work_limit, @@ -354,16 +393,17 @@ uint32_t chain_state::retarget_timespan(const data& values, return limit(timespan, minimum_timespan, maximum_timespan); } -constexpr bool patch_timewarp(uint32_t forks, const uint256_t& limit, - const uint256_t& target) NOEXCEPT +constexpr bool patch_timewarp(const chain_state::forks_t& forks, + const uint256_t& limit, const uint256_t& target) NOEXCEPT { - return script::is_enabled(forks, forks::retarget_overflow_patch) && + return forks.retarget_overflow_patch && floored_log2(target) >= floored_log2(limit); } -uint32_t chain_state::work_required_retarget(const data& values, uint32_t forks, - uint32_t proof_of_work_limit, uint32_t minimum_timespan, - uint32_t maximum_timespan, uint32_t retargeting_interval_seconds) NOEXCEPT +uint32_t chain_state::work_required_retarget(const data& values, + const forks_t& forks, uint32_t proof_of_work_limit, + uint32_t minimum_timespan, uint32_t maximum_timespan, + uint32_t retargeting_interval_seconds) NOEXCEPT { static const auto limit = compact::expand(proof_of_work_limit); auto target = compact::expand(bits_high(values)); @@ -422,12 +462,21 @@ uint32_t chain_state::easy_work_required(const data& values, return proof_of_work_limit; } +size_t chain_state::bip30_deactivate_height(size_t height, + const checkpoint& bip30_deactivate_checkpoint) NOEXCEPT +{ + const auto activation_height = bip30_deactivate_checkpoint.height(); + + // Require bip30_deactivate hash at heights at/above bip30_deactivate active. + return height < activation_height ? map::unrequested : activation_height; +} + size_t chain_state::bip9_bit0_height(size_t height, const checkpoint& bip9_bit0_active_checkpoint) NOEXCEPT { const auto activation_height = bip9_bit0_active_checkpoint.height(); - // Require bip9_bit0 hash at heights at/above bip9_bit0 activation. + // Require bip9_bit0 hash at heights at/above bip9_bit0 active. return height < activation_height ? map::unrequested : activation_height; } @@ -436,7 +485,7 @@ size_t chain_state::bip9_bit1_height(size_t height, { const auto activation_height = bip9_bit1_active_checkpoint.height(); - // Require bip9_bit1 hash at heights at/above bip9_bit1 activation. + // Require bip9_bit1 hash at heights at/above bip9_bit1 active. return height < activation_height ? map::unrequested : activation_height; } @@ -449,7 +498,7 @@ chain_state::map chain_state::get_map(size_t height, if (is_zero(height)) return {}; - const auto forks = settings.enabled_forks(); + const auto& forks = settings.forks; const auto interval = settings.retargeting_interval(); map map{}; @@ -472,38 +521,46 @@ chain_state::map chain_state::get_map(size_t height, // The most recent past retarget height. map.timestamp_retarget = retarget_height(height, forks, interval); + // The checkpoint at/above which bip30_deactivate rule is enforced. + if (forks.bip30 && forks.bip30_deactivate) + map.bip30_deactivate_height = bip30_deactivate_height(height, + settings.bip30_deactivate_checkpoint); + // The checkpoint at/above which bip9_bit0 rules are enforced. - map.bip9_bit0_height = bip9_bit0_height(height, - settings.bip9_bit0_active_checkpoint); + if (forks.bip68 || forks.bip112 || forks.bip113) + map.bip9_bit0_height = bip9_bit0_height(height, + settings.bip9_bit0_active_checkpoint); // The checkpoint at/above which bip9_bit1 rules are enforced. - map.bip9_bit1_height = bip9_bit1_height(height, - settings.bip9_bit1_active_checkpoint); + if (forks.bip141 || forks.bip143 || forks.bip147) + map.bip9_bit1_height = bip9_bit1_height(height, + settings.bip9_bit1_active_checkpoint); return map; } -uint32_t chain_state::signal_version(uint32_t forks, - const system::settings& settings) NOEXCEPT +uint32_t chain_state::signal_version(const system::settings& settings) NOEXCEPT { - if (script::is_enabled(forks, forks::bip65_rule)) - return settings.bip65_version; - - if (script::is_enabled(forks, forks::bip66_rule)) - return settings.bip66_version; + const auto& forks = settings.forks; - if (script::is_enabled(forks, forks::bip34_rule)) - return settings.bip34_version; + // TODO: these can be retired. + // Signal bip9 bit1 if any of the group is configured. + if (forks.bip141 || forks.bip143 || forks.bip147) + return settings.bip9_version_base | settings.bip9_version_bit1; // TODO: these can be retired. // Signal bip9 bit0 if any of the group is configured. - if (script::is_enabled(forks, forks::bip9_bit0_group)) + if (forks.bip68 || forks.bip112 || forks.bip113) return settings.bip9_version_base | settings.bip9_version_bit0; - // TODO: these can be retired. - // Signal bip9 bit1 if any of the group is configured. - if (script::is_enabled(forks, forks::bip9_bit1_group)) - return settings.bip9_version_base | settings.bip9_version_bit1; + if (forks.bip65) + return settings.bip65_version; + + if (forks.bip66) + return settings.bip66_version; + + if (forks.bip34) + return settings.bip34_version; return settings.first_version; } @@ -516,10 +573,7 @@ chain_state::data chain_state::to_pool(const chain_state& top, const system::settings& settings) NOEXCEPT { // Alias configured forks. - const auto forks = top.forks_; - - // Retargeting is only activated via configuration. - const auto retarget = script::is_enabled(forks, forks::retarget); + const auto& forks = top.forks_; // Copy data from presumed previous-height block state. chain_state::data data{ top.data_ }; @@ -548,28 +602,26 @@ chain_state::data chain_state::to_pool(const chain_state& top, if (data.timestamp.ordered.size() > timestamp_count(height, forks)) data.timestamp.ordered.pop_front(); - // Regtest does not perform retargeting. // If promoting from retarget height, move that timestamp into retarget. - if (retarget && is_retarget_height(sub1(height), + if (forks.retarget && is_retarget_height(sub1(height), settings.retargeting_interval())) { // Conditionally patch time warp bug (e.g. Litecoin). - const auto patch = script::is_enabled(forks, forks::time_warp_patch); - - data.timestamp.retarget = (patch && height != one) ? + data.timestamp.retarget = (forks.time_warp_patch && height != one) ? *std::next(data.timestamp.ordered.crbegin()) : data.timestamp.self; } // Replace previous block state with tx pool chain state for next height // Preserve top block timestamp for use in computation of staleness. + // Preserve data.bip30_deactivate_hash promotion. // Preserve data.bip9_bit0_hash promotion. // Preserve data.bip9_bit1_hash promotion. // bits.self is unused. data.height = height; data.hash = {}; data.bits.self = 0; - data.version.self = signal_version(forks, settings); + data.version.self = signal_version(settings); return data; } @@ -579,7 +631,7 @@ chain_state::chain_state(const chain_state& top, const system::settings& settings) NOEXCEPT : data_(to_pool(top, settings)), forks_(top.forks_), - active_(activation(data_, forks_, settings)), + activations_(activation(data_, forks_, settings)), work_required_(work_required(data_, forks_, settings)), median_time_past_(median_time_past(data_, forks_)) { @@ -617,7 +669,7 @@ chain_state::chain_state(const chain_state& pool, const block& block, const system::settings& settings) NOEXCEPT : data_(to_block(pool, block, settings)), forks_(pool.forks_), - active_(activation(data_, forks_, settings)), + activations_(activation(data_, forks_, settings)), work_required_(work_required(data_, forks_, settings)), median_time_past_(median_time_past(data_, forks_)) { @@ -656,7 +708,7 @@ chain_state::chain_state(const chain_state& parent, const header& header, const system::settings& settings) NOEXCEPT : data_(to_header(parent, header, settings)), forks_(parent.forks_), - active_(activation(data_, forks_, settings)), + activations_(activation(data_, forks_, settings)), work_required_(work_required(data_, forks_, settings)), median_time_past_(median_time_past(data_, forks_)) { @@ -666,8 +718,8 @@ chain_state::chain_state(const chain_state& parent, const header& header, chain_state::chain_state(data&& values, const system::settings& settings) NOEXCEPT : data_(std::move(values)), - forks_(settings.enabled_forks()), - active_(activation(data_, forks_, settings)), + forks_(settings.forks), + activations_(activation(data_, forks_, settings)), work_required_(work_required(data_, forks_, settings)), median_time_past_(median_time_past(data_, forks_)) { @@ -680,7 +732,7 @@ chain::context chain_state::context() const NOEXCEPT { return { - forks(), + flags(), timestamp(), median_time_past(), possible_narrow_cast(height()), @@ -701,7 +753,7 @@ const uint256_t& chain_state::cumulative_work() const NOEXCEPT uint32_t chain_state::minimum_block_version() const NOEXCEPT { - return active_.minimum_block_version; + return activations_.minimum_block_version; } uint32_t chain_state::work_required() const NOEXCEPT @@ -721,9 +773,9 @@ uint32_t chain_state::median_time_past() const NOEXCEPT return median_time_past_; } -uint32_t chain_state::forks() const NOEXCEPT +uint32_t chain_state::flags() const NOEXCEPT { - return active_.forks; + return activations_.flags; } size_t chain_state::height() const NOEXCEPT diff --git a/src/chain/context.cpp b/src/chain/context.cpp index 5900a4e42a..27f06e9cd7 100644 --- a/src/chain/context.cpp +++ b/src/chain/context.cpp @@ -27,12 +27,12 @@ namespace chain { bool context::is_enabled(chain::forks fork) const NOEXCEPT { - return to_bool(fork & forks); + return to_bool(fork & flags); } bool operator==(const context& left, const context& right) NOEXCEPT { - return left.forks == right.forks + return left.flags == right.flags && left.timestamp == right.timestamp && left.median_time_past == right.median_time_past && left.height == right.height diff --git a/src/settings.cpp b/src/settings.cpp index 6059eacf6f..20e04861eb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -27,26 +27,7 @@ namespace libbitcoin { namespace system { settings::settings() NOEXCEPT - : bip16(true), - bip30(true), - bip34(true), - bip42(true), - bip65(true), - bip66(true), - bip68(true), - bip90(true), - bip112(true), - bip113(true), - bip141(true), - bip143(true), - bip147(true), - retarget(true), - difficult(true), - time_warp_patch(false), - retarget_overflow_patch(false), - scrypt_proof_of_work(false), - - initial_subsidy_bitcoin(50), + : initial_subsidy_bitcoin(50), subsidy_interval_blocks(210000), timestamp_limit_seconds(2 * 60 * 60), @@ -63,6 +44,26 @@ settings::settings() NOEXCEPT bip9_version_bit1(1 << 1), bip9_version_base(0x20000000) { + forks.bip16 = true; + forks.bip30 = true; + forks.bip30_deactivate = true; + forks.bip30_reactivate = true; + forks.bip34 = true; + forks.bip42 = true; + forks.bip65 = true; + forks.bip66 = true; + forks.bip68 = true; + forks.bip90 = true; + forks.bip112 = true; + forks.bip113 = true; + forks.bip141 = true; + forks.bip143 = true; + forks.bip147 = true; + forks.retarget = true; // !regtest + forks.difficult = true; // !testnet + forks.time_warp_patch = false; // litecoin + forks.retarget_overflow_patch = false; // litecoin + forks.scrypt_proof_of_work = false; // litecoin } settings::settings(chain::selection context) NOEXCEPT @@ -111,13 +112,37 @@ settings::settings(chain::selection context) NOEXCEPT 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00 }, false); + + forks.bip16 = true; + forks.bip30 = true; + forks.bip30_deactivate = true; + forks.bip30_reactivate = true; + forks.bip34 = true; + forks.bip42 = true; + forks.bip65 = true; + forks.bip66 = true; + forks.bip68 = true; + forks.bip90 = true; + forks.bip112 = true; + forks.bip113 = true; + forks.bip141 = true; + forks.bip143 = true; + forks.bip147 = true; + forks.retarget = true; // !regtest + forks.difficult = true; // !testnet + forks.time_warp_patch = false; // litecoin + forks.retarget_overflow_patch = false; // litecoin + forks.scrypt_proof_of_work = false; // litecoin + + bip16_activation_time = 0x4f779a80; bip34_activation_threshold = 750; bip34_enforcement_threshold = 950; bip34_activation_sample = 1000; - bip65_freeze = 388381; - bip66_freeze = 363725; - bip34_freeze = 227931; - bip16_activation_time = 0x4f779a80; + bip90_bip34_height = 227931; + bip90_bip65_height = 388381; + bip90_bip66_height = 363725; + bip30_reactivate_height = 1983702; + bip30_deactivate_checkpoint = { "000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8", 227931 }; bip9_bit0_active_checkpoint = { "000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5", 419328 }; bip9_bit1_active_checkpoint = { "0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893", 481824 }; checkpoints = @@ -183,14 +208,39 @@ settings::settings(chain::selection context) NOEXCEPT 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00 }, false); + + forks.bip16 = true; + forks.bip30 = true; + forks.bip30_deactivate = true; + forks.bip30_reactivate = true; + forks.bip34 = true; + forks.bip42 = true; + forks.bip65 = true; + forks.bip66 = true; + forks.bip68 = true; + forks.bip90 = true; + forks.bip112 = true; + forks.bip113 = true; + forks.bip141 = true; + forks.bip143 = true; + forks.bip147 = true; + forks.retarget = true; // !regtest + forks.difficult = false; // !testnet + forks.time_warp_patch = false; // litecoin + forks.retarget_overflow_patch = false; // litecoin + forks.scrypt_proof_of_work = false; // litecoin + + bip16_activation_time = 0x4f3af580; bip34_activation_threshold = 51; bip34_enforcement_threshold = 75; bip34_activation_sample = 100; + bip90_bip34_height = 21111; + bip90_bip65_height = 581885; + bip90_bip66_height = 330776; - bip65_freeze = 581885; - bip66_freeze = 330776; - bip34_freeze = 21111; - bip16_activation_time = 0x4f3af580; + // yes, 1983702 is only relevant to mainnet (lazy bitcoind impl). + bip30_reactivate_height = 1983702; + bip30_deactivate_checkpoint = { "0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8", 21111 }; bip9_bit0_active_checkpoint = { "00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb", 770112 }; bip9_bit1_active_checkpoint = { "00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca", 834624 }; checkpoints = @@ -246,10 +296,36 @@ settings::settings(chain::selection context) NOEXCEPT 0xac, 0x00, 0x00, 0x00, 0x00 }, false); - bip65_freeze = 1351; - bip66_freeze = 1251; - bip34_freeze = 0; + forks.bip16 = true; + forks.bip30 = true; + forks.bip30_deactivate = true; + forks.bip30_reactivate = true; + forks.bip34 = true; + forks.bip42 = true; + forks.bip65 = true; + forks.bip66 = true; + forks.bip68 = true; + forks.bip90 = true; + forks.bip112 = true; + forks.bip113 = true; + forks.bip141 = true; + forks.bip143 = true; + forks.bip147 = true; + forks.retarget = false; // !regtest + forks.difficult = true; // !testnet + forks.time_warp_patch = false; // litecoin + forks.retarget_overflow_patch = false; // litecoin + forks.scrypt_proof_of_work = false; // litecoin + bip16_activation_time = 0x4f3af580; + bip34_activation_threshold = 0; + bip34_enforcement_threshold = 0; + bip34_activation_sample = 0; + bip90_bip34_height = 100000000; + bip90_bip65_height = 1351; + bip90_bip66_height = 1251; + bip30_reactivate_height = 0; + bip30_deactivate_checkpoint = { "0000000000000000000000000000000000000000000000000000000000000000", 0 }; // bip9's are fixed and closed, so assume genesis activation. // bip90 assumes a historical bip34 activation block, so use genesis. @@ -317,33 +393,6 @@ uint64_t settings::bitcoin_to_satoshi(uint64_t value) const NOEXCEPT BC_POP_WARNING() } -uint32_t settings::enabled_forks() const NOEXCEPT -{ - using namespace chain; - - // TODO: optimize to prevent recomputation. - uint32_t forks = forks::no_rules; - forks |= (bip16 ? static_cast(forks::bip16_rule) : 0); - forks |= (bip30 ? static_cast(forks::bip30_rule) : 0); - forks |= (bip34 ? static_cast(forks::bip34_rule) : 0); - forks |= (bip42 ? static_cast(forks::bip42_rule) : 0); - forks |= (bip65 ? static_cast(forks::bip65_rule) : 0); - forks |= (bip66 ? static_cast(forks::bip66_rule) : 0); - forks |= (bip68 ? static_cast(forks::bip68_rule) : 0); - forks |= (bip90 ? static_cast(forks::bip90_rule) : 0); - forks |= (bip112 ? static_cast(forks::bip112_rule) : 0); - forks |= (bip113 ? static_cast(forks::bip113_rule) : 0); - forks |= (bip141 ? static_cast(forks::bip141_rule) : 0); - forks |= (bip143 ? static_cast(forks::bip143_rule) : 0); - forks |= (bip147 ? static_cast(forks::bip147_rule) : 0); - forks |= (retarget ? static_cast(forks::retarget) : 0); - forks |= (difficult ? static_cast(forks::difficult) : 0); - forks |= (time_warp_patch ? static_cast(forks::time_warp_patch) : 0); - forks |= (retarget_overflow_patch ? static_cast(forks::retarget_overflow_patch) : 0); - forks |= (scrypt_proof_of_work ? static_cast(forks::scrypt_proof_of_work) : 0); - return forks; -} - // These are used internal to system. // ---------------------------------------------------------------------------- diff --git a/test/chain/chain_state.cpp b/test/chain/chain_state.cpp index 0b860d2124..9eae67d73a 100644 --- a/test/chain/chain_state.cpp +++ b/test/chain/chain_state.cpp @@ -41,8 +41,8 @@ BOOST_AUTO_TEST_CASE(chain_state__work_required_retarget__overflow_patch_disable settings settings(chain::selection::mainnet); settings.proof_of_work_limit = 0x1e0fffff; const auto values = get_values(settings.retargeting_interval()); - const auto forks = chain::forks::retarget; - const auto work = test_chain_state::work_required(values, forks, settings); + settings.forks.retarget = true; + const auto work = test_chain_state::work_required(values, settings.forks, settings); BOOST_REQUIRE_EQUAL(work, 0x1e0884d1u); } @@ -51,8 +51,9 @@ BOOST_AUTO_TEST_CASE(chain_state__work_required_retarget__overflow_patch_enabled settings settings(chain::selection::mainnet); settings.proof_of_work_limit = 0x1e0fffff; const auto values = get_values(settings.retargeting_interval()); - const auto forks = chain::forks::retarget | chain::forks::retarget_overflow_patch; - const auto work = test_chain_state::work_required(values, forks, settings); + settings.forks.retarget = true; + settings.forks.retarget_overflow_patch = true; + const auto work = test_chain_state::work_required(values, settings.forks, settings); BOOST_REQUIRE_EQUAL(work, settings.proof_of_work_limit); } diff --git a/test/settings.cpp b/test/settings.cpp index 45bbb84f1e..f542b575e0 100644 --- a/test/settings.cpp +++ b/test/settings.cpp @@ -80,13 +80,13 @@ BOOST_AUTO_TEST_CASE(settings__construct__mainnet_context__expected) BOOST_REQUIRE_EQUAL(configuration.bip9_version_bit0, 1u); BOOST_REQUIRE_EQUAL(configuration.bip9_version_bit1, 2u); BOOST_REQUIRE_EQUAL(configuration.bip9_version_base, 0x20000000u); + BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1333238400u); BOOST_REQUIRE_EQUAL(configuration.bip34_activation_threshold, 750u); BOOST_REQUIRE_EQUAL(configuration.bip34_enforcement_threshold, 950u); BOOST_REQUIRE_EQUAL(configuration.bip34_activation_sample, 1000u); - BOOST_REQUIRE_EQUAL(configuration.bip65_freeze, 388381u); - BOOST_REQUIRE_EQUAL(configuration.bip66_freeze, 363725u); - BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 227931u); - BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1333238400u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip34_height, 227931u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip65_height, 388381u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip66_height, 363725u); const chain::checkpoint bit0_active("000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5", 419328u); BOOST_REQUIRE_EQUAL(configuration.bip9_bit0_active_checkpoint, bit0_active); const chain::checkpoint bit1_active("0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893", 481824u); @@ -125,13 +125,13 @@ BOOST_AUTO_TEST_CASE(settings__construct__testnet_context__expected) BOOST_REQUIRE_EQUAL(configuration.bip9_version_bit0, 1u); BOOST_REQUIRE_EQUAL(configuration.bip9_version_bit1, 2u); BOOST_REQUIRE_EQUAL(configuration.bip9_version_base, 0x20000000u); + BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1329264000u); BOOST_REQUIRE_EQUAL(configuration.bip34_activation_threshold, 51u); BOOST_REQUIRE_EQUAL(configuration.bip34_enforcement_threshold, 75u); BOOST_REQUIRE_EQUAL(configuration.bip34_activation_sample, 100u); - BOOST_REQUIRE_EQUAL(configuration.bip65_freeze, 581885u); - BOOST_REQUIRE_EQUAL(configuration.bip66_freeze, 330776u); - BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 21111u); - BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1329264000u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip34_height, 21111u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip65_height, 581885u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip66_height, 330776u); const chain::checkpoint bit0_active("00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb", 770112u); BOOST_REQUIRE_EQUAL(configuration.bip9_bit0_active_checkpoint, bit0_active); const chain::checkpoint bit1_active("00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca", 834624u); @@ -165,10 +165,10 @@ BOOST_AUTO_TEST_CASE(settings__construct__regtest_context__expected) BOOST_REQUIRE_EQUAL(configuration.bip9_version_bit0, 1u); BOOST_REQUIRE_EQUAL(configuration.bip9_version_bit1, 2u); BOOST_REQUIRE_EQUAL(configuration.bip9_version_base, 0x20000000u); - BOOST_REQUIRE_EQUAL(configuration.bip65_freeze, 1351u); - BOOST_REQUIRE_EQUAL(configuration.bip66_freeze, 1251u); - BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 0u); BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1329264000u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip34_height, 100000000u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip65_height, 1351u); + BOOST_REQUIRE_EQUAL(configuration.bip90_bip66_height, 1251u); const chain::checkpoint genesis(genesis_block.hash(), 0u); BOOST_REQUIRE_EQUAL(configuration.bip9_bit0_active_checkpoint, genesis); BOOST_REQUIRE_EQUAL(configuration.bip9_bit1_active_checkpoint, genesis);