mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Replace get_revoke_commit_msgs
macro with a function
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.
This commit is contained in:
parent
b5912eccf0
commit
90b2f5e1aa
2 changed files with 38 additions and 25 deletions
|
@ -8831,7 +8831,7 @@ pub mod bench {
|
||||||
let payment_event = SendEvent::from_event($node_a.get_and_clear_pending_msg_events().pop().unwrap());
|
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_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);
|
$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_revoke_and_ack(&$node_b.get_our_node_id(), &raa);
|
||||||
$node_a.handle_commitment_signed(&$node_b.get_our_node_id(), &cs);
|
$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()));
|
$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"),
|
_ => 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_revoke_and_ack(&$node_a.get_our_node_id(), &raa);
|
||||||
$node_b.handle_commitment_signed(&$node_a.get_our_node_id(), &cs);
|
$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()));
|
$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()));
|
||||||
|
|
|
@ -482,23 +482,22 @@ 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)
|
(announcement, as_update, bs_update, channel_id, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
/// Gets an RAA and CS which were sent in response to a commitment update
|
/// Gets an RAA and CS which were sent in response to a commitment update
|
||||||
macro_rules! get_revoke_commit_msgs {
|
///
|
||||||
($node: expr, $node_id: expr) => {
|
/// Should only be used directly when the `$node` is not actually a [`Node`].
|
||||||
{
|
macro_rules! do_get_revoke_commit_msgs {
|
||||||
use $crate::util::events::MessageSendEvent;
|
($node: expr, $recipient: expr) => { {
|
||||||
let events = $node.node.get_and_clear_pending_msg_events();
|
let events = $node.node.get_and_clear_pending_msg_events();
|
||||||
assert_eq!(events.len(), 2);
|
assert_eq!(events.len(), 2);
|
||||||
(match events[0] {
|
(match events[0] {
|
||||||
MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
|
MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
|
||||||
assert_eq!(*node_id, $node_id);
|
assert_eq!(node_id, $recipient);
|
||||||
(*msg).clone()
|
(*msg).clone()
|
||||||
},
|
},
|
||||||
_ => panic!("Unexpected event"),
|
_ => panic!("Unexpected event"),
|
||||||
}, match events[1] {
|
}, match events[1] {
|
||||||
MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
|
MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
|
||||||
assert_eq!(*node_id, $node_id);
|
assert_eq!(node_id, $recipient);
|
||||||
assert!(updates.update_add_htlcs.is_empty());
|
assert!(updates.update_add_htlcs.is_empty());
|
||||||
assert!(updates.update_fulfill_htlcs.is_empty());
|
assert!(updates.update_fulfill_htlcs.is_empty());
|
||||||
assert!(updates.update_fail_htlcs.is_empty());
|
assert!(updates.update_fail_htlcs.is_empty());
|
||||||
|
@ -508,7 +507,21 @@ macro_rules! get_revoke_commit_msgs {
|
||||||
},
|
},
|
||||||
_ => panic!("Unexpected event"),
|
_ => 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) => {
|
||||||
|
$crate::ln::functional_test_utils::get_revoke_commit_msgs(&$node, &$node_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue