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