@@ -7813,4 +7813,99 @@ mod tests {
7813
7813
let spend_tx = check_static_output ! ( events, nodes, 0 , 0 , 1 , 1 ) ;
7814
7814
check_spends ! ( spend_tx, node_txn[ 0 ] . clone( ) ) ;
7815
7815
}
7816
+
7817
+ #[ test]
7818
+ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx ( ) {
7819
+ let nodes = create_network ( 2 ) ;
7820
+
7821
+ // Create some initial channels
7822
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7823
+
7824
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
7825
+ let revoked_local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7826
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
7827
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
7828
+
7829
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage) ;
7830
+
7831
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7832
+ // A will generate HTLC-Timeout from revoked commitment tx
7833
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7834
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7835
+ match events[ 0 ] {
7836
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7837
+ _ => panic ! ( "Unexpected event" ) ,
7838
+ }
7839
+ let revoked_htlc_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7840
+ assert_eq ! ( revoked_htlc_txn. len( ) , 2 ) ;
7841
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input. len( ) , 1 ) ;
7842
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
7843
+ check_spends ! ( revoked_htlc_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
7844
+
7845
+ // B will generate justice tx from A's revoked commitment/HTLC tx
7846
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 0 ] . clone( ) ] } , 1 ) ;
7847
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7848
+ match events[ 0 ] {
7849
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7850
+ _ => panic ! ( "Unexpected event" ) ,
7851
+ }
7852
+
7853
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7854
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
7855
+ assert_eq ! ( node_txn[ 3 ] . input. len( ) , 1 ) ;
7856
+ check_spends ! ( node_txn[ 3 ] , revoked_htlc_txn[ 0 ] . clone( ) ) ;
7857
+
7858
+ let events = nodes[ 1 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7859
+ // Check B's ChannelMonitor was able to generate the right spendable output descriptor
7860
+ let spend_tx = check_static_output ! ( events, nodes, 1 , 1 , 1 , 1 ) ;
7861
+ check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7862
+ }
7863
+
7864
+ #[ test]
7865
+ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx ( ) {
7866
+ let nodes = create_network ( 2 ) ;
7867
+
7868
+ // Create some initial channels
7869
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7870
+
7871
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
7872
+ let revoked_local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7873
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
7874
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
7875
+
7876
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage) ;
7877
+
7878
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7879
+ // B will generate HTLC-Success from revoked commitment tx
7880
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7881
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7882
+ match events[ 0 ] {
7883
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7884
+ _ => panic ! ( "Unexpected event" ) ,
7885
+ }
7886
+ let revoked_htlc_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7887
+
7888
+ assert_eq ! ( revoked_htlc_txn. len( ) , 2 ) ;
7889
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input. len( ) , 1 ) ;
7890
+ assert_eq ! ( revoked_htlc_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
7891
+ check_spends ! ( revoked_htlc_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
7892
+
7893
+ // A will generate justice tx from B's revoked commitment/HTLC tx
7894
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 0 ] . clone( ) ] } , 1 ) ;
7895
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7896
+ match events[ 0 ] {
7897
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7898
+ _ => panic ! ( "Unexpected event" ) ,
7899
+ }
7900
+
7901
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7902
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
7903
+ assert_eq ! ( node_txn[ 3 ] . input. len( ) , 1 ) ;
7904
+ check_spends ! ( node_txn[ 3 ] , revoked_htlc_txn[ 0 ] . clone( ) ) ;
7905
+
7906
+ let events = nodes[ 0 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7907
+ // Check A's ChannelMonitor was able to generate the right spendable output descriptor
7908
+ let spend_tx = check_static_output ! ( events, nodes, 1 , 2 , 1 , 0 ) ;
7909
+ check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7910
+ }
7816
7911
}
0 commit comments