Skip to content

Commit

Permalink
[qa] Respond to getheaders and do not assume a getdata on inv
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Nov 7, 2016
1 parent d768f15 commit 3451203
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
7 changes: 7 additions & 0 deletions qa/rpc-tests/p2p-compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
self.last_cmpctblock = None
self.block_announced = False
self.last_getdata = None
self.last_getheaders = None
self.last_getblocktxn = None
self.last_block = None
self.last_blocktxn = None
Expand Down Expand Up @@ -64,6 +65,9 @@ def on_inv(self, conn, message):
def on_getdata(self, conn, message):
self.last_getdata = message

def on_getheaders(self, conn, message):
self.last_getheaders = message

def on_getblocktxn(self, conn, message):
self.last_getblocktxn = message

Expand Down Expand Up @@ -393,6 +397,9 @@ def test_compactblock_requests(self, node, test_node, version, segwit):

if announce == "inv":
test_node.send_message(msg_inv([CInv(2, block.sha256)]))
success = wait_until(lambda: test_node.last_getheaders is not None, timeout=30)
assert(success)
test_node.send_header_for_blocks([block])
else:
test_node.send_header_for_blocks([block])
success = wait_until(lambda: test_node.last_getdata is not None, timeout=30)
Expand Down
14 changes: 12 additions & 2 deletions qa/rpc-tests/p2p-segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def on_getdata(self, conn, message):
self.getdataset.add(inv.hash)
self.last_getdata = message

def on_getheaders(self, conn, message):
self.last_getheaders = message

def on_pong(self, conn, message):
self.last_pong = message

Expand Down Expand Up @@ -97,6 +100,10 @@ def wait_for_getdata(self, timeout=60):
test_function = lambda: self.last_getdata != None
self.sync(test_function, timeout)

def wait_for_getheaders(self, timeout=60):
test_function = lambda: self.last_getheaders != None
self.sync(test_function, timeout)

def wait_for_inv(self, expected_inv, timeout=60):
test_function = lambda: self.last_inv != expected_inv
self.sync(test_function, timeout)
Expand All @@ -111,12 +118,15 @@ def announce_tx_and_wait_for_getdata(self, tx, timeout=60):
def announce_block_and_wait_for_getdata(self, block, use_header, timeout=60):
with mininode_lock:
self.last_getdata = None
self.last_getheaders = None
msg = msg_headers()
msg.headers = [ CBlockHeader(block) ]
if use_header:
msg = msg_headers()
msg.headers = [ CBlockHeader(block) ]
self.send_message(msg)
else:
self.send_message(msg_inv(inv=[CInv(2, block.sha256)]))
self.wait_for_getheaders()
self.send_message(msg)
self.wait_for_getdata()
return

Expand Down
11 changes: 5 additions & 6 deletions qa/rpc-tests/sendheaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,13 @@ def run_test(self):
if j == 0:
# Announce via inv
test_node.send_block_inv(tip)
test_node.wait_for_getdata([tip], timeout=5)
test_node.wait_for_getheaders(timeout=5)
# Should have received a getheaders now
test_node.send_header_for_blocks(blocks)
# Test that duplicate inv's won't result in duplicate
# getdata requests, or duplicate headers announcements
inv_node.send_block_inv(tip)
# Should have received a getheaders as well!
test_node.send_header_for_blocks(blocks)
test_node.wait_for_getdata([x.sha256 for x in blocks[0:-1]], timeout=5)
[ inv_node.send_block_inv(x.sha256) for x in blocks[0:-1] ]
[ inv_node.send_block_inv(x.sha256) for x in blocks ]
test_node.wait_for_getdata([x.sha256 for x in blocks], timeout=5)
inv_node.sync_with_ping()
else:
# Announce via headers
Expand Down

0 comments on commit 3451203

Please sign in to comment.