From 9dd514ccf05a3bc13f04a70423afe5463f3674a0 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 28 Mar 2024 17:29:10 -0400 Subject: [PATCH 01/10] Remove incorrect include. --- src/chain/block.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/chain/block.cpp b/src/chain/block.cpp index 04e1e1fec9..0696a0a79a 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include namespace libbitcoin { From 9744ca15eb271877b14a96ca7dc1a4539715d1fd Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 28 Mar 2024 17:29:37 -0400 Subject: [PATCH 02/10] Comments on chain_state conversion of system::settings chain::forks. --- include/bitcoin/system/chain/chain_state.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/bitcoin/system/chain/chain_state.hpp b/include/bitcoin/system/chain/chain_state.hpp index 9e15e6b26b..b3c10e4715 100644 --- a/include/bitcoin/system/chain/chain_state.hpp +++ b/include/bitcoin/system/chain/chain_state.hpp @@ -48,6 +48,12 @@ class BC_API chain_state typedef std::deque timestamps; typedef std::shared_ptr ptr; typedef struct { size_t count; size_t high; } range; + + /// Chain state accepts configured forks and maps them onto active forks + /// for the a given validaton context (i.e. block). These are exposed as + /// chain::chain_state.flags() and chain::context.flags. system::settings + /// settings are using within chain_state to compute context, but are never + /// used directly within chain classes, which would be an abstraction leak. typedef struct { bool bip16; From b740bcf54abbd6d4d22647e82dc76a4a7f67a575 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 28 Mar 2024 18:08:58 -0400 Subject: [PATCH 03/10] Rename forks to flags. --- .../libbitcoin-system.vcxproj | 4 +- .../libbitcoin-system.vcxproj.filters | 4 +- include/bitcoin/system.hpp | 2 +- include/bitcoin/system/chain/chain.hpp | 2 +- include/bitcoin/system/chain/chain_state.hpp | 4 +- include/bitcoin/system/chain/context.hpp | 6 +- .../chain/enums/{forks.hpp => flags.hpp} | 26 +- include/bitcoin/system/chain/enums/policy.hpp | 2 +- include/bitcoin/system/chain/operation.hpp | 2 +- include/bitcoin/system/chain/script.hpp | 15 +- .../system/impl/machine/interpreter.ipp | 50 ++-- .../bitcoin/system/impl/machine/program.ipp | 26 +- include/bitcoin/system/machine/program.hpp | 10 +- src/chain/block.cpp | 2 +- src/chain/chain_state.cpp | 40 ++-- src/chain/context.cpp | 6 +- src/chain/enums/opcode.cpp | 6 +- src/chain/input.cpp | 2 +- src/chain/operation.cpp | 6 +- src/chain/script.cpp | 16 +- src/chain/transaction.cpp | 6 +- src/config/script.cpp | 2 +- test/chain/enums/opcode.cpp | 116 ++++----- test/chain/operation.cpp | 8 +- test/chain/script.cpp | 224 +++++++++--------- 25 files changed, 294 insertions(+), 293 deletions(-) rename include/bitcoin/system/chain/enums/{forks.hpp => flags.hpp} (93%) diff --git a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj index 12374c7e41..f6df65a402 100644 --- a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj @@ -252,7 +252,7 @@ - + @@ -610,4 +610,4 @@ - + \ No newline at end of file diff --git a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters index ee53e616c0..b2d538d89f 100644 --- a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters @@ -635,7 +635,7 @@ include\bitcoin\system\chain\enums - + include\bitcoin\system\chain\enums @@ -1604,4 +1604,4 @@ resource - + \ No newline at end of file diff --git a/include/bitcoin/system.hpp b/include/bitcoin/system.hpp index f95ee83499..9a65b19da8 100755 --- a/include/bitcoin/system.hpp +++ b/include/bitcoin/system.hpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/bitcoin/system/chain/chain.hpp b/include/bitcoin/system/chain/chain.hpp index 090b687dff..77560a3a3d 100644 --- a/include/bitcoin/system/chain/chain.hpp +++ b/include/bitcoin/system/chain/chain.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/bitcoin/system/chain/chain_state.hpp b/include/bitcoin/system/chain/chain_state.hpp index b3c10e4715..fb8823a5b6 100644 --- a/include/bitcoin/system/chain/chain_state.hpp +++ b/include/bitcoin/system/chain/chain_state.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ class BC_API chain_state typedef std::shared_ptr ptr; typedef struct { size_t count; size_t high; } range; - /// Chain state accepts configured forks and maps them onto active forks + /// Chain state accepts configured forks and maps them onto active flags /// for the a given validaton context (i.e. block). These are exposed as /// chain::chain_state.flags() and chain::context.flags. system::settings /// settings are using within chain_state to compute context, but are never diff --git a/include/bitcoin/system/chain/context.hpp b/include/bitcoin/system/chain/context.hpp index 679b695cb5..1a53d4355d 100644 --- a/include/bitcoin/system/chain/context.hpp +++ b/include/bitcoin/system/chain/context.hpp @@ -20,7 +20,7 @@ #define LIBBITCOIN_SYSTEM_CHAIN_CONTEXT_HPP #include -#include +#include #include namespace libbitcoin { @@ -30,8 +30,8 @@ namespace chain { class BC_API context final { public: - /// Determine if the fork is active for this block. - bool is_enabled(chain::forks fork) const NOEXCEPT; + /// Determine if the flag is active for this block. + bool is_enabled(chain::flags flag) const NOEXCEPT; /// Header context within chain. uint32_t flags; diff --git a/include/bitcoin/system/chain/enums/forks.hpp b/include/bitcoin/system/chain/enums/flags.hpp similarity index 93% rename from include/bitcoin/system/chain/enums/forks.hpp rename to include/bitcoin/system/chain/enums/flags.hpp index f47c9e384b..7a9250765d 100644 --- a/include/bitcoin/system/chain/enums/forks.hpp +++ b/include/bitcoin/system/chain/enums/flags.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_SYSTEM_CHAIN_ENUMS_FORKS_HPP -#define LIBBITCOIN_SYSTEM_CHAIN_ENUMS_FORKS_HPP +#ifndef LIBBITCOIN_SYSTEM_CHAIN_ENUMS_FLAGS_HPP +#define LIBBITCOIN_SYSTEM_CHAIN_ENUMS_FLAGS_HPP #include #include @@ -26,7 +26,7 @@ namespace libbitcoin { namespace system { namespace chain { -enum forks : uint32_t +enum flags : uint32_t { /// Rules start at satoshi v0.3.0. /// Only satoshi-released hard forks, and enforced soft forks are included. @@ -133,25 +133,25 @@ enum forks : uint32_t /// Rules that use bip34-based activation. bip34_activations = - forks::bip34_rule | - forks::bip65_rule | - forks::bip66_rule, + flags::bip34_rule | + flags::bip65_rule | + flags::bip66_rule, /// Rules that use BIP9 bit 0 first time activation. bip9_bit0_group = - forks::bip68_rule | - forks::bip112_rule | - forks::bip113_rule, + flags::bip68_rule | + flags::bip112_rule | + flags::bip113_rule, /// Rules that use BIP9 bit 1 first time activation. bip9_bit1_group = - forks::bip141_rule | - forks::bip143_rule | - forks::bip147_rule, + flags::bip141_rule | + flags::bip143_rule | + flags::bip147_rule, /////// Rules that use BIP9 bit 4 first time activation. ////bip9_bit4_group = - //// forks::bip91_rule, + //// flags::bip91_rule, /// Mask to set all rule bits. all_rules = bit_all diff --git a/include/bitcoin/system/chain/enums/policy.hpp b/include/bitcoin/system/chain/enums/policy.hpp index d564e4cfb9..b670d1ec1e 100644 --- a/include/bitcoin/system/chain/enums/policy.hpp +++ b/include/bitcoin/system/chain/enums/policy.hpp @@ -26,7 +26,7 @@ namespace libbitcoin { namespace system { namespace chain { -/// Analog to chain::forks but without impacting validation. These provide +/// Analog to chain::flags but without impacting validation. These provide /// additional validation context, giving a node the option to reject an /// unconfirmed transaction. enum policy : uint32_t diff --git a/include/bitcoin/system/chain/operation.hpp b/include/bitcoin/system/chain/operation.hpp index 46c7f21092..89250f0a69 100644 --- a/include/bitcoin/system/chain/operation.hpp +++ b/include/bitcoin/system/chain/operation.hpp @@ -394,7 +394,7 @@ class BC_API operation void to_data(writer& sink) const NOEXCEPT; // TODO: move to config serialization wrapper. - std::string to_string(uint32_t active_forks) const NOEXCEPT; + std::string to_string(uint32_t active_flags) const NOEXCEPT; /// Properties. /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/system/chain/script.hpp b/include/bitcoin/system/chain/script.hpp index ddc43ec42b..e5065f1677 100644 --- a/include/bitcoin/system/chain/script.hpp +++ b/include/bitcoin/system/chain/script.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,10 +51,11 @@ class BC_API script /// Utilities. /// ----------------------------------------------------------------------- - /// Determine if the fork is enabled in the active forks set. - static constexpr bool is_enabled(uint32_t active_forks, forks fork) NOEXCEPT + /// Determine if the flag is enabled in the active flags set. + static constexpr bool is_enabled(uint32_t active_flags, + chain::flags flag) NOEXCEPT { - return to_bool(fork & active_forks); + return to_bool(flag & active_flags); } static inline bool is_push_only(const operations& ops) NOEXCEPT @@ -471,7 +472,7 @@ class BC_API script void to_data(writer& sink, bool prefix) const NOEXCEPT; // TODO: move to config serialization wrapper. - std::string to_string(uint32_t active_forks) const NOEXCEPT; + std::string to_string(uint32_t active_flags) const NOEXCEPT; /// Properties. /// ----------------------------------------------------------------------- @@ -489,8 +490,8 @@ class BC_API script /// ----------------------------------------------------------------------- /// Pattern optimizations. - bool is_pay_to_witness(uint32_t forks) const NOEXCEPT; - bool is_pay_to_script_hash(uint32_t forks) const NOEXCEPT; + bool is_pay_to_witness(uint32_t active_flags) const NOEXCEPT; + bool is_pay_to_script_hash(uint32_t active_flags) const NOEXCEPT; /// Common pattern detection. const data_chunk& witness_program() const NOEXCEPT; diff --git a/include/bitcoin/system/impl/machine/interpreter.ipp b/include/bitcoin/system/impl/machine/interpreter.ipp index e6a692d7c8..3e281c9d2e 100644 --- a/include/bitcoin/system/impl/machine/interpreter.ipp +++ b/include/bitcoin/system/impl/machine/interpreter.ipp @@ -70,7 +70,7 @@ template inline op_error_t interpreter:: op_nop(opcode) const NOEXCEPT { - if (state::is_enabled(forks::nops_rule)) + if (state::is_enabled(flags::nops_rule)) return error::op_success; ////return op_unevaluated(code); @@ -141,7 +141,7 @@ template inline op_error_t interpreter:: op_ver() const NOEXCEPT { - if (state::is_enabled(forks::nops_rule)) + if (state::is_enabled(flags::nops_rule)) return op_unevaluated(opcode::op_ver); return error::op_not_implemented; @@ -187,7 +187,7 @@ template inline op_error_t interpreter:: op_verif() const NOEXCEPT { - if (state::is_enabled(forks::nops_rule)) + if (state::is_enabled(flags::nops_rule)) return op_unevaluated(opcode::op_verif); return error::op_not_implemented; @@ -197,7 +197,7 @@ template inline op_error_t interpreter:: op_vernotif() const NOEXCEPT { - if (state::is_enabled(forks::nops_rule)) + if (state::is_enabled(flags::nops_rule)) return op_unevaluated(opcode::op_vernotif); return error::op_not_implemented; @@ -243,7 +243,7 @@ template inline op_error_t interpreter:: op_return() const NOEXCEPT { - if (state::is_enabled(forks::nops_rule)) + if (state::is_enabled(flags::nops_rule)) return op_unevaluated(opcode::op_return); return error::op_not_implemented; @@ -515,7 +515,7 @@ template inline op_error_t interpreter:: op_cat() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_cat); return error::op_not_implemented; @@ -525,7 +525,7 @@ template inline op_error_t interpreter:: op_substr() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_substr); return error::op_not_implemented; @@ -535,7 +535,7 @@ template inline op_error_t interpreter:: op_left() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_left); return error::op_not_implemented; @@ -545,7 +545,7 @@ template inline op_error_t interpreter:: op_right() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_right); return error::op_not_implemented; @@ -566,7 +566,7 @@ template inline op_error_t interpreter:: op_invert() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_invert); return error::op_not_implemented; @@ -576,7 +576,7 @@ template inline op_error_t interpreter:: op_and() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_and); return error::op_not_implemented; @@ -586,7 +586,7 @@ template inline op_error_t interpreter:: op_or() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_or); return error::op_not_implemented; @@ -596,7 +596,7 @@ template inline op_error_t interpreter:: op_xor() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_xor); return error::op_not_implemented; @@ -652,7 +652,7 @@ template inline op_error_t interpreter:: op_mul2() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_mul2); return error::op_not_implemented; @@ -662,7 +662,7 @@ template inline op_error_t interpreter:: op_div2() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_div2); return error::op_not_implemented; @@ -749,7 +749,7 @@ template inline op_error_t interpreter:: op_mul() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_mul); return error::op_not_implemented; @@ -759,7 +759,7 @@ template inline op_error_t interpreter:: op_div() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_div); return error::op_not_implemented; @@ -769,7 +769,7 @@ template inline op_error_t interpreter:: op_mod() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_mod); return error::op_not_implemented; @@ -779,7 +779,7 @@ template inline op_error_t interpreter:: op_lshift() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_lshift); return error::op_not_implemented; @@ -789,7 +789,7 @@ template inline op_error_t interpreter:: op_rshift() const NOEXCEPT { - if (state::is_enabled(forks::cats_rule)) + if (state::is_enabled(flags::cats_rule)) return op_unevaluated(opcode::op_rshift); return error::op_not_implemented; @@ -1008,7 +1008,7 @@ inline op_error_t interpreter:: op_check_sig() NOEXCEPT { const auto verify = op_check_sig_verify(); - const auto bip66 = state::is_enabled(forks::bip66_rule); + const auto bip66 = state::is_enabled(flags::bip66_rule); // BIP66: invalid signature encoding fails the operation. if (bip66 && verify == error::op_check_sig_verify_parse) @@ -1058,7 +1058,7 @@ inline op_error_t interpreter:: op_check_multisig() NOEXCEPT { const auto verify = op_check_multisig_verify(); - const auto bip66 = state::is_enabled(forks::bip66_rule); + const auto bip66 = state::is_enabled(flags::bip66_rule); // BIP66: invalid signature encoding fails the operation. if (bip66 && verify == error::op_check_multisig_verify_parse) @@ -1072,7 +1072,7 @@ template inline op_error_t interpreter:: op_check_multisig_verify() NOEXCEPT { - const auto bip147 = state::is_enabled(forks::bip147_rule); + const auto bip147 = state::is_enabled(flags::bip147_rule); size_t count; if (!state::pop_index32(count)) @@ -1153,7 +1153,7 @@ inline op_error_t interpreter:: op_check_locktime_verify() const NOEXCEPT { // BIP65: nop2 subsumed by checklocktimeverify when bip65 fork is active. - if (!state::is_enabled(forks::bip65_rule)) + if (!state::is_enabled(flags::bip65_rule)) return op_nop(opcode::nop2); // BIP65: the tx sequence is 0xffffffff. @@ -1185,7 +1185,7 @@ inline op_error_t interpreter:: op_check_sequence_verify() const NOEXCEPT { // BIP112: nop3 subsumed by checksequenceverify when bip112 fork is active. - if (!state::is_enabled(forks::bip112_rule)) + if (!state::is_enabled(flags::bip112_rule)) return op_nop(opcode::nop3); // BIP112: the stack is empty. diff --git a/include/bitcoin/system/impl/machine/program.ipp b/include/bitcoin/system/impl/machine/program.ipp index a2961ca64a..e5b45a4b78 100644 --- a/include/bitcoin/system/impl/machine/program.ipp +++ b/include/bitcoin/system/impl/machine/program.ipp @@ -45,11 +45,11 @@ using namespace system::error; template inline program:: program(const chain::transaction& tx, const input_iterator& input, - uint32_t forks) NOEXCEPT + uint32_t active_flags) NOEXCEPT : transaction_(tx), input_(input), script_((*input)->script_ptr()), - forks_(forks), + flags_(active_flags), value_(max_uint64), version_(script_version::unversioned), witness_(), @@ -67,7 +67,7 @@ program(const program& other, const script::cptr& script) NOEXCEPT : transaction_(other.transaction_), input_(other.input_), script_(script), - forks_(other.forks_), + flags_(other.flags_), value_(other.value_), version_(other.version_), witness_(), @@ -82,7 +82,7 @@ program(program&& other, const script::cptr& script) NOEXCEPT : transaction_(other.transaction_), input_(other.input_), script_(script), - forks_(other.forks_), + flags_(other.flags_), value_(other.value_), version_(other.version_), witness_(), @@ -97,12 +97,12 @@ program(program&& other, const script::cptr& script) NOEXCEPT template inline program:: program(const chain::transaction& tx, const input_iterator& input, - const script::cptr& script, uint32_t forks, script_version version, + const script::cptr& script, uint32_t active_flags, script_version version, const chunk_cptrs_ptr& witness) NOEXCEPT : transaction_(tx), input_(input), script_(script), - forks_(forks), + flags_(active_flags), value_((*input)->prevout->value()), version_(version), witness_(witness), @@ -170,9 +170,9 @@ transaction() const NOEXCEPT template INLINE bool program:: -is_enabled(chain::forks rule) const NOEXCEPT +is_enabled(chain::flags flag) const NOEXCEPT { - return to_bool(forks_ & rule); + return to_bool(flags_ & flag); } // TODO: only perform is_push_size check on witness initialized stack. @@ -182,7 +182,7 @@ INLINE script_error_t program:: validate() const NOEXCEPT { // TODO: nops rule must first be enabled in tests and config. - const auto bip141 = is_enabled(forks::bip141_rule); + const auto bip141 = is_enabled(flags::bip141_rule); // The script was determined by the parser to contain an invalid opcode. if (is_prefail()) @@ -742,7 +742,7 @@ subscript(const chunk_xptrs& endorsements) const NOEXCEPT { // bip141: establishes the version property. // bip143: op stripping is not applied to bip141 v0 scripts. - if (is_enabled(forks::bip143_rule) && version_ == script_version::zero) + if (is_enabled(flags::bip143_rule) && version_ == script_version::zero) return script_; // Transform into a set of endorsement push ops and one op_codeseparator. @@ -777,7 +777,7 @@ prepare(ec_signature& signature, const data_chunk&, hash_digest& hash, hash = signature_hash(*subscript({ endorsement }), flags); // Parse DER signature into an EC signature (bip66 sets strict). - const auto bip66 = is_enabled(forks::bip66_rule); + const auto bip66 = is_enabled(flags::bip66_rule); return parse_signature(signature, distinguished, bip66); } @@ -797,7 +797,7 @@ prepare(ec_signature& signature, const data_chunk&, hash_cache& cache, signature_hash(cache, sub, flags); // Parse DER signature into an EC signature (bip66 sets strict). - const auto bip66 = is_enabled(forks::bip66_rule); + const auto bip66 = is_enabled(flags::bip66_rule); return parse_signature(signature, distinguished, bip66); } @@ -809,7 +809,7 @@ INLINE hash_digest program:: signature_hash(const script& sub, uint8_t flags) const NOEXCEPT { // The bip141 fork establishes witness version, hashing is a distinct fork. - const auto bip143 = is_enabled(forks::bip143_rule); + const auto bip143 = is_enabled(flags::bip143_rule); // bip143: the method of signature hashing is changed for v0 scripts. return transaction_.signature_hash(input_, sub, value_, flags, version_, diff --git a/include/bitcoin/system/machine/program.hpp b/include/bitcoin/system/machine/program.hpp index c2e2338cfe..6d4fb76b46 100644 --- a/include/bitcoin/system/machine/program.hpp +++ b/include/bitcoin/system/machine/program.hpp @@ -46,7 +46,7 @@ class program /// Input script run (default/empty stack). inline program(const chain::transaction& transaction, - const input_iterator& input, uint32_t forks) NOEXCEPT; + const input_iterator& input, uint32_t active_flags) NOEXCEPT; /// Legacy p2sh or prevout script run (copied input stack). inline program(const program& other, @@ -59,7 +59,7 @@ class program /// Witness script run (witness-initialized stack). inline program(const chain::transaction& transaction, const input_iterator& input, const chain::script::cptr& script, - uint32_t forks, chain::script_version version, + uint32_t active_flags, chain::script_version version, const chunk_cptrs_ptr& stack) NOEXCEPT; /// Program result. @@ -80,7 +80,7 @@ class program INLINE op_iterator end() const NOEXCEPT; INLINE const chain::input& input() const NOEXCEPT; INLINE const chain::transaction& transaction() const NOEXCEPT; - INLINE bool is_enabled(chain::forks rule) const NOEXCEPT; + INLINE bool is_enabled(chain::flags flag) const NOEXCEPT; INLINE error::script_error_t validate() const NOEXCEPT; /// Primary stack. @@ -163,7 +163,7 @@ class program inline bool prepare(ec_signature& signature, const data_chunk& key, hash_digest& hash, const chunk_xptr& endorsement) const NOEXCEPT; - /// Prepare signature, with caching for multisig with same flags. + /// Prepare signature, with caching for multisig with same sighash flags. inline bool prepare(ec_signature& signature, const data_chunk& key, hash_cache& cache, uint8_t& flags, const data_chunk& endorsement, const chain::script& sub) const NOEXCEPT; @@ -194,7 +194,7 @@ class program const chain::transaction& transaction_; const input_iterator input_; const chain::script::cptr script_; - const uint32_t forks_; + const uint32_t flags_; const uint64_t value_; const chain::script_version version_; const chunk_cptrs_ptr witness_; diff --git a/src/chain/block.cpp b/src/chain/block.cpp index 0696a0a79a..d441adf9b5 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/chain/chain_state.cpp b/src/chain/chain_state.cpp index 1892bad393..465e62ff30 100644 --- a/src/chain/chain_state.cpp +++ b/src/chain/chain_state.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -103,55 +103,55 @@ chain_state::activations chain_state::activation(const data& values, const forks_t& forks, const system::settings& settings) NOEXCEPT { // Initialize activation results with genesis values. - activations result{ forks::no_rules, settings.first_version }; + activations result{ flags::no_rules, settings.first_version }; // regtest is only activated via configuration. if (forks.retarget) { - result.flags |= forks::retarget; + result.flags |= flags::retarget; } // testnet is activated based on configuration alone. if (forks.difficult) { - result.flags |= forks::difficult; + result.flags |= flags::difficult; } // time_warp_patch is activated based on configuration alone. if (forks.time_warp_patch) { - result.flags |= forks::time_warp_patch; + result.flags |= flags::time_warp_patch; } // retarget_overflow_patch is activated based on configuration alone. if (forks.retarget_overflow_patch) { - result.flags |= forks::retarget_overflow_patch; + result.flags |= flags::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; + result.flags |= flags::scrypt_proof_of_work; } // bip42 is activated based on configuration alone (soft fork). if (forks.bip42) { - result.flags |= forks::bip42_rule; + result.flags |= flags::bip42_rule; } // bip90 is activated based on configuration alone (hard fork). if (forks.bip90) { - result.flags |= forks::bip90_rule; + result.flags |= flags::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; + result.flags |= flags::bip16_rule; } const auto height = values.height; @@ -192,7 +192,7 @@ chain_state::activations chain_state::activation(const data& values, (is_active(count_2, settings.bip34_activation_threshold) && version >= settings.bip34_version)) { - result.flags |= forks::bip34_rule; + result.flags |= flags::bip34_rule; } // bip66 is active based on 75% of preceding 1000 mainnet blocks. @@ -200,7 +200,7 @@ chain_state::activations chain_state::activation(const data& values, (is_active(count_3, settings.bip34_activation_threshold) && version >= settings.bip66_version)) { - result.flags |= forks::bip66_rule; + result.flags |= flags::bip66_rule; } // bip65 is active based on 75% of preceding 1000 mainnet blocks. @@ -208,7 +208,7 @@ chain_state::activations chain_state::activation(const data& values, (is_active(count_4, settings.bip34_activation_threshold) && version >= settings.bip65_version)) { - result.flags |= forks::bip65_rule; + result.flags |= flags::bip65_rule; } // version 4/3/2 enforced based on 95% of preceding 1000 mainnet blocks. @@ -237,17 +237,17 @@ 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.flags |= forks::bip68_rule; - result.flags |= forks::bip112_rule; - result.flags |= forks::bip113_rule; + result.flags |= flags::bip68_rule; + result.flags |= flags::bip112_rule; + result.flags |= flags::bip113_rule; } // bip9_bit1 forks are enforced above the bip9_bit1 checkpoint. if (values.bip9_bit1_hash == settings.bip9_bit1_active_checkpoint.hash()) { - result.flags |= forks::bip141_rule; - result.flags |= forks::bip143_rule; - result.flags |= forks::bip147_rule; + result.flags |= flags::bip141_rule; + result.flags |= flags::bip143_rule; + result.flags |= flags::bip147_rule; } // bip30_deactivate fork enforced above bip30_deactivate (bip34) checkpoint. @@ -264,7 +264,7 @@ chain_state::activations chain_state::activation(const data& values, if (forks.bip30 && (!bip30_deactivate || bip30_reactivate) && !is_bip30_exception({ values.hash, height })) { - result.flags |= forks::bip30_rule; + result.flags |= flags::bip30_rule; } return result; diff --git a/src/chain/context.cpp b/src/chain/context.cpp index 27f06e9cd7..f3d143494b 100644 --- a/src/chain/context.cpp +++ b/src/chain/context.cpp @@ -18,16 +18,16 @@ */ #include -#include +#include #include namespace libbitcoin { namespace system { namespace chain { -bool context::is_enabled(chain::forks fork) const NOEXCEPT +bool context::is_enabled(chain::flags flag) const NOEXCEPT { - return to_bool(fork & flags); + return to_bool(flag & flags); } bool operator==(const context& left, const context& right) NOEXCEPT diff --git a/src/chain/enums/opcode.cpp b/src/chain/enums/opcode.cpp index 1671082b07..1011401f99 100644 --- a/src/chain/enums/opcode.cpp +++ b/src/chain/enums/opcode.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -308,10 +308,10 @@ std::string opcode_to_mnemonic(opcode value, uint32_t active_forks) NOEXCEPT case opcode::nop1: return "nop1"; case opcode::checklocktimeverify: - return script::is_enabled(active_forks, forks::bip65_rule) ? + return script::is_enabled(active_forks, flags::bip65_rule) ? "checklocktimeverify" : "nop2"; case opcode::checksequenceverify: - return script::is_enabled(active_forks, forks::bip112_rule) ? + return script::is_enabled(active_forks, flags::bip112_rule) ? "checksequenceverify" : "nop3"; case opcode::nop4: return "nop4"; diff --git a/src/chain/input.cpp b/src/chain/input.cpp index 0634e95944..2e634862d0 100644 --- a/src/chain/input.cpp +++ b/src/chain/input.cpp @@ -346,7 +346,7 @@ bool input::extract_sigop_script(chain::script& out, } // TODO: Prior to block 79400 sigops were limited only by policy. -// TODO: Create legacy sigops fork flag and pass here, return 0 if false. +// TODO: Create legacy sigops fork/flag and pass here, return 0 if false. // TODO: this was an unbipped flag day soft fork, prior to BIP16/141. // TODO: if (nHeight > 79400 && GetSigOpCount() > MAX_BLOCK_SIGOPS). size_t input::signature_operations(bool bip16, bool bip141) const NOEXCEPT diff --git a/src/chain/operation.cpp b/src/chain/operation.cpp index 9cbd3c0f9c..a951b465b9 100644 --- a/src/chain/operation.cpp +++ b/src/chain/operation.cpp @@ -419,7 +419,7 @@ static std::string opcode_to_prefix(opcode code, } } -std::string operation::to_string(uint32_t active_forks) const NOEXCEPT +std::string operation::to_string(uint32_t active_flags) const NOEXCEPT { if (!is_valid()) return "(?)"; @@ -428,7 +428,7 @@ std::string operation::to_string(uint32_t active_forks) const NOEXCEPT return "<" + encode_base16(*data_) + ">"; if (data_->empty()) - return opcode_to_mnemonic(code_, active_forks); + return opcode_to_mnemonic(code_, active_flags); // Data encoding uses single token with explicit size prefix as required. return "[" + opcode_to_prefix(code_, *data_) + encode_base16(*data_) + "]"; @@ -615,7 +615,7 @@ operation tag_invoke(json::value_to_tag, void tag_invoke(json::value_from_tag, json::value& value, const operation& operation) NOEXCEPT { - value = operation.to_string(forks::all_rules); + value = operation.to_string(flags::all_rules); } BC_POP_WARNING() diff --git a/src/chain/script.cpp b/src/chain/script.cpp index d9310516eb..30f4ba7993 100644 --- a/src/chain/script.cpp +++ b/src/chain/script.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -306,7 +306,7 @@ void script::to_data(writer& sink, bool prefix) const NOEXCEPT op->to_data(sink); } -std::string script::to_string(uint32_t active_forks) const NOEXCEPT +std::string script::to_string(uint32_t active_flags) const NOEXCEPT { auto first = true; std::ostringstream text; @@ -316,7 +316,7 @@ std::string script::to_string(uint32_t active_forks) const NOEXCEPT for (const auto& op: ops()) { - text << (first ? "" : " ") << op.to_string(active_forks); + text << (first ? "" : " ") << op.to_string(active_flags); first = false; } @@ -452,17 +452,17 @@ script_pattern script::input_pattern() const NOEXCEPT return script_pattern::non_standard; } -bool script::is_pay_to_witness(uint32_t forks) const NOEXCEPT +bool script::is_pay_to_witness(uint32_t active_flags) const NOEXCEPT { // This is an optimization over using script::pattern. - return is_enabled(forks, forks::bip141_rule) && + return is_enabled(active_flags, flags::bip141_rule) && is_witness_program_pattern(ops()); } -bool script::is_pay_to_script_hash(uint32_t forks) const NOEXCEPT +bool script::is_pay_to_script_hash(uint32_t active_flags) const NOEXCEPT { // This is an optimization over using script::pattern. - return is_enabled(forks, forks::bip16_rule) && + return is_enabled(active_flags, flags::bip16_rule) && is_pay_script_hash_pattern(ops()); } @@ -543,7 +543,7 @@ script tag_invoke(json::value_to_tag