@@ -7723,4 +7723,99 @@ mod tests {
7723
7723
let spend_tx = check_static_output ! ( events, nodes, 0 , 0 , 1 , 1 ) ;
7724
7724
check_spends ! ( spend_tx, node_txn[ 0 ] . clone( ) ) ;
7725
7725
}
7726
+
7727
+ #[ test]
7728
+ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx ( ) {
7729
+ let nodes = create_network ( 2 ) ;
7730
+
7731
+ // Create some initial channels
7732
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7733
+
7734
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
7735
+ let revoked_local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7736
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
7737
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
7738
+
7739
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage) ;
7740
+
7741
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7742
+ // A will generate HTLC-Timeout from revoked commitment tx
7743
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7744
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7745
+ match events[ 0 ] {
7746
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7747
+ _ => panic ! ( "Unexpected event" ) ,
7748
+ }
7749
+ let revoked_htlc_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7750
+ assert_eq ! ( revoked_htlc_txn. len( ) , 2 ) ;
7751
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input. len( ) , 1 ) ;
7752
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
7753
+ check_spends ! ( revoked_htlc_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
7754
+
7755
+ // B will generate justice tx from A's revoked commitment/HTLC tx
7756
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 0 ] . clone( ) ] } , 1 ) ;
7757
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7758
+ match events[ 0 ] {
7759
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7760
+ _ => panic ! ( "Unexpected event" ) ,
7761
+ }
7762
+
7763
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7764
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
7765
+ assert_eq ! ( node_txn[ 3 ] . input. len( ) , 1 ) ;
7766
+ check_spends ! ( node_txn[ 3 ] , revoked_htlc_txn[ 0 ] . clone( ) ) ;
7767
+
7768
+ let events = nodes[ 1 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7769
+ // Check B's ChannelMonitor was able to generate the right spendable output descriptor
7770
+ let spend_tx = check_static_output ! ( events, nodes, 1 , 1 , 1 , 1 ) ;
7771
+ check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7772
+ }
7773
+
7774
+ #[ test]
7775
+ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx ( ) {
7776
+ let nodes = create_network ( 2 ) ;
7777
+
7778
+ // Create some initial channels
7779
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7780
+
7781
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
7782
+ let revoked_local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7783
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
7784
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
7785
+
7786
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage) ;
7787
+
7788
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7789
+ // B will generate HTLC-Success from revoked commitment tx
7790
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7791
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7792
+ match events[ 0 ] {
7793
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7794
+ _ => panic ! ( "Unexpected event" ) ,
7795
+ }
7796
+ let revoked_htlc_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7797
+
7798
+ assert_eq ! ( revoked_htlc_txn. len( ) , 2 ) ;
7799
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input. len( ) , 1 ) ;
7800
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
7801
+ check_spends ! ( revoked_htlc_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
7802
+
7803
+ // A will generate justice tx from B's revoked commitment/HTLC tx
7804
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 0 ] . clone( ) ] } , 1 ) ;
7805
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7806
+ match events[ 0 ] {
7807
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7808
+ _ => panic ! ( "Unexpected event" ) ,
7809
+ }
7810
+
7811
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7812
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
7813
+ assert_eq ! ( node_txn[ 3 ] . input. len( ) , 1 ) ;
7814
+ check_spends ! ( node_txn[ 3 ] , revoked_htlc_txn[ 0 ] . clone( ) ) ;
7815
+
7816
+ let events = nodes[ 0 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7817
+ // Check A's ChannelMonitor was able to generate the right spendable output descriptor
7818
+ let spend_tx = check_static_output ! ( events, nodes, 1 , 2 , 1 , 0 ) ;
7819
+ check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7820
+ }
7726
7821
}
0 commit comments