From 1f01f2ef672ba6054b0cd0ba2606960cb550ab0c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 9 Aug 2024 13:20:35 +0000 Subject: [PATCH] Use `check_added_monitors` test utility in invoice utils tests In a coming commit, the `lightning-invoice::utils` module will move to the `lightning` crate, causing its tests to be included in the global lockorder tests done in that crate. This should be fine, except that the `lightning-invoice::utils` module currently holds the `added_monitors` lock too long causing lockorder violations. Instead, this commit replaces the legacy monitors-added test with the `check_added_monitors` test utility. --- lightning-invoice/src/utils.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index 669e6f50f..5b94c3ada 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -905,20 +905,15 @@ mod test { nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(*invoice.payment_secret()), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap(); - let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); - assert_eq!(added_monitors.len(), 1); - added_monitors.clear(); + check_added_monitors(&nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) - }; nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); - let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap(); - assert_eq!(added_monitors.len(), 1); - added_monitors.clear(); + check_added_monitors(&nodes[1], 1); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); } @@ -1362,9 +1357,7 @@ mod test { nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(*invoice.payment_secret()), PaymentId(payment_hash.0), params, Retry::Attempts(0)).unwrap(); - let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); - assert_eq!(added_monitors.len(), 1); - added_monitors.clear(); + check_added_monitors(&nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); -- 2.39.5