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