Skip to content

Commit 9907dc8

Browse files
committed
f Refactor expect..and_htlc_handling_failed macro
1 parent e8256d5 commit 9907dc8

14 files changed

+186
-174
lines changed

lightning-dns-resolver/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ mod test {
179179
use lightning::types::payment::PaymentHash;
180180
use lightning::util::logger::Logger;
181181

182-
use lightning::{
183-
commitment_signed_dance, expect_payment_claimed,
184-
get_htlc_update_msgs,
185-
};
182+
use lightning::{commitment_signed_dance, expect_payment_claimed, get_htlc_update_msgs};
186183
use lightning_types::string::UntrustedString;
187184

188185
use std::ops::Deref;

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,9 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
975975

976976
// Fail the payment backwards, failing the monitor update on nodes[1]'s receipt of the RAA
977977
nodes[2].node.fail_htlc_backwards(&payment_hash_1);
978-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
979-
nodes[2],
980-
[HTLCHandlingFailureType::Receive { payment_hash: payment_hash_1 }]
978+
expect_pending_htlc_processing_and_htlc_handling_failed(
979+
&nodes[2],
980+
&[HTLCHandlingFailureType::Receive { payment_hash: payment_hash_1 }],
981981
);
982982
check_added_monitors!(nodes[2], 1);
983983

@@ -1067,9 +1067,9 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
10671067
let (latest_update, _) = get_latest_mon_update_id(&nodes[1], chan_2.2);
10681068
nodes[1].chain_monitor.chain_monitor.force_channel_monitor_updated(chan_2.2, latest_update);
10691069
check_added_monitors!(nodes[1], 0);
1070-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
1071-
nodes[1],
1072-
[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_2.2 }]
1070+
expect_pending_htlc_processing_and_htlc_handling_failed(
1071+
&nodes[1],
1072+
&[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_2.2 }],
10731073
);
10741074
check_added_monitors!(nodes[1], 1);
10751075

@@ -1973,9 +1973,9 @@ fn test_monitor_update_on_pending_forwards() {
19731973

19741974
let (_, payment_hash_1, ..) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
19751975
nodes[2].node.fail_htlc_backwards(&payment_hash_1);
1976-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
1977-
nodes[2],
1978-
[HTLCHandlingFailureType::Receive { payment_hash: payment_hash_1 }]
1976+
expect_pending_htlc_processing_and_htlc_handling_failed(
1977+
&nodes[2],
1978+
&[HTLCHandlingFailureType::Receive { payment_hash: payment_hash_1 }],
19791979
);
19801980
check_added_monitors!(nodes[2], 1);
19811981

@@ -1998,9 +1998,9 @@ fn test_monitor_update_on_pending_forwards() {
19981998
commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false);
19991999

20002000
chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
2001-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
2002-
nodes[1],
2003-
[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_2.2 }]
2001+
expect_pending_htlc_processing_and_htlc_handling_failed(
2002+
&nodes[1],
2003+
&[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_2.2 }],
20042004
);
20052005
check_added_monitors!(nodes[1], 1);
20062006

@@ -2501,9 +2501,9 @@ fn test_fail_htlc_on_broadcast_after_claim() {
25012501
check_closed_broadcast!(nodes[1], true);
25022502
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
25032503
check_added_monitors!(nodes[1], 1);
2504-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
2505-
nodes[1],
2506-
[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_id_2 }]
2504+
expect_pending_htlc_processing_and_htlc_handling_failed(
2505+
&nodes[1],
2506+
&[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_id_2 }],
25072507
);
25082508

25092509
nodes[0].node.handle_update_fulfill_htlc(node_b_id, &bs_updates.update_fulfill_htlcs[0]);
@@ -2887,9 +2887,9 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
28872887
msgs::UpdateFulfillHTLC { channel_id: chan_id_2, htlc_id: 0, payment_preimage };
28882888
if second_fails {
28892889
nodes[2].node.fail_htlc_backwards(&payment_hash);
2890-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
2891-
nodes[2],
2892-
[HTLCHandlingFailureType::Receive { payment_hash }]
2890+
expect_pending_htlc_processing_and_htlc_handling_failed(
2891+
&nodes[2],
2892+
&[HTLCHandlingFailureType::Receive { payment_hash }],
28932893
);
28942894
check_added_monitors!(nodes[2], 1);
28952895
get_htlc_update_msgs!(nodes[2], node_b_id);
@@ -2936,9 +2936,9 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
29362936
let mut reconnect_args = ReconnectArgs::new(&nodes[1], &nodes[2]);
29372937
reconnect_args.pending_htlc_fails.0 = 1;
29382938
reconnect_nodes(reconnect_args);
2939-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
2940-
nodes[1],
2941-
[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_id_2 }]
2939+
expect_pending_htlc_processing_and_htlc_handling_failed(
2940+
&nodes[1],
2941+
&[HTLCHandlingFailureType::Forward { node_id: Some(node_c_id), channel_id: chan_id_2 }],
29422942
);
29432943
} else {
29442944
let mut reconnect_args = ReconnectArgs::new(&nodes[1], &nodes[2]);

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16915,7 +16915,9 @@ mod tests {
1691516915
check_added_monitors!(nodes[1], 0);
1691616916
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1691716917
expect_pending_htlc_processing(&nodes[1], true);
16918-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], [HTLCHandlingFailureType::Receive { payment_hash: our_payment_hash }]);
16918+
let events = nodes[1].node.get_and_clear_pending_events();
16919+
let fail = HTLCHandlingFailureType::Receive { payment_hash: our_payment_hash };
16920+
expect_pending_htlcs_forwardable_conditions(events, &[fail]);
1691916921
check_added_monitors!(nodes[1], 1);
1692016922
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1692116923
assert!(updates.update_add_htlcs.is_empty());
@@ -17135,7 +17137,9 @@ mod tests {
1713517137
// We have to forward pending HTLCs twice - once tries to forward the payment forward (and
1713617138
// fails), the second will process the resulting failure and fail the HTLC backward
1713717139
expect_pending_htlc_processing(&nodes[1], true);
17138-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], [HTLCHandlingFailureType::Receive { payment_hash }]);
17140+
let events = nodes[1].node.get_and_clear_pending_events();
17141+
let fail = HTLCHandlingFailureType::Receive { payment_hash };
17142+
expect_pending_htlcs_forwardable_conditions(events, &[fail]);
1713917143
nodes[1].node.get_and_clear_pending_events();
1714017144
check_added_monitors!(nodes[1], 1);
1714117145
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
@@ -17181,7 +17185,9 @@ mod tests {
1718117185
check_added_monitors!(nodes[1], 0);
1718217186
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1718317187
expect_pending_htlc_processing(&nodes[1], true);
17184-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], [HTLCHandlingFailureType::Receive { payment_hash }]);
17188+
let events = nodes[1].node.get_and_clear_pending_events();
17189+
let fail = HTLCHandlingFailureType::Receive { payment_hash };
17190+
expect_pending_htlcs_forwardable_conditions(events, &[fail]);
1718517191
check_added_monitors!(nodes[1], 1);
1718617192
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1718717193
assert!(updates.update_add_htlcs.is_empty());
@@ -17228,7 +17234,9 @@ mod tests {
1722817234
check_added_monitors!(nodes[1], 0);
1722917235
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1723017236
expect_pending_htlc_processing(&nodes[1], true);
17231-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], [HTLCHandlingFailureType::Receive { payment_hash }]);
17237+
let events = nodes[1].node.get_and_clear_pending_events();
17238+
let fail = HTLCHandlingFailureType::Receive { payment_hash };
17239+
expect_pending_htlcs_forwardable_conditions(events, &[fail]);
1723217240
check_added_monitors!(nodes[1], 1);
1723317241
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1723417242
assert!(updates.update_add_htlcs.is_empty());

lightning/src/ln/functional_test_utils.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,23 +2385,16 @@ pub fn expect_pending_htlcs_forwardable_conditions(
23852385
}
23862386
}
23872387

2388-
#[macro_export]
2389-
/// Handles a PendingHTLCsForwardable and HTLCHandlingFailed event
2390-
macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed {
2391-
($node: expr, $expected_failures: expr) => {{
2392-
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions(
2393-
$node.node.get_and_clear_pending_events(),
2394-
&$expected_failures,
2395-
);
2396-
$node.node.process_pending_htlc_forwards();
2397-
2398-
// Ensure process_pending_htlc_forwards is idempotent.
2399-
$node.node.process_pending_htlc_forwards();
2400-
}};
2388+
pub fn expect_pending_htlc_processing_and_htlc_handling_failed(
2389+
node: &Node<'_, '_, '_>, expected_failures: &[HTLCHandlingFailureType],
2390+
) {
2391+
let events = node.node.get_and_clear_pending_events();
2392+
expect_pending_htlcs_forwardable_conditions(events, expected_failures);
2393+
expect_pending_htlc_processing(node, false);
2394+
assert!(node.node.get_and_clear_pending_events().is_empty());
24012395
}
24022396

2403-
pub fn expect_pending_htlc_processing(node: &Node<'_, '_, '_>, process_twice: bool)
2404-
{
2397+
pub fn expect_pending_htlc_processing(node: &Node<'_, '_, '_>, process_twice: bool) {
24052398
assert!(node.node.is_pending_htlc_processing());
24062399
node.node.process_pending_htlc_forwards();
24072400
if process_twice {
@@ -2413,7 +2406,6 @@ pub fn expect_pending_htlc_processing(node: &Node<'_, '_, '_>, process_twice: bo
24132406
assert!(!node.node.is_pending_htlc_processing());
24142407
}
24152408

2416-
24172409
#[macro_export]
24182410
/// Performs the "commitment signed dance" - the series of message exchanges which occur after a
24192411
/// commitment update.
@@ -2561,12 +2553,12 @@ pub fn do_commitment_signed_dance(
25612553
}
25622554

25632555
if fail_backwards {
2564-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
2565-
node_a,
2566-
[crate::events::HTLCHandlingFailureType::Forward {
2556+
expect_pending_htlc_processing_and_htlc_handling_failed(
2557+
&node_a,
2558+
&[crate::events::HTLCHandlingFailureType::Forward {
25672559
node_id: Some(node_b_id),
2568-
channel_id
2569-
}]
2560+
channel_id,
2561+
}],
25702562
);
25712563
check_added_monitors!(node_a, 1);
25722564

@@ -3924,9 +3916,9 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(
39243916
repeat(HTLCHandlingFailureType::Receive { payment_hash: our_payment_hash })
39253917
.take(expected_paths.len())
39263918
.collect();
3927-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
3928-
expected_paths[0].last().unwrap(),
3929-
expected_destinations
3919+
expect_pending_htlc_processing_and_htlc_handling_failed(
3920+
&expected_paths[0].last().unwrap(),
3921+
&expected_destinations,
39303922
);
39313923

39323924
pass_failed_payment_back(
@@ -4006,12 +3998,12 @@ pub fn pass_failed_payment_back<'a, 'b, 'c>(
40063998
update_next_node
40073999
);
40084000
if !update_next_node {
4009-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(
4010-
node,
4011-
[HTLCHandlingFailureType::Forward {
4001+
expect_pending_htlc_processing_and_htlc_handling_failed(
4002+
&node,
4003+
&[HTLCHandlingFailureType::Forward {
40124004
node_id: Some(prev_node.node.get_our_node_id()),
4013-
channel_id: next_msgs.as_ref().unwrap().0.channel_id
4014-
}]
4005+
channel_id: next_msgs.as_ref().unwrap().0.channel_id,
4006+
}],
40154007
);
40164008
}
40174009
}

0 commit comments

Comments
 (0)