@@ -7873,4 +7873,75 @@ mod tests {
7873
7873
let spend_tx = check_static_output ! ( events, nodes, 1 , 2 , 1 , 0 ) ;
7874
7874
check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7875
7875
}
7876
+
7877
+ #[ test]
7878
+ fn test_dynamic_spendable_outputs_local_htlc_success_tx ( ) {
7879
+ let nodes = create_network ( 2 ) ;
7880
+
7881
+ // Create some initial channels
7882
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7883
+
7884
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 9000000 ) . 0 ;
7885
+ let local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7886
+ assert_eq ! ( local_txn[ 0 ] . input. len( ) , 1 ) ;
7887
+ check_spends ! ( local_txn[ 0 ] , chan_1. 3 . clone( ) ) ;
7888
+
7889
+ // Give B knowledge of preimage to be able to generate a local HTLC-Success Tx
7890
+ nodes[ 1 ] . node . claim_funds ( payment_preimage) ;
7891
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
7892
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7893
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7894
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7895
+ match events[ 0 ] {
7896
+ MessageSendEvent :: UpdateHTLCs { .. } => { } ,
7897
+ _ => panic ! ( "Unexpected event" ) ,
7898
+ }
7899
+ match events[ 1 ] {
7900
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7901
+ _ => panic ! ( "Unexepected event" ) ,
7902
+ }
7903
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7904
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
7905
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
7906
+ check_spends ! ( node_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7907
+
7908
+ // Verify that B is able to spend its own HTLC-Success tx thanks to spendable output event given back by its ChannelMonitor
7909
+ let spend_txn = check_dynamic_output ! ( nodes[ 1 ] ) ;
7910
+ assert_eq ! ( spend_txn. len( ) , 1 ) ;
7911
+ check_spends ! ( spend_txn[ 0 ] , node_txn[ 0 ] . clone( ) ) ;
7912
+ }
7913
+
7914
+ #[ test]
7915
+ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx ( ) {
7916
+ let nodes = create_network ( 2 ) ;
7917
+
7918
+ // Create some initial channels
7919
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7920
+
7921
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 9000000 ) . 0 ;
7922
+ let local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7923
+ assert_eq ! ( local_txn[ 0 ] . input. len( ) , 1 ) ;
7924
+ check_spends ! ( local_txn[ 0 ] , chan_1. 3 . clone( ) ) ;
7925
+
7926
+ // Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
7927
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7928
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ local_txn[ 0 ] . clone( ) ] } , 200 ) ;
7929
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7930
+ match events[ 0 ] {
7931
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7932
+ _ => panic ! ( "Unexepected event" ) ,
7933
+ }
7934
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7935
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
7936
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
7937
+ check_spends ! ( node_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7938
+
7939
+ // Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
7940
+ let spend_txn = check_dynamic_output ! ( nodes[ 0 ] ) ;
7941
+ assert_eq ! ( spend_txn. len( ) , 4 ) ;
7942
+ assert_eq ! ( spend_txn[ 0 ] , spend_txn[ 2 ] ) ;
7943
+ assert_eq ! ( spend_txn[ 1 ] , spend_txn[ 3 ] ) ;
7944
+ check_spends ! ( spend_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7945
+ check_spends ! ( spend_txn[ 1 ] , node_txn[ 0 ] . clone( ) ) ;
7946
+ }
7876
7947
}
0 commit comments