9
9
10
10
//! Further functional tests which test blockchain reorganizations.
11
11
12
- use crate :: sign:: EcdsaChannelSigner ;
12
+ use crate :: sign:: { EcdsaChannelSigner , SpendableOutputDescriptor } ;
13
13
use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , LATENCY_GRACE_PERIOD_BLOCKS , Balance } ;
14
14
use crate :: chain:: transaction:: OutPoint ;
15
15
use crate :: chain:: chaininterface:: { LowerBoundedFeeEstimator , compute_feerate_sat_per_1000_weight} ;
@@ -21,6 +21,7 @@ use crate::ln::msgs::ChannelMessageHandler;
21
21
use crate :: util:: config:: UserConfig ;
22
22
use crate :: util:: crypto:: sign;
23
23
use crate :: util:: ser:: Writeable ;
24
+ use crate :: util:: scid_utils:: block_from_scid;
24
25
use crate :: util:: test_utils;
25
26
26
27
use bitcoin:: blockdata:: transaction:: EcdsaSighashType ;
@@ -92,14 +93,15 @@ fn chanmon_fail_from_stale_commitment() {
92
93
expect_payment_failed_with_update ! ( nodes[ 0 ] , payment_hash, false , update_a. contents. short_channel_id, true ) ;
93
94
}
94
95
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 {
96
97
let mut spendable = node. chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
97
98
assert_eq ! ( spendable. len( ) , 1 ) ;
98
- if let Event :: SpendableOutputs { outputs, .. } = spendable. pop ( ) . unwrap ( ) {
99
+ if let Event :: SpendableOutputs { mut outputs, .. } = spendable. pop ( ) . unwrap ( ) {
99
100
assert_eq ! ( outputs. len( ) , 1 ) ;
100
101
let spend_tx = node. keys_manager . backing . spend_spendable_outputs ( & [ & outputs[ 0 ] ] , Vec :: new ( ) ,
101
102
Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_RETURN ) . into_script ( ) , 253 , None , & Secp256k1 :: new ( ) ) . unwrap ( ) ;
102
103
check_spends ! ( spend_tx, spendable_tx) ;
104
+ outputs. pop ( ) . unwrap ( )
103
105
} else { panic ! ( ) ; }
104
106
}
105
107
@@ -196,8 +198,8 @@ fn chanmon_claim_value_coop_close() {
196
198
assert_eq ! ( shutdown_tx, nodes[ 1 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . split_off( 0 ) ) ;
197
199
assert_eq ! ( shutdown_tx. len( ) , 1 ) ;
198
200
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 ] ) ) ;
201
203
202
204
assert ! ( nodes[ 0 ] . node. list_channels( ) . is_empty( ) ) ;
203
205
assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
@@ -216,16 +218,35 @@ fn chanmon_claim_value_coop_close() {
216
218
} ] ,
217
219
nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
218
220
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 ) ;
221
231
222
232
assert_eq ! ( Vec :: <Balance >:: new( ) ,
223
233
nodes[ 0 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
224
234
assert_eq ! ( Vec :: <Balance >:: new( ) ,
225
235
nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
226
236
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
+ ) ;
229
250
230
251
check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: CooperativeClosure , [ nodes[ 1 ] . node. get_our_node_id( ) ] , 1000000 ) ;
231
252
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: CooperativeClosure , [ nodes[ 0 ] . node. get_our_node_id( ) ] , 1000000 ) ;
0 commit comments