@@ -5708,7 +5708,13 @@ mod tests {
5708
5708
get_announce_close_broadcast_events ( & nodes, 3 , 4 ) ;
5709
5709
assert_eq ! ( nodes[ 3 ] . node. list_channels( ) . len( ) , 0 ) ;
5710
5710
assert_eq ! ( nodes[ 4 ] . node. list_channels( ) . len( ) , 0 ) ;
5711
+ }
5712
+
5713
+ #[ test]
5714
+ fn test_justice_tx ( ) {
5715
+ // Test justice txn built on revoked HTLC-Success tx, against both sides
5711
5716
5717
+ let nodes = create_network ( 2 ) ;
5712
5718
// Create some new channels:
5713
5719
let chan_5 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
5714
5720
@@ -5747,6 +5753,45 @@ mod tests {
5747
5753
test_revoked_htlc_claim_txn_broadcast ( & nodes[ 1 ] , node_txn[ 1 ] . clone ( ) ) ;
5748
5754
}
5749
5755
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
5756
+
5757
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
5758
+ assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
5759
+
5760
+ // We test justice_tx build by A on B's revoked HTLC-Success tx
5761
+ // Create some new channels:
5762
+ let chan_6 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
5763
+
5764
+ // A pending HTLC which will be revoked:
5765
+ let payment_preimage_4 = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
5766
+ // Get the will-be-revoked local txn from B
5767
+ let revoked_local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . iter ( ) . next ( ) . unwrap ( ) . 1 . last_local_commitment_txn . clone ( ) ;
5768
+ assert_eq ! ( revoked_local_txn. len( ) , 1 ) ; // Only commitment tx
5769
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
5770
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_6. 3 . txid( ) ) ;
5771
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 2 ) ; // Only HTLC and output back to A are present
5772
+ // Revoke the old state
5773
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage_4) ;
5774
+ {
5775
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
5776
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
5777
+ {
5778
+ let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
5779
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
5780
+ assert_eq ! ( node_txn. pop( ) . unwrap( ) , node_txn[ 0 ] ) ; // An outpoint registration will result in a 2nd block_connected
5781
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ; // We claim the received HTLC output
5782
+
5783
+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
5784
+ node_txn. swap_remove ( 0 ) ;
5785
+ }
5786
+ test_txn_broadcast ( & nodes[ 0 ] , & chan_6, None , HTLCType :: NONE ) ;
5787
+
5788
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
5789
+ let node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_6, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , HTLCType :: SUCCESS ) ;
5790
+ header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
5791
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 1 ] . clone( ) ] } , 1 ) ;
5792
+ test_revoked_htlc_claim_txn_broadcast ( & nodes[ 0 ] , node_txn[ 1 ] . clone ( ) ) ;
5793
+ }
5794
+ get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
5750
5795
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
5751
5796
assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
5752
5797
}
0 commit comments