Replace `get_revoke_commit_msgs` macro with a function
authorMatt Corallo <git@bluematt.me>
Fri, 10 Feb 2023 19:39:09 +0000 (19:39 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 1 Mar 2023 18:29:12 +0000 (18:29 +0000)
The `get_revoke_commit_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 324,763 LoC to 322,183 LoC.

lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs

index 0757e117ce2e7660648856053070c12773b2b6b1..cd2c4011dd53c3142ed5e7e889d0a4b3f233dd8d 100644 (file)
@@ -8831,7 +8831,7 @@ pub mod bench {
                                let payment_event = SendEvent::from_event($node_a.get_and_clear_pending_msg_events().pop().unwrap());
                                $node_b.handle_update_add_htlc(&$node_a.get_our_node_id(), &payment_event.msgs[0]);
                                $node_b.handle_commitment_signed(&$node_a.get_our_node_id(), &payment_event.commitment_msg);
-                               let (raa, cs) = get_revoke_commit_msgs!(NodeHolder { node: &$node_b }, $node_a.get_our_node_id());
+                               let (raa, cs) = do_get_revoke_commit_msgs!(NodeHolder { node: &$node_b }, &$node_a.get_our_node_id());
                                $node_a.handle_revoke_and_ack(&$node_b.get_our_node_id(), &raa);
                                $node_a.handle_commitment_signed(&$node_b.get_our_node_id(), &cs);
                                $node_b.handle_revoke_and_ack(&$node_a.get_our_node_id(), &get_event_msg!(NodeHolder { node: &$node_a }, MessageSendEvent::SendRevokeAndACK, $node_b.get_our_node_id()));
@@ -8850,7 +8850,7 @@ pub mod bench {
                                        _ => panic!("Failed to generate claim event"),
                                }
 
-                               let (raa, cs) = get_revoke_commit_msgs!(NodeHolder { node: &$node_a }, $node_b.get_our_node_id());
+                               let (raa, cs) = do_get_revoke_commit_msgs!(NodeHolder { node: &$node_a }, &$node_b.get_our_node_id());
                                $node_b.handle_revoke_and_ack(&$node_a.get_our_node_id(), &raa);
                                $node_b.handle_commitment_signed(&$node_a.get_our_node_id(), &cs);
                                $node_a.handle_revoke_and_ack(&$node_b.get_our_node_id(), &get_event_msg!(NodeHolder { node: &$node_b }, MessageSendEvent::SendRevokeAndACK, $node_a.get_our_node_id()));
index 542dc65949857a3d1031c49be8c0da08db6fdb55..536e313a28c19d9805dea1b2af443b217397e013 100644 (file)
@@ -482,33 +482,46 @@ pub fn create_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(node_a: &'a Node<'b,
        (announcement, as_update, bs_update, channel_id, tx)
 }
 
+/// Gets an RAA and CS which were sent in response to a commitment update
+///
+/// Should only be used directly when the `$node` is not actually a [`Node`].
+macro_rules! do_get_revoke_commit_msgs {
+       ($node: expr, $recipient: expr) => { {
+               let events = $node.node.get_and_clear_pending_msg_events();
+               assert_eq!(events.len(), 2);
+               (match events[0] {
+                       MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
+                               assert_eq!(node_id, $recipient);
+                               (*msg).clone()
+                       },
+                       _ => panic!("Unexpected event"),
+               }, match events[1] {
+                       MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
+                               assert_eq!(node_id, $recipient);
+                               assert!(updates.update_add_htlcs.is_empty());
+                               assert!(updates.update_fulfill_htlcs.is_empty());
+                               assert!(updates.update_fail_htlcs.is_empty());
+                               assert!(updates.update_fail_malformed_htlcs.is_empty());
+                               assert!(updates.update_fee.is_none());
+                               updates.commitment_signed.clone()
+                       },
+                       _ => panic!("Unexpected event"),
+               })
+       } }
+}
+
+/// Gets an RAA and CS which were sent in response to a commitment update
+pub fn get_revoke_commit_msgs(node: &Node, recipient: &PublicKey) -> (msgs::RevokeAndACK, msgs::CommitmentSigned) {
+       do_get_revoke_commit_msgs!(node, recipient)
+}
+
 #[macro_export]
 /// Gets an RAA and CS which were sent in response to a commitment update
+///
+/// Don't use this, use the identically-named function instead.
 macro_rules! get_revoke_commit_msgs {
        ($node: expr, $node_id: expr) => {
-               {
-                       use $crate::util::events::MessageSendEvent;
-                       let events = $node.node.get_and_clear_pending_msg_events();
-                       assert_eq!(events.len(), 2);
-                       (match events[0] {
-                               MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
-                                       assert_eq!(*node_id, $node_id);
-                                       (*msg).clone()
-                               },
-                               _ => panic!("Unexpected event"),
-                       }, match events[1] {
-                               MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
-                                       assert_eq!(*node_id, $node_id);
-                                       assert!(updates.update_add_htlcs.is_empty());
-                                       assert!(updates.update_fulfill_htlcs.is_empty());
-                                       assert!(updates.update_fail_htlcs.is_empty());
-                                       assert!(updates.update_fail_malformed_htlcs.is_empty());
-                                       assert!(updates.update_fee.is_none());
-                                       updates.commitment_signed.clone()
-                               },
-                               _ => panic!("Unexpected event"),
-                       })
-               }
+               $crate::ln::functional_test_utils::get_revoke_commit_msgs(&$node, &$node_id)
        }
 }