@@ -44,7 +44,7 @@ use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
44
44
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
45
45
use crate::chain::channelmonitor::{Balance, ChannelMonitor, ChannelMonitorUpdate, WithChannelMonitor, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER, MAX_BLOCKS_FOR_CONF, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent};
46
46
use crate::chain::transaction::{OutPoint, TransactionData};
47
- use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFunds, ClosureReason, HTLCDestination, PaymentFailureReason, ReplayEvent};
47
+ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFunds, ClosureReason, HTLCDestination, PaymentFailureReason, ReplayEvent, HTLCDestinationFailure };
48
48
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
49
49
// construct one themselves.
50
50
use crate::ln::inbound_payment;
@@ -3292,7 +3292,7 @@ macro_rules! handle_monitor_update_completion {
3292
3292
}
3293
3293
$self.finalize_claims(updates.finalized_claimed_htlcs);
3294
3294
for failure in updates.failed_htlcs.drain(..) {
3295
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
3295
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(HTLCDestinationFailure::Downstream) };
3296
3296
$self.fail_htlc_backwards_internal(&failure.0, &failure.1, &failure.2, receiver);
3297
3297
}
3298
3298
} }
@@ -3910,8 +3910,9 @@ where
3910
3910
}
3911
3911
3912
3912
for htlc_source in failed_htlcs.drain(..) {
3913
- let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
3914
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(*counterparty_node_id), channel_id: *channel_id };
3913
+ let details = LocalHTLCFailureReason::ChannelClosed;
3914
+ let reason = HTLCFailReason::from_failure_code(details.failure_code());
3915
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(*counterparty_node_id), channel_id: *channel_id, reason: Some(details.into()) };
3915
3916
self.fail_htlc_backwards_internal(&htlc_source.0, &htlc_source.1, &reason, receiver);
3916
3917
}
3917
3918
@@ -4033,8 +4034,9 @@ where
4033
4034
shutdown_res.closure_reason, shutdown_res.dropped_outbound_htlcs.len());
4034
4035
for htlc_source in shutdown_res.dropped_outbound_htlcs.drain(..) {
4035
4036
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
4036
- let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
4037
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
4037
+ let details = LocalHTLCFailureReason::ChannelClosed;
4038
+ let reason = HTLCFailReason::from_failure_code(details.failure_code());
4039
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(details.into()) };
4038
4040
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
4039
4041
}
4040
4042
if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
@@ -5754,13 +5756,14 @@ where
5754
5756
let mut decode_update_add_htlcs = new_hash_map();
5755
5757
mem::swap(&mut decode_update_add_htlcs, &mut self.decode_update_add_htlcs.lock().unwrap());
5756
5758
5757
- let get_failed_htlc_destination = |outgoing_scid_opt: Option<u64>, payment_hash: PaymentHash| {
5759
+ let get_failed_htlc_destination = |outgoing_scid_opt: Option<u64>, payment_hash: PaymentHash, reason: HTLCFailureDetails | {
5758
5760
if let Some(outgoing_scid) = outgoing_scid_opt {
5759
5761
match self.short_to_chan_info.read().unwrap().get(&outgoing_scid) {
5760
5762
Some((outgoing_counterparty_node_id, outgoing_channel_id)) =>
5761
5763
HTLCDestination::NextHopChannel {
5762
5764
node_id: Some(*outgoing_counterparty_node_id),
5763
5765
channel_id: *outgoing_channel_id,
5766
+ reason: Some(HTLCDestinationFailure::Local { reason }),
5764
5767
},
5765
5768
None => HTLCDestination::UnknownNextHop {
5766
5769
requested_forward_scid: outgoing_scid,
@@ -5822,10 +5825,10 @@ where
5822
5825
Some(Ok(_)) => {},
5823
5826
Some(Err((err, reason))) => {
5824
5827
let htlc_fail = self.htlc_failure_from_update_add_err(
5825
- &update_add_htlc, &incoming_counterparty_node_id, err, reason,
5828
+ &update_add_htlc, &incoming_counterparty_node_id, err, reason.clone() ,
5826
5829
is_intro_node_blinded_forward, &shared_secret,
5827
5830
);
5828
- let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5831
+ let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash, reason );
5829
5832
htlc_fails.push((htlc_fail, htlc_destination));
5830
5833
continue;
5831
5834
},
@@ -5839,10 +5842,10 @@ where
5839
5842
&update_add_htlc, next_packet_details
5840
5843
) {
5841
5844
let htlc_fail = self.htlc_failure_from_update_add_err(
5842
- &update_add_htlc, &incoming_counterparty_node_id, err, reason,
5845
+ &update_add_htlc, &incoming_counterparty_node_id, err, reason.clone() ,
5843
5846
is_intro_node_blinded_forward, &shared_secret,
5844
5847
);
5845
- let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5848
+ let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash, reason );
5846
5849
htlc_fails.push((htlc_fail, htlc_destination));
5847
5850
continue;
5848
5851
}
@@ -5854,7 +5857,7 @@ where
5854
5857
) {
5855
5858
Ok(info) => htlc_forwards.push((info, update_add_htlc.htlc_id)),
5856
5859
Err(inbound_err) => {
5857
- let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5860
+ let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash, inbound_err.reason.clone() );
5858
5861
htlc_fails.push((self.construct_pending_htlc_fail_msg(&update_add_htlc, &incoming_counterparty_node_id, shared_secret, inbound_err), htlc_destination));
5859
5862
},
5860
5863
}
@@ -6128,11 +6131,11 @@ where
6128
6131
.get_mut(&forward_chan_id)
6129
6132
.and_then(Channel::as_funded_mut)
6130
6133
{
6131
- let failure_code = 0x1000|7 ;
6132
- let data = self.get_htlc_inbound_temp_fail_data(failure_code);
6134
+ let details = LocalHTLCFailureReason::ChannelNotReady ;
6135
+ let data = self.get_htlc_inbound_temp_fail_data(details. failure_code() );
6133
6136
failed_forwards.push((htlc_source, payment_hash,
6134
- HTLCFailReason::reason(failure_code, data),
6135
- HTLCDestination::NextHopChannel { node_id: Some(chan.context.get_counterparty_node_id()), channel_id: forward_chan_id }
6137
+ HTLCFailReason::reason(details. failure_code() , data),
6138
+ HTLCDestination::NextHopChannel { node_id: Some(chan.context.get_counterparty_node_id()), channel_id: forward_chan_id, reason: Some(details.into()) }
6136
6139
));
6137
6140
} else {
6138
6141
forwarding_channel_not_found!(core::iter::once(forward_info).chain(draining_pending_forwards));
@@ -6977,17 +6980,21 @@ where
6977
6980
} else {
6978
6981
// We shouldn't be trying to fail holding cell HTLCs on an unfunded channel.
6979
6982
debug_assert!(false);
6980
- ((0x4000|10) .into(), Vec::new())
6983
+ (LocalHTLCFailureReason::ChannelNotReady .into(), Vec::new())
6981
6984
}
6982
6985
},
6983
- hash_map::Entry::Vacant(_) => ((0x4000|10) .into(), Vec::new())
6986
+ hash_map::Entry::Vacant(_) => (LocalHTLCFailureReason::UnknownNextPeer .into(), Vec::new())
6984
6987
}
6985
- } else { ((0x4000|10) .into(), Vec::new()) }
6988
+ } else { (LocalHTLCFailureReason::UnknownNextPeer .into(), Vec::new()) }
6986
6989
};
6987
6990
6988
6991
for (htlc_src, payment_hash) in htlcs_to_fail.drain(..) {
6989
- let reason = HTLCFailReason::reason(failure_reason.failure_code(), onion_failure_data.clone());
6990
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id.clone()), channel_id };
6992
+ let reason = HTLCFailReason::reason(failure_reason.clone().failure_code(), onion_failure_data.clone());
6993
+ let receiver = HTLCDestination::NextHopChannel {
6994
+ node_id: Some(counterparty_node_id.clone()),
6995
+ channel_id,
6996
+ reason: Some(HTLCDestinationFailure::Local{ reason: failure_reason.clone().into() }),
6997
+ };
6991
6998
self.fail_htlc_backwards_internal(&htlc_src, &payment_hash, &reason, receiver);
6992
6999
}
6993
7000
}
@@ -8772,8 +8779,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8772
8779
}
8773
8780
}
8774
8781
for htlc_source in dropped_htlcs.drain(..) {
8775
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id.clone()), channel_id: msg.channel_id };
8776
- let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
8782
+ let details = LocalHTLCFailureReason::ShutdownSent;
8783
+ let reason = HTLCFailReason::from_failure_code(details.failure_code());
8784
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id.clone()), channel_id: msg.channel_id, reason: Some(details.into()) };
8777
8785
self.fail_htlc_backwards_internal(&htlc_source.0, &htlc_source.1, &reason, receiver);
8778
8786
}
8779
8787
if let Some(shutdown_res) = finish_shutdown {
@@ -9598,8 +9606,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9598
9606
);
9599
9607
} else {
9600
9608
log_trace!(logger, "Failing HTLC with hash {} from our monitor", &htlc_update.payment_hash);
9601
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
9602
- let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
9609
+ let details = LocalHTLCFailureReason::ChannelClosed;
9610
+ let reason = HTLCFailReason::from_failure_code(details.failure_code());
9611
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(details.into())};
9603
9612
self.fail_htlc_backwards_internal(&htlc_update.source, &htlc_update.payment_hash, &reason, receiver);
9604
9613
}
9605
9614
},
@@ -11689,10 +11698,10 @@ where
11689
11698
let res = f(funded_channel);
11690
11699
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
11691
11700
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
11692
- let failure_code = 0x1000|14; /* expiry_too_soon */
11693
- let data = self.get_htlc_inbound_temp_fail_data(failure_code);
11694
- timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(failure_code, data),
11695
- HTLCDestination::NextHopChannel { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
11701
+ let details = LocalHTLCFailureReason::ExpiryTooSoon;
11702
+ let data = self.get_htlc_inbound_temp_fail_data(details. failure_code() );
11703
+ timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(details. failure_code() , data),
11704
+ HTLCDestination::NextHopChannel { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id(), reason: Some(details.into()) }));
11696
11705
}
11697
11706
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
11698
11707
if let Some(channel_ready) = channel_ready_opt {
@@ -11814,8 +11823,9 @@ where
11814
11823
let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
11815
11824
htlc_msat_height_data.extend_from_slice(&height.to_be_bytes());
11816
11825
11826
+ let details = LocalHTLCFailureReason::FailBackBuffer;
11817
11827
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(),
11818
- HTLCFailReason::reason(0x4000 | 15 , htlc_msat_height_data),
11828
+ HTLCFailReason::reason(details.failure_code() , htlc_msat_height_data),
11819
11829
HTLCDestination::FailedPayment { payment_hash: payment_hash.clone() }));
11820
11830
false
11821
11831
} else { true }
@@ -14917,8 +14927,9 @@ where
14917
14927
14918
14928
for htlc_source in failed_htlcs.drain(..) {
14919
14929
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
14920
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
14921
- let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
14930
+ let details = LocalHTLCFailureReason::ChannelClosed;
14931
+ let reason = HTLCFailReason::from_failure_code(details.failure_code());
14932
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(details.into()) };
14922
14933
channel_manager.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
14923
14934
}
14924
14935
0 commit comments