forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge bitcoin#28287: add
sendmsgtopeer
rpc and a test for net-level…
… deadlock situation `random_bytes()` is introduced in bitcoin#25625 but the function def alone doesn't warrant a full backport, so we'll only implement the section relevant to this PR.
- Loading branch information
Showing
7 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2023-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. | ||
|
||
import threading | ||
from test_framework.messages import MAX_PROTOCOL_MESSAGE_LENGTH | ||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import random_bytes | ||
|
||
class NetDeadlockTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 2 | ||
|
||
def run_test(self): | ||
node0 = self.nodes[0] | ||
node1 = self.nodes[1] | ||
|
||
self.log.info("Simultaneously send a large message on both sides") | ||
rand_msg = random_bytes(MAX_PROTOCOL_MESSAGE_LENGTH).hex() | ||
|
||
thread0 = threading.Thread(target=node0.sendmsgtopeer, args=(0, "unknown", rand_msg)) | ||
thread1 = threading.Thread(target=node1.sendmsgtopeer, args=(0, "unknown", rand_msg)) | ||
|
||
thread0.start() | ||
thread1.start() | ||
thread0.join() | ||
thread1.join() | ||
|
||
self.log.info("Check whether a deadlock happened") | ||
self.nodes[0].generate(1) | ||
self.sync_blocks() | ||
|
||
|
||
if __name__ == '__main__': | ||
NetDeadlockTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters