@@ -7908,4 +7908,75 @@ mod tests {
7908
7908
let spend_tx = check_static_output ! ( events, nodes, 1 , 2 , 1 , 0 ) ;
7909
7909
check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7910
7910
}
7911
+
7912
+ #[ test]
7913
+ fn test_dynamic_spendable_outputs_local_htlc_success_tx ( ) {
7914
+ let nodes = create_network ( 2 ) ;
7915
+
7916
+ // Create some initial channels
7917
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7918
+
7919
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 9000000 ) . 0 ;
7920
+ let local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7921
+ assert_eq ! ( local_txn[ 0 ] . input. len( ) , 1 ) ;
7922
+ check_spends ! ( local_txn[ 0 ] , chan_1. 3 . clone( ) ) ;
7923
+
7924
+ // Give B knowledge of preimage to be able to generate a local HTLC-Success Tx
7925
+ nodes[ 1 ] . node . claim_funds ( payment_preimage) ;
7926
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
7927
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7928
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7929
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7930
+ match events[ 0 ] {
7931
+ MessageSendEvent :: UpdateHTLCs { .. } => { } ,
7932
+ _ => panic ! ( "Unexpected event" ) ,
7933
+ }
7934
+ match events[ 1 ] {
7935
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7936
+ _ => panic ! ( "Unexepected event" ) ,
7937
+ }
7938
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7939
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
7940
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
7941
+ check_spends ! ( node_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7942
+
7943
+ // Verify that B is able to spend its own HTLC-Success tx thanks to spendable output event given back by its ChannelMonitor
7944
+ let spend_txn = check_dynamic_output_p2wsh ! ( nodes[ 1 ] ) ;
7945
+ assert_eq ! ( spend_txn. len( ) , 1 ) ;
7946
+ check_spends ! ( spend_txn[ 0 ] , node_txn[ 0 ] . clone( ) ) ;
7947
+ }
7948
+
7949
+ #[ test]
7950
+ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx ( ) {
7951
+ let nodes = create_network ( 2 ) ;
7952
+
7953
+ // Create some initial channels
7954
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7955
+
7956
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 9000000 ) . 0 ;
7957
+ let local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7958
+ assert_eq ! ( local_txn[ 0 ] . input. len( ) , 1 ) ;
7959
+ check_spends ! ( local_txn[ 0 ] , chan_1. 3 . clone( ) ) ;
7960
+
7961
+ // Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
7962
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7963
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ local_txn[ 0 ] . clone( ) ] } , 200 ) ;
7964
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7965
+ match events[ 0 ] {
7966
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7967
+ _ => panic ! ( "Unexepected event" ) ,
7968
+ }
7969
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7970
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
7971
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
7972
+ check_spends ! ( node_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7973
+
7974
+ // Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
7975
+ let spend_txn = check_dynamic_output_p2wsh ! ( nodes[ 0 ] ) ;
7976
+ assert_eq ! ( spend_txn. len( ) , 4 ) ;
7977
+ assert_eq ! ( spend_txn[ 0 ] , spend_txn[ 2 ] ) ;
7978
+ assert_eq ! ( spend_txn[ 1 ] , spend_txn[ 3 ] ) ;
7979
+ check_spends ! ( spend_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7980
+ check_spends ! ( spend_txn[ 1 ] , node_txn[ 0 ] . clone( ) ) ;
7981
+ }
7911
7982
}
0 commit comments