Skip to content

Commit 6d985f8

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 753c4fe commit 6d985f8

14 files changed

+94
-94
lines changed

lightning/src/events/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ pub enum HTLCHandlingType {
501501
/// * The counterparty node modified the HTLC in transit,
502502
/// * A probing attack where an intermediary node is trying to detect if we are the ultimate
503503
/// recipient for a payment.
504-
FailedPayment {
504+
ReceiveFailed {
505505
/// The payment hash of the payment we attempted to process.
506506
payment_hash: PaymentHash
507507
},
@@ -519,7 +519,7 @@ impl_writeable_tlv_based_enum_upgradable!(HTLCHandlingType,
519519
(0, requested_forward_scid, required),
520520
},
521521
(3, InvalidOnion) => {},
522-
(4, FailedPayment) => {
522+
(4, ReceiveFailed) => {
523523
(0, payment_hash, required),
524524
},
525525
);

lightning/src/ln/async_payments_tests.rs

Lines changed: 5 additions & 5 deletions
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());
@@ -698,7 +698,7 @@ fn amount_doesnt_match_invreq() {
698698
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev)
699699
.with_payment_preimage(keysend_preimage)
700700
.without_claimable_event()
701-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
701+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
702702
do_pass_along_path(args);
703703

704704
// Modify the invoice request stored in our outbounds to be the correct one, to make sure the
@@ -914,7 +914,7 @@ fn invalid_async_receive_with_retry<F1, F2>(
914914
nodes[2].node.fail_htlc_backwards(&payment_hash);
915915
expect_pending_htlcs_forwardable_conditions(
916916
nodes[2].node.get_and_clear_pending_events(),
917-
&[HTLCHandlingType::FailedPayment { payment_hash }],
917+
&[HTLCHandlingType::ReceiveFailed { payment_hash }],
918918
);
919919
nodes[2].node.process_pending_htlc_forwards();
920920
check_added_monitors!(nodes[2], 1);
@@ -934,7 +934,7 @@ fn invalid_async_receive_with_retry<F1, F2>(
934934
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev)
935935
.with_payment_preimage(keysend_preimage)
936936
.without_claimable_event()
937-
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
937+
.expect_failure(HTLCHandlingType::ReceiveFailed { payment_hash });
938938
do_pass_along_path(args);
939939
fail_blinded_htlc_backwards(payment_hash, 1, &[&nodes[0], &nodes[1], &nodes[2]], true);
940940

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

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 8 additions & 8 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
824824

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

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

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

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

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5746,7 +5746,7 @@ where
57465746
},
57475747
}
57485748
} else {
5749-
HTLCHandlingType::FailedPayment { payment_hash }
5749+
HTLCHandlingType::ReceiveFailed { payment_hash }
57505750
}
57515751
};
57525752

@@ -5919,7 +5919,7 @@ where
59195919
let reason = if $next_hop_unknown {
59205920
HTLCHandlingType::UnknownNextHop { requested_forward_scid: short_chan_id }
59215921
} else {
5922-
HTLCHandlingType::FailedPayment{ payment_hash }
5922+
HTLCHandlingType::ReceiveFailed{ payment_hash }
59235923
};
59245924

59255925
failed_forwards.push((htlc_source, payment_hash,
@@ -6258,7 +6258,7 @@ where
62586258
cltv_expiry: Some(cltv_expiry),
62596259
}), payment_hash,
62606260
HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, htlc_msat_height_data),
6261-
HTLCHandlingType::FailedPayment { payment_hash: $payment_hash },
6261+
HTLCHandlingType::ReceiveFailed { payment_hash: $payment_hash },
62626262
));
62636263
continue 'next_forwardable_htlc;
62646264
}
@@ -6816,7 +6816,7 @@ where
68166816
let source = HTLCSource::PreviousHopData(htlc_source.0.clone());
68176817
let failure_reason = LocalHTLCFailureReason::MPPTimeout;
68186818
let reason = HTLCFailReason::from_failure_code(failure_reason);
6819-
let receiver = HTLCHandlingType::FailedPayment { payment_hash: htlc_source.1 };
6819+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash: htlc_source.1 };
68206820
self.fail_htlc_backwards_internal(&source, &htlc_source.1, &reason, receiver);
68216821
}
68226822

@@ -6881,7 +6881,7 @@ where
68816881
for htlc in payment.htlcs {
68826882
let reason = self.get_htlc_fail_reason_from_failure_code(failure_code, &htlc);
68836883
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
6884-
let receiver = HTLCHandlingType::FailedPayment { payment_hash: *payment_hash };
6884+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash: *payment_hash };
68856885
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
68866886
}
68876887
}
@@ -7109,7 +7109,7 @@ where
71097109
for htlc in htlcs {
71107110
let reason = self.get_htlc_fail_reason_from_failure_code(FailureCode::InvalidOnionPayload(None), &htlc);
71117111
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
7112-
let receiver = HTLCHandlingType::FailedPayment { payment_hash };
7112+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash };
71137113
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
71147114
}
71157115
return;
@@ -7215,7 +7215,7 @@ where
72157215
htlc_msat_height_data.extend_from_slice(&self.best_block.read().unwrap().height.to_be_bytes());
72167216
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
72177217
let reason = HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, htlc_msat_height_data);
7218-
let receiver = HTLCHandlingType::FailedPayment { payment_hash };
7218+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash };
72197219
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
72207220
}
72217221
self.claimable_payments.lock().unwrap().pending_claiming_payments.remove(&payment_hash);
@@ -11773,7 +11773,7 @@ where
1177311773
let reason = LocalHTLCFailureReason::PaymentClaimBuffer;
1177411774
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(),
1177511775
HTLCFailReason::reason(reason, htlc_msat_height_data),
11776-
HTLCHandlingType::FailedPayment { payment_hash: payment_hash.clone() }));
11776+
HTLCHandlingType::ReceiveFailed { payment_hash: payment_hash.clone() }));
1177711777
false
1177811778
} else { true }
1177911779
});
@@ -15040,7 +15040,7 @@ mod tests {
1504015040
check_added_monitors!(nodes[1], 0);
1504115041
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1504215042
expect_pending_htlcs_forwardable!(nodes[1]);
15043-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash: our_payment_hash }]);
15043+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash: our_payment_hash }]);
1504415044
check_added_monitors!(nodes[1], 1);
1504515045
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1504615046
assert!(updates.update_add_htlcs.is_empty());
@@ -15221,7 +15221,7 @@ mod tests {
1522115221
// We have to forward pending HTLCs twice - once tries to forward the payment forward (and
1522215222
// fails), the second will process the resulting failure and fail the HTLC backward
1522315223
expect_pending_htlcs_forwardable!(nodes[1]);
15224-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15224+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1522515225
check_added_monitors!(nodes[1], 1);
1522615226
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1522715227
assert!(updates.update_add_htlcs.is_empty());
@@ -15266,7 +15266,7 @@ mod tests {
1526615266
check_added_monitors!(nodes[1], 0);
1526715267
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1526815268
expect_pending_htlcs_forwardable!(nodes[1]);
15269-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15269+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1527015270
check_added_monitors!(nodes[1], 1);
1527115271
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1527215272
assert!(updates.update_add_htlcs.is_empty());
@@ -15313,7 +15313,7 @@ mod tests {
1531315313
check_added_monitors!(nodes[1], 0);
1531415314
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1531515315
expect_pending_htlcs_forwardable!(nodes[1]);
15316-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15316+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1531715317
check_added_monitors!(nodes[1], 1);
1531815318
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1531915319
assert!(updates.update_add_htlcs.is_empty());
@@ -15370,7 +15370,7 @@ mod tests {
1537015370
nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
1537115371
commitment_signed_dance!(nodes[1], nodes[0], &updates.commitment_signed, false);
1537215372
expect_pending_htlcs_forwardable!(nodes[1]);
15373-
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash: mismatch_payment_hash }]);
15373+
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash: mismatch_payment_hash }]);
1537415374
check_added_monitors(&nodes[1], 1);
1537515375
let _ = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1537615376

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,7 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
28612861
fail_payment_along_path(nodes_to_fail_payment.as_slice());
28622862
expect_htlc_handling_failed_destinations!(
28632863
path.last().unwrap().node.get_and_clear_pending_events(),
2864-
&[HTLCHandlingType::FailedPayment { payment_hash: *payment_hash }]
2864+
&[HTLCHandlingType::ReceiveFailed { payment_hash: *payment_hash }]
28652865
);
28662866
}
28672867
}
@@ -3172,7 +3172,7 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
31723172
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
31733173
}
31743174
expected_paths[0].last().unwrap().node.fail_htlc_backwards(&our_payment_hash);
3175-
let expected_destinations: Vec<HTLCHandlingType> = repeat(HTLCHandlingType::FailedPayment { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
3175+
let expected_destinations: Vec<HTLCHandlingType> = repeat(HTLCHandlingType::ReceiveFailed { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
31763176
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(expected_paths[0].last().unwrap(), expected_destinations);
31773177

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

0 commit comments

Comments
 (0)