From 8eeb96e6014af4312dd4612ea030f1c123eab933 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 18 Feb 2024 10:28:18 -0500 Subject: [PATCH 1/4] bip30 comments and updates. --- src/chain/block.cpp | 6 ++--- src/chain/chain_state.cpp | 48 +++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/chain/block.cpp b/src/chain/block.cpp index 30f1597140..53036c4736 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -564,7 +564,7 @@ bool block::is_unspent_coinbase_collision() const NOEXCEPT if (txs_->empty() || txs_->front()->inputs_ptr()->empty()) return false; - // May only commit a coinbase that has already been confirmed spent. + // May only commit duplicate coinbase that is already confirmed spent. return !txs_->front()->inputs_ptr()->front()->metadata.spent; } @@ -741,10 +741,8 @@ code block::accept(const context& ctx, size_t subsidy_interval, code block::confirm(const context& ctx) const NOEXCEPT { const auto bip30 = ctx.is_enabled(bip30_rule); - const auto bip34 = ctx.is_enabled(bip34_rule); - // confirmations required. - if (bip30 && !bip34 && is_unspent_coinbase_collision()) + if (bip30 && is_unspent_coinbase_collision()) return error::unspent_coinbase_collision; return confirm_transactions(ctx); diff --git a/src/chain/chain_state.cpp b/src/chain/chain_state.cpp index fb991c663a..c26902c5a9 100644 --- a/src/chain/chain_state.cpp +++ b/src/chain/chain_state.cpp @@ -75,6 +75,9 @@ constexpr bool is_retarget_height(size_t height, return is_zero(retarget_distance(height, retargeting_interval)); } +// bip30 is active for all but two mainnet blocks that violate the rule. +// These two blocks each have a coinbase transaction that exactly duplicates +// another that is not spent by the arrival of the corresponding duplicate. inline bool is_bip30_exception(const checkpoint& check, bool mainnet) NOEXCEPT { return mainnet && @@ -102,9 +105,6 @@ chain_state::activations chain_state::activation(const data& values, const auto version = values.version.self; const auto& history = values.version.ordered; const auto frozen = script::is_enabled(forks, forks::bip90_rule); - ////const auto difficult = script::is_enabled(forks, forks::difficult); - ////const auto retarget = script::is_enabled(forks, forks::retarget); - ////const auto mainnet = retarget && difficult; //************************************************************************* // CONSENSUS: Though unspecified in bip34, the satoshi implementation @@ -124,6 +124,7 @@ chain_state::activations chain_state::activation(const data& values, settings.bip65_version); }; // Compute bip34-based activation version summaries. + // TODO: avoid these computations if forks not configured. const auto count_2 = std::count_if(history.begin(), history.end(), ge_2); const auto count_3 = std::count_if(history.begin(), history.end(), ge_3); const auto count_4 = std::count_if(history.begin(), history.end(), ge_4); @@ -163,26 +164,35 @@ chain_state::activations chain_state::activation(const data& values, result.forks |= (forks::bip16_rule & forks); } - ////// bip30 is active for all but two mainnet blocks that violate the rule. - ////// These two blocks each have a coinbase transaction that exactly duplicates - ////// another that is not spent by the arrival of the corresponding duplicate. - ////// This was later applied to the full history in implementation (a no-op). - ////if (!is_bip30_exception({ values.hash, height }, mainnet)) - ////{ - //// result.forks |= (forks::bip30_rule & forks); - ////} - // bip34 is activated based on 75% of preceding 1000 mainnet blocks. if (bip34_ice || (is_active(count_2, settings.activation_threshold) && version >= settings.bip34_version)) { + // TODO: check is_enabled(bip34_rule, forks) before above calculations. result.forks |= (forks::bip34_rule & forks); } + else + { + const auto difficult = script::is_enabled(forks, forks::difficult); + const auto retarget = script::is_enabled(forks, forks::retarget); + const auto mainnet = retarget && difficult; + + // If not a bip30 exception block (unspent duplicate coinbase allowed) and + // bip34 not active (duplicate coinbase presumed impossible) then must + // ensure spentness of any existing duplicate coinbase. The bip30 rule is + // always disabled by retroactive application to all blocks prior to bip34 + // with the unconditional activation of bip34 by bip90 (hard fork). + if (!is_bip30_exception({ values.hash, height }, mainnet)) + { + result.forks |= (forks::bip30_rule & forks); + } + } // bip66 is activated based on 75% of preceding 1000 mainnet blocks. if (bip66_ice || (is_active(count_3, settings.activation_threshold) && version >= settings.bip66_version)) { + // TODO: check is_enabled(bip66_rule, forks) before above calculations. result.forks |= (forks::bip66_rule & forks); } @@ -190,20 +200,24 @@ chain_state::activations chain_state::activation(const data& values, if (bip65_ice || (is_active(count_4, settings.activation_threshold) && version >= settings.bip65_version)) { + // TODO: check is_enabled(bip65_rule, forks) before above calculations. result.forks |= (forks::bip65_rule & forks); } // version 4/3/2 enforced based on 95% of preceding 1000 mainnet blocks. if (bip65_ice || is_enforced(count_4, settings.enforcement_threshold)) { + // TODO: requires is_enabled(bip65_rule, forks). result.minimum_block_version = settings.bip65_version; } else if (bip66_ice || is_enforced(count_3, settings.enforcement_threshold)) { + // TODO: requires is_enabled(bip66_rule, forks). result.minimum_block_version = settings.bip66_version; } else if (bip34_ice || is_enforced(count_2, settings.enforcement_threshold)) { + // TODO: requires is_enabled(bip34_rule, forks). result.minimum_block_version = settings.bip34_version; } else @@ -666,16 +680,6 @@ chain::context chain_state::context() const NOEXCEPT }; } -/// Current zulu (utc) time in seconds since epoch, using the wall clock. -/// Although not defined, epoch is almost always: 00:00, Jan 1 1970 UTC. -/// BUGBUG: en.wikipedia.org/wiki/Year_2038_problem -inline uint64_t zulu_time_seconds() NOEXCEPT -{ - using wall_clock = std::chrono::system_clock; - const auto now = wall_clock::now(); - return sign_cast(wall_clock::to_time_t(now)); -} - } // namespace chain } // namespace system } // namespace libbitcoin From 36df431e0145b8d6d1629484bcd18f6f9b482ac6 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 18 Feb 2024 11:19:46 -0500 Subject: [PATCH 2/4] Restore bip9 checkpoint-based "activations". --- include/bitcoin/system/chain/chain_state.hpp | 22 ++++- include/bitcoin/system/settings.hpp | 6 +- src/chain/chain_state.cpp | 97 +++++++++++++++----- src/settings.cpp | 12 +-- test/settings.cpp | 12 +-- 5 files changed, 110 insertions(+), 39 deletions(-) diff --git a/include/bitcoin/system/chain/chain_state.hpp b/include/bitcoin/system/chain/chain_state.hpp index 59d9fd5c46..bdc1aae566 100644 --- a/include/bitcoin/system/chain/chain_state.hpp +++ b/include/bitcoin/system/chain/chain_state.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -79,6 +80,12 @@ class BC_API chain_state /// (block - (block % 2016 == 0 ? 2016 : block % 2016)) size_t timestamp_retarget{}; + + /// mainnet: 419328, testnet: 770112 (or map::unrequested) + size_t bip9_bit0_height; + + /// mainnet: 481824, testnet: 834624 (or map::unrequested) + size_t bip9_bit1_height; }; /// Values used to populate chain state at the target height. @@ -90,6 +97,12 @@ class BC_API chain_state /// Hash of the candidate block or null_hash for memory pool. hash_digest hash{}; + /// Hash of the bip9_bit0 block or null_hash if unrequested. + hash_digest bip9_bit0_hash; + + /// Hash of the bip9_bit1 block or null_hash if unrequested. + hash_digest bip9_bit1_hash; + /// Values must be ordered by height with high (block - 1) last. struct { @@ -193,14 +206,19 @@ class BC_API chain_state static size_t bits_count(size_t height, uint32_t forks, size_t retargeting_interval) NOEXCEPT; static size_t version_count(size_t height, uint32_t forks, - size_t activation_sample) NOEXCEPT; + 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, size_t retargeting_interval) 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, + const checkpoint& bip9_bit1_active_checkpoint) NOEXCEPT; static data to_pool(const chain_state& top, const system::settings& settings) NOEXCEPT; - static data to_block(const chain_state& pool, const block& block) NOEXCEPT; + static data to_block(const chain_state& pool, const block& block, + const system::settings& settings) NOEXCEPT; static data to_header(const chain_state& parent, const header& header, const system::settings& settings) NOEXCEPT; diff --git a/include/bitcoin/system/settings.hpp b/include/bitcoin/system/settings.hpp index 6296f429d5..8889bf1c5c 100644 --- a/include/bitcoin/system/settings.hpp +++ b/include/bitcoin/system/settings.hpp @@ -102,9 +102,9 @@ class BC_API settings uint32_t bip9_version_base; /// Activation parameters (bip34-style activations). - size_t activation_threshold{}; - size_t enforcement_threshold{}; - size_t activation_sample{}; + size_t bip34_activation_threshold{}; + size_t bip34_enforcement_threshold{}; + size_t bip34_activation_sample{}; /// Frozen activation heights (frozen_activations). size_t bip65_freeze{}; diff --git a/src/chain/chain_state.cpp b/src/chain/chain_state.cpp index c26902c5a9..2b4739cc9e 100644 --- a/src/chain/chain_state.cpp +++ b/src/chain/chain_state.cpp @@ -39,6 +39,7 @@ namespace system { namespace chain { // github.com/bitcoin/bips/blob/master/bip-0030.mediawiki#specification +// As bip30 exceptions apply only to bitcoin mainnet these can be embedded. static const checkpoint mainnet_bip30_exception_checkpoint1 { "00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec", 91842 @@ -51,14 +52,14 @@ static const checkpoint mainnet_bip30_exception_checkpoint2 // Inlines. // ---------------------------------------------------------------------------- -constexpr bool is_active(size_t count, size_t activation_threshold) NOEXCEPT +constexpr bool is_active(size_t count, size_t bip34_activation_threshold) NOEXCEPT { - return count >= activation_threshold; + return count >= bip34_activation_threshold; } -constexpr bool is_enforced(size_t count, size_t enforcement_threshold) NOEXCEPT +constexpr bool is_enforced(size_t count, size_t bip34_enforcement_threshold) NOEXCEPT { - return count >= enforcement_threshold; + return count >= bip34_enforcement_threshold; } // Determine the number of blocks back to the closest retarget height. @@ -158,14 +159,15 @@ chain_state::activations chain_state::activation(const data& values, // 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 history (~55% rule). + // bip16 was activated based on manual inspection of signal history (~55% rule). if (values.timestamp.self >= settings.bip16_activation_time) { result.forks |= (forks::bip16_rule & forks); } // bip34 is activated based on 75% of preceding 1000 mainnet blocks. - if (bip34_ice || (is_active(count_2, settings.activation_threshold) && + // bip30 is disabled by bip34 or unconditional activation of it by bip90. + if (bip34_ice || (is_active(count_2, settings.bip34_activation_threshold) && version >= settings.bip34_version)) { // TODO: check is_enabled(bip34_rule, forks) before above calculations. @@ -177,11 +179,7 @@ chain_state::activations chain_state::activation(const data& values, const auto retarget = script::is_enabled(forks, forks::retarget); const auto mainnet = retarget && difficult; - // If not a bip30 exception block (unspent duplicate coinbase allowed) and - // bip34 not active (duplicate coinbase presumed impossible) then must - // ensure spentness of any existing duplicate coinbase. The bip30 rule is - // always disabled by retroactive application to all blocks prior to bip34 - // with the unconditional activation of bip34 by bip90 (hard fork). + // If not bip30 exception, existing duplicate coinbase must be spent. if (!is_bip30_exception({ values.hash, height }, mainnet)) { result.forks |= (forks::bip30_rule & forks); @@ -189,7 +187,7 @@ chain_state::activations chain_state::activation(const data& values, } // bip66 is activated based on 75% of preceding 1000 mainnet blocks. - if (bip66_ice || (is_active(count_3, settings.activation_threshold) && + if (bip66_ice || (is_active(count_3, settings.bip34_activation_threshold) && version >= settings.bip66_version)) { // TODO: check is_enabled(bip66_rule, forks) before above calculations. @@ -197,7 +195,7 @@ chain_state::activations chain_state::activation(const data& values, } // bip65 is activated based on 75% of preceding 1000 mainnet blocks. - if (bip65_ice || (is_active(count_4, settings.activation_threshold) && + if (bip65_ice || (is_active(count_4, settings.bip34_activation_threshold) && version >= settings.bip65_version)) { // TODO: check is_enabled(bip65_rule, forks) before above calculations. @@ -205,17 +203,17 @@ chain_state::activations chain_state::activation(const data& values, } // version 4/3/2 enforced based on 95% of preceding 1000 mainnet blocks. - if (bip65_ice || is_enforced(count_4, settings.enforcement_threshold)) + if (bip65_ice || is_enforced(count_4, settings.bip34_enforcement_threshold)) { // TODO: requires is_enabled(bip65_rule, forks). result.minimum_block_version = settings.bip65_version; } - else if (bip66_ice || is_enforced(count_3, settings.enforcement_threshold)) + else if (bip66_ice || is_enforced(count_3, settings.bip34_enforcement_threshold)) { // TODO: requires is_enabled(bip66_rule, forks). result.minimum_block_version = settings.bip66_version; } - else if (bip34_ice || is_enforced(count_2, settings.enforcement_threshold)) + else if (bip34_ice || is_enforced(count_2, settings.bip34_enforcement_threshold)) { // TODO: requires is_enabled(bip34_rule, forks). result.minimum_block_version = settings.bip34_version; @@ -225,6 +223,18 @@ chain_state::activations chain_state::activation(const data& values, result.minimum_block_version = settings.first_version; } + // 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); + } + + // 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); + } + return result; } @@ -248,7 +258,7 @@ size_t chain_state::bits_count(size_t height, uint32_t forks, } size_t chain_state::version_count(size_t height, uint32_t forks, - size_t activation_sample) NOEXCEPT + size_t bip34_activation_sample) NOEXCEPT { if (script::is_enabled(forks, forks::bip90_rule) || !script::is_enabled(forks, forks::bip34_activations)) @@ -256,7 +266,7 @@ size_t chain_state::version_count(size_t height, uint32_t forks, return zero; } - return std::min(height, activation_sample); + return std::min(height, bip34_activation_sample); } size_t chain_state::timestamp_count(size_t height, uint32_t) NOEXCEPT @@ -421,6 +431,24 @@ uint32_t chain_state::easy_work_required(const data& values, return proof_of_work_limit; } +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 above historical bip9_bit0 activation. + return height > activation_height ? activation_height : map::unrequested; +} + +size_t chain_state::bip9_bit1_height(size_t height, + const checkpoint& bip9_bit1_active_checkpoint) NOEXCEPT +{ + const auto activation_height = bip9_bit1_active_checkpoint.height(); + + // Require bip9_bit1 hash at heights above historical bip9_bit1 activation. + return height > activation_height ? activation_height : map::unrequested; +} + // Public static // ---------------------------------------------------------------------------- @@ -448,10 +476,19 @@ chain_state::map chain_state::get_map(size_t height, map.version_self = height; map.version.high = sub1(height); map.version.count = version_count(height, forks, - settings.activation_sample); + settings.bip34_activation_sample); // The most recent past retarget height. map.timestamp_retarget = retarget_height(height, forks, interval); + + // The checkpoint above which bip9_bit0 rules are enforced. + map.bip9_bit0_height = bip9_bit0_height(height, + settings.bip9_bit0_active_checkpoint); + + // The checkpoint above which bip9_bit1 rules are enforced. + map.bip9_bit1_height = bip9_bit1_height(height, + settings.bip9_bit1_active_checkpoint); + return map; } @@ -513,7 +550,7 @@ chain_state::data chain_state::to_pool(const chain_state& top, // If version collection overflows, dequeue oldest member. if (data.version.ordered.size() > version_count(height, forks, - settings.activation_sample)) + settings.bip34_activation_sample)) data.version.ordered.pop_front(); // If timestamp collection overflows, dequeue oldest member. @@ -558,7 +595,7 @@ chain_state::chain_state(const chain_state& top, } chain_state::data chain_state::to_block(const chain_state& pool, - const block& block) NOEXCEPT + const block& block, const system::settings& settings) NOEXCEPT { // Copy data from presumed same-height pool state. chain_state::data data{ pool.data_ }; @@ -571,6 +608,14 @@ chain_state::data chain_state::to_block(const chain_state& pool, data.version.self = header.version(); data.timestamp.self = header.timestamp(); + // Cache hash of bip9 bit0 height block, otherwise use preceding state. + if (data.height == settings.bip9_bit0_active_checkpoint.height()) + data.bip9_bit0_hash = data.hash; + + // Cache hash of bip9 bit1 height block, otherwise use preceding state. + if (data.height == settings.bip9_bit1_active_checkpoint.height()) + data.bip9_bit1_hash = data.hash; + return data; } @@ -578,7 +623,7 @@ chain_state::data chain_state::to_block(const chain_state& pool, // This assumes that the pool state is the same height as the block. chain_state::chain_state(const chain_state& pool, const block& block, const system::settings& settings) NOEXCEPT - : data_(to_block(pool, block)), + : data_(to_block(pool, block, settings)), forks_(pool.forks_), active_(activation(data_, forks_, settings)), work_required_(work_required(data_, forks_, settings)), @@ -601,6 +646,14 @@ chain_state::data chain_state::to_header(const chain_state& parent, data.version.self = header.version(); data.timestamp.self = header.timestamp(); + // Cache hash of bip9 bit0 height block, otherwise use preceding state. + if (data.height == settings.bip9_bit0_active_checkpoint.height()) + data.bip9_bit0_hash = data.hash; + + // Cache hash of bip9 bit1 height block, otherwise use preceding state. + if (data.height == settings.bip9_bit1_active_checkpoint.height()) + data.bip9_bit1_hash = data.hash; + return data; } diff --git a/src/settings.cpp b/src/settings.cpp index 2ceee52e7a..48aa0aee1d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -111,9 +111,9 @@ settings::settings(chain::selection context) NOEXCEPT 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00 }, false); - activation_threshold = 750; - enforcement_threshold = 950; - activation_sample = 1000; + bip34_activation_threshold = 750; + bip34_enforcement_threshold = 950; + bip34_activation_sample = 1000; bip65_freeze = 388381; bip66_freeze = 363725; bip34_freeze = 227931; @@ -168,9 +168,9 @@ settings::settings(chain::selection context) NOEXCEPT 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00 }, false); - activation_threshold = 51; - enforcement_threshold = 75; - activation_sample = 100; + bip34_activation_threshold = 51; + bip34_enforcement_threshold = 75; + bip34_activation_sample = 100; bip65_freeze = 581885; bip66_freeze = 330776; diff --git a/test/settings.cpp b/test/settings.cpp index 0738174565..ccce1f6ad9 100644 --- a/test/settings.cpp +++ b/test/settings.cpp @@ -62,9 +62,9 @@ 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.activation_threshold, 750u); - BOOST_REQUIRE_EQUAL(configuration.enforcement_threshold, 950u); - BOOST_REQUIRE_EQUAL(configuration.activation_sample, 1000u); + 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); @@ -100,9 +100,9 @@ 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.activation_threshold, 51u); - BOOST_REQUIRE_EQUAL(configuration.enforcement_threshold, 75u); - BOOST_REQUIRE_EQUAL(configuration.activation_sample, 100u); + 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); From 5fb2b61abad62513e749c89dfd2b7f9ac3e3976b Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 18 Feb 2024 11:37:35 -0500 Subject: [PATCH 3/4] Remove dead code. --- src/settings.cpp | 12 ++++++------ test/settings.cpp | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 48aa0aee1d..e5adf6cc64 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -118,8 +118,8 @@ settings::settings(chain::selection context) NOEXCEPT bip66_freeze = 363725; bip34_freeze = 227931; bip16_activation_time = 0x4f779a80; - bip34_active_checkpoint = - { "000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8", bip34_freeze }; + ////bip34_active_checkpoint = + //// { "000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8", bip34_freeze }; bip9_bit0_active_checkpoint = { "000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5", 419328 }; bip9_bit1_active_checkpoint = @@ -176,8 +176,8 @@ settings::settings(chain::selection context) NOEXCEPT bip66_freeze = 330776; bip34_freeze = 21111; bip16_activation_time = 0x4f3af580; - bip34_active_checkpoint = - { "0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8", bip34_freeze }; + ////bip34_active_checkpoint = + //// { "0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8", bip34_freeze }; bip9_bit0_active_checkpoint = { "00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb", 770112 }; bip9_bit1_active_checkpoint = @@ -236,8 +236,8 @@ settings::settings(chain::selection context) NOEXCEPT // bip9's are fixed and closed, so assume genesis activation. // bip90 assumes a historical bip34 activation block, so use genesis. - bip34_active_checkpoint = - { "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", 0 }; + ////bip34_active_checkpoint = + //// { "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", 0 }; bip9_bit0_active_checkpoint = { "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", 0 }; bip9_bit1_active_checkpoint = diff --git a/test/settings.cpp b/test/settings.cpp index ccce1f6ad9..3177ef931c 100644 --- a/test/settings.cpp +++ b/test/settings.cpp @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(settings__construct__mainnet_context__expected) BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 227931u); BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1333238400u); const chain::checkpoint bip34_active("000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8", configuration.bip34_freeze); - BOOST_REQUIRE_EQUAL(configuration.bip34_active_checkpoint, bip34_active); + ////BOOST_REQUIRE_EQUAL(configuration.bip34_active_checkpoint, bip34_active); const chain::checkpoint bit0_active("000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5", 419328u); BOOST_REQUIRE_EQUAL(configuration.bip9_bit0_active_checkpoint, bit0_active); const chain::checkpoint bit1_active("0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893", 481824u); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(settings__construct__testnet_context__expected) BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 21111u); BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1329264000u); const chain::checkpoint bip34_active("0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8", configuration.bip34_freeze); - BOOST_REQUIRE_EQUAL(configuration.bip34_active_checkpoint, bip34_active); + ////BOOST_REQUIRE_EQUAL(configuration.bip34_active_checkpoint, bip34_active); const chain::checkpoint bit0_active("00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb", 770112u); BOOST_REQUIRE_EQUAL(configuration.bip9_bit0_active_checkpoint, bit0_active); const chain::checkpoint bit1_active("00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca", 834624u); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(settings__construct__regtest_context__expected) BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 0u); BOOST_REQUIRE_EQUAL(configuration.bip16_activation_time, 1329264000u); const chain::checkpoint genesis(genesis_block.hash(), 0u); - BOOST_REQUIRE_EQUAL(configuration.bip34_active_checkpoint, genesis); + ////BOOST_REQUIRE_EQUAL(configuration.bip34_active_checkpoint, genesis); BOOST_REQUIRE_EQUAL(configuration.bip9_bit0_active_checkpoint, genesis); BOOST_REQUIRE_EQUAL(configuration.bip9_bit1_active_checkpoint, genesis); BOOST_REQUIRE_EQUAL(configuration.initial_subsidy_bitcoin, 50u); From 79aa9e1badfa7b21d8531e348e9ba2f56a995451 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 18 Feb 2024 11:37:48 -0500 Subject: [PATCH 4/4] Rename ice vars to bip90. --- src/chain/chain_state.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/chain/chain_state.cpp b/src/chain/chain_state.cpp index 2b4739cc9e..2e0d9dcb93 100644 --- a/src/chain/chain_state.cpp +++ b/src/chain/chain_state.cpp @@ -105,7 +105,7 @@ chain_state::activations chain_state::activation(const data& values, const auto height = values.height; const auto version = values.version.self; const auto& history = values.version.ordered; - const auto frozen = script::is_enabled(forks, forks::bip90_rule); + const auto bip90 = script::is_enabled(forks, forks::bip90_rule); //************************************************************************* // CONSENSUS: Though unspecified in bip34, the satoshi implementation @@ -131,9 +131,9 @@ 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 bip34_ice = frozen && height >= settings.bip34_freeze; - const auto bip66_ice = frozen && height >= settings.bip66_freeze; - const auto bip65_ice = frozen && height >= settings.bip65_freeze; + 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 }; @@ -167,7 +167,7 @@ chain_state::activations chain_state::activation(const data& values, // bip34 is activated based on 75% of preceding 1000 mainnet blocks. // bip30 is disabled by bip34 or unconditional activation of it by bip90. - if (bip34_ice || (is_active(count_2, settings.bip34_activation_threshold) && + if (bip90_34 || (is_active(count_2, settings.bip34_activation_threshold) && version >= settings.bip34_version)) { // TODO: check is_enabled(bip34_rule, forks) before above calculations. @@ -187,7 +187,7 @@ chain_state::activations chain_state::activation(const data& values, } // bip66 is activated based on 75% of preceding 1000 mainnet blocks. - if (bip66_ice || (is_active(count_3, settings.bip34_activation_threshold) && + if (bip90_66 || (is_active(count_3, settings.bip34_activation_threshold) && version >= settings.bip66_version)) { // TODO: check is_enabled(bip66_rule, forks) before above calculations. @@ -195,7 +195,7 @@ chain_state::activations chain_state::activation(const data& values, } // bip65 is activated based on 75% of preceding 1000 mainnet blocks. - if (bip65_ice || (is_active(count_4, settings.bip34_activation_threshold) && + if (bip90_65 || (is_active(count_4, settings.bip34_activation_threshold) && version >= settings.bip65_version)) { // TODO: check is_enabled(bip65_rule, forks) before above calculations. @@ -203,17 +203,17 @@ chain_state::activations chain_state::activation(const data& values, } // version 4/3/2 enforced based on 95% of preceding 1000 mainnet blocks. - if (bip65_ice || is_enforced(count_4, settings.bip34_enforcement_threshold)) + if (bip90_65 || is_enforced(count_4, settings.bip34_enforcement_threshold)) { // TODO: requires is_enabled(bip65_rule, forks). result.minimum_block_version = settings.bip65_version; } - else if (bip66_ice || is_enforced(count_3, settings.bip34_enforcement_threshold)) + else if (bip90_66 || is_enforced(count_3, settings.bip34_enforcement_threshold)) { // TODO: requires is_enabled(bip66_rule, forks). result.minimum_block_version = settings.bip66_version; } - else if (bip34_ice || is_enforced(count_2, settings.bip34_enforcement_threshold)) + else if (bip90_34 || is_enforced(count_2, settings.bip34_enforcement_threshold)) { // TODO: requires is_enabled(bip34_rule, forks). result.minimum_block_version = settings.bip34_version;