From: Matt Corallo Date: Fri, 10 Feb 2023 19:56:42 +0000 (+0000) Subject: Replace `get_err_msg` macro with a function X-Git-Tag: v0.0.115~76^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=35bb0f467645b3c756c0b998bb7ea052bac57581;p=rust-lightning Replace `get_err_msg` macro with a function The `get_err_msg!()` 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 322,183 LoC to 321,985 LoC. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index cd2c4011d..559c723f8 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -8469,7 +8469,7 @@ mod tests { // A MAX_UNFUNDED_CHANS_PER_PEER + 1 channel will be summarily rejected open_channel_msg.temporary_channel_id = nodes[0].keys_manager.get_secure_random_bytes(); nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); - assert_eq!(get_err_msg!(nodes[1], nodes[0].node.get_our_node_id()).channel_id, + assert_eq!(get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()).channel_id, open_channel_msg.temporary_channel_id); // Further, because all of our channels with nodes[0] are inbound, and none of them funded, @@ -8516,7 +8516,7 @@ mod tests { open_channel_msg.temporary_channel_id = nodes[0].keys_manager.get_secure_random_bytes(); } nodes[1].node.handle_open_channel(&last_random_pk, &open_channel_msg); - assert_eq!(get_err_msg!(nodes[1], last_random_pk).channel_id, + assert_eq!(get_err_msg(&nodes[1], &last_random_pk).channel_id, open_channel_msg.temporary_channel_id); // Of course, however, outbound channels are always allowed @@ -8558,7 +8558,7 @@ mod tests { // Once we have MAX_UNFUNDED_CHANS_PER_PEER unfunded channels, new inbound channels will be // rejected. nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); - assert_eq!(get_err_msg!(nodes[1], nodes[0].node.get_our_node_id()).channel_id, + assert_eq!(get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()).channel_id, open_channel_msg.temporary_channel_id); // but we can still open an outbound channel. @@ -8567,7 +8567,7 @@ mod tests { // but even with such an outbound channel, additional inbound channels will still fail. nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); - assert_eq!(get_err_msg!(nodes[1], nodes[0].node.get_our_node_id()).channel_id, + assert_eq!(get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()).channel_id, open_channel_msg.temporary_channel_id); } @@ -8623,7 +8623,7 @@ mod tests { } _ => panic!("Unexpected event"), } - assert_eq!(get_err_msg!(nodes[1], last_random_pk).channel_id, + assert_eq!(get_err_msg(&nodes[1], &last_random_pk).channel_id, open_channel_msg.temporary_channel_id); // ...however if we accept the same channel 0conf it should work just fine. @@ -8665,7 +8665,7 @@ mod tests { _ => panic!("Unexpected event"), } - let error_msg = get_err_msg!(nodes[1], nodes[0].node.get_our_node_id()); + let error_msg = get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()); nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &error_msg); let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 536e313a2..6c3c6e76d 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -544,22 +544,17 @@ macro_rules! get_event_msg { } /// Get an error message from the pending events queue. -#[macro_export] -macro_rules! get_err_msg { - ($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::HandleError { - action: $crate::ln::msgs::ErrorAction::SendErrorMessage { ref msg }, ref node_id - } => { - assert_eq!(*node_id, $node_id); - (*msg).clone() - }, - _ => panic!("Unexpected event"), - } - } +pub fn get_err_msg(node: &Node, recipient: &PublicKey) -> msgs::ErrorMessage { + let events = node.node.get_and_clear_pending_msg_events(); + assert_eq!(events.len(), 1); + match events[0] { + MessageSendEvent::HandleError { + action: msgs::ErrorAction::SendErrorMessage { ref msg }, ref node_id + } => { + assert_eq!(node_id, recipient); + (*msg).clone() + }, + _ => panic!("Unexpected event"), } } diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 7636f5c63..cf71122d5 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -278,7 +278,7 @@ fn test_scid_privacy_on_pub_channel() { assert_eq!(open_channel.channel_flags & 1, 1); // The `announce_channel` bit is set. nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); - let err = get_err_msg!(nodes[1], nodes[0].node.get_our_node_id()); + let err = get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()); assert_eq!(err.data, "SCID Alias/Privacy Channel Type cannot be set on a public channel"); } @@ -721,7 +721,7 @@ fn test_0conf_close_no_early_chan_update() { nodes[0].node.force_close_all_channels_broadcasting_latest_txn(); check_added_monitors!(nodes[0], 1); check_closed_event!(&nodes[0], 1, ClosureReason::HolderForceClosed); - let _ = get_err_msg!(nodes[0], nodes[1].node.get_our_node_id()); + let _ = get_err_msg(&nodes[0], &nodes[1].node.get_our_node_id()); } #[test]