Skip to content

Commit 2caefd1

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 560e73a commit 2caefd1

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
@@ -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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5754,7 +5754,7 @@ where
57545754
},
57555755
}
57565756
} else {
5757-
HTLCHandlingType::FailedPayment { payment_hash }
5757+
HTLCHandlingType::ReceiveFailed { payment_hash }
57585758
}
57595759
};
57605760

@@ -5927,7 +5927,7 @@ where
59275927
let reason = if $next_hop_unknown {
59285928
HTLCHandlingType::UnknownNextHop { requested_forward_scid: short_chan_id }
59295929
} else {
5930-
HTLCHandlingType::FailedPayment{ payment_hash }
5930+
HTLCHandlingType::ReceiveFailed{ payment_hash }
59315931
};
59325932

59335933
failed_forwards.push((htlc_source, payment_hash,
@@ -6266,7 +6266,7 @@ where
62666266
cltv_expiry: Some(cltv_expiry),
62676267
}), payment_hash,
62686268
HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, htlc_msat_height_data),
6269-
HTLCHandlingType::FailedPayment { payment_hash: $payment_hash },
6269+
HTLCHandlingType::ReceiveFailed { payment_hash: $payment_hash },
62706270
));
62716271
continue 'next_forwardable_htlc;
62726272
}
@@ -6824,7 +6824,7 @@ where
68246824
let source = HTLCSource::PreviousHopData(htlc_source.0.clone());
68256825
let failure_reason = LocalHTLCFailureReason::MPPTimeout;
68266826
let reason = HTLCFailReason::from_failure_code(failure_reason);
6827-
let receiver = HTLCHandlingType::FailedPayment { payment_hash: htlc_source.1 };
6827+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash: htlc_source.1 };
68286828
self.fail_htlc_backwards_internal(&source, &htlc_source.1, &reason, receiver);
68296829
}
68306830

@@ -6889,7 +6889,7 @@ where
68896889
for htlc in payment.htlcs {
68906890
let reason = self.get_htlc_fail_reason_from_failure_code(failure_code, &htlc);
68916891
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
6892-
let receiver = HTLCHandlingType::FailedPayment { payment_hash: *payment_hash };
6892+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash: *payment_hash };
68936893
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
68946894
}
68956895
}
@@ -7117,7 +7117,7 @@ where
71177117
for htlc in htlcs {
71187118
let reason = self.get_htlc_fail_reason_from_failure_code(FailureCode::InvalidOnionPayload(None), &htlc);
71197119
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
7120-
let receiver = HTLCHandlingType::FailedPayment { payment_hash };
7120+
let receiver = HTLCHandlingType::ReceiveFailed { payment_hash };
71217121
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
71227122
}
71237123
return;
@@ -7223,7 +7223,7 @@ where
72237223
htlc_msat_height_data.extend_from_slice(&self.best_block.read().unwrap().height.to_be_bytes());
72247224
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
72257225
let reason = HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, htlc_msat_height_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);
@@ -11816,7 +11816,7 @@ where
1181611816
let reason = LocalHTLCFailureReason::PaymentClaimBuffer;
1181711817
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(),
1181811818
HTLCFailReason::reason(reason, htlc_msat_height_data),
11819-
HTLCHandlingType::FailedPayment { payment_hash: payment_hash.clone() }));
11819+
HTLCHandlingType::ReceiveFailed { payment_hash: payment_hash.clone() }));
1182011820
false
1182111821
} else { true }
1182211822
});
@@ -15100,7 +15100,7 @@ mod tests {
1510015100
check_added_monitors!(nodes[1], 0);
1510115101
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1510215102
expect_pending_htlcs_forwardable!(nodes[1]);
15103-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash: our_payment_hash }]);
15103+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash: our_payment_hash }]);
1510415104
check_added_monitors!(nodes[1], 1);
1510515105
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1510615106
assert!(updates.update_add_htlcs.is_empty());
@@ -15281,7 +15281,7 @@ mod tests {
1528115281
// We have to forward pending HTLCs twice - once tries to forward the payment forward (and
1528215282
// fails), the second will process the resulting failure and fail the HTLC backward
1528315283
expect_pending_htlcs_forwardable!(nodes[1]);
15284-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15284+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1528515285
check_added_monitors!(nodes[1], 1);
1528615286
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1528715287
assert!(updates.update_add_htlcs.is_empty());
@@ -15326,7 +15326,7 @@ mod tests {
1532615326
check_added_monitors!(nodes[1], 0);
1532715327
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1532815328
expect_pending_htlcs_forwardable!(nodes[1]);
15329-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15329+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1533015330
check_added_monitors!(nodes[1], 1);
1533115331
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1533215332
assert!(updates.update_add_htlcs.is_empty());
@@ -15373,7 +15373,7 @@ mod tests {
1537315373
check_added_monitors!(nodes[1], 0);
1537415374
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
1537515375
expect_pending_htlcs_forwardable!(nodes[1]);
15376-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::FailedPayment { payment_hash }]);
15376+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCHandlingType::ReceiveFailed { payment_hash }]);
1537715377
check_added_monitors!(nodes[1], 1);
1537815378
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1537915379
assert!(updates.update_add_htlcs.is_empty());
@@ -15430,7 +15430,7 @@ mod tests {
1543015430
nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
1543115431
commitment_signed_dance!(nodes[1], nodes[0], &updates.commitment_signed, false);
1543215432
expect_pending_htlcs_forwardable!(nodes[1]);
15433-
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash: mismatch_payment_hash }]);
15433+
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::ReceiveFailed { payment_hash: mismatch_payment_hash }]);
1543415434
check_added_monitors(&nodes[1], 1);
1543515435
let _ = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
1543615436

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,7 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
28642864
fail_payment_along_path(nodes_to_fail_payment.as_slice());
28652865
expect_htlc_handling_failed_destinations!(
28662866
path.last().unwrap().node.get_and_clear_pending_events(),
2867-
&[HTLCHandlingType::FailedPayment { payment_hash: *payment_hash }]
2867+
&[HTLCHandlingType::ReceiveFailed { payment_hash: *payment_hash }]
28682868
);
28692869
}
28702870
}
@@ -3176,7 +3176,7 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
31763176
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
31773177
}
31783178
expected_paths[0].last().unwrap().node.fail_htlc_backwards(&our_payment_hash);
3179-
let expected_destinations: Vec<HTLCHandlingType> = repeat(HTLCHandlingType::FailedPayment { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
3179+
let expected_destinations: Vec<HTLCHandlingType> = repeat(HTLCHandlingType::ReceiveFailed { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
31803180
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(expected_paths[0].last().unwrap(), expected_destinations);
31813181

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

0 commit comments

Comments
 (0)