Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor names to remove flag/fork ambiguities. #1429

Merged
merged 10 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ include_bitcoin_system_HEADERS = \
include/bitcoin/system/constraints.hpp \
include/bitcoin/system/define.hpp \
include/bitcoin/system/exceptions.hpp \
include/bitcoin/system/forks.hpp \
include/bitcoin/system/funclets.hpp \
include/bitcoin/system/have.hpp \
include/bitcoin/system/literals.hpp \
Expand Down Expand Up @@ -449,7 +450,7 @@ include_bitcoin_system_chain_HEADERS = \
include_bitcoin_system_chain_enumsdir = ${includedir}/bitcoin/system/chain/enums
include_bitcoin_system_chain_enums_HEADERS = \
include/bitcoin/system/chain/enums/coverage.hpp \
include/bitcoin/system/chain/enums/forks.hpp \
include/bitcoin/system/chain/enums/flags.hpp \
include/bitcoin/system/chain/enums/magic_numbers.hpp \
include/bitcoin/system/chain/enums/numbers.hpp \
include/bitcoin/system/chain/enums/opcode.hpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\compact.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\context.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\coverage.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\forks.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\flags.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\magic_numbers.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\numbers.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\opcode.hpp" />
Expand Down Expand Up @@ -332,6 +332,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\system\error\script_error_t.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\error\transaction_error_t.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\exceptions.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\forks.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\funclets.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\hash\accumulator.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\hash\algorithm.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\coverage.hpp">
<Filter>include\bitcoin\system\chain\enums</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\forks.hpp">
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\flags.hpp">
<Filter>include\bitcoin\system\chain\enums</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\system\chain\enums\magic_numbers.hpp">
Expand Down Expand Up @@ -875,6 +875,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\system\exceptions.hpp">
<Filter>include\bitcoin\system</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\system\forks.hpp">
<Filter>include\bitcoin\system</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\system\funclets.hpp">
<Filter>include\bitcoin\system</Filter>
</ClInclude>
Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <bitcoin/system/constraints.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/exceptions.hpp>
#include <bitcoin/system/forks.hpp>
#include <bitcoin/system/funclets.hpp>
#include <bitcoin/system/have.hpp>
#include <bitcoin/system/literals.hpp>
Expand All @@ -44,7 +45,7 @@
#include <bitcoin/system/chain/transaction.hpp>
#include <bitcoin/system/chain/witness.hpp>
#include <bitcoin/system/chain/enums/coverage.hpp>
#include <bitcoin/system/chain/enums/forks.hpp>
#include <bitcoin/system/chain/enums/flags.hpp>
#include <bitcoin/system/chain/enums/magic_numbers.hpp>
#include <bitcoin/system/chain/enums/numbers.hpp>
#include <bitcoin/system/chain/enums/opcode.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/chain/chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <bitcoin/system/chain/compact.hpp>
#include <bitcoin/system/chain/context.hpp>
#include <bitcoin/system/chain/enums/coverage.hpp>
#include <bitcoin/system/chain/enums/forks.hpp>
#include <bitcoin/system/chain/enums/flags.hpp>
#include <bitcoin/system/chain/enums/magic_numbers.hpp>
#include <bitcoin/system/chain/enums/numbers.hpp>
#include <bitcoin/system/chain/enums/opcode.hpp>
Expand Down
48 changes: 14 additions & 34 deletions include/bitcoin/system/chain/chain_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#ifndef LIBBITCOIN_SYSTEM_CHAIN_CHAIN_STATE_HPP
#define LIBBITCOIN_SYSTEM_CHAIN_CHAIN_STATE_HPP

#include <memory>
#include <deque>
#include <memory>
#include <bitcoin/system/chain/checkpoint.hpp>
#include <bitcoin/system/chain/context.hpp>
#include <bitcoin/system/chain/enums/forks.hpp>
#include <bitcoin/system/chain/enums/flags.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/forks.hpp>
#include <bitcoin/system/hash/hash.hpp>
#include <bitcoin/system/math/math.hpp>

Expand All @@ -38,6 +39,8 @@ namespace chain {
class block;
class header;

/// system::settings are using within chain_state to compute context, but are
/// not used directly within chain classes, which would be an abstraction leak.
class BC_API chain_state
{
public:
Expand All @@ -48,29 +51,6 @@ class BC_API chain_state
typedef std::deque<uint32_t> timestamps;
typedef std::shared_ptr<chain_state> 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.
Expand Down Expand Up @@ -224,23 +204,23 @@ class BC_API chain_state

/// No failure sentinel.
static activations activation(const data& values,
const forks_t& forks, const system::settings& settings) NOEXCEPT;
const forks& forks, const system::settings& settings) NOEXCEPT;

/// Returns zero if data is invalid.
static uint32_t median_time_past(const data& values,
const forks_t& forks) NOEXCEPT;
const forks& forks) NOEXCEPT;

/// Returns zero if data is invalid.
static uint32_t work_required(const data& values,
const forks_t& forks, const system::settings& settings) NOEXCEPT;
const forks& forks, const system::settings& settings) NOEXCEPT;

private:
static size_t bits_count(size_t height, const forks_t& forks,
static size_t bits_count(size_t height, const forks& forks,
size_t retargeting_interval) NOEXCEPT;
static size_t version_count(size_t height, const forks_t& forks,
static size_t version_count(size_t height, const forks& forks,
size_t bip34_activation_sample) NOEXCEPT;
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,
static size_t timestamp_count(size_t height, const forks& forks) NOEXCEPT;
static size_t retarget_height(size_t height, const forks& forks,
size_t retargeting_interval) NOEXCEPT;

static size_t bip30_deactivate_height(size_t height,
Expand All @@ -258,7 +238,7 @@ class BC_API chain_state
const system::settings& settings) NOEXCEPT;

static uint32_t work_required_retarget(const data& values,
const forks_t& forks, uint32_t proof_of_work_limit,
const forks& 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,
Expand All @@ -269,7 +249,7 @@ class BC_API chain_state

// These are thread safe.
const data data_;
const forks_t& forks_;
const forks& forks_;
const activations activations_;
const uint32_t work_required_;
const uint32_t median_time_past_;
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/system/chain/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define LIBBITCOIN_SYSTEM_CHAIN_CONTEXT_HPP

#include <bitcoin/system/define.hpp>
#include <bitcoin/system/chain/enums/forks.hpp>
#include <bitcoin/system/chain/enums/flags.hpp>
#include <bitcoin/system/chain/enums/policy.hpp>

namespace libbitcoin {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <bitcoin/system/define.hpp>
#include <bitcoin/system/math/math.hpp>
Expand All @@ -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.
Expand Down Expand Up @@ -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<uint32_t>
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/chain/enums/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/chain/operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// -----------------------------------------------------------------------
Expand Down
15 changes: 8 additions & 7 deletions include/bitcoin/system/chain/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string>
#include <vector>
#include <bitcoin/system/chain/enums/coverage.hpp>
#include <bitcoin/system/chain/enums/forks.hpp>
#include <bitcoin/system/chain/enums/flags.hpp>
#include <bitcoin/system/chain/enums/magic_numbers.hpp>
#include <bitcoin/system/chain/enums/script_pattern.hpp>
#include <bitcoin/system/chain/enums/script_version.hpp>
Expand All @@ -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
Expand Down Expand Up @@ -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.
/// -----------------------------------------------------------------------
Expand All @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions include/bitcoin/system/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,18 @@ class BC_API transaction

// signature_hash exposed for op_check_multisig caching.
hash_digest signature_hash(const input_iterator& input, const script& sub,
uint64_t value, uint8_t flags, script_version version,
uint64_t value, uint8_t sighash_flags, script_version version,
bool bip143) const NOEXCEPT;

bool check_signature(const ec_signature& signature,
const data_slice& public_key, const script& sub, uint32_t index,
uint64_t value, uint8_t flags, script_version version,
uint64_t value, uint8_t sighash_flags, script_version version,
bool bip143) const NOEXCEPT;

bool create_endorsement(endorsement& out, const ec_secret& secret,
const script& sub, uint32_t index, uint64_t value, uint8_t flags,
script_version version, bool bip143) const NOEXCEPT;
const script& sub, uint32_t index, uint64_t value,
uint8_t sighash_flags, script_version version,
bool bip143) const NOEXCEPT;

/// Guards (for tx pool without compact blocks).
/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -226,15 +227,15 @@ class BC_API transaction
input_iterator input_at(uint32_t index) const NOEXCEPT;
uint32_t input_index(const input_iterator& input) const NOEXCEPT;
void signature_hash_single(writer& sink, const input_iterator& input,
const script& sub, uint8_t flags) const NOEXCEPT;
const script& sub, uint8_t sighash_flags) const NOEXCEPT;
void signature_hash_none(writer& sink, const input_iterator& input,
const script& sub, uint8_t flags) const NOEXCEPT;
const script& sub, uint8_t sighash_flags) const NOEXCEPT;
void signature_hash_all(writer& sink, const input_iterator& input,
const script& sub, uint8_t flags) const NOEXCEPT;
const script& sub, uint8_t sighash_flags) const NOEXCEPT;
hash_digest unversioned_signature_hash(const input_iterator& input,
const script& sub, uint8_t flags) const NOEXCEPT;
const script& sub, uint8_t sighash_flags) const NOEXCEPT;
hash_digest version_0_signature_hash(const input_iterator& input,
const script& sub, uint64_t value, uint8_t flags,
const script& sub, uint64_t value, uint8_t sighash_flags,
bool bip143) const NOEXCEPT;

// Transaction should be stored as shared (adds 16 bytes).
Expand Down
Loading