Skip to content

Commit 432b585

Browse files
committed
ln+events+liquidity/refactor: rename FailedPayment to ReceiveRejected
Rename variant to be more specific to the current context - a FailedPayment could be a payment that we failed to dispatch or one that we rejected on receive.
1 parent 13c62ee commit 432b585

14 files changed

+94
-94
lines changed

lightning/src/events/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ pub enum HTLCHandlingType {
502502
/// * The counterparty node modified the HTLC in transit,
503503
/// * A probing attack where an intermediary node is trying to detect if we are the ultimate
504504
/// recipient for a payment.
505-
FailedPayment {
505+
ReceiveFailed {
506506
/// The payment hash of the payment we attempted to process.
507507
payment_hash: PaymentHash
508508
},
@@ -520,7 +520,7 @@ impl_writeable_tlv_based_enum_upgradable!(HTLCHandlingType,
520520
(0, requested_forward_scid, required),
521521
},
522522
(3, InvalidOnion) => {},
523-
(4, FailedPayment) => {
523+
(4, ReceiveFailed) => {
524524
(0, payment_hash, required),
525525
},
526526
);

lightning/src/ln/async_payments_tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn invalid_keysend_payment_secret() {
172172
PassAlongPathArgs::new(&nodes[0], &expected_route[0], amt_msat, payment_hash, ev.clone())
173173
.with_payment_secret(invalid_payment_secret)
174174
.with_payment_preimage(keysend_preimage)
175-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
175+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
176176
do_pass_along_path(args);
177177

178178
let updates_2_1 = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -701,7 +701,7 @@ fn amount_doesnt_match_invreq() {
701701
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev)
702702
.with_payment_preimage(keysend_preimage)
703703
.without_claimable_event()
704-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
704+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
705705
do_pass_along_path(args);
706706

707707
// Modify the invoice request stored in our outbounds to be the correct one, to make sure the
@@ -917,7 +917,7 @@ fn invalid_async_receive_with_retry<F1, F2>(
917917
nodes[2].node.fail_htlc_backwards(&payment_hash);
918918
expect_pending_htlcs_forwardable_conditions(
919919
nodes[2].node.get_and_clear_pending_events(),
920-
&[HTLCHandlingType::FailedPayment { payment_hash }],
920+
&[HTLCHandlingType::ReceiveFailed { payment_hash }],
921921
);
922922
nodes[2].node.process_pending_htlc_forwards();
923923
check_added_monitors!(nodes[2], 1);
@@ -937,7 +937,7 @@ fn invalid_async_receive_with_retry<F1, F2>(
937937
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev)
938938
.with_payment_preimage(keysend_preimage)
939939
.without_claimable_event()
940-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
940+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
941941
do_pass_along_path(args);
942942
fail_blinded_htlc_backwards(payment_hash, 1, &[&nodes[0], &nodes[1], &nodes[2]], true);
943943

@@ -1103,7 +1103,7 @@ fn expired_static_invoice_payment_path() {
11031103
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev)
11041104
.with_payment_preimage(keysend_preimage)
11051105
.without_claimable_event()
1106-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
1106+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
11071107
do_pass_along_path(args);
11081108
fail_blinded_htlc_backwards(payment_hash, 1, &[&nodes[0], &nodes[1], &nodes[2]], false);
11091109
nodes[2].logger.assert_log_contains(

lightning/src/ln/blinded_payment_tests.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ fn three_hop_blinded_path_fail() {
830830

831831
nodes[3].node.fail_htlc_backwards(&payment_hash);
832832
expect_pending_htlcs_forwardable_conditions(
833-
nodes[3].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]
833+
nodes[3].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash }]
834834
);
835835
nodes[3].node.process_pending_htlc_forwards();
836836
check_added_monitors!(nodes[3], 1);
@@ -958,7 +958,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
958958
);
959959
nodes[2].node.fail_htlc_backwards(&payment_hash);
960960
expect_pending_htlcs_forwardable_conditions(
961-
nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]
961+
nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash }]
962962
);
963963
nodes[2].node.process_pending_htlc_forwards();
964964
check_added_monitors!(nodes[2], 1);
@@ -998,7 +998,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
998998
check_added_monitors!(nodes[2], 0);
999999
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
10001000
expect_pending_htlcs_forwardable!(nodes[2]);
1001-
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]);
1001+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash }]);
10021002
check_added_monitors(&nodes[2], 1);
10031003
},
10041004
ReceiveCheckFail::ChannelCheck => {
@@ -1014,7 +1014,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
10141014
nodes[2].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown);
10151015
commitment_signed_dance!(nodes[2], nodes[1], (), false, true, false, false);
10161016
expect_pending_htlcs_forwardable!(nodes[2]);
1017-
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]);
1017+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash }]);
10181018
check_added_monitors(&nodes[2], 1);
10191019
},
10201020
ReceiveCheckFail::ProcessPendingHTLCsCheck => {
@@ -1024,15 +1024,15 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
10241024
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
10251025
expect_pending_htlcs_forwardable!(nodes[2]);
10261026
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[2],
1027-
vec![HTLCHandlingType::FailedPayment { payment_hash }]);
1027+
vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
10281028
check_added_monitors!(nodes[2], 1);
10291029
},
10301030
ReceiveCheckFail::PaymentConstraints => {
10311031
nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]);
10321032
check_added_monitors!(nodes[2], 0);
10331033
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
10341034
expect_pending_htlcs_forwardable!(nodes[2]);
1035-
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]);
1035+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash }]);
10361036
check_added_monitors(&nodes[2], 1);
10371037
}
10381038
}
@@ -1121,7 +1121,7 @@ fn blinded_path_retries() {
11211121
($intro_node: expr) => {
11221122
nodes[3].node.fail_htlc_backwards(&payment_hash);
11231123
expect_pending_htlcs_forwardable_conditions(
1124-
nodes[3].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]
1124+
nodes[3].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash }]
11251125
);
11261126
nodes[3].node.process_pending_htlc_forwards();
11271127
check_added_monitors!(nodes[3], 1);
@@ -2435,7 +2435,7 @@ fn test_trampoline_forward_rejection() {
24352435
let args = PassAlongPathArgs::new(&nodes[0], route, amt_msat, payment_hash, first_message_event)
24362436
.with_payment_preimage(payment_preimage)
24372437
.without_claimable_event()
2438-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
2438+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
24392439
do_pass_along_path(args);
24402440

24412441
{

lightning/src/ln/chanmon_update_fail_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
825825

826826
// Fail the payment backwards, failing the monitor update on nodes[1]'s receipt of the RAA
827827
nodes[2].node.fail_htlc_backwards(&payment_hash_1);
828-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCHandlingType::FailedPayment { payment_hash: payment_hash_1 }]);
828+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCHandlingType::ReceiveFailed { payment_hash: payment_hash_1 }]);
829829
check_added_monitors!(nodes[2], 1);
830830

831831
let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -1731,7 +1731,7 @@ fn test_monitor_update_on_pending_forwards() {
17311731

17321732
let (_, payment_hash_1, ..) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
17331733
nodes[2].node.fail_htlc_backwards(&payment_hash_1);
1734-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCHandlingType::FailedPayment { payment_hash: payment_hash_1 }]);
1734+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCHandlingType::ReceiveFailed { payment_hash: payment_hash_1 }]);
17351735
check_added_monitors!(nodes[2], 1);
17361736

17371737
let cs_fail_update = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -2512,7 +2512,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
25122512
};
25132513
if second_fails {
25142514
nodes[2].node.fail_htlc_backwards(&payment_hash);
2515-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
2515+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
25162516
check_added_monitors!(nodes[2], 1);
25172517
get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
25182518
} else {

lightning/src/ln/channelmanager.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -5757,7 +5757,7 @@ where
57575757
},
57585758
}
57595759
} else {
5760-
HTLCHandlingType::FailedPayment { payment_hash }
5760+
HTLCHandlingType::ReceiveFailed { payment_hash }
57615761
}
57625762
};
57635763

@@ -5931,7 +5931,7 @@ where
59315931
let reason = if $next_hop_unknown {
59325932
HTLCHandlingType::UnknownNextHop { requested_forward_scid: short_chan_id }
59335933
} else {
5934-
HTLCHandlingType::FailedPayment{ payment_hash }
5934+
HTLCHandlingType::ReceiveFailed{ payment_hash }
59355935
};
59365936

59375937
failed_forwards.push((htlc_source, payment_hash,
@@ -6267,7 +6267,7 @@ where
62676267
cltv_expiry: Some(cltv_expiry),
62686268
}), payment_hash,
62696269
HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, err_data),
6270-
HTLCHandlingType::FailedPayment { payment_hash: $payment_hash },
6270+
HTLCHandlingType::ReceiveFailed { payment_hash: $payment_hash },
62716271
));
62726272
continue 'next_forwardable_htlc;
62736273
}
@@ -6825,7 +6825,7 @@ where
68256825
let source = HTLCSource::PreviousHopData(htlc_source.0.clone());
68266826
let failure_reason = LocalHTLCFailureReason::MPPTimeout;
68276827
let reason = HTLCFailReason::from_failure_code(failure_reason);
6828-
let receiver = HTLCHandlingType::FailedPayment { payment_hash: htlc_source.1 };
6828+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash: htlc_source.1 };
68296829
self.fail_htlc_backwards_internal(&source, &htlc_source.1, &reason, receiver);
68306830
}
68316831

@@ -6890,7 +6890,7 @@ where
68906890
for htlc in payment.htlcs {
68916891
let reason = self.get_htlc_fail_reason_from_failure_code(failure_code, &htlc);
68926892
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
6893-
let receiver = HTLCHandlingType::FailedPayment { payment_hash: *payment_hash };
6893+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash: *payment_hash };
68946894
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
68956895
}
68966896
}
@@ -7118,7 +7118,7 @@ where
71187118
for htlc in htlcs {
71197119
let reason = self.get_htlc_fail_reason_from_failure_code(FailureCode::InvalidOnionPayload(None), &htlc);
71207120
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
7121-
let receiver = HTLCHandlingType::FailedPayment { payment_hash };
7121+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash };
71227122
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
71237123
}
71247124
return;
@@ -7223,7 +7223,7 @@ where
72237223
let err_data = invalid_payment_err_data(htlc.value, self.best_block.read().unwrap().height);
72247224
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
72257225
let reason = HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, err_data);
7226-
let receiver = HTLCHandlingType::FailedPayment { payment_hash };
7226+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash };
72277227
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
72287228
}
72297229
self.claimable_payments.lock().unwrap().pending_claiming_payments.remove(&payment_hash);
@@ -11814,7 +11814,7 @@ where
1181411814
let reason = LocalHTLCFailureReason::PaymentClaimBuffer;
1181511815
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(),
1181611816
HTLCFailReason::reason(reason, invalid_payment_err_data(htlc.value, height)),
11817-
HTLCHandlingType::FailedPayment { payment_hash: payment_hash.clone() }));
11817+
HTLCHandlingType::ReceiveFailed { payment_hash: payment_hash.clone() }));
1181811818
false
1181911819
} else { true }
1182011820
});
@@ -15098,7 +15098,7 @@ mod tests {
1509815098
check_added_monitors!(nodes[1], 0);
1509915099
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1510015100
expect_pending_htlcs_forwardable!(nodes[1]);
15101-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash: our_payment_hash }]);
15101+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash: our_payment_hash }]);
1510215102
check_added_monitors!(nodes[1], 1);
1510315103
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1510415104
assert!(updates.update_add_htlcs.is_empty());
@@ -15279,7 +15279,7 @@ mod tests {
1527915279
// We have to forward pending HTLCs twice - once tries to forward the payment forward (and
1528015280
// fails), the second will process the resulting failure and fail the HTLC backward
1528115281
expect_pending_htlcs_forwardable!(nodes[1]);
15282-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15282+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1528315283
check_added_monitors!(nodes[1], 1);
1528415284
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1528515285
assert!(updates.update_add_htlcs.is_empty());
@@ -15324,7 +15324,7 @@ mod tests {
1532415324
check_added_monitors!(nodes[1], 0);
1532515325
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1532615326
expect_pending_htlcs_forwardable!(nodes[1]);
15327-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15327+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1532815328
check_added_monitors!(nodes[1], 1);
1532915329
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1533015330
assert!(updates.update_add_htlcs.is_empty());
@@ -15371,7 +15371,7 @@ mod tests {
1537115371
check_added_monitors!(nodes[1], 0);
1537215372
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1537315373
expect_pending_htlcs_forwardable!(nodes[1]);
15374-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15374+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1537515375
check_added_monitors!(nodes[1], 1);
1537615376
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1537715377
assert!(updates.update_add_htlcs.is_empty());
@@ -15428,7 +15428,7 @@ mod tests {
1542815428
nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
1542915429
commitment_signed_dance!(nodes[1], nodes[0], &updates.commitment_signed, false);
1543015430
expect_pending_htlcs_forwardable!(nodes[1]);
15431-
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash: mismatch_payment_hash }]);
15431+
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash: mismatch_payment_hash }]);
1543215432
check_added_monitors(&nodes[1], 1);
1543315433
let _ = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1543415434

lightning/src/ln/functional_test_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,7 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
28682868
fail_payment_along_path(nodes_to_fail_payment.as_slice());
28692869
expect_htlc_handling_failed_destinations!(
28702870
path.last().unwrap().node.get_and_clear_pending_events(),
2871-
&[HTLCHandlingType::FailedPayment { payment_hash: *payment_hash }]
2871+
&[HTLCHandlingType::ReceiveFailed { payment_hash: *payment_hash }]
28722872
);
28732873
}
28742874
}
@@ -3182,7 +3182,7 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
31823182
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
31833183
}
31843184
expected_paths[0].last().unwrap().node.fail_htlc_backwards(&our_payment_hash);
3185-
let expected_destinations: Vec<HTLCHandlingType> = repeat(HTLCHandlingType::FailedPayment { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
3185+
let expected_destinations: Vec<HTLCHandlingType> = repeat(HTLCHandlingType::ReceiveFailed { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
31863186
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(expected_paths[0].last().unwrap(), expected_destinations);
31873187

31883188
pass_failed_payment_back(origin_node, expected_paths, skip_last, our_payment_hash, PaymentFailureReason::RecipientRejected);

0 commit comments

Comments
 (0)