@@ -1280,6 +1280,9 @@ mod tests {
12801280 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
12811281 let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 2 ;
12821282
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+
12831286 // Route two payments to be claimed at the same time.
12841287 let ( payment_preimage_1, payment_hash_1, ..) =
12851288 route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
@@ -1305,57 +1308,34 @@ mod tests {
13051308 // fail either way but if it fails intermittently it's depending on the ordering of updates.
13061309 let mut update_iter = updates. iter ( ) ;
13071310 let next_update = update_iter. next ( ) . unwrap ( ) . clone ( ) ;
1311+ let node_b_mon = & nodes[ 1 ] . chain_monitor . chain_monitor ;
1312+
13081313 // Should contain next_update when pending updates listed.
1314+ let pending_updates = node_b_mon. list_pending_monitor_updates ( ) ;
13091315 #[ 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 ( ) ;
13171317 #[ 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+
13321324 // Should not contain the previously pending next_update when pending updates listed.
1325+ let pending_updates = node_b_mon. list_pending_monitor_updates ( ) ;
13331326 #[ 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 ( ) ;
13411328 #[ 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+
13511333 assert ! ( nodes[ 1 ] . chain_monitor. release_pending_monitor_events( ) . is_empty( ) ) ;
13521334 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
13531335 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 ( ) ;
13591339
13601340 let claim_events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
13611341 assert_eq ! ( claim_events. len( ) , 2 ) ;
@@ -1375,63 +1355,40 @@ mod tests {
13751355 // Now manually walk the commitment signed dance - because we claimed two payments
13761356 // back-to-back it doesn't fit into the neat walk commitment_signed_dance does.
13771357
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 ] ) ;
13831360 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 ) ;
13881362 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) ;
13911364
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) ;
13931366 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) ;
13981369 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) ;
14041371
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 ] ) ;
14091375 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 ) ;
14141379 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) ;
14161381 expect_payment_path_successful ! ( nodes[ 0 ] ) ;
14171382 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) ;
14201384
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) ;
14221386 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) ;
14271388 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) ;
14331390
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) ;
14351392 expect_payment_path_successful ! ( nodes[ 0 ] ) ;
14361393 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
14371394 }
@@ -1443,6 +1400,9 @@ mod tests {
14431400 let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
14441401 let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
14451402
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+
14461406 // Use FullBlockViaListen to avoid duplicate calls to process_chain_data and skips_blocks() in
14471407 // case of other connect_styles.
14481408 * nodes[ 0 ] . connect_style . borrow_mut ( ) = ConnectStyle :: FullBlockViaListen ;
@@ -1480,15 +1440,10 @@ mod tests {
14801440 // Now, close channel_2 i.e. b/w node-0 and node-2 to create pending_claim in node[0].
14811441 nodes[ 0 ]
14821442 . 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 ( ) )
14881444 . unwrap ( ) ;
14891445 let closure_reason =
14901446 ClosureReason :: HolderForceClosed { broadcasted_latest_txn : Some ( true ) } ;
1491- let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
14921447 check_closed_event ! ( & nodes[ 0 ] , 1 , closure_reason, false , [ node_c_id] , 1000000 ) ;
14931448 check_closed_broadcast ( & nodes[ 0 ] , 1 , true ) ;
14941449 let close_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
@@ -1498,7 +1453,6 @@ mod tests {
14981453 check_added_monitors ( & nodes[ 2 ] , 1 ) ;
14991454 check_closed_broadcast ( & nodes[ 2 ] , 1 , true ) ;
15001455 let closure_reason = ClosureReason :: CommitmentTxConfirmed ;
1501- let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
15021456 check_closed_event ! ( & nodes[ 2 ] , 1 , closure_reason, false , [ node_a_id] , 1000000 ) ;
15031457
15041458 chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . clear ( ) ;
0 commit comments