@@ -764,6 +764,54 @@ def request_cb_announcements(self, peer, node, version):
764
764
msg .announce = True
765
765
peer .send_and_ping (msg )
766
766
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 )
767
815
768
816
def run_test (self ):
769
817
# Setup the p2p connections and start up the network thread.
@@ -848,6 +896,10 @@ def run_test(self):
848
896
self .test_invalid_tx_in_compactblock (self .nodes [1 ], self .segwit_node , False )
849
897
self .test_invalid_tx_in_compactblock (self .nodes [1 ], self .old_node , False )
850
898
899
+ print ("\t Testing 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
+
851
903
# Advance to segwit activation
852
904
print ("\n Advancing to segwit activation\n " )
853
905
self .activate_segwit (self .nodes [1 ])
0 commit comments