Skip to content
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
8 changes: 8 additions & 0 deletions doc/release-notes-future-time-window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Logging and RPC help
--------------------

- A block refused as `time-too-new` is logged with the limit the rule applied,
the node's adjusted time plus this chain's 3 minutes, rather than plus
Bitcoin's two hours. The help of `importmulti`, `importdescriptors` and
`pruneblockchain` gives the same window in seconds where it said two hours.
The rule itself does not change.
2 changes: 1 addition & 1 deletion src/consensus/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum class BlockValidationResult {
BLOCK_MUTATED, //!< the block's data didn't match the data committed to by the PoW
BLOCK_MISSING_PREV, //!< We don't have the previous block the checked one is built on
BLOCK_INVALID_PREV, //!< A block this one builds on is invalid
BLOCK_TIME_FUTURE, //!< block timestamp was > 2 hours in the future (or our clock is bad)
BLOCK_TIME_FUTURE, //!< block timestamp was more than MAX_FUTURE_BLOCK_TIME in the future (or our clock is bad)
BLOCK_CHECKPOINT, //!< the block failed to meet one of our checkpoints
BLOCK_CHAINLOCK, //!< the block conflicts with the ChainLock
};
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ class PeerManagerImpl final : public PeerManager
/** Various helpers for headers processing, invoked by ProcessHeadersMessage() */
/** Deal with state tracking and headers sync for peers that send the
* occasional non-connecting header (this can happen due to BIP 130 headers
* announcements for blocks interacting with the 2hr (MAX_FUTURE_BLOCK_TIME) rule). */
* announcements for blocks interacting with the MAX_FUTURE_BLOCK_TIME rule). */
void HandleFewUnconnectingHeaders(CNode& pfrom, Peer& peer, const std::vector<CBlockHeader>& headers)
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex);
/** Return true if the headers connect to each other, false otherwise */
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ static RPCHelpMan pruneblockchain()
return RPCHelpMan{"pruneblockchain", "",
{
{"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The block height to prune up to. May be set to a discrete height, or to a " + UNIX_EPOCH_TIME + "\n"
" to prune blocks whose block time is at least 2 hours older than the provided timestamp."},
" to prune blocks whose block time is at least " + strprintf("%d", TIMESTAMP_WINDOW) + " seconds older than the provided timestamp."},
},
RPCResult{
RPCResult::Type::NUM, "", "Height of the last block pruned"},
Expand All @@ -1047,7 +1047,7 @@ static RPCHelpMan pruneblockchain()
// Height value more than a billion is too high to be a block height, and
// too low to be a block time (corresponds to timestamp from Sep 2001).
if (heightParam > 1000000000) {
// Add a 2 hour buffer to include blocks which might have had old timestamps
// Add a TIMESTAMP_WINDOW buffer to include blocks which might have had old timestamps
const CBlockIndex* pindex = active_chain.FindEarliestAtLeast(heightParam - TIMESTAMP_WINDOW, 0);
if (!pindex) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find block with at least the specified timestamp.");
Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
// upgrade from one software version to the next after a consensus rule
// change is potentially tricky and issue-specific (see NeedsRedownload()
// for one approach that was used for BIP 141 deployment).
// Also, currently the rule against blocks more than 2 hours in the future
// Also, currently the rule against blocks more than MAX_FUTURE_BLOCK_TIME in the future
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
// re-enforce that rule here (at least until we make it impossible for
// GetAdjustedTime() to go backward).
Expand Down Expand Up @@ -4181,7 +4181,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio

// Check timestamp
if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME)
return state.Invalid(BlockValidationResult::BLOCK_TIME_FUTURE, "time-too-new", strprintf("block timestamp too far in the future %d %d", block.GetBlockTime(), nAdjustedTime + 2 * 60 * 60));
return state.Invalid(BlockValidationResult::BLOCK_TIME_FUTURE, "time-too-new", strprintf("block timestamp too far in the future %d %d", block.GetBlockTime(), nAdjustedTime + MAX_FUTURE_BLOCK_TIME));

// Reject blocks with outdated version
if ((block.nVersion < 2 && DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB)) ||
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ RPCHelpMan importmulti()
" or the string \"now\" to substitute the current synced blockchain time. The timestamp of the oldest\n"
" key will determine how far back blockchain rescans need to begin for missing wallet transactions.\n"
" \"now\" can be specified to bypass scanning, for keys which are known to never have been used, and\n"
" 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key\n"
" 0 can be specified to scan the entire blockchain. Blocks up to " + strprintf("%d", TIMESTAMP_WINDOW) + " seconds before the earliest key\n"
" creation time of all keys being imported by the importmulti call will be scanned.",
/* oneline_description */ "", {"timestamp | \"now\"", "integer / string"}
},
Expand Down Expand Up @@ -1908,7 +1908,7 @@ RPCHelpMan importdescriptors() {
{"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Time from which to start rescanning the blockchain for this descriptor, in " + UNIX_EPOCH_TIME + "\n"
" Use the string \"now\" to substitute the current synced blockchain time.\n"
" \"now\" can be specified to bypass scanning, for outputs which are known to never have been used, and\n"
" 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest timestamp\n"
" 0 can be specified to scan the entire blockchain. Blocks up to " + strprintf("%d", TIMESTAMP_WINDOW) + " seconds before the earliest timestamp\n"
" of all descriptors being imported will be scanned.",
/* oneline_description */ "", {"timestamp | \"now\"", "integer / string"}
},
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4824,7 +4824,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t>& mapKeyBirth) const {
for (const auto& entry : mapKeyFirstBlock) {
int64_t block_time;
CHECK_NONFATAL(chain().findBlock(entry.second->hashBlock, FoundBlock().time(block_time)));
mapKeyBirth[entry.first] = block_time - TIMESTAMP_WINDOW; // block times can be 2h off
mapKeyBirth[entry.first] = block_time - TIMESTAMP_WINDOW; // block times can be TIMESTAMP_WINDOW off
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/functional/interface_usdt_utxocache.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from bcc import BPF, USDT # type: ignore[import]
except ImportError:
pass
from test_framework.blocktools import BLOCK_SUBSIDY
from test_framework.messages import COIN
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
Expand Down Expand Up @@ -192,7 +193,7 @@ def handle_utxocache_uncache(_, data, __):
assert_equal(block_1_coinbase_txid, bytes(event.txid[::-1]).hex())
assert_equal(0, event.index) # prevout index
assert_equal(EARLY_BLOCK_HEIGHT, event.height)
assert_equal(500 * COIN, event.value)
assert_equal(BLOCK_SUBSIDY * COIN, event.value)
assert_equal(True, event.is_coinbase)

handle_uncache_succeeds += 1
Expand Down
6 changes: 5 additions & 1 deletion test/functional/mining_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
bad_block = copy.deepcopy(block)
bad_block.nTime = 2**31 - 1
assert_template(node, bad_block, 'time-too-new')
assert_submitblock(bad_block, 'time-too-new', 'time-too-new')
# The log names the limit the rule applied: the node's adjusted time plus MAX_FUTURE_BLOCK_TIME (3 minutes),
# not Bitcoin's two hours.
adjusted_time = node.mocktime + node.getnetworkinfo()['timeoffset']
with node.assert_debug_log([f'block timestamp too far in the future {bad_block.nTime} {adjusted_time + 3 * 60}']):
assert_submitblock(bad_block, 'time-too-new', 'time-too-new')
bad_block.nTime = 0
assert_template(node, bad_block, 'time-too-old')
assert_submitblock(bad_block, 'time-too-old', 'time-too-old')
Expand Down
Loading