Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2022-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test logic for setting -maxtipage on command line.7Nodes don't consider themselves out of "initial block download" as long as8their best known block header time is more than -maxtipage in the past.9"""11import time13from test_framework.test_framework import BitcoinTestFramework14from test_framework.util import assert_equal17DEFAULT_MAX_TIP_AGE = 24 * 60 * 6020class MaxTipAgeTest(BitcoinTestFramework):21def set_test_params(self):22self.setup_clean_chain = True23self.num_nodes = 225def test_maxtipage(self, maxtipage, set_parameter=True, test_deltas=True):26node_miner = self.nodes[0]27node_ibd = self.nodes[1]29self.restart_node(1, [f'-maxtipage={maxtipage}'] if set_parameter else None)30self.connect_nodes(0, 1)31cur_time = int(time.time())33if test_deltas:34# tips older than maximum age -> stay in IBD35node_ibd.setmocktime(cur_time)36for delta in [5, 4, 3, 2, 1]:37node_miner.setmocktime(cur_time - maxtipage - delta)38self.generate(node_miner, 1)39assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], True)41# tip within maximum age -> leave IBD42node_miner.setmocktime(max(cur_time - maxtipage, 0))43self.generate(node_miner, 1)44assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], False)46# reset time to system time so we don't have a time offset with the ibd node the next47# time we connect to it, ensuring TimeOffsets::WarnIfOutOfSync() doesn't output to stderr48node_miner.setmocktime(0)50def run_test(self):51self.log.info("Test IBD with maximum tip age of 24 hours (default).")52self.test_maxtipage(DEFAULT_MAX_TIP_AGE, set_parameter=False)54for hours in [20, 10, 5, 2, 1]:55maxtipage = hours * 60 * 6056self.log.info(f"Test IBD with maximum tip age of {hours} hours (-maxtipage={maxtipage}).")57self.test_maxtipage(maxtipage)59max_long_val = 922337203685477580760self.log.info(f"Test IBD with highest allowable maximum tip age ({max_long_val}).")61self.test_maxtipage(max_long_val, test_deltas=False)64if __name__ == '__main__':65MaxTipAgeTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.