9
9
10
10
//! Further functional tests which test blockchain reorganizations.
11
11
12
- use chain:: channelmonitor:: ANTI_REORG_DELAY ;
13
- use ln:: { PaymentPreimage , PaymentHash } ;
12
+ use chain:: channelmonitor:: { ANTI_REORG_DELAY , ClaimableBalance } ;
13
+ use chain:: transaction:: OutPoint ;
14
+ use ln:: { channel, PaymentPreimage , PaymentHash } ;
15
+ use ln:: channelmanager:: BREAKDOWN_TIMEOUT ;
14
16
use ln:: features:: InitFeatures ;
15
17
use ln:: msgs:: { ChannelMessageHandler , HTLCFailChannelUpdate , ErrorAction } ;
16
18
use util:: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
@@ -19,6 +21,10 @@ use routing::router::get_route;
19
21
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
20
22
use bitcoin:: hashes:: Hash ;
21
23
24
+ use bitcoin:: blockdata:: script:: Builder ;
25
+ use bitcoin:: blockdata:: opcodes;
26
+ use bitcoin:: secp256k1:: Secp256k1 ;
27
+
22
28
use prelude:: * ;
23
29
24
30
use ln:: functional_test_utils:: * ;
@@ -79,3 +85,292 @@ fn chanmon_fail_from_stale_commitment() {
79
85
expect_payment_failed ! ( nodes[ 0 ] , payment_hash, false ) ;
80
86
expect_payment_failure_chan_update ! ( nodes[ 0 ] , update_a. contents. short_channel_id, true ) ;
81
87
}
88
+
89
+ #[ test]
90
+ fn chanmon_claim_value_coop_close ( ) {
91
+ // Tests `get_claimable_balances` returns the correct values across a simple cooperative claim.
92
+ // Specifically, this tests that the channel non-HTLC balances show up in
93
+ // `get_claimable_balances` until the cooperative claims have confirmed and generated a
94
+ // `SpendableOutputs` event, and no longer.
95
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
96
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
97
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
98
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
99
+
100
+ let ( _, _, chan_id, funding_tx) =
101
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 1_000_000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
102
+ let funding_outpoint = OutPoint { txid : funding_tx. txid ( ) , index : 0 } ;
103
+ assert_eq ! ( funding_outpoint. to_channel_id( ) , chan_id) ;
104
+
105
+ let chan_feerate = get_feerate ! ( nodes[ 0 ] , chan_id) as u64 ;
106
+
107
+ assert_eq ! ( vec![ ClaimableBalance :: ClaimableOnChannelClose {
108
+ claimable_amount_satoshis: 1_000_000 - 1_000 - chan_feerate * channel:: COMMITMENT_TX_BASE_WEIGHT / 1000
109
+ } ] ,
110
+ nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
111
+ assert_eq ! ( vec![ ClaimableBalance :: ClaimableOnChannelClose { claimable_amount_satoshis: 1_000 , } ] ,
112
+ nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
113
+
114
+ nodes[ 0 ] . node . close_channel ( & chan_id) . unwrap ( ) ;
115
+ let node_0_shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
116
+ nodes[ 1 ] . node . handle_shutdown ( & nodes[ 0 ] . node . get_our_node_id ( ) , & InitFeatures :: known ( ) , & node_0_shutdown) ;
117
+ let node_1_shutdown = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendShutdown , nodes[ 0 ] . node. get_our_node_id( ) ) ;
118
+ nodes[ 0 ] . node . handle_shutdown ( & nodes[ 1 ] . node . get_our_node_id ( ) , & InitFeatures :: known ( ) , & node_1_shutdown) ;
119
+
120
+ let node_0_closing_signed = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendClosingSigned , nodes[ 1 ] . node. get_our_node_id( ) ) ;
121
+ nodes[ 1 ] . node . handle_closing_signed ( & nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_closing_signed) ;
122
+ let ( _, node_1_closing_signed) = get_closing_signed_broadcast ! ( nodes[ 1 ] . node, nodes[ 0 ] . node. get_our_node_id( ) ) ;
123
+ nodes[ 0 ] . node . handle_closing_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_closing_signed. unwrap ( ) ) ;
124
+ let ( _, node_0_none) = get_closing_signed_broadcast ! ( nodes[ 0 ] . node, nodes[ 1 ] . node. get_our_node_id( ) ) ;
125
+ assert ! ( node_0_none. is_none( ) ) ;
126
+
127
+ let shutdown_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
128
+ assert_eq ! ( shutdown_tx, nodes[ 1 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . split_off( 0 ) ) ;
129
+ assert_eq ! ( shutdown_tx. len( ) , 1 ) ;
130
+
131
+ mine_transaction ( & nodes[ 0 ] , & shutdown_tx[ 0 ] ) ;
132
+ mine_transaction ( & nodes[ 1 ] , & shutdown_tx[ 0 ] ) ;
133
+
134
+ assert ! ( nodes[ 0 ] . node. list_channels( ) . is_empty( ) ) ;
135
+ assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
136
+
137
+ assert ! ( nodes[ 0 ] . chain_monitor. chain_monitor. get_and_clear_pending_events( ) . is_empty( ) ) ;
138
+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_and_clear_pending_events( ) . is_empty( ) ) ;
139
+
140
+ assert_eq ! ( vec![ ClaimableBalance :: ClaimableAwaitingConfirmations {
141
+ claimable_amount_satoshis: 1_000_000 - 1_000 - chan_feerate * channel:: COMMITMENT_TX_BASE_WEIGHT / 1000 ,
142
+ confirmation_height: nodes[ 0 ] . best_block_info( ) . 1 + ANTI_REORG_DELAY - 1 ,
143
+ } ] ,
144
+ nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
145
+ assert_eq ! ( vec![ ClaimableBalance :: ClaimableAwaitingConfirmations {
146
+ claimable_amount_satoshis: 1000 ,
147
+ confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + ANTI_REORG_DELAY - 1 ,
148
+ } ] ,
149
+ nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
150
+
151
+ connect_blocks ( & nodes[ 0 ] , ANTI_REORG_DELAY - 1 ) ;
152
+ connect_blocks ( & nodes[ 1 ] , ANTI_REORG_DELAY - 1 ) ;
153
+
154
+ assert_eq ! ( Vec :: <ClaimableBalance >:: new( ) ,
155
+ nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
156
+ assert_eq ! ( Vec :: <ClaimableBalance >:: new( ) ,
157
+ nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
158
+
159
+ let mut node_a_spendable = nodes[ 0 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
160
+ assert_eq ! ( node_a_spendable. len( ) , 1 ) ;
161
+ if let Event :: SpendableOutputs { outputs } = node_a_spendable. pop ( ) . unwrap ( ) {
162
+ assert_eq ! ( outputs. len( ) , 1 ) ;
163
+ let spend_tx = nodes[ 0 ] . keys_manager . backing . spend_spendable_outputs ( & [ & outputs[ 0 ] ] , Vec :: new ( ) ,
164
+ Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_RETURN ) . into_script ( ) , 253 , & Secp256k1 :: new ( ) ) . unwrap ( ) ;
165
+ check_spends ! ( spend_tx, shutdown_tx[ 0 ] ) ;
166
+ }
167
+
168
+ let mut node_b_spendable = nodes[ 1 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
169
+ assert_eq ! ( node_b_spendable. len( ) , 1 ) ;
170
+ if let Event :: SpendableOutputs { outputs } = node_b_spendable. pop ( ) . unwrap ( ) {
171
+ assert_eq ! ( outputs. len( ) , 1 ) ;
172
+ let spend_tx = nodes[ 1 ] . keys_manager . backing . spend_spendable_outputs ( & [ & outputs[ 0 ] ] , Vec :: new ( ) ,
173
+ Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_RETURN ) . into_script ( ) , 253 , & Secp256k1 :: new ( ) ) . unwrap ( ) ;
174
+ check_spends ! ( spend_tx, shutdown_tx[ 0 ] ) ;
175
+ }
176
+ }
177
+
178
+ fn sorted_vec < T : Ord > ( mut v : Vec < T > ) -> Vec < T > {
179
+ v. sort_unstable ( ) ;
180
+ v
181
+ }
182
+
183
+ #[ test]
184
+ fn test_claim_value_force_close ( ) {
185
+ // Tests `get_claimable_balances` with an HTLC across a force-close.
186
+ // We build a channel with an HTLC pending, then force close the channel and check that the
187
+ // `get_claimable_balances` return value is correct as transactions confirm on-chain.
188
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
189
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
190
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
191
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
192
+
193
+ let ( _, _, chan_id, funding_tx) =
194
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 1_000_000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
195
+ let funding_outpoint = OutPoint { txid : funding_tx. txid ( ) , index : 0 } ;
196
+ assert_eq ! ( funding_outpoint. to_channel_id( ) , chan_id) ;
197
+
198
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 3_000_000 ) . 0 ;
199
+ // This HTLC will be dust, and not be claimable at all:
200
+ let ( dust_payment_preimage, dust_payment_hash, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 3_000 ) ;
201
+
202
+ let htlc_cltv_timeout = nodes[ 0 ] . best_block_info ( ) . 1 + TEST_FINAL_CLTV + 1 ; // Note ChannelManager adds one to CLTV timeouts for safety
203
+
204
+ let chan_feerate = get_feerate ! ( nodes[ 0 ] , chan_id) as u64 ;
205
+
206
+ let remote_txn = get_local_commitment_txn ! ( nodes[ 1 ] , chan_id) ;
207
+ // Before B receives the payment preimage, it only suggests the push_msat value of 1_000 sats
208
+ // as claimable. A lists both its to-self balance and the (possibly-claimable) HTLC.
209
+ assert_eq ! ( sorted_vec( vec![ ClaimableBalance :: ClaimableOnChannelClose {
210
+ claimable_amount_satoshis: 1_000_000 - 3_000 - 1_000 - 3 - chan_feerate *
211
+ ( channel:: COMMITMENT_TX_BASE_WEIGHT + channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ,
212
+ } , ClaimableBalance :: PossiblyClaimableHTLCAwaitingTimeout {
213
+ claimable_amount_satoshis: 3_000 ,
214
+ claimable_height: htlc_cltv_timeout,
215
+ } ] ) ,
216
+ sorted_vec( nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
217
+ assert_eq ! ( vec![ ClaimableBalance :: ClaimableOnChannelClose {
218
+ claimable_amount_satoshis: 1_000 ,
219
+ } ] ,
220
+ nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
221
+
222
+ nodes[ 1 ] . node . claim_funds ( payment_preimage) ;
223
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
224
+ get_htlc_update_msgs ! ( & nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
225
+ // We claim the dust payment here as well, but it won't impact our claimable balances as its
226
+ // dust and thus doesn't appear on chain at all.
227
+ nodes[ 1 ] . node . claim_funds ( dust_payment_preimage) ;
228
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
229
+
230
+ // Once B has received the payment preimage, it includes the value of the HTLC in its
231
+ // "claimable if you were to close the channel" balance.
232
+ assert_eq ! ( sorted_vec( vec![ ClaimableBalance :: ClaimableOnChannelClose {
233
+ claimable_amount_satoshis: 1_000_000 - // Channel funding value in satoshis
234
+ 3_000 - // The larger HTLC value in satoshis
235
+ 1_000 - // The push_msat value in satoshis
236
+ 3 - // The dust HTLC value in satoshis
237
+ // The commitment transaction fee with one HTLC output:
238
+ chan_feerate * ( channel:: COMMITMENT_TX_BASE_WEIGHT + channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ,
239
+ } , ClaimableBalance :: PossiblyClaimableHTLCAwaitingTimeout {
240
+ claimable_amount_satoshis: 3_000 ,
241
+ claimable_height: htlc_cltv_timeout,
242
+ } ] ) ,
243
+ sorted_vec( nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
244
+ assert_eq ! ( vec![ ClaimableBalance :: ClaimableOnChannelClose {
245
+ claimable_amount_satoshis: 1_000 + 3_000 ,
246
+ } ] ,
247
+ nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
248
+
249
+ // Broadcast the closing transaction (which has the pending HTLC in it) and get B's broadcasted
250
+ // HTLC claim transaction with preimage.
251
+ let node_b_commitment_claimable = nodes[ 1 ] . best_block_info ( ) . 1 + BREAKDOWN_TIMEOUT as u32 ;
252
+ mine_transaction ( & nodes[ 0 ] , & remote_txn[ 0 ] ) ;
253
+ mine_transaction ( & nodes[ 1 ] , & remote_txn[ 0 ] ) ;
254
+
255
+ let b_broadcast_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
256
+ assert_eq ! ( b_broadcast_txn. len( ) , 3 ) ;
257
+ assert_eq ! ( b_broadcast_txn[ 0 ] , b_broadcast_txn[ 2 ] ) ;
258
+ // b_broadcast_txn[0] should spend the HTLC output of the commitment tx for 3_000 sats
259
+ check_spends ! ( b_broadcast_txn[ 0 ] , remote_txn[ 0 ] ) ;
260
+ assert_eq ! ( b_broadcast_txn[ 0 ] . input. len( ) , 1 ) ;
261
+ assert_eq ! ( remote_txn[ 0 ] . output[ b_broadcast_txn[ 0 ] . input[ 0 ] . previous_output. vout as usize ] . value, 3_000 ) ;
262
+ check_spends ! ( b_broadcast_txn[ 1 ] , funding_tx) ;
263
+
264
+ assert ! ( nodes[ 0 ] . node. list_channels( ) . is_empty( ) ) ;
265
+ check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
266
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
267
+ assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
268
+ check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
269
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
270
+ assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
271
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
272
+
273
+ // Once the commitment transaction confirms, we will wait until ANTI_REORG_DELAY until we
274
+ // generate any `SpendableOutputs` events. Thus, the same balances will still be listed
275
+ // available in `get_claimable_balances`. However, both will swap from `ClaimableOnClose` to
276
+ // other ClaimableBalance variants, as close has already happened.
277
+ assert ! ( nodes[ 0 ] . chain_monitor. chain_monitor. get_and_clear_pending_events( ) . is_empty( ) ) ;
278
+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_and_clear_pending_events( ) . is_empty( ) ) ;
279
+
280
+ assert_eq ! ( sorted_vec( vec![ ClaimableBalance :: ClaimableAwaitingConfirmations {
281
+ claimable_amount_satoshis: 1_000_000 - 3_000 - 1_000 - 3 - chan_feerate *
282
+ ( channel:: COMMITMENT_TX_BASE_WEIGHT + channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ,
283
+ confirmation_height: nodes[ 0 ] . best_block_info( ) . 1 + ANTI_REORG_DELAY - 1 ,
284
+ } , ClaimableBalance :: PossiblyClaimableHTLCAwaitingTimeout {
285
+ claimable_amount_satoshis: 3_000 ,
286
+ claimable_height: htlc_cltv_timeout,
287
+ } ] ) ,
288
+ sorted_vec( nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
289
+ // The main non-HTLC balance is just awaiting confirmations, but the claimable height is the
290
+ // CSV delay, not ANTI_REORG_DELAY.
291
+ assert_eq ! ( sorted_vec( vec![ ClaimableBalance :: ClaimableAwaitingConfirmations {
292
+ claimable_amount_satoshis: 1_000 ,
293
+ confirmation_height: node_b_commitment_claimable,
294
+ } ,
295
+ // The HTLC balance is "contentious" as our counterparty could claim it if we wait too
296
+ // long.
297
+ ClaimableBalance :: ContentiousClaimable {
298
+ claimable_amount_satoshis: 3_000 ,
299
+ timeout_height: htlc_cltv_timeout,
300
+ } ] ) ,
301
+ sorted_vec( nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
302
+
303
+ connect_blocks ( & nodes[ 0 ] , ANTI_REORG_DELAY - 1 ) ;
304
+ expect_payment_failed ! ( nodes[ 0 ] , dust_payment_hash, true ) ;
305
+ connect_blocks ( & nodes[ 1 ] , ANTI_REORG_DELAY - 1 ) ;
306
+
307
+ // After ANTI_REORG_DELAY, A will consider its balance fully spendable and generate a
308
+ // `SpendableOutputs` event. However, B still has to wait for the CSV delay.
309
+ assert_eq ! ( vec![ ClaimableBalance :: PossiblyClaimableHTLCAwaitingTimeout {
310
+ claimable_amount_satoshis: 3_000 ,
311
+ claimable_height: htlc_cltv_timeout,
312
+ } ] ,
313
+ nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
314
+ assert_eq ! ( sorted_vec( vec![ ClaimableBalance :: ClaimableAwaitingConfirmations {
315
+ claimable_amount_satoshis: 1_000 ,
316
+ confirmation_height: node_b_commitment_claimable,
317
+ } , ClaimableBalance :: ContentiousClaimable {
318
+ claimable_amount_satoshis: 3_000 ,
319
+ timeout_height: htlc_cltv_timeout,
320
+ } ] ) ,
321
+ sorted_vec( nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
322
+
323
+ let mut node_a_spendable = nodes[ 0 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
324
+ assert_eq ! ( node_a_spendable. len( ) , 1 ) ;
325
+ if let Event :: SpendableOutputs { outputs } = node_a_spendable. pop ( ) . unwrap ( ) {
326
+ assert_eq ! ( outputs. len( ) , 1 ) ;
327
+ let spend_tx = nodes[ 0 ] . keys_manager . backing . spend_spendable_outputs ( & [ & outputs[ 0 ] ] , Vec :: new ( ) ,
328
+ Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_RETURN ) . into_script ( ) , 253 , & Secp256k1 :: new ( ) ) . unwrap ( ) ;
329
+ check_spends ! ( spend_tx, remote_txn[ 0 ] ) ;
330
+ }
331
+
332
+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_and_clear_pending_events( ) . is_empty( ) ) ;
333
+
334
+ // After broadcasting the HTLC claim transaction, node A will still consider the HTLC
335
+ // possibly-claimable up to ANTI_REORG_DELAY, at which point it will drop it.
336
+ mine_transaction ( & nodes[ 0 ] , & b_broadcast_txn[ 0 ] ) ;
337
+ expect_payment_sent ! ( nodes[ 0 ] , payment_preimage) ;
338
+ assert_eq ! ( vec![ ClaimableBalance :: PossiblyClaimableHTLCAwaitingTimeout {
339
+ claimable_amount_satoshis: 3_000 ,
340
+ claimable_height: htlc_cltv_timeout,
341
+ } ] ,
342
+ nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
343
+ connect_blocks ( & nodes[ 0 ] , ANTI_REORG_DELAY - 1 ) ;
344
+ assert_eq ! ( Vec :: <ClaimableBalance >:: new( ) ,
345
+ nodes[ 0 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
346
+
347
+ // Node B will no longer consider the HTLC "contentious" after the HTLC claim transaction
348
+ // confirms, and consider it simply "awaiting confirmations".
349
+ mine_transaction ( & nodes[ 1 ] , & b_broadcast_txn[ 0 ] ) ;
350
+ assert_eq ! ( sorted_vec( vec![ ClaimableBalance :: ClaimableAwaitingConfirmations {
351
+ claimable_amount_satoshis: 1_000 ,
352
+ confirmation_height: node_b_commitment_claimable,
353
+ } , ClaimableBalance :: ClaimableAwaitingConfirmations {
354
+ claimable_amount_satoshis: 3_000 ,
355
+ confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + ANTI_REORG_DELAY - 1 ,
356
+ } ] ) ,
357
+ sorted_vec( nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
358
+
359
+ // Finally, after ANTI_REORG_DELAY confirmations on the HTLC transaction, plus reaching the
360
+ // commitment output CSV, we'll get a SpendableOutputs event for both and have no further
361
+ // claimable balance for node B.
362
+ connect_blocks ( & nodes[ 1 ] , BREAKDOWN_TIMEOUT as u32 - ANTI_REORG_DELAY - 1 ) ;
363
+ assert_eq ! ( nodes[ 1 ] . best_block_info( ) . 1 , node_b_commitment_claimable) ;
364
+
365
+ let mut node_b_spendable = nodes[ 1 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
366
+ assert_eq ! ( node_b_spendable. len( ) , 1 ) ;
367
+ if let Event :: SpendableOutputs { outputs } = node_b_spendable. pop ( ) . unwrap ( ) {
368
+ assert_eq ! ( outputs. len( ) , 1 ) ;
369
+ let spend_tx = nodes[ 1 ] . keys_manager . backing . spend_spendable_outputs ( & [ & outputs[ 0 ] ] , Vec :: new ( ) ,
370
+ Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_RETURN ) . into_script ( ) , 253 , & Secp256k1 :: new ( ) ) . unwrap ( ) ;
371
+ check_spends ! ( spend_tx, remote_txn[ 0 ] ) ;
372
+ }
373
+
374
+ assert_eq ! ( Vec :: <ClaimableBalance >:: new( ) ,
375
+ nodes[ 1 ] . chain_monitor. chain_monitor. monitors. read( ) . unwrap( ) . get( & funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ;
376
+ }
0 commit comments