@@ -189,7 +189,7 @@ fn test_onchain_htlc_timeout_delay_remote_commitment() {
189
189
do_test_onchain_htlc_reorg ( false , false ) ;
190
190
}
191
191
192
- fn do_test_unconf_chan ( reload_node : bool ) {
192
+ fn do_test_unconf_chan ( reload_node : bool , reorg_after_reload : bool ) {
193
193
// After creating a chan between nodes, we disconnect all blocks previously seen to force a
194
194
// channel close on nodes[0] side. We also use this to provide very basic testing of logic
195
195
// around freeing background events which store monitor updates during block_[dis]connected.
@@ -214,14 +214,16 @@ fn do_test_unconf_chan(reload_node: bool) {
214
214
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. block_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
215
215
headers. push ( header. clone ( ) ) ;
216
216
}
217
- while !headers. is_empty ( ) {
218
- nodes[ 0 ] . node . block_disconnected ( & headers. pop ( ) . unwrap ( ) ) ;
219
- }
220
- check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
221
- {
222
- let channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
223
- assert_eq ! ( channel_state. by_id. len( ) , 0 ) ;
224
- assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
217
+ if !reorg_after_reload {
218
+ while !headers. is_empty ( ) {
219
+ nodes[ 0 ] . node . block_disconnected ( & headers. pop ( ) . unwrap ( ) ) ;
220
+ }
221
+ check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
222
+ {
223
+ let channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
224
+ assert_eq ! ( channel_state. by_id. len( ) , 0 ) ;
225
+ assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
226
+ }
225
227
}
226
228
227
229
if reload_node {
@@ -264,14 +266,28 @@ fn do_test_unconf_chan(reload_node: bool) {
264
266
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
265
267
}
266
268
269
+ if reorg_after_reload {
270
+ while !headers. is_empty ( ) {
271
+ nodes[ 0 ] . node . block_disconnected ( & headers. pop ( ) . unwrap ( ) ) ;
272
+ }
273
+ check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
274
+ {
275
+ let channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
276
+ assert_eq ! ( channel_state. by_id. len( ) , 0 ) ;
277
+ assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
278
+ }
279
+ }
280
+
267
281
nodes[ 0 ] . node . test_process_background_events ( ) ; // Required to free the pending background monitor update
268
282
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
269
283
}
270
284
271
285
#[ test]
272
286
fn test_unconf_chan ( ) {
273
- do_test_unconf_chan ( true ) ;
274
- do_test_unconf_chan ( false ) ;
287
+ do_test_unconf_chan ( true , true ) ;
288
+ do_test_unconf_chan ( false , true ) ;
289
+ do_test_unconf_chan ( true , false ) ;
290
+ do_test_unconf_chan ( false , false ) ;
275
291
}
276
292
277
293
#[ test]
0 commit comments