Skip to content

Commit

Permalink
Merge pull request #1018 from toxeus/time_warp
Browse files Browse the repository at this point in the history
Add time warp patch hard fork.
  • Loading branch information
toxeus committed Aug 26, 2018
2 parents 3bcd51a + 471be31 commit fb006d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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
8 changes: 7 additions & 1 deletion 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 @@ -126,6 +127,9 @@ chain_state::activations chain_state::activation(const data& values,
// bip90 is activated based on configuration alone (hard fork).
result.forks |= (rule_fork::bip90_rule & forks);

// time_warp_patch is activated based on configuration alone (hard fork).
result.forks |= (rule_fork::time_warp_patch & forks);

// bip16 was activated based on manual inspection of history (~55% rule).
if (values.timestamp.self >= settings.bip16_activation_time)
{
Expand Down Expand Up @@ -513,7 +517,9 @@ 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 = (script::is_enabled(forks,
rule_fork::time_warp_patch) && 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 fb006d0

Please sign in to comment.