Skip to content

Commit 813ede9

Browse files
committed
[qa] Update compactblocks test for multi-peer reconstruction
1 parent 7017298 commit 813ede9

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

qa/rpc-tests/p2p-compactblocks.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,54 @@ def request_cb_announcements(self, peer, node, version):
764764
msg.announce = True
765765
peer.send_and_ping(msg)
766766

767+
def test_compactblock_reconstruction_multiple_peers(self, node, stalling_peer, delivery_peer):
768+
assert(len(self.utxos))
769+
770+
def announce_cmpct_block(node, peer):
771+
utxo = self.utxos.pop(0)
772+
block = self.build_block_with_transactions(node, utxo, 5)
773+
774+
cmpct_block = HeaderAndShortIDs()
775+
cmpct_block.initialize_from_block(block)
776+
msg = msg_cmpctblock(cmpct_block.to_p2p())
777+
peer.send_and_ping(msg)
778+
with mininode_lock:
779+
assert(peer.last_getblocktxn is not None)
780+
return block, cmpct_block
781+
782+
block, cmpct_block = announce_cmpct_block(node, stalling_peer)
783+
784+
for tx in block.vtx[1:]:
785+
delivery_peer.send_message(msg_tx(tx))
786+
delivery_peer.sync_with_ping()
787+
mempool = node.getrawmempool()
788+
for tx in block.vtx[1:]:
789+
assert(tx.hash in mempool)
790+
791+
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
792+
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
793+
794+
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
795+
796+
# Now test that delivering an invalid compact block won't break relay
797+
798+
block, cmpct_block = announce_cmpct_block(node, stalling_peer)
799+
for tx in block.vtx[1:]:
800+
delivery_peer.send_message(msg_tx(tx))
801+
delivery_peer.sync_with_ping()
802+
803+
cmpct_block.prefilled_txn[0].tx.wit.vtxinwit = [ CTxInWitness() ]
804+
cmpct_block.prefilled_txn[0].tx.wit.vtxinwit[0].scriptWitness.stack = [ser_uint256(0)]
805+
806+
cmpct_block.use_witness = True
807+
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
808+
assert(int(node.getbestblockhash(), 16) != block.sha256)
809+
810+
msg = msg_blocktxn()
811+
msg.block_transactions.blockhash = block.sha256
812+
msg.block_transactions.transactions = block.vtx[1:]
813+
stalling_peer.send_and_ping(msg)
814+
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
767815

768816
def run_test(self):
769817
# Setup the p2p connections and start up the network thread.
@@ -848,6 +896,10 @@ def run_test(self):
848896
self.test_invalid_tx_in_compactblock(self.nodes[1], self.segwit_node, False)
849897
self.test_invalid_tx_in_compactblock(self.nodes[1], self.old_node, False)
850898

899+
print("\tTesting reconstructing compact blocks from all peers...")
900+
self.test_compactblock_reconstruction_multiple_peers(self.nodes[1], self.segwit_node, self.old_node)
901+
sync_blocks(self.nodes)
902+
851903
# Advance to segwit activation
852904
print ("\nAdvancing to segwit activation\n")
853905
self.activate_segwit(self.nodes[1])

0 commit comments

Comments
 (0)