@@ -4129,6 +4129,59 @@ fn test_static_spendable_outputs_preimage_tx() {
4129
4129
check_spends ! ( spend_txn[ 0 ] , node_txn[ 0 ] ) ;
4130
4130
}
4131
4131
4132
+ #[ test]
4133
+ fn test_static_spendable_outputs_timeout_tx ( ) {
4134
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
4135
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
4136
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
4137
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
4138
+
4139
+ // Create some initial channels
4140
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
4141
+
4142
+ // Rebalance the network a bit by relaying one payment through all the channels ...
4143
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 8000000 , 8_000_000 ) ;
4144
+
4145
+ let ( _, our_payment_hash) = route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3_000_000 ) ;
4146
+
4147
+ let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get_mut ( & chan_1. 2 ) . unwrap ( ) . channel_monitor ( ) . get_latest_local_commitment_txn ( ) ;
4148
+ assert_eq ! ( commitment_tx[ 0 ] . input. len( ) , 1 ) ;
4149
+ assert_eq ! ( commitment_tx[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
4150
+
4151
+ // Settle A's commitment tx on B' chain
4152
+ let header = BlockHeader { version : 0x2000_0000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
4153
+ nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 0 ) ;
4154
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
4155
+ match events[ 0 ] {
4156
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
4157
+ _ => panic ! ( "Unexpected event" ) ,
4158
+ }
4159
+
4160
+ // Check B's monitor was able to send back output descriptor event for timeout tx on A's commitment tx
4161
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
4162
+ assert_eq ! ( node_txn. len( ) , 3 ) ; // ChannelManager : 2 (local commitent tx + HTLC-timeout), ChannelMonitor: timeout tx
4163
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4164
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , ACCEPTED_HTLC_SCRIPT_WEIGHT ) ;
4165
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4166
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] ) ;
4167
+
4168
+ let header_1 = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
4169
+ nodes[ 1 ] . block_notifier . block_connected ( & Block { header : header_1, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
4170
+ connect_blocks ( & nodes[ 1 ] . block_notifier , ANTI_REORG_DELAY - 1 , 1 , true , header. bitcoin_hash ( ) ) ;
4171
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4172
+ assert_eq ! ( events. len( ) , 1 ) ;
4173
+ match events[ 0 ] {
4174
+ Event :: PaymentFailed { payment_hash, .. } => {
4175
+ assert_eq ! ( payment_hash, our_payment_hash) ;
4176
+ } ,
4177
+ _ => panic ! ( "Unexpected event" ) ,
4178
+ }
4179
+
4180
+ let spend_txn = check_spendable_outputs ! ( nodes[ 1 ] , 1 ) ;
4181
+ assert_eq ! ( spend_txn. len( ) , 3 ) ; // SpendableOutput: remote_commitment_tx.to_remote (*2), timeout_tx.output (*1)
4182
+ check_spends ! ( spend_txn[ 2 ] , node_txn[ 0 ] . clone( ) ) ;
4183
+ }
4184
+
4132
4185
#[ test]
4133
4186
fn test_static_spendable_outputs_justice_tx_revoked_commitment_tx ( ) {
4134
4187
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
0 commit comments