Skip to content

Commit

Permalink
Merge b739240 into 27caa32
Browse files Browse the repository at this point in the history
  • Loading branch information
toxeus committed Aug 22, 2018
2 parents 27caa32 + b739240 commit 7ff6019
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/bitcoin/bitcoin/machine/rule_fork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ enum rule_fork : uint32_t
/// Prevent dummy value malleability (soft fork, feature).
bip147_rule = 1u << 13,

/// Fix Satoshi's time warp bug (hard fork, feature).
time_warp_patch = 1u << 14,

// TODO: future bitcoin forks work forward from << 14.
// TODO: splitcoin/altcoin forks work backwards from << 30.
////time_warp_patch = 1u << 29,
Expand Down
13 changes: 11 additions & 2 deletions src/chain/chain_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <boost/range/adaptor/reversed.hpp>
#include <bitcoin/bitcoin/chain/block.hpp>
#include <bitcoin/bitcoin/chain/chain_state.hpp>
Expand Down Expand Up @@ -86,6 +87,8 @@ chain_state::activations chain_state::activation(const data& values,
const auto difficult = script::is_enabled(forks, rule_fork::difficult);
const auto retarget = script::is_enabled(forks, rule_fork::retarget);
const auto mainnet = retarget && difficult;
const auto time_warp = script::is_enabled(forks, rule_fork::time_warp_patch
);

//*************************************************************************
// CONSENSUS: Though unspecified in bip34, the satoshi implementation
Expand Down Expand Up @@ -191,6 +194,9 @@ chain_state::activations chain_state::activation(const data& values,
result.minimum_block_version = settings.first_version;
}

if (time_warp)
result.forks |= (rule_fork::time_warp_patch & forks);

// TODO: add configurable option to apply transaction version policy.
result.maximum_transaction_version = max_uint32;
return result;
Expand Down Expand Up @@ -481,8 +487,10 @@ chain_state::data chain_state::to_pool(const chain_state& top,
// Alias configured forks.
const auto forks = top.forks_;

// Retargeting is only activated via configuration.
// Retargeting and time_warp_patch are only activated via configuration.
const auto retarget = script::is_enabled(forks, rule_fork::retarget);
const auto time_warp = script::is_enabled(forks, rule_fork::time_warp_patch
);

// Copy data from presumed previous-height block state.
auto data = top.data_;
Expand Down Expand Up @@ -513,7 +521,8 @@ chain_state::data chain_state::to_pool(const chain_state& top,
// If promoting from retarget height, move that timestamp into retarget.
if (retarget &&
is_retarget_height(height - 1u, settings.retargeting_interval))
data.timestamp.retarget = data.timestamp.self;
data.timestamp.retarget = (time_warp && height != 1) ?
*std::next(data.timestamp.ordered.crbegin()) : data.timestamp.self;

// Replace previous block state with tx pool chain state for next height
// Preserve top block timestamp for use in computation of staleness.
Expand Down

0 comments on commit 7ff6019

Please sign in to comment.