@@ -1280,6 +1280,9 @@ mod tests {
1280
1280
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1281
1281
let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 2 ;
1282
1282
1283
+ let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
1284
+ let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
1285
+
1283
1286
// Route two payments to be claimed at the same time.
1284
1287
let ( payment_preimage_1, payment_hash_1, ..) =
1285
1288
route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
@@ -1305,57 +1308,34 @@ mod tests {
1305
1308
// fail either way but if it fails intermittently it's depending on the ordering of updates.
1306
1309
let mut update_iter = updates. iter ( ) ;
1307
1310
let next_update = update_iter. next ( ) . unwrap ( ) . clone ( ) ;
1311
+ let node_b_mon = & nodes[ 1 ] . chain_monitor . chain_monitor ;
1312
+
1308
1313
// Should contain next_update when pending updates listed.
1314
+ let pending_updates = node_b_mon. list_pending_monitor_updates ( ) ;
1309
1315
#[ cfg( not( c_bindings) ) ]
1310
- assert ! ( nodes[ 1 ]
1311
- . chain_monitor
1312
- . chain_monitor
1313
- . list_pending_monitor_updates( )
1314
- . get( & channel_id)
1315
- . unwrap( )
1316
- . contains( & next_update) ) ;
1316
+ let pending_chan_updates = pending_updates. get ( & channel_id) . unwrap ( ) ;
1317
1317
#[ cfg( c_bindings) ]
1318
- assert ! ( nodes[ 1 ]
1319
- . chain_monitor
1320
- . chain_monitor
1321
- . list_pending_monitor_updates( )
1322
- . iter( )
1323
- . find( |( chan_id, _) | * chan_id == channel_id)
1324
- . unwrap( )
1325
- . 1
1326
- . contains( & next_update) ) ;
1327
- nodes[ 1 ]
1328
- . chain_monitor
1329
- . chain_monitor
1330
- . channel_monitor_updated ( channel_id, next_update. clone ( ) )
1331
- . unwrap ( ) ;
1318
+ let pending_chan_updates =
1319
+ & pending_updates. iter ( ) . find ( |( chan_id, _) | * chan_id == channel_id) . unwrap ( ) . 1 ;
1320
+ assert ! ( pending_chan_updates. contains( & next_update) ) ;
1321
+
1322
+ node_b_mon. channel_monitor_updated ( channel_id, next_update. clone ( ) ) . unwrap ( ) ;
1323
+
1332
1324
// Should not contain the previously pending next_update when pending updates listed.
1325
+ let pending_updates = node_b_mon. list_pending_monitor_updates ( ) ;
1333
1326
#[ cfg( not( c_bindings) ) ]
1334
- assert ! ( !nodes[ 1 ]
1335
- . chain_monitor
1336
- . chain_monitor
1337
- . list_pending_monitor_updates( )
1338
- . get( & channel_id)
1339
- . unwrap( )
1340
- . contains( & next_update) ) ;
1327
+ let pending_chan_updates = pending_updates. get ( & channel_id) . unwrap ( ) ;
1341
1328
#[ cfg( c_bindings) ]
1342
- assert ! ( !nodes[ 1 ]
1343
- . chain_monitor
1344
- . chain_monitor
1345
- . list_pending_monitor_updates( )
1346
- . iter( )
1347
- . find( |( chan_id, _) | * chan_id == channel_id)
1348
- . unwrap( )
1349
- . 1
1350
- . contains( & next_update) ) ;
1329
+ let pending_chan_updates =
1330
+ & pending_updates. iter ( ) . find ( |( chan_id, _) | * chan_id == channel_id) . unwrap ( ) . 1 ;
1331
+ assert ! ( !pending_chan_updates. contains( & next_update) ) ;
1332
+
1351
1333
assert ! ( nodes[ 1 ] . chain_monitor. release_pending_monitor_events( ) . is_empty( ) ) ;
1352
1334
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1353
1335
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
1354
- nodes[ 1 ]
1355
- . chain_monitor
1356
- . chain_monitor
1357
- . channel_monitor_updated ( channel_id, update_iter. next ( ) . unwrap ( ) . clone ( ) )
1358
- . unwrap ( ) ;
1336
+
1337
+ let next_update = update_iter. next ( ) . unwrap ( ) . clone ( ) ;
1338
+ node_b_mon. channel_monitor_updated ( channel_id, next_update) . unwrap ( ) ;
1359
1339
1360
1340
let claim_events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
1361
1341
assert_eq ! ( claim_events. len( ) , 2 ) ;
@@ -1375,63 +1355,40 @@ mod tests {
1375
1355
// Now manually walk the commitment signed dance - because we claimed two payments
1376
1356
// back-to-back it doesn't fit into the neat walk commitment_signed_dance does.
1377
1357
1378
- let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1379
- nodes[ 0 ] . node . handle_update_fulfill_htlc (
1380
- nodes[ 1 ] . node . get_our_node_id ( ) ,
1381
- & updates. update_fulfill_htlcs [ 0 ] ,
1382
- ) ;
1358
+ let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , node_a_id) ;
1359
+ nodes[ 0 ] . node . handle_update_fulfill_htlc ( node_b_id, & updates. update_fulfill_htlcs [ 0 ] ) ;
1383
1360
expect_payment_sent ( & nodes[ 0 ] , payment_preimage_1, None , false , false ) ;
1384
- nodes[ 0 ] . node . handle_commitment_signed_batch_test (
1385
- nodes[ 1 ] . node . get_our_node_id ( ) ,
1386
- & updates. commitment_signed ,
1387
- ) ;
1361
+ nodes[ 0 ] . node . handle_commitment_signed_batch_test ( node_b_id, & updates. commitment_signed ) ;
1388
1362
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1389
- let ( as_first_raa, as_first_update) =
1390
- get_revoke_commit_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1363
+ let ( as_first_raa, as_first_update) = get_revoke_commit_msgs ! ( nodes[ 0 ] , node_b_id) ;
1391
1364
1392
- nodes[ 1 ] . node . handle_revoke_and_ack ( nodes [ 0 ] . node . get_our_node_id ( ) , & as_first_raa) ;
1365
+ nodes[ 1 ] . node . handle_revoke_and_ack ( node_a_id , & as_first_raa) ;
1393
1366
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1394
- let bs_second_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1395
- nodes[ 1 ]
1396
- . node
1397
- . handle_commitment_signed_batch_test ( nodes[ 0 ] . node . get_our_node_id ( ) , & as_first_update) ;
1367
+ let bs_second_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , node_a_id) ;
1368
+ nodes[ 1 ] . node . handle_commitment_signed_batch_test ( node_a_id, & as_first_update) ;
1398
1369
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1399
- let bs_first_raa = get_event_msg ! (
1400
- nodes[ 1 ] ,
1401
- MessageSendEvent :: SendRevokeAndACK ,
1402
- nodes[ 0 ] . node. get_our_node_id( )
1403
- ) ;
1370
+ let bs_first_raa = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendRevokeAndACK , node_a_id) ;
1404
1371
1405
- nodes[ 0 ] . node . handle_update_fulfill_htlc (
1406
- nodes[ 1 ] . node . get_our_node_id ( ) ,
1407
- & bs_second_updates. update_fulfill_htlcs [ 0 ] ,
1408
- ) ;
1372
+ nodes[ 0 ]
1373
+ . node
1374
+ . handle_update_fulfill_htlc ( node_b_id, & bs_second_updates. update_fulfill_htlcs [ 0 ] ) ;
1409
1375
expect_payment_sent ( & nodes[ 0 ] , payment_preimage_2, None , false , false ) ;
1410
- nodes[ 0 ] . node . handle_commitment_signed_batch_test (
1411
- nodes[ 1 ] . node . get_our_node_id ( ) ,
1412
- & bs_second_updates. commitment_signed ,
1413
- ) ;
1376
+ nodes[ 0 ]
1377
+ . node
1378
+ . handle_commitment_signed_batch_test ( node_b_id, & bs_second_updates. commitment_signed ) ;
1414
1379
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1415
- nodes[ 0 ] . node . handle_revoke_and_ack ( nodes [ 1 ] . node . get_our_node_id ( ) , & bs_first_raa) ;
1380
+ nodes[ 0 ] . node . handle_revoke_and_ack ( node_b_id , & bs_first_raa) ;
1416
1381
expect_payment_path_successful ! ( nodes[ 0 ] ) ;
1417
1382
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1418
- let ( as_second_raa, as_second_update) =
1419
- get_revoke_commit_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1383
+ let ( as_second_raa, as_second_update) = get_revoke_commit_msgs ! ( nodes[ 0 ] , node_b_id) ;
1420
1384
1421
- nodes[ 1 ] . node . handle_revoke_and_ack ( nodes [ 0 ] . node . get_our_node_id ( ) , & as_second_raa) ;
1385
+ nodes[ 1 ] . node . handle_revoke_and_ack ( node_a_id , & as_second_raa) ;
1422
1386
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1423
- nodes[ 1 ] . node . handle_commitment_signed_batch_test (
1424
- nodes[ 0 ] . node . get_our_node_id ( ) ,
1425
- & as_second_update,
1426
- ) ;
1387
+ nodes[ 1 ] . node . handle_commitment_signed_batch_test ( node_a_id, & as_second_update) ;
1427
1388
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1428
- let bs_second_raa = get_event_msg ! (
1429
- nodes[ 1 ] ,
1430
- MessageSendEvent :: SendRevokeAndACK ,
1431
- nodes[ 0 ] . node. get_our_node_id( )
1432
- ) ;
1389
+ let bs_second_raa = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendRevokeAndACK , node_a_id) ;
1433
1390
1434
- nodes[ 0 ] . node . handle_revoke_and_ack ( nodes [ 1 ] . node . get_our_node_id ( ) , & bs_second_raa) ;
1391
+ nodes[ 0 ] . node . handle_revoke_and_ack ( node_b_id , & bs_second_raa) ;
1435
1392
expect_payment_path_successful ! ( nodes[ 0 ] ) ;
1436
1393
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1437
1394
}
@@ -1443,6 +1400,9 @@ mod tests {
1443
1400
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
1444
1401
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
1445
1402
1403
+ let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
1404
+ let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
1405
+
1446
1406
// Use FullBlockViaListen to avoid duplicate calls to process_chain_data and skips_blocks() in
1447
1407
// case of other connect_styles.
1448
1408
* nodes[ 0 ] . connect_style . borrow_mut ( ) = ConnectStyle :: FullBlockViaListen ;
@@ -1480,15 +1440,10 @@ mod tests {
1480
1440
// Now, close channel_2 i.e. b/w node-0 and node-2 to create pending_claim in node[0].
1481
1441
nodes[ 0 ]
1482
1442
. node
1483
- . force_close_broadcasting_latest_txn (
1484
- & channel_2,
1485
- & nodes[ 2 ] . node . get_our_node_id ( ) ,
1486
- "Channel force-closed" . to_string ( ) ,
1487
- )
1443
+ . force_close_broadcasting_latest_txn ( & channel_2, & node_c_id, "closed" . to_string ( ) )
1488
1444
. unwrap ( ) ;
1489
1445
let closure_reason =
1490
1446
ClosureReason :: HolderForceClosed { broadcasted_latest_txn : Some ( true ) } ;
1491
- let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
1492
1447
check_closed_event ! ( & nodes[ 0 ] , 1 , closure_reason, false , [ node_c_id] , 1000000 ) ;
1493
1448
check_closed_broadcast ( & nodes[ 0 ] , 1 , true ) ;
1494
1449
let close_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
@@ -1498,7 +1453,6 @@ mod tests {
1498
1453
check_added_monitors ( & nodes[ 2 ] , 1 ) ;
1499
1454
check_closed_broadcast ( & nodes[ 2 ] , 1 , true ) ;
1500
1455
let closure_reason = ClosureReason :: CommitmentTxConfirmed ;
1501
- let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
1502
1456
check_closed_event ! ( & nodes[ 2 ] , 1 , closure_reason, false , [ node_a_id] , 1000000 ) ;
1503
1457
1504
1458
chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . clear ( ) ;
0 commit comments