Skip to content

Commit

Permalink
Merge pull request #1019 from toxeus/master
Browse files Browse the repository at this point in the history
Improve bc::settings member naming.
  • Loading branch information
evoskuil committed Aug 23, 2018
2 parents 27caa32 + ee0a474 commit 3bcd51a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
10 changes: 5 additions & 5 deletions include/bitcoin/bitcoin/chain/chain_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class BC_API chain_state

/// Checkpoints must be ordered by height with greatest at back.
static map get_map(size_t height, const checkpoints& checkpoints,
uint32_t forks, size_t retargeting_interval, size_t net_sample,
uint32_t forks, size_t retargeting_interval, size_t activation_sample,
const config::checkpoint& bip9_bit0_active_checkpoint,
const config::checkpoint& bip9_bit1_active_checkpoint);

Expand Down Expand Up @@ -197,7 +197,7 @@ class BC_API chain_state
static size_t bits_count(size_t height, uint32_t forks,
size_t retargeting_interval);
static size_t version_count(size_t height, uint32_t forks,
size_t net_sample);
size_t activation_sample);
static size_t timestamp_count(size_t height, uint32_t forks);
static size_t retarget_height(size_t height, uint32_t forks,
size_t retargeting_interval);
Expand All @@ -214,10 +214,10 @@ class BC_API chain_state
const settings& settings);

static uint32_t work_required_retarget(const data& values,
uint32_t proof_of_work_limit, uint32_t min_timespan,
uint32_t max_timespan, uint32_t target_timespan_seconds);
uint32_t proof_of_work_limit, uint32_t minimum_timespan,
uint32_t maximum_timespan, uint32_t target_timespan_seconds);
static uint32_t retarget_timespan(const chain_state::data& values,
uint32_t min_timespan, uint32_t max_timespan);
uint32_t minimum_timespan, uint32_t maximum_timespan);

// easy blocks
static uint32_t easy_work_required(const data& values,
Expand Down
10 changes: 5 additions & 5 deletions include/bitcoin/bitcoin/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class BC_API settings
uint32_t proof_of_work_limit;

// The upper and lower bounds for the retargeting timespan.
uint32_t min_timespan;
uint32_t max_timespan;
uint32_t minimum_timespan;
uint32_t maximum_timespan;

// The target number of blocks for 2 weeks of work (2016 blocks).
size_t retargeting_interval;
Expand All @@ -70,9 +70,9 @@ class BC_API settings
uint32_t bip9_version_base;

// Activation parameters (bip34-style activations).
size_t net_active;
size_t net_enforce;
size_t net_sample;
size_t activation_threshold;
size_t enforcement_threshold;
size_t activation_sample;

// Frozen activation heights (frozen_activations).
size_t bip65_freeze;
Expand Down
44 changes: 22 additions & 22 deletions src/chain/chain_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ using namespace boost::adaptors;
// Inlines.
//-----------------------------------------------------------------------------

inline bool is_active(size_t count, size_t net_active)
inline bool is_active(size_t count, size_t activation_threshold)
{
return count >= net_active;
return count >= activation_threshold;
}

inline bool is_enforced(size_t count, size_t net_enforce)
inline bool is_enforced(size_t count, size_t enforcement_threshold)
{
return count >= net_enforce;
return count >= enforcement_threshold;
}

inline bool is_bip30_exception(const checkpoint& check, bool mainnet)
Expand Down Expand Up @@ -141,21 +141,21 @@ chain_state::activations chain_state::activation(const data& values,
}

// bip34 is activated based on 75% of preceding 1000 mainnet blocks.
if (bip34_ice || (is_active(count_2, settings.net_active) && version >=
if (bip34_ice || (is_active(count_2, settings.activation_threshold) && version >=
settings.bip34_version))
{
result.forks |= (rule_fork::bip34_rule & forks);
}

// bip66 is activated based on 75% of preceding 1000 mainnet blocks.
if (bip66_ice || (is_active(count_3, settings.net_active) && version >=
if (bip66_ice || (is_active(count_3, settings.activation_threshold) && version >=
settings.bip66_version))
{
result.forks |= (rule_fork::bip66_rule & forks);
}

// bip65 is activated based on 75% of preceding 1000 mainnet blocks.
if (bip65_ice || (is_active(count_4, settings.net_active) && version >=
if (bip65_ice || (is_active(count_4, settings.activation_threshold) && version >=
settings.bip65_version))
{
result.forks |= (rule_fork::bip65_rule & forks);
Expand All @@ -174,15 +174,15 @@ 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.net_enforce))
if (bip65_ice || is_enforced(count_4, settings.enforcement_threshold))
{
result.minimum_block_version = settings.bip65_version;
}
else if (bip66_ice || is_enforced(count_3, settings.net_enforce))
else if (bip66_ice || is_enforced(count_3, settings.enforcement_threshold))
{
result.minimum_block_version = settings.bip66_version;
}
else if (bip34_ice || is_enforced(count_2, settings.net_enforce))
else if (bip34_ice || is_enforced(count_2, settings.enforcement_threshold))
{
result.minimum_block_version = settings.bip34_version;
}
Expand Down Expand Up @@ -216,15 +216,15 @@ 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 net_sample)
size_t activation_sample)
{
if (script::is_enabled(forks, rule_fork::bip90_rule) ||
!script::is_enabled(forks, rule_fork::bip34_activations))
{
return 0;
}

return std::min(height, net_sample);
return std::min(height, activation_sample);
}

size_t chain_state::timestamp_count(size_t height, uint32_t)
Expand Down Expand Up @@ -294,8 +294,8 @@ uint32_t chain_state::work_required(const data& values, uint32_t forks,
// Mainnet and testnet retarget on interval.
if (is_retarget_height(values.height, settings.retargeting_interval))
return work_required_retarget(values,
settings.proof_of_work_limit, settings.min_timespan,
settings.max_timespan, settings.target_timespan_seconds);
settings.proof_of_work_limit, settings.minimum_timespan,
settings.maximum_timespan, settings.target_timespan_seconds);

// Testnet retargets easy on inter-interval.
if (!script::is_enabled(forks, rule_fork::difficult))
Expand All @@ -308,16 +308,16 @@ uint32_t chain_state::work_required(const data& values, uint32_t forks,
}

uint32_t chain_state::work_required_retarget(const data& values,
uint32_t proof_of_work_limit, uint32_t min_timespan,
uint32_t max_timespan, uint32_t target_timespan_seconds)
uint32_t proof_of_work_limit, uint32_t minimum_timespan,
uint32_t maximum_timespan, uint32_t target_timespan_seconds)
{
static const uint256_t pow_limit(compact{ proof_of_work_limit });

const compact bits(bits_high(values));
BITCOIN_ASSERT_MSG(!bits.is_overflowed(), "previous block has bad bits");

uint256_t target(bits);
target *= retarget_timespan(values, min_timespan, max_timespan);
target *= retarget_timespan(values, minimum_timespan, maximum_timespan);
target /= target_timespan_seconds;

// The proof_of_work_limit constant is pre-normalized.
Expand All @@ -327,7 +327,7 @@ uint32_t chain_state::work_required_retarget(const data& values,

// Get the bounded total time spanning the highest 2016 blocks.
uint32_t chain_state::retarget_timespan(const data& values,
uint32_t min_timespan, uint32_t max_timespan)
uint32_t minimum_timespan, uint32_t maximum_timespan)
{
const auto high = timestamp_high(values);
const auto retarget = values.timestamp.retarget;
Expand All @@ -337,7 +337,7 @@ uint32_t chain_state::retarget_timespan(const data& values,
// order to prevent underflow before applying the range constraint.
//*************************************************************************
const auto timespan = cast_subtract<int64_t>(high, retarget);
return range_constrain(timespan, min_timespan, max_timespan);
return range_constrain(timespan, minimum_timespan, maximum_timespan);
}

uint32_t chain_state::easy_work_required(const data& values,
Expand Down Expand Up @@ -409,7 +409,7 @@ size_t chain_state::retarget_distance(size_t height,
// static
chain_state::map chain_state::get_map(size_t height,
const checkpoints& /* checkpoints */, uint32_t forks,
size_t retargeting_interval, size_t net_sample,
size_t retargeting_interval, size_t activation_sample,
const config::checkpoint& bip9_bit0_active_checkpoint,
const config::checkpoint& bip9_bit1_active_checkpoint)
{
Expand All @@ -431,7 +431,7 @@ chain_state::map chain_state::get_map(size_t height,
// The height bound of the version sample for activations.
map.version_self = height;
map.version.high = height - 1;
map.version.count = version_count(height, forks, net_sample);
map.version.count = version_count(height, forks, activation_sample);

// The most recent past retarget height.
map.timestamp_retarget = retarget_height(height, forks,
Expand Down Expand Up @@ -502,7 +502,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.net_sample))
settings.activation_sample))
data.version.ordered.pop_front();

// If timestamp collection overflows, dequeue oldest member.
Expand Down
16 changes: 8 additions & 8 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ settings::settings()
easy_spacing_seconds(20 * 60),
timestamp_future_seconds(2 * 60 * 60),
target_timespan_seconds(2 * 7 * 24 * 60 * 60),
min_timespan(target_timespan_seconds / retargeting_factor),
max_timespan(target_timespan_seconds * retargeting_factor),
minimum_timespan(target_timespan_seconds / retargeting_factor),
maximum_timespan(target_timespan_seconds * retargeting_factor),
retargeting_interval(target_timespan_seconds / target_spacing_seconds),
first_version(1),
bip34_version(2),
Expand Down Expand Up @@ -90,9 +90,9 @@ settings::settings(config::settings context)
0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57,
0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f,
0xac, 0x00, 0x00, 0x00, 0x00});
net_active = 750;
net_enforce = 950;
net_sample = 1000;
activation_threshold = 750;
enforcement_threshold = 950;
activation_sample = 1000;
bip65_freeze = 388381;
bip66_freeze = 363725;
bip34_freeze = 227931;
Expand Down Expand Up @@ -151,9 +151,9 @@ settings::settings(config::settings context)
0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57,
0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f,
0xac, 0x00, 0x00, 0x00, 0x00});
net_active = 51;
net_enforce = 75;
net_sample = 100;
activation_threshold = 51;
enforcement_threshold = 75;
activation_sample = 100;
bip65_freeze = 581885;
bip66_freeze = 330776;
bip34_freeze = 21111;
Expand Down
28 changes: 14 additions & 14 deletions test/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ BOOST_AUTO_TEST_CASE(settings__construct__default_context__expected)
BOOST_REQUIRE_EQUAL(configuration.easy_spacing_seconds, 1200);
BOOST_REQUIRE_EQUAL(configuration.timestamp_future_seconds, 7200);
BOOST_REQUIRE_EQUAL(configuration.target_timespan_seconds, 1209600);
BOOST_REQUIRE_EQUAL(configuration.min_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.max_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.minimum_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.maximum_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.retargeting_interval, 2016);
BOOST_REQUIRE_EQUAL(configuration.first_version, 1);
BOOST_REQUIRE_EQUAL(configuration.bip34_version, 2);
Expand Down Expand Up @@ -69,8 +69,8 @@ BOOST_AUTO_TEST_CASE(settings__construct__mainnet_context__expected)
BOOST_REQUIRE_EQUAL(configuration.timestamp_future_seconds, 7200);
BOOST_REQUIRE_EQUAL(configuration.target_timespan_seconds, 1209600);
BOOST_REQUIRE_EQUAL(configuration.proof_of_work_limit, 0x1d00ffff);
BOOST_REQUIRE_EQUAL(configuration.min_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.max_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.minimum_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.maximum_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.retargeting_interval, 2016);
const chain::block genesis_block = configuration.genesis_block;
BOOST_REQUIRE_EQUAL(genesis_block.to_data(), data_chunk({
Expand Down Expand Up @@ -117,9 +117,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, 0x20000000);
BOOST_REQUIRE_EQUAL(configuration.net_active, 750);
BOOST_REQUIRE_EQUAL(configuration.net_enforce, 950);
BOOST_REQUIRE_EQUAL(configuration.net_sample, 1000);
BOOST_REQUIRE_EQUAL(configuration.activation_threshold, 750);
BOOST_REQUIRE_EQUAL(configuration.enforcement_threshold, 950);
BOOST_REQUIRE_EQUAL(configuration.activation_sample, 1000);
BOOST_REQUIRE_EQUAL(configuration.bip65_freeze, 388381);
BOOST_REQUIRE_EQUAL(configuration.bip66_freeze, 363725);
BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 227931);
Expand Down Expand Up @@ -158,8 +158,8 @@ BOOST_AUTO_TEST_CASE(settings__construct__testnet_context__expected)
BOOST_REQUIRE_EQUAL(configuration.timestamp_future_seconds, 7200);
BOOST_REQUIRE_EQUAL(configuration.target_timespan_seconds, 1209600);
BOOST_REQUIRE_EQUAL(configuration.proof_of_work_limit, 0x1d00ffff);
BOOST_REQUIRE_EQUAL(configuration.min_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.max_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.minimum_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.maximum_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.retargeting_interval, 2016);
const chain::block genesis_block = configuration.genesis_block;
BOOST_REQUIRE_EQUAL(genesis_block.to_data(), data_chunk({
Expand Down Expand Up @@ -206,9 +206,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, 0x20000000);
BOOST_REQUIRE_EQUAL(configuration.net_active, 51);
BOOST_REQUIRE_EQUAL(configuration.net_enforce, 75);
BOOST_REQUIRE_EQUAL(configuration.net_sample, 100);
BOOST_REQUIRE_EQUAL(configuration.activation_threshold, 51);
BOOST_REQUIRE_EQUAL(configuration.enforcement_threshold, 75);
BOOST_REQUIRE_EQUAL(configuration.activation_sample, 100);
BOOST_REQUIRE_EQUAL(configuration.bip65_freeze, 581885);
BOOST_REQUIRE_EQUAL(configuration.bip66_freeze, 330776);
BOOST_REQUIRE_EQUAL(configuration.bip34_freeze, 21111);
Expand Down Expand Up @@ -247,8 +247,8 @@ BOOST_AUTO_TEST_CASE(settings__construct__regtest_context__expected)
BOOST_REQUIRE_EQUAL(configuration.timestamp_future_seconds, 7200);
BOOST_REQUIRE_EQUAL(configuration.target_timespan_seconds, 1209600);
BOOST_REQUIRE_EQUAL(configuration.proof_of_work_limit, 0x207fffff);
BOOST_REQUIRE_EQUAL(configuration.min_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.max_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.minimum_timespan, 302400);
BOOST_REQUIRE_EQUAL(configuration.maximum_timespan, 4838400);
BOOST_REQUIRE_EQUAL(configuration.retargeting_interval, 2016);
const chain::block genesis_block = configuration.genesis_block;
BOOST_REQUIRE_EQUAL(genesis_block.to_data(), data_chunk({
Expand Down

0 comments on commit 3bcd51a

Please sign in to comment.