@@ -3209,7 +3209,7 @@ mod tests {
3209
3209
use chain:: chaininterface;
3210
3210
use chain:: transaction:: OutPoint ;
3211
3211
use chain:: chaininterface:: { ChainListener , ChainWatchInterface } ;
3212
- use chain:: keysinterface:: KeysInterface ;
3212
+ use chain:: keysinterface:: { KeysInterface , SpendableOutputDescriptor } ;
3213
3213
use chain:: keysinterface;
3214
3214
use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , OnionKeys , PaymentFailReason , RAACommitmentOrder } ;
3215
3215
use ln:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdateErr , CLTV_CLAIM_BUFFER , HTLC_FAIL_TIMEOUT_BLOCKS , ManyChannelMonitor } ;
@@ -3224,8 +3224,11 @@ mod tests {
3224
3224
use util:: config:: UserConfig ;
3225
3225
3226
3226
use bitcoin:: util:: hash:: { BitcoinHash , Sha256dHash } ;
3227
+ use bitcoin:: util:: bip143;
3227
3228
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
3228
- use bitcoin:: blockdata:: transaction:: { Transaction , TxOut } ;
3229
+ use bitcoin:: blockdata:: transaction:: { Transaction , TxOut , TxIn , SigHashType } ;
3230
+ use bitcoin:: blockdata:: script:: { Builder , Script } ;
3231
+ use bitcoin:: blockdata:: opcodes;
3229
3232
use bitcoin:: blockdata:: constants:: genesis_block;
3230
3233
use bitcoin:: network:: constants:: Network ;
3231
3234
@@ -7532,4 +7535,76 @@ mod tests {
7532
7535
assert_eq ! ( msg. channel_id, channel_id) ;
7533
7536
} else { panic ! ( "Unexpected result" ) ; }
7534
7537
}
7538
+
7539
+ macro_rules! check_dynamic_output {
7540
+ ( $node: expr) => {
7541
+ {
7542
+ let events = $node. chan_monitor. simple_monitor. get_and_clear_pending_events( ) ;
7543
+ let mut txn = Vec :: new( ) ;
7544
+ for event in events {
7545
+ match event {
7546
+ Event :: SpendableOutputs { ref outputs } => {
7547
+ for outp in outputs {
7548
+ match * outp {
7549
+ SpendableOutputDescriptor :: DynamicOutput { ref outpoint, ref local_delayedkey, ref witness_script, ref to_self_delay, ref output } => {
7550
+ let input = TxIn {
7551
+ previous_output: outpoint. clone( ) ,
7552
+ script_sig: Script :: new( ) ,
7553
+ sequence: * to_self_delay as u32 ,
7554
+ witness: Vec :: new( ) ,
7555
+ } ;
7556
+ let outp = TxOut {
7557
+ script_pubkey: Builder :: new( ) . push_opcode( opcodes:: All :: OP_RETURN ) . into_script( ) ,
7558
+ value: output. value,
7559
+ } ;
7560
+ let mut spend_tx = Transaction {
7561
+ version: 2 ,
7562
+ lock_time: 0 ,
7563
+ input: vec![ input] ,
7564
+ output: vec![ outp] ,
7565
+ } ;
7566
+ let sighash = Message :: from_slice( & bip143:: SighashComponents :: new( & spend_tx) . sighash_all( & spend_tx. input[ 0 ] , witness_script, output. value) [ ..] ) . unwrap( ) ;
7567
+ let secp_ctx = Secp256k1 :: new( ) ;
7568
+ let local_delaysig = secp_ctx. sign( & sighash, local_delayedkey) ;
7569
+ spend_tx. input[ 0 ] . witness. push( local_delaysig. serialize_der( & secp_ctx) . to_vec( ) ) ;
7570
+ spend_tx. input[ 0 ] . witness[ 0 ] . push( SigHashType :: All as u8 ) ;
7571
+ spend_tx. input[ 0 ] . witness. push( vec!( 0 ) ) ;
7572
+ spend_tx. input[ 0 ] . witness. push( witness_script. clone( ) . into_bytes( ) ) ;
7573
+ txn. push( spend_tx) ;
7574
+ } ,
7575
+ _ => panic!( "Unexpected event" ) ,
7576
+ }
7577
+ }
7578
+ } ,
7579
+ _ => panic!( "Unexpected event" ) ,
7580
+ } ;
7581
+ }
7582
+ txn
7583
+ }
7584
+ }
7585
+ }
7586
+
7587
+ #[ test]
7588
+ fn test_claim_sizeable_push_msat ( ) {
7589
+ // Incidentally test SpendableOutput event generation due to detection of to_local output on commitment tx
7590
+ let nodes = create_network ( 2 ) ;
7591
+
7592
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 99000000 ) ;
7593
+ nodes[ 1 ] . node . force_close_channel ( & chan. 2 ) ;
7594
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7595
+ match events[ 0 ] {
7596
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7597
+ _ => panic ! ( "Unexpected event" ) ,
7598
+ }
7599
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7600
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
7601
+ check_spends ! ( node_txn[ 0 ] , chan. 3 . clone( ) ) ;
7602
+ assert_eq ! ( node_txn[ 0 ] . output. len( ) , 2 ) ; // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
7603
+
7604
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7605
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 0 ) ;
7606
+ let spend_txn = check_dynamic_output ! ( nodes[ 1 ] ) ;
7607
+ assert_eq ! ( spend_txn. len( ) , 1 ) ;
7608
+ check_spends ! ( spend_txn[ 0 ] , node_txn[ 0 ] . clone( ) ) ;
7609
+ }
7535
7610
}
0 commit comments