merge bitcoin#23636: Remove GetAdjustedTime from init.cpp

This commit is contained in:
Kittywhiskers Van Gogh 2024-10-03 20:01:43 +00:00
parent 150ca008fe
commit 145d94d700
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
12 changed files with 35 additions and 12 deletions

View File

@ -23,6 +23,7 @@
#include <protocol.h>
#include <shutdown.h>
#include <spork.h>
#include <timedata.h>
#include <util/ranges.h>
#include <util/time.h>
#include <validation.h>

View File

@ -12,6 +12,7 @@
#include <masternode/sync.h>
#include <messagesigner.h>
#include <net_processing.h>
#include <timedata.h>
#include <util/string.h>
#include <util/system.h>
#include <validation.h>

View File

@ -2056,7 +2056,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
const CBlockIndex* tip = chainstate->m_chain.Tip();
RPCNotifyBlockChange(tip);
if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
strLoadError = _("The block database contains a block which appears to be from the future. "
"This may be due to your computer's date and time being set incorrectly. "
"Only rebuild the block database if you are sure that your computer's date and time are correct");

View File

@ -12,6 +12,7 @@
#include <netmessagemaker.h>
#include <addrdb.h>
#include <addrman.h>
#include <banman.h>
#include <clientversion.h>
#include <compat.h>

View File

@ -6,7 +6,6 @@
#ifndef BITCOIN_NET_H
#define BITCOIN_NET_H
#include <addrman.h>
#include <bip324.h>
#include <bloom.h>
#include <chainparams.h>
@ -50,14 +49,15 @@
#include <unordered_set>
#include <vector>
class AddrMan;
class BanMan;
class CConnman;
class CDeterministicMNList;
class CDeterministicMNManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CScheduler;
class CNode;
class BanMan;
class CScheduler;
struct bilingual_str;
/** Default for -whitelistrelay. */

View File

@ -6,6 +6,7 @@
#include <core_io.h>
#include <evo/deterministicmns.h>
#include <governance/classes.h>
#include <governance/common.h>
#include <governance/governance.h>
#include <governance/validators.h>
#include <governance/vote.h>
@ -19,7 +20,7 @@
#include <rpc/server.h>
#include <rpc/server_util.h>
#include <rpc/util.h>
#include <governance/common.h>
#include <timedata.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <validation.h>

View File

@ -5,6 +5,7 @@
#include <rpc/server.h>
#include <addrman.h>
#include <banman.h>
#include <chainparams.h>
#include <clientversion.h>

View File

@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <addrman.h>
#include <chainparams.h>
#include <chainparamsbase.h>
#include <net.h>

View File

@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <addrman.h>
#include <chainparams.h>
#include <chainparamsbase.h>
#include <net.h>

View File

@ -15,14 +15,12 @@ becomes valid.
import copy
import time
from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
from test_framework.blocktools import MAX_FUTURE_BLOCK_TIME, create_block, create_coinbase, create_tx_with_script
from test_framework.messages import COIN
from test_framework.p2p import P2PDataStore
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
class InvalidBlockRequestTest(BitcoinTestFramework):
def set_test_params(self):

View File

@ -27,9 +27,10 @@ import subprocess
from test_framework.address import ADDRESS_BCRT1_P2SH_OP_TRUE
from test_framework.blocktools import (
MAX_FUTURE_BLOCK_TIME,
TIME_GENESIS_BLOCK,
create_block,
create_coinbase,
TIME_GENESIS_BLOCK,
)
from test_framework.governance import EXPECTED_STDERR_NO_GOV_PRUNE
from test_framework.messages import (
@ -48,25 +49,27 @@ from test_framework.util import (
assert_is_hex_string,
assert_is_hash_string,
get_datadir_path,
set_node_times,
)
from test_framework.wallet import MiniWallet
HEIGHT = 200 # blocks mined
TIME_RANGE_STEP = 156 # ten-minute steps
TIME_RANGE_STEP = 156 # two and a half minute steps
TIME_RANGE_MTP = TIME_GENESIS_BLOCK + (HEIGHT - 6) * TIME_RANGE_STEP
TIME_RANGE_TIP = TIME_GENESIS_BLOCK + (HEIGHT - 1) * TIME_RANGE_STEP
TIME_RANGE_END = TIME_GENESIS_BLOCK + HEIGHT * TIME_RANGE_STEP
class BlockchainTest(BitcoinTestFramework):
def set_test_params(self):
self.disable_mocktime = True
self.setup_clean_chain = True
self.num_nodes = 1
self.supports_cli = False
def run_test(self):
self.mine_chain()
self._test_max_future_block_time()
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1', '-txindex=0']) # Set extra args with pruning after rescan is complete
# Actual tests
@ -85,10 +88,23 @@ class BlockchainTest(BitcoinTestFramework):
self.log.info(f"Generate {HEIGHT} blocks after the genesis block in 156 sec")
for t in range(TIME_GENESIS_BLOCK, TIME_RANGE_END, TIME_RANGE_STEP):
# 156 sec steps from genesis block time
set_node_times(self.nodes, t)
self.nodes[0].setmocktime(t)
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_P2SH_OP_TRUE)
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
def _test_max_future_block_time(self):
self.stop_node(0)
self.log.info("A block tip of more than MAX_FUTURE_BLOCK_TIME in the future raises an error")
self.nodes[0].assert_start_raises_init_error(
extra_args=[f"-mocktime={TIME_RANGE_TIP - MAX_FUTURE_BLOCK_TIME - 1}"],
expected_msg=": The block database contains a block which appears to be from the future."
" This may be due to your computer's date and time being set incorrectly."
f" Only rebuild the block database if you are sure that your computer's date and time are correct.{os.linesep}"
"Please restart with -reindex or -reindex-chainstate to recover.",
)
self.log.info("A block tip of MAX_FUTURE_BLOCK_TIME in the future is fine")
self.start_node(0, extra_args=[f"-mocktime={TIME_RANGE_TIP - MAX_FUTURE_BLOCK_TIME}"])
def _test_getblockchaininfo(self):
self.log.info("Test getblockchaininfo")

View File

@ -31,6 +31,8 @@ MAX_BLOCK_SIGOPS = 40000
# Genesis block time (regtest)
TIME_GENESIS_BLOCK = 1417713337
MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
# Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
COINBASE_MATURITY = 100