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