mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-08 20:28:55 +02:00
Add test for getheaders behavior
Expect responses to a getheaders iff the node has a chain with more than nMinimumChainWork
This commit is contained in:
parent
ef6dbe6863
commit
a35f963edf
@ -17,6 +17,7 @@ only succeeds past a given node once its nMinimumChainWork has been exceeded.
|
||||
|
||||
import time
|
||||
|
||||
from test_framework.p2p import P2PInterface, msg_getheaders
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
|
||||
@ -41,6 +42,9 @@ class MinimumChainWorkTest(BitcoinTestFramework):
|
||||
for i in range(self.num_nodes-1):
|
||||
self.connect_nodes(i+1, i)
|
||||
|
||||
# Set clock of node2 2 days ahead, to keep it in IBD during this test.
|
||||
self.nodes[2].setmocktime(int(time.time()) + 48*60*60)
|
||||
|
||||
def run_test(self):
|
||||
# Start building a chain on node0. node2 shouldn't be able to sync until node1's
|
||||
# minchainwork is exceeded
|
||||
@ -71,6 +75,15 @@ class MinimumChainWorkTest(BitcoinTestFramework):
|
||||
assert self.nodes[1].getbestblockhash() != self.nodes[0].getbestblockhash()
|
||||
assert_equal(self.nodes[2].getblockcount(), starting_blockcount)
|
||||
|
||||
self.log.info("Check that getheaders requests to node2 are ignored")
|
||||
peer = self.nodes[2].add_p2p_connection(P2PInterface())
|
||||
msg = msg_getheaders()
|
||||
msg.locator.vHave = [int(self.nodes[2].getbestblockhash(), 16)]
|
||||
msg.hashstop = 0
|
||||
peer.send_and_ping(msg)
|
||||
time.sleep(5)
|
||||
assert "headers" not in peer.last_message
|
||||
|
||||
self.log.info("Generating one more block")
|
||||
self.generate(self.nodes[0], 1)
|
||||
|
||||
@ -85,5 +98,13 @@ class MinimumChainWorkTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
self.log.info(f"Blockcounts: {[n.getblockcount() for n in self.nodes]}")
|
||||
|
||||
self.log.info("Test that getheaders requests to node2 are not ignored")
|
||||
peer.send_and_ping(msg)
|
||||
assert "headers" in peer.last_message
|
||||
|
||||
# Verify that node2 is in fact still in IBD (otherwise this test may
|
||||
# not be exercising the logic we want!)
|
||||
assert_equal(self.nodes[2].getblockchaininfo()['initialblockdownload'], True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
MinimumChainWorkTest().main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user