Skip to content

Commit a04888a

Browse files
author
MarcoFalke
committed
Merge #13915: [qa] Add test for max number of entries in locator
fa85c98 qa: Add p2p_invalid_locator test (MarcoFalke) Pull request description: Should not be merged *before* #13907 Tree-SHA512: a67ca407854c421ed20a184d0b0dc90085aed3e3431d9652a107fa3022244767e67f67e50449b7e95721f56906836b134615875f28a21e8a012eb22cfe6a66a5
2 parents a08533c + fa85c98 commit a04888a

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2015-2017 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+
"""Test node responses to invalid locators.
6+
"""
7+
8+
from test_framework.messages import msg_getheaders, msg_getblocks, MAX_LOCATOR_SZ
9+
from test_framework.mininode import P2PInterface
10+
from test_framework.test_framework import BitcoinTestFramework
11+
12+
13+
class InvalidLocatorTest(BitcoinTestFramework):
14+
def set_test_params(self):
15+
self.num_nodes = 1
16+
self.setup_clean_chain = False
17+
18+
def run_test(self):
19+
node = self.nodes[0] # convenience reference to the node
20+
node.generate(1) # Get node out of IBD
21+
22+
self.log.info('Test max locator size')
23+
block_count = node.getblockcount()
24+
for msg in [msg_getheaders(), msg_getblocks()]:
25+
self.log.info('Wait for disconnect when sending {} hashes in locator'.format(MAX_LOCATOR_SZ + 1))
26+
node.add_p2p_connection(P2PInterface())
27+
msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ + 1), -1)]
28+
node.p2p.send_message(msg)
29+
node.p2p.wait_for_disconnect()
30+
node.disconnect_p2ps()
31+
32+
self.log.info('Wait for response when sending {} hashes in locator'.format(MAX_LOCATOR_SZ))
33+
node.add_p2p_connection(P2PInterface())
34+
msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)]
35+
node.p2p.send_message(msg)
36+
if type(msg) == msg_getheaders:
37+
node.p2p.wait_for_header(int(node.getbestblockhash(), 16))
38+
else:
39+
node.p2p.wait_for_block(int(node.getbestblockhash(), 16))
40+
41+
42+
if __name__ == '__main__':
43+
InvalidLocatorTest().main()

test/functional/test_framework/messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
3333

3434
MAX_INV_SZ = 50000
35+
MAX_LOCATOR_SZ = 101
3536
MAX_BLOCK_BASE_SIZE = 1000000
3637

3738
COIN = 100000000 # 1 btc in satoshis

test/functional/test_framework/mininode.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ def wait_for_block(self, blockhash, timeout=60):
332332
test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
333333
wait_until(test_function, timeout=timeout, lock=mininode_lock)
334334

335+
def wait_for_header(self, blockhash, timeout=60):
336+
def test_function():
337+
last_headers = self.last_message.get('headers')
338+
if not last_headers:
339+
return False
340+
return last_headers.headers[0].rehash() == blockhash
341+
342+
wait_until(test_function, timeout=timeout, lock=mininode_lock)
343+
335344
def wait_for_getdata(self, timeout=60):
336345
"""Waits for a getdata message.
337346

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
'wallet_keypool.py',
116116
'p2p_mempool.py',
117117
'mining_prioritisetransaction.py',
118+
'p2p_invalid_locator.py',
118119
'p2p_invalid_block.py',
119120
'p2p_invalid_tx.py',
120121
'rpc_createmultisig.py',

0 commit comments

Comments
 (0)