@@ -7818,4 +7818,73 @@ mod tests {
7818
7818
let spend_tx = check_static_output ! ( events, nodes, 1 , 2 , 1 , 0 ) ;
7819
7819
check_spends ! ( spend_tx, node_txn[ 3 ] . clone( ) ) ;
7820
7820
}
7821
+
7822
+ #[ test]
7823
+ fn test_dynamic_spendable_outputs_local_htlc_success_tx ( ) {
7824
+ let nodes = create_network ( 2 ) ;
7825
+
7826
+ // Create some initial channels
7827
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7828
+
7829
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 9000000 ) . 0 ;
7830
+ let local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7831
+ assert_eq ! ( local_txn[ 0 ] . input. len( ) , 1 ) ;
7832
+ check_spends ! ( local_txn[ 0 ] , chan_1. 3 . clone( ) ) ;
7833
+
7834
+ // Give B knowledge of preimage to be able to generate a local HTLC-Success Tx
7835
+ nodes[ 1 ] . node . claim_funds ( payment_preimage) ;
7836
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
7837
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7838
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ local_txn[ 0 ] . clone( ) ] } , 1 ) ;
7839
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7840
+ match events[ 0 ] {
7841
+ MessageSendEvent :: UpdateHTLCs { .. } => { } ,
7842
+ _ => panic ! ( "Unexpected event" ) ,
7843
+ }
7844
+ match events[ 1 ] {
7845
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7846
+ _ => panic ! ( "Unexepected event" ) ,
7847
+ }
7848
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7849
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
7850
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
7851
+ check_spends ! ( node_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7852
+
7853
+ // Verify that B is able to spend its own HTLC-Success tx thanks to spendable output event given back by its ChannelMonitor
7854
+ let events = nodes[ 1 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7855
+ let spend_tx = check_dynamic_output ! ( events, 0 , 0 , node_txn[ 0 ] . output[ 0 ] . value) ;
7856
+ check_spends ! ( spend_tx, node_txn[ 0 ] . clone( ) ) ;
7857
+ }
7858
+
7859
+ #[ test]
7860
+ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx ( ) {
7861
+ let nodes = create_network ( 2 ) ;
7862
+
7863
+ // Create some initial channels
7864
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7865
+
7866
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 9000000 ) . 0 ;
7867
+ let local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
7868
+ assert_eq ! ( local_txn[ 0 ] . input. len( ) , 1 ) ;
7869
+ check_spends ! ( local_txn[ 0 ] , chan_1. 3 . clone( ) ) ;
7870
+
7871
+ // Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
7872
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7873
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ local_txn[ 0 ] . clone( ) ] } , 200 ) ;
7874
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7875
+ println ! ( "events {}" , events. len( ) ) ;
7876
+ match events[ 0 ] {
7877
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7878
+ _ => panic ! ( "Unexepected event" ) ,
7879
+ }
7880
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7881
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
7882
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
7883
+ check_spends ! ( node_txn[ 0 ] , local_txn[ 0 ] . clone( ) ) ;
7884
+
7885
+ // Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
7886
+ let events = nodes[ 0 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7887
+ let spend_tx = check_dynamic_output ! ( events, 0 , 1 , node_txn[ 0 ] . output[ 0 ] . value) ;
7888
+ check_spends ! ( spend_tx, node_txn[ 0 ] . clone( ) ) ;
7889
+ }
7821
7890
}
0 commit comments