]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Replace `check_closed_broadcast` macro with a function
authorMatt Corallo <git@bluematt.me>
Fri, 10 Feb 2023 20:07:54 +0000 (20:07 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 1 Mar 2023 18:30:18 +0000 (18:30 +0000)
The `check_closed_broadcast!()` 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 313,312 LoC to 309,522 LoC.

lightning/src/ln/functional_test_utils.rs

index ded630547377913d8f731441f33f60719cd1dec3..e4f37efaa3198da510812b8a7ac8996d0b076508 100644 (file)
@@ -1231,30 +1231,35 @@ macro_rules! check_warn_msg {
 
 /// Check that a channel's closing channel update has been broadcasted, and optionally
 /// check whether an error message event has occurred.
-#[macro_export]
-macro_rules! check_closed_broadcast {
-       ($node: expr, $with_error_msg: expr) => {{
-               use $crate::util::events::MessageSendEvent;
-               use $crate::ln::msgs::ErrorAction;
-
-               let msg_events = $node.node.get_and_clear_pending_msg_events();
-               assert_eq!(msg_events.len(), if $with_error_msg { 2 } else { 1 });
-               match msg_events[0] {
-                       MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
-                               assert_eq!(msg.contents.flags & 2, 2);
+pub fn check_closed_broadcast(node: &Node, with_error_msg: bool) -> Option<msgs::ErrorMessage> {
+       let msg_events = node.node.get_and_clear_pending_msg_events();
+       assert_eq!(msg_events.len(), if with_error_msg { 2 } else { 1 });
+       match msg_events[0] {
+               MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
+                       assert_eq!(msg.contents.flags & 2, 2);
+               },
+               _ => panic!("Unexpected event"),
+       }
+       if with_error_msg {
+               match msg_events[1] {
+                       MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
+                               // TODO: Check node_id
+                               Some(msg.clone())
                        },
                        _ => panic!("Unexpected event"),
                }
-               if $with_error_msg {
-                       match msg_events[1] {
-                               MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
-                                       // TODO: Check node_id
-                                       Some(msg.clone())
-                               },
-                               _ => panic!("Unexpected event"),
-                       }
-               } else { None }
-       }}
+       } else { None }
+}
+
+/// Check that a channel's closing channel update has been broadcasted, and optionally
+/// check whether an error message event has occurred.
+///
+/// Don't use this, use the identically-named function instead.
+#[macro_export]
+macro_rules! check_closed_broadcast {
+       ($node: expr, $with_error_msg: expr) => {
+               $crate::ln::functional_test_utils::check_closed_broadcast(&$node, $with_error_msg)
+       }
 }
 
 /// Check that a channel's closing channel events has been issued