p2p_net_deadlock.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2023-present The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 import threading
7 from test_framework.test_framework import BitcoinTestFramework
8 from random import randbytes
9
10
11 class NetDeadlockTest(BitcoinTestFramework):
12 def set_test_params(self):
13 self.setup_clean_chain = True
14 self.num_nodes = 2
15
16 def run_test(self):
17 node0 = self.nodes[0]
18 node1 = self.nodes[1]
19
20 self.log.info("Simultaneously send a large message on both sides")
21 rand_msg = randbytes(4000000).hex()
22
23 thread0 = threading.Thread(target=node0.sendmsgtopeer, args=(0, "unknown", rand_msg))
24 thread1 = threading.Thread(target=node1.sendmsgtopeer, args=(0, "unknown", rand_msg))
25
26 thread0.start()
27 thread1.start()
28 thread0.join()
29 thread1.join()
30
31 self.log.info("Check whether a deadlock happened")
32 self.generate(node0, 1)
33 self.sync_blocks()
34
35
36 if __name__ == '__main__':
37 NetDeadlockTest(__file__).main()
38