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

lightning/src/ln/functional_test_utils.rs

index e4f37efaa3198da510812b8a7ac8996d0b076508..31aa24b706ff8f7520985dccbef1f99081c8bb70 100644 (file)
@@ -20,6 +20,7 @@ use crate::routing::router::{self, PaymentParameters, Route};
 use crate::ln::features::InitFeatures;
 use crate::ln::msgs;
 use crate::ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
+use crate::util::events::ClosureReason;
 use crate::util::enforcing_trait_impls::EnforcingSigner;
 use crate::util::scid_utils;
 use crate::util::test_utils;
@@ -1263,31 +1264,35 @@ macro_rules! check_closed_broadcast {
 }
 
 /// Check that a channel's closing channel events has been issued
+pub fn check_closed_event(node: &Node, events_count: usize, expected_reason: ClosureReason, is_check_discard_funding: bool) {
+       let events = node.node.get_and_clear_pending_events();
+       assert_eq!(events.len(), events_count, "{:?}", events);
+       let mut issues_discard_funding = false;
+       for event in events {
+               match event {
+                       Event::ChannelClosed { ref reason, .. } => {
+                               assert_eq!(*reason, expected_reason);
+                       },
+                       Event::DiscardFunding { .. } => {
+                               issues_discard_funding = true;
+                       }
+                       _ => panic!("Unexpected event"),
+               }
+       }
+       assert_eq!(is_check_discard_funding, issues_discard_funding);
+}
+
+/// Check that a channel's closing channel events has been issued
+///
+/// Don't use this, use the identically-named function instead.
 #[macro_export]
 macro_rules! check_closed_event {
        ($node: expr, $events: expr, $reason: expr) => {
                check_closed_event!($node, $events, $reason, false);
        };
-       ($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {{
-               use $crate::util::events::Event;
-
-               let events = $node.node.get_and_clear_pending_events();
-               assert_eq!(events.len(), $events, "{:?}", events);
-               let expected_reason = $reason;
-               let mut issues_discard_funding = false;
-               for event in events {
-                       match event {
-                               Event::ChannelClosed { ref reason, .. } => {
-                                       assert_eq!(*reason, expected_reason);
-                               },
-                               Event::DiscardFunding { .. } => {
-                                       issues_discard_funding = true;
-                               }
-                               _ => panic!("Unexpected event"),
-                       }
-               }
-               assert_eq!($is_check_discard_funding, issues_discard_funding);
-       }}
+       ($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {
+               $crate::ln::functional_test_utils::check_closed_event(&$node, $events, $reason, $is_check_discard_funding);
+       }
 }
 
 pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: &Node<'a, 'b, 'c>, channel_id: &[u8; 32], funding_tx: Transaction, close_inbound_first: bool) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, Transaction) {