Skip to content

Commit 560e73a

Browse files
committed
ln+events+liquidity/refactor: HTLCDestination renamed HTLCHandlingType
HTLCDestination currently contains a combination of information about the type of HTLC we handled to fail (a payment, a forward etc) and error information for a select set of cases (unknown next peer, for example). In preparation for a refactor that will split the failure reason out into its own enum, this commit renames HTLCDestination to HTLCHandlingType.
1 parent f3010bb commit 560e73a

17 files changed

+245
-247
lines changed

lightning-liquidity/src/lsps2/service.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::prelude::hash_map::Entry;
3131
use crate::prelude::{new_hash_map, HashMap};
3232
use crate::sync::{Arc, Mutex, MutexGuard, RwLock};
3333

34-
use lightning::events::HTLCDestination;
34+
use lightning::events::HTLCHandlingType;
3535
use lightning::ln::channelmanager::{AChannelManager, InterceptId};
3636
use lightning::ln::msgs::{ErrorAction, LightningError};
3737
use lightning::ln::types::ChannelId;
@@ -882,10 +882,8 @@ where
882882
/// or if the payment queue is empty
883883
///
884884
/// [`Event::HTLCHandlingFailed`]: lightning::events::Event::HTLCHandlingFailed
885-
pub fn htlc_handling_failed(
886-
&self, failed_next_destination: HTLCDestination,
887-
) -> Result<(), APIError> {
888-
if let HTLCDestination::NextHopChannel { channel_id, .. } = failed_next_destination {
885+
pub fn htlc_handling_failed(&self, handling_type: HTLCHandlingType) -> Result<(), APIError> {
886+
if let HTLCHandlingType::NextHopChannel { channel_id, .. } = handling_type {
889887
let peer_by_channel_id = self.peer_by_channel_id.read().unwrap();
890888
if let Some(counterparty_node_id) = peer_by_channel_id.get(&channel_id) {
891889
let outer_state_lock = self.per_peer_state.read().unwrap();

lightning/src/events/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
465465
},
466466
);
467467

468-
/// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
468+
/// The type of HTLC that is being handled in [`Event::HTLCHandlingFailed`].
469469
#[derive(Clone, Debug, PartialEq, Eq)]
470-
pub enum HTLCDestination {
470+
pub enum HTLCHandlingType {
471471
/// We tried forwarding to a channel but failed to do so. An example of such an instance is when
472472
/// there is insufficient capacity in our outbound channel.
473473
NextHopChannel {
@@ -507,7 +507,7 @@ pub enum HTLCDestination {
507507
},
508508
}
509509

510-
impl_writeable_tlv_based_enum_upgradable!(HTLCDestination,
510+
impl_writeable_tlv_based_enum_upgradable!(HTLCHandlingType,
511511
(0, NextHopChannel) => {
512512
(0, node_id, required),
513513
(2, channel_id, required),
@@ -1447,8 +1447,8 @@ pub enum Event {
14471447
HTLCHandlingFailed {
14481448
/// The channel over which the HTLC was received.
14491449
prev_channel_id: ChannelId,
1450-
/// Destination of the HTLC that failed to be processed.
1451-
failed_next_destination: HTLCDestination,
1450+
/// The type of HTLC that was handled.
1451+
handling_type: HTLCHandlingType,
14521452
},
14531453
/// Indicates that a transaction originating from LDK needs to have its fee bumped. This event
14541454
/// requires confirmed external funds to be readily available to spend.
@@ -1752,11 +1752,11 @@ impl Writeable for Event {
17521752
(8, path.blinded_tail, option),
17531753
})
17541754
},
1755-
&Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
1755+
&Event::HTLCHandlingFailed { ref prev_channel_id, ref handling_type } => {
17561756
25u8.write(writer)?;
17571757
write_tlv_fields!(writer, {
17581758
(0, prev_channel_id, required),
1759-
(2, failed_next_destination, required),
1759+
(2, handling_type, required),
17601760
})
17611761
},
17621762
&Event::BumpTransaction(ref event)=> {
@@ -2201,14 +2201,14 @@ impl MaybeReadable for Event {
22012201
25u8 => {
22022202
let mut f = || {
22032203
let mut prev_channel_id = ChannelId::new_zero();
2204-
let mut failed_next_destination_opt = UpgradableRequired(None);
2204+
let mut handling_type_opt = UpgradableRequired(None);
22052205
read_tlv_fields!(reader, {
22062206
(0, prev_channel_id, required),
2207-
(2, failed_next_destination_opt, upgradable_required),
2207+
(2, handling_type_opt, upgradable_required),
22082208
});
22092209
Ok(Some(Event::HTLCHandlingFailed {
22102210
prev_channel_id,
2211-
failed_next_destination: _init_tlv_based_struct_field!(failed_next_destination_opt, upgradable_required),
2211+
handling_type: _init_tlv_based_struct_field!(handling_type_opt, upgradable_required),
22122212
}))
22132213
};
22142214
f()

lightning/src/ln/async_payments_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::blinded_path::message::{MessageContext, OffersContext};
1111
use crate::blinded_path::payment::PaymentContext;
1212
use crate::blinded_path::payment::{AsyncBolt12OfferContext, BlindedPaymentTlvs};
1313
use crate::chain::channelmonitor::{HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
14-
use crate::events::{Event, HTLCDestination, PaymentFailureReason};
14+
use crate::events::{Event, HTLCHandlingType, PaymentFailureReason};
1515
use crate::ln::blinded_payment_tests::{fail_blinded_htlc_backwards, get_blinded_route_parameters};
1616
use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
1717
use crate::ln::functional_test_utils::*;
@@ -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(HTLCDestination::FailedPayment { payment_hash });
175+
.expect_failure(HTLCHandlingType::FailedPayment { 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(HTLCDestination::FailedPayment { payment_hash });
701+
.expect_failure(HTLCHandlingType::FailedPayment { 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-
&[HTLCDestination::FailedPayment { payment_hash }],
917+
&[HTLCHandlingType::FailedPayment { 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(HTLCDestination::FailedPayment { payment_hash });
937+
.expect_failure(HTLCHandlingType::FailedPayment { 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(HTLCDestination::FailedPayment { payment_hash });
1103+
.expect_failure(HTLCHandlingType::FailedPayment { 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: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
1515
use crate::blinded_path;
1616
use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12RefundContext, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentForwardNode, PaymentRelay, UnauthenticatedReceiveTlvs, PAYMENT_PADDING_ROUND_OFF};
1717
use crate::blinded_path::utils::is_padded;
18-
use crate::events::{Event, HTLCDestination, PaymentFailureReason};
18+
use crate::events::{Event, HTLCHandlingType, PaymentFailureReason};
1919
use crate::ln::types::ChannelId;
2020
use crate::types::payment::{PaymentHash, PaymentSecret};
2121
use crate::ln::channelmanager;
@@ -425,10 +425,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
425425
nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]);
426426
do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false);
427427
let failed_destination = match check {
428-
ForwardCheckFail::InboundOnionCheck => HTLCDestination::InvalidOnion,
429-
ForwardCheckFail::ForwardPayloadEncodedAsReceive => HTLCDestination::InvalidOnion,
428+
ForwardCheckFail::InboundOnionCheck => HTLCHandlingType::InvalidOnion,
429+
ForwardCheckFail::ForwardPayloadEncodedAsReceive => HTLCHandlingType::InvalidOnion,
430430
ForwardCheckFail::OutboundChannelCheck =>
431-
HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_1_2.2 },
431+
HTLCHandlingType::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_1_2.2 },
432432
};
433433
expect_htlc_handling_failed_destinations!(
434434
nodes[1].node.get_and_clear_pending_events(), &[failed_destination.clone()]
@@ -457,9 +457,9 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
457457

458458
expect_pending_htlcs_forwardable!(nodes[2]);
459459
let failed_destination = match check {
460-
ForwardCheckFail::InboundOnionCheck|ForwardCheckFail::ForwardPayloadEncodedAsReceive => HTLCDestination::InvalidOnion,
460+
ForwardCheckFail::InboundOnionCheck|ForwardCheckFail::ForwardPayloadEncodedAsReceive => HTLCHandlingType::InvalidOnion,
461461
ForwardCheckFail::OutboundChannelCheck =>
462-
HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 },
462+
HTLCHandlingType::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 },
463463
};
464464
expect_htlc_handling_failed_destinations!(
465465
nodes[2].node.get_and_clear_pending_events(), &[failed_destination.clone()]
@@ -527,7 +527,7 @@ fn failed_backwards_to_intro_node() {
527527
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event.commitment_msg, true, true);
528528

529529
expect_pending_htlcs_forwardable!(nodes[2]);
530-
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCDestination::InvalidOnion]);
530+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::InvalidOnion]);
531531
check_added_monitors(&nodes[2], 1);
532532

533533
let mut updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -606,7 +606,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
606606
$curr_node.node.peer_disconnected($next_node.node.get_our_node_id());
607607
expect_pending_htlcs_forwardable!($curr_node);
608608
expect_htlc_handling_failed_destinations!($curr_node.node.get_and_clear_pending_events(),
609-
vec![HTLCDestination::NextHopChannel { node_id: Some($next_node.node.get_our_node_id()), channel_id: $failed_chan_id }]);
609+
vec![HTLCHandlingType::NextHopChannel { node_id: Some($next_node.node.get_our_node_id()), channel_id: $failed_chan_id }]);
610610
},
611611
ProcessPendingHTLCsCheck::FwdChannelClosed => {
612612
// Force close the next-hop channel so when we go to forward in process_pending_htlc_forwards,
@@ -626,7 +626,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
626626

627627
$curr_node.node.process_pending_htlc_forwards();
628628
expect_htlc_handling_failed_destinations!($curr_node.node.get_and_clear_pending_events(),
629-
vec![HTLCDestination::UnknownNextHop { requested_forward_scid: $failed_scid }]);
629+
vec![HTLCHandlingType::UnknownNextHop { requested_forward_scid: $failed_scid }]);
630630
$curr_node.node.process_pending_htlc_forwards();
631631
},
632632
}
@@ -725,7 +725,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
725725

726726
if intercept_node_fails {
727727
nodes[1].node.fail_intercepted_htlc(intercept_id).unwrap();
728-
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCDestination::UnknownNextHop { requested_forward_scid: intercept_scid }]);
728+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingType::UnknownNextHop { requested_forward_scid: intercept_scid }]);
729729
nodes[1].node.process_pending_htlc_forwards();
730730
check_added_monitors!(&nodes[1], 1);
731731
fail_blinded_htlc_backwards(payment_hash, 1, &[&nodes[0], &nodes[1]], false);
@@ -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(), &[HTLCDestination::FailedPayment { payment_hash }]
833+
nodes[3].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { 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(), &[HTLCDestination::FailedPayment { payment_hash }]
961+
nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]
962962
);
963963
nodes[2].node.process_pending_htlc_forwards();
964964
check_added_monitors!(nodes[2], 1);
@@ -988,7 +988,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
988988
check_added_monitors!(nodes[2], 0);
989989
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
990990
expect_pending_htlcs_forwardable!(nodes[2]);
991-
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCDestination::InvalidOnion]);
991+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::InvalidOnion]);
992992
check_added_monitors(&nodes[2], 1);
993993
},
994994
ReceiveCheckFail::ReceiveRequirements => {
@@ -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(), &[HTLCDestination::FailedPayment { payment_hash }]);
1001+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { 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(), &[HTLCDestination::FailedPayment { payment_hash }]);
1017+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { 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![HTLCDestination::FailedPayment { payment_hash }]);
1027+
vec![HTLCHandlingType::FailedPayment { 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(), &[HTLCDestination::FailedPayment { payment_hash }]);
1035+
expect_htlc_handling_failed_destinations!(nodes[2].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { 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(), &[HTLCDestination::FailedPayment { payment_hash }]
1124+
nodes[3].node.get_and_clear_pending_events(), &[HTLCHandlingType::FailedPayment { payment_hash }]
11251125
);
11261126
nodes[3].node.process_pending_htlc_forwards();
11271127
check_added_monitors!(nodes[3], 1);
@@ -1243,7 +1243,7 @@ fn min_htlc() {
12431243
expect_pending_htlcs_forwardable!(nodes[1]);
12441244
expect_htlc_handling_failed_destinations!(
12451245
nodes[1].node.get_and_clear_pending_events(),
1246-
&[HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_1_2.2 }]
1246+
&[HTLCHandlingType::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_1_2.2 }]
12471247
);
12481248
check_added_monitors(&nodes[1], 1);
12491249
let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
@@ -1436,7 +1436,7 @@ fn fails_receive_tlvs_authentication() {
14361436
expect_pending_htlcs_forwardable!(nodes[1]);
14371437
nodes[1].node.process_pending_htlc_forwards();
14381438
check_added_monitors!(nodes[1], 1);
1439-
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCDestination::InvalidOnion]);
1439+
expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCHandlingType::InvalidOnion]);
14401440

14411441
let mut update_fail = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
14421442
assert!(update_fail.update_fail_htlcs.len() == 1);
@@ -2141,7 +2141,7 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
21412141
let args = PassAlongPathArgs::new(&nodes[0], route, amt_msat, payment_hash, first_message_event)
21422142
.with_payment_preimage(payment_preimage)
21432143
.without_claimable_event()
2144-
.expect_failure(HTLCDestination::InvalidOnion);
2144+
.expect_failure(HTLCHandlingType::InvalidOnion);
21452145
do_pass_along_path(args);
21462146

21472147
{
@@ -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(HTLCDestination::FailedPayment { payment_hash });
2438+
.expect_failure(HTLCHandlingType::FailedPayment { payment_hash });
24392439
do_pass_along_path(args);
24402440

24412441
{

0 commit comments

Comments
 (0)