99
1010//! Further functional tests which test blockchain reorganizations.
1111
12- use crate :: sign:: EcdsaChannelSigner ;
12+ use crate :: sign:: { EcdsaChannelSigner , SpendableOutputDescriptor } ;
1313use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , LATENCY_GRACE_PERIOD_BLOCKS , Balance } ;
1414use crate :: chain:: transaction:: OutPoint ;
1515use crate :: chain:: chaininterface:: { LowerBoundedFeeEstimator , compute_feerate_sat_per_1000_weight} ;
@@ -21,6 +21,7 @@ use crate::ln::msgs::ChannelMessageHandler;
2121use crate :: util:: config:: UserConfig ;
2222use crate :: util:: crypto:: sign;
2323use crate :: util:: ser:: Writeable ;
24+ use crate :: util:: scid_utils:: block_from_scid;
2425use crate :: util:: test_utils;
2526
2627use bitcoin:: blockdata:: transaction:: EcdsaSighashType ;
@@ -92,14 +93,15 @@ fn chanmon_fail_from_stale_commitment() {
9293 expect_payment_failed_with_update ! ( nodes[ 0 ] , payment_hash, false , update_a. contents. short_channel_id, true ) ;
9394}
9495
95- fn test_spendable_output < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , spendable_tx : & Transaction ) {
96+ fn test_spendable_output < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , spendable_tx : & Transaction ) -> SpendableOutputDescriptor {
9697 let mut spendable = node. chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
9798 assert_eq ! ( spendable. len( ) , 1 ) ;
98- if let Event :: SpendableOutputs { outputs, .. } = spendable. pop ( ) . unwrap ( ) {
99+ if let Event :: SpendableOutputs { mut outputs, .. } = spendable. pop ( ) . unwrap ( ) {
99100 assert_eq ! ( outputs. len( ) , 1 ) ;
100101 let spend_tx = node. keys_manager . backing . spend_spendable_outputs ( & [ & outputs[ 0 ] ] , Vec :: new ( ) ,
101102 Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_RETURN ) . into_script ( ) , 253 , None , & Secp256k1 :: new ( ) ) . unwrap ( ) ;
102103 check_spends ! ( spend_tx, spendable_tx) ;
104+ outputs. pop ( ) . unwrap ( )
103105 } else { panic ! ( ) ; }
104106}
105107
@@ -196,8 +198,8 @@ fn chanmon_claim_value_coop_close() {
196198 assert_eq ! ( shutdown_tx, nodes[ 1 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . split_off( 0 ) ) ;
197199 assert_eq ! ( shutdown_tx. len( ) , 1 ) ;
198200
199- mine_transaction ( & nodes[ 0 ] , & shutdown_tx[ 0 ] ) ;
200- mine_transaction ( & nodes[ 1 ] , & shutdown_tx[ 0 ] ) ;
201+ let shutdown_tx_conf_height_a = block_from_scid ( & mine_transaction ( & nodes[ 0 ] , & shutdown_tx[ 0 ] ) ) ;
202+ let shutdown_tx_conf_height_b = block_from_scid ( & mine_transaction ( & nodes[ 1 ] , & shutdown_tx[ 0 ] ) ) ;
201203
202204 assert ! ( nodes[ 0 ] . node. list_channels( ) . is_empty( ) ) ;
203205 assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
@@ -216,16 +218,35 @@ fn chanmon_claim_value_coop_close() {
216218 } ] ,
217219 nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
218220
219- connect_blocks ( & nodes[ 0 ] , ANTI_REORG_DELAY - 1 ) ;
220- connect_blocks ( & nodes[ 1 ] , ANTI_REORG_DELAY - 1 ) ;
221+ connect_blocks ( & nodes[ 0 ] , ANTI_REORG_DELAY - 2 ) ;
222+ connect_blocks ( & nodes[ 1 ] , ANTI_REORG_DELAY - 2 ) ;
223+
224+ assert ! ( get_monitor!( nodes[ 0 ] , chan_id)
225+ . get_spendable_output( & shutdown_tx[ 0 ] , shutdown_tx_conf_height_a) . is_none( ) ) ;
226+ assert ! ( get_monitor!( nodes[ 1 ] , chan_id)
227+ . get_spendable_output( & shutdown_tx[ 0 ] , shutdown_tx_conf_height_b) . is_none( ) ) ;
228+
229+ connect_blocks ( & nodes[ 0 ] , 1 ) ;
230+ connect_blocks ( & nodes[ 1 ] , 1 ) ;
221231
222232 assert_eq ! ( Vec :: <Balance >:: new( ) ,
223233 nodes[ 0 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
224234 assert_eq ! ( Vec :: <Balance >:: new( ) ,
225235 nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
226236
227- test_spendable_output ( & nodes[ 0 ] , & shutdown_tx[ 0 ] ) ;
228- test_spendable_output ( & nodes[ 1 ] , & shutdown_tx[ 0 ] ) ;
237+ let spendable_output_a = test_spendable_output ( & nodes[ 0 ] , & shutdown_tx[ 0 ] ) ;
238+ assert_eq ! (
239+ get_monitor!( nodes[ 0 ] , chan_id)
240+ . get_spendable_output( & shutdown_tx[ 0 ] , shutdown_tx_conf_height_a) . unwrap( ) ,
241+ spendable_output_a
242+ ) ;
243+
244+ let spendable_output_b = test_spendable_output ( & nodes[ 1 ] , & shutdown_tx[ 0 ] ) ;
245+ assert_eq ! (
246+ get_monitor!( nodes[ 1 ] , chan_id)
247+ . get_spendable_output( & shutdown_tx[ 0 ] , shutdown_tx_conf_height_b) . unwrap( ) ,
248+ spendable_output_b
249+ ) ;
229250
230251 check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: CooperativeClosure , [ nodes[ 1 ] . node. get_our_node_id( ) ] , 1000000 ) ;
231252 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: CooperativeClosure , [ nodes[ 0 ] . node. get_our_node_id( ) ] , 1000000 ) ;
0 commit comments