Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#30761: test: Avoid intermittent timeout in p2p_…
Browse files Browse the repository at this point in the history
…headers_sync_with_minchainwork.py

fa247e6 test: Avoid intermittent timeout in p2p_headers_sync_with_minchainwork.py (MarcoFalke)

Pull request description:

  Similar to bitcoin/bitcoin#30705:

  The goal of this test case is to check that the sync works at all, not to check any timeout.

  On extremely slow hardware (for example qemu virtual hardware), downloading the 4110 BLOCKS_TO_MINE may take longer than the block download timeout.

  Fix it by pinning the time using mocktime temporarily, and advance it immediately after the sync.

ACKs for top commit:
  stratospher:
    ACK fa247e6. Checked the timeout downloading block logs before/after using `setmocktime`.
  tdb3:
    ACK fa247e6

Tree-SHA512: f61632a8d9e484f1b888aafbf87f7adf71b8692387bd77f603cdbc0de49f30d42e654741d46ae1ff8b9706a5559ee0faabdb192ed0db7449010b68bfcdbaa42d
  • Loading branch information
fanquake committed Sep 2, 2024
2 parents 99e35fb + fa247e6 commit a74bdee
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/functional/p2p_headers_sync_with_minchainwork.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright (c) 2019-2022 The Bitcoin Core developers
# Copyright (c) 2019-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test that we reject low difficulty headers to prevent our block tree from filling up with useless bloat"""
Expand All @@ -21,6 +21,8 @@

from test_framework.util import assert_equal

import time

NODE1_BLOCKS_REQUIRED = 15
NODE2_BLOCKS_REQUIRED = 2047

Expand Down Expand Up @@ -48,6 +50,10 @@ def reconnect_all(self):
self.connect_nodes(0, 2)
self.connect_nodes(0, 3)

def mocktime_all(self, time):
for n in self.nodes:
n.setmocktime(time)

def test_chains_sync_when_long_enough(self):
self.log.info("Generate blocks on the node with no required chainwork, and verify nodes 1 and 2 have no new headers in their headers tree")
with self.nodes[1].assert_debug_log(expected_msgs=["[net] Ignoring low-work chain (height=14)"]), self.nodes[2].assert_debug_log(expected_msgs=["[net] Ignoring low-work chain (height=14)"]), self.nodes[3].assert_debug_log(expected_msgs=["Synchronizing blockheaders, height: 14"]):
Expand Down Expand Up @@ -149,7 +155,9 @@ def test_large_reorgs_can_succeed(self):

self.reconnect_all()

self.mocktime_all(int(time.time())) # Temporarily hold time to avoid internal timeouts
self.sync_blocks(timeout=300) # Ensure tips eventually agree
self.mocktime_all(0)


def run_test(self):
Expand Down

0 comments on commit a74bdee

Please sign in to comment.