Replace `get_htlc_update_msgs` macro with a function
authorMatt Corallo <git@bluematt.me>
Fri, 10 Feb 2023 19:57:00 +0000 (19:57 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 1 Mar 2023 18:29:43 +0000 (18:29 +0000)
The `get_htlc_update_msgs!()` macro has no reason to be a macro
so here we move its logic to a function and leave the macro in
place to avoid touching every line of code in the tests.

This reduces the `--profile=test --lib` `Zpretty=expanded` code
size from 321,985 LoC to 316,856 LoC.

lightning/src/ln/functional_test_utils.rs

index 6c3c6e76d422cb9967cc694d8a640d50cdd46de2..458d303fc101cd2af99564896ba3b9e91212b486 100644 (file)
@@ -576,21 +576,26 @@ macro_rules! get_event {
        }
 }
 
+/// Gets an UpdateHTLCs MessageSendEvent
+pub fn get_htlc_update_msgs(node: &Node, recipient: &PublicKey) -> msgs::CommitmentUpdate {
+       let events = node.node.get_and_clear_pending_msg_events();
+       assert_eq!(events.len(), 1);
+       match events[0] {
+               MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
+                       assert_eq!(node_id, recipient);
+                       (*updates).clone()
+               },
+               _ => panic!("Unexpected event"),
+       }
+}
+
 #[macro_export]
 /// Gets an UpdateHTLCs MessageSendEvent
+///
+/// Don't use this, use the identically-named function instead.
 macro_rules! get_htlc_update_msgs {
        ($node: expr, $node_id: expr) => {
-               {
-                       let events = $node.node.get_and_clear_pending_msg_events();
-                       assert_eq!(events.len(), 1);
-                       match events[0] {
-                               $crate::util::events::MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
-                                       assert_eq!(*node_id, $node_id);
-                                       (*updates).clone()
-                               },
-                               _ => panic!("Unexpected event"),
-                       }
-               }
+               $crate::ln::functional_test_utils::get_htlc_update_msgs(&$node, &$node_id)
        }
 }