diff --git a/doc/release-notes-future-time-window.md b/doc/release-notes-future-time-window.md new file mode 100644 index 000000000..28fe76a0f --- /dev/null +++ b/doc/release-notes-future-time-window.md @@ -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. diff --git a/src/consensus/validation.h b/src/consensus/validation.h index d4b0c9288..6f89d4e3c 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -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 }; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 57bd7cf74..1bd0c75f3 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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& headers) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex); /** Return true if the headers connect to each other, false otherwise */ diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 440bda3e5..545b8dbaf 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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"}, @@ -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."); diff --git a/src/validation.cpp b/src/validation.cpp index 150c88bcb..7f64341b0 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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). @@ -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)) || diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index f6ad84229..ee7a2c796 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -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"} }, @@ -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"} }, diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 2b6240e16..5d7c085c2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4824,7 +4824,7 @@ void CWallet::GetKeyBirthTimes(std::map& 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 } } diff --git a/test/functional/interface_usdt_utxocache.py b/test/functional/interface_usdt_utxocache.py index 75714d4a1..ed98bea29 100755 --- a/test/functional/interface_usdt_utxocache.py +++ b/test/functional/interface_usdt_utxocache.py @@ -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 @@ -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 diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index 2a4814066..4a5bf0b59 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -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')