@@ -3294,7 +3294,8 @@ macro_rules! handle_monitor_update_completion {
3294
3294
}
3295
3295
$self.finalize_claims(updates.finalized_claimed_htlcs);
3296
3296
for failure in updates.failed_htlcs.drain(..) {
3297
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
3297
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id),
3298
+ channel_id, reason: Some(failure.2.clone().into()) };
3298
3299
$self.fail_htlc_backwards_internal(&failure.0, &failure.1, &failure.2, receiver);
3299
3300
}
3300
3301
} }
@@ -3914,7 +3915,7 @@ where
3914
3915
for htlc_source in failed_htlcs.drain(..) {
3915
3916
let failure_reason = LocalHTLCFailureReason::ChannelClosed;
3916
3917
let reason = HTLCFailReason::from_failure_code(failure_reason);
3917
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(*counterparty_node_id), channel_id: *channel_id };
3918
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(*counterparty_node_id), channel_id: *channel_id, reason: Some(failure_reason.into()) };
3918
3919
self.fail_htlc_backwards_internal(&htlc_source.0, &htlc_source.1, &reason, receiver);
3919
3920
}
3920
3921
@@ -4038,7 +4039,7 @@ where
4038
4039
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
4039
4040
let failure_reason = LocalHTLCFailureReason::ChannelClosed;
4040
4041
let reason = HTLCFailReason::from_failure_code(failure_reason);
4041
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
4042
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(failure_reason.into()) };
4042
4043
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
4043
4044
}
4044
4045
if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
@@ -5749,20 +5750,21 @@ where
5749
5750
let mut decode_update_add_htlcs = new_hash_map();
5750
5751
mem::swap(&mut decode_update_add_htlcs, &mut self.decode_update_add_htlcs.lock().unwrap());
5751
5752
5752
- let get_failed_htlc_destination = |outgoing_scid_opt: Option<u64>, payment_hash: PaymentHash| {
5753
+ let get_failed_htlc_destination = |outgoing_scid_opt: Option<u64>, payment_hash: PaymentHash, reason: LocalHTLCFailureReason | {
5753
5754
if let Some(outgoing_scid) = outgoing_scid_opt {
5754
5755
match self.short_to_chan_info.read().unwrap().get(&outgoing_scid) {
5755
5756
Some((outgoing_counterparty_node_id, outgoing_channel_id)) =>
5756
5757
HTLCDestination::NextHopChannel {
5757
5758
node_id: Some(*outgoing_counterparty_node_id),
5758
5759
channel_id: *outgoing_channel_id,
5760
+ reason: Some(reason.into()),
5759
5761
},
5760
5762
None => HTLCDestination::UnknownNextHop {
5761
5763
requested_forward_scid: outgoing_scid,
5762
5764
},
5763
5765
}
5764
5766
} else {
5765
- HTLCDestination::FailedPayment { payment_hash }
5767
+ HTLCDestination::FailedPayment { payment_hash, reason: Some(reason) }
5766
5768
}
5767
5769
};
5768
5770
@@ -5817,10 +5819,10 @@ where
5817
5819
Some(Ok(_)) => {},
5818
5820
Some(Err((err, reason))) => {
5819
5821
let htlc_fail = self.htlc_failure_from_update_add_err(
5820
- &update_add_htlc, &incoming_counterparty_node_id, err, reason,
5822
+ &update_add_htlc, &incoming_counterparty_node_id, err, reason.clone() ,
5821
5823
is_intro_node_blinded_forward, &shared_secret,
5822
5824
);
5823
- let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5825
+ let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash, reason );
5824
5826
htlc_fails.push((htlc_fail, htlc_destination));
5825
5827
continue;
5826
5828
},
@@ -5837,7 +5839,7 @@ where
5837
5839
&update_add_htlc, &incoming_counterparty_node_id, err, reason,
5838
5840
is_intro_node_blinded_forward, &shared_secret,
5839
5841
);
5840
- let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5842
+ let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash, reason );
5841
5843
htlc_fails.push((htlc_fail, htlc_destination));
5842
5844
continue;
5843
5845
}
@@ -5849,7 +5851,7 @@ where
5849
5851
) {
5850
5852
Ok(info) => htlc_forwards.push((info, update_add_htlc.htlc_id)),
5851
5853
Err(inbound_err) => {
5852
- let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash);
5854
+ let htlc_destination = get_failed_htlc_destination(outgoing_scid_opt, update_add_htlc.payment_hash, inbound_err.reason );
5853
5855
htlc_fails.push((self.construct_pending_htlc_fail_msg(&update_add_htlc, &incoming_counterparty_node_id, shared_secret, inbound_err), htlc_destination));
5854
5856
},
5855
5857
}
@@ -5935,7 +5937,7 @@ where
5935
5937
let reason = if $next_hop_unknown {
5936
5938
HTLCDestination::UnknownNextHop { requested_forward_scid: short_chan_id }
5937
5939
} else {
5938
- HTLCDestination::FailedPayment{ payment_hash }
5940
+ HTLCDestination::FailedPayment{ payment_hash, reason: Some($reason) }
5939
5941
};
5940
5942
5941
5943
failed_forwards.push((htlc_source, payment_hash,
@@ -6125,7 +6127,7 @@ where
6125
6127
let data = self.get_htlc_inbound_temp_fail_data(reason);
6126
6128
failed_forwards.push((htlc_source, payment_hash,
6127
6129
HTLCFailReason::reason(reason, data),
6128
- HTLCDestination::NextHopChannel { node_id: Some(chan.context.get_counterparty_node_id()), channel_id: forward_chan_id }
6130
+ HTLCDestination::NextHopChannel { node_id: Some(chan.context.get_counterparty_node_id()), channel_id: forward_chan_id, reason: Some(reason.into()) }
6129
6131
));
6130
6132
} else {
6131
6133
forwarding_channel_not_found!(core::iter::once(forward_info).chain(draining_pending_forwards));
@@ -6266,6 +6268,7 @@ where
6266
6268
htlc_msat_height_data.extend_from_slice(
6267
6269
&self.best_block.read().unwrap().height.to_be_bytes(),
6268
6270
);
6271
+ let reason = LocalHTLCFailureReason::IncorrectPaymentDetails;
6269
6272
failed_forwards.push((HTLCSource::PreviousHopData(HTLCPreviousHopData {
6270
6273
short_channel_id: $htlc.prev_hop.short_channel_id,
6271
6274
user_channel_id: $htlc.prev_hop.user_channel_id,
@@ -6278,8 +6281,8 @@ where
6278
6281
blinded_failure,
6279
6282
cltv_expiry: Some(cltv_expiry),
6280
6283
}), payment_hash,
6281
- HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails , htlc_msat_height_data),
6282
- HTLCDestination::FailedPayment { payment_hash: $payment_hash },
6284
+ HTLCFailReason::reason(reason , htlc_msat_height_data),
6285
+ HTLCDestination::FailedPayment { payment_hash: $payment_hash, reason: Some(reason) },
6283
6286
));
6284
6287
continue 'next_forwardable_htlc;
6285
6288
}
@@ -6837,7 +6840,7 @@ where
6837
6840
let source = HTLCSource::PreviousHopData(htlc_source.0.clone());
6838
6841
let failure_reason = LocalHTLCFailureReason::MPPTimeout;
6839
6842
let reason = HTLCFailReason::from_failure_code(failure_reason);
6840
- let receiver = HTLCDestination::FailedPayment { payment_hash: htlc_source.1 };
6843
+ let receiver = HTLCDestination::FailedPayment { payment_hash: htlc_source.1, reason: Some(failure_reason) };
6841
6844
self.fail_htlc_backwards_internal(&source, &htlc_source.1, &reason, receiver);
6842
6845
}
6843
6846
@@ -6902,7 +6905,7 @@ where
6902
6905
for htlc in payment.htlcs {
6903
6906
let reason = self.get_htlc_fail_reason_from_failure_code(failure_code, &htlc);
6904
6907
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
6905
- let receiver = HTLCDestination::FailedPayment { payment_hash: *payment_hash };
6908
+ let receiver = HTLCDestination::FailedPayment { payment_hash: *payment_hash, reason: Some(failure_code.into()) };
6906
6909
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
6907
6910
}
6908
6911
}
@@ -6980,8 +6983,12 @@ where
6980
6983
};
6981
6984
6982
6985
for (htlc_src, payment_hash) in htlcs_to_fail.drain(..) {
6983
- let reason = HTLCFailReason::reason(failure_reason, onion_failure_data.clone());
6984
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id.clone()), channel_id };
6986
+ let reason = HTLCFailReason::reason(failure_reason.clone(), onion_failure_data.clone());
6987
+ let receiver = HTLCDestination::NextHopChannel {
6988
+ node_id: Some(counterparty_node_id.clone()),
6989
+ channel_id,
6990
+ reason: Some(failure_reason.into()),
6991
+ };
6985
6992
self.fail_htlc_backwards_internal(&htlc_src, &payment_hash, &reason, receiver);
6986
6993
}
6987
6994
}
@@ -7128,9 +7135,10 @@ where
7128
7135
Ok((htlcs, payment_info)) => (htlcs, payment_info),
7129
7136
Err(htlcs) => {
7130
7137
for htlc in htlcs {
7131
- let reason = self.get_htlc_fail_reason_from_failure_code(FailureCode::InvalidOnionPayload(None), &htlc);
7138
+ let failure_code = FailureCode::InvalidOnionPayload(None);
7139
+ let reason = self.get_htlc_fail_reason_from_failure_code(failure_code, &htlc);
7132
7140
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
7133
- let receiver = HTLCDestination::FailedPayment { payment_hash };
7141
+ let receiver = HTLCDestination::FailedPayment { payment_hash, reason: Some(failure_code.into()) };
7134
7142
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
7135
7143
}
7136
7144
return;
@@ -7228,8 +7236,9 @@ where
7228
7236
let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
7229
7237
htlc_msat_height_data.extend_from_slice(&self.best_block.read().unwrap().height.to_be_bytes());
7230
7238
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
7231
- let reason = HTLCFailReason::reason(LocalHTLCFailureReason::IncorrectPaymentDetails, htlc_msat_height_data);
7232
- let receiver = HTLCDestination::FailedPayment { payment_hash };
7239
+ let failure_code = LocalHTLCFailureReason::IncorrectPaymentDetails;
7240
+ let reason = HTLCFailReason::reason(failure_code, htlc_msat_height_data);
7241
+ let receiver = HTLCDestination::FailedPayment { payment_hash, reason: Some(failure_code.into()) };
7233
7242
self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
7234
7243
}
7235
7244
self.claimable_payments.lock().unwrap().pending_claiming_payments.remove(&payment_hash);
@@ -8766,8 +8775,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8766
8775
}
8767
8776
}
8768
8777
for htlc_source in dropped_htlcs.drain(..) {
8769
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id.clone()), channel_id: msg.channel_id };
8770
- let reason = HTLCFailReason::from_failure_code(LocalHTLCFailureReason::ShutdownSent);
8778
+ let failure_reason = LocalHTLCFailureReason::ShutdownSent;
8779
+ let reason = HTLCFailReason::from_failure_code(failure_reason);
8780
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id.clone()), channel_id: msg.channel_id, reason: Some(failure_reason.into()) };
8771
8781
self.fail_htlc_backwards_internal(&htlc_source.0, &htlc_source.1, &reason, receiver);
8772
8782
}
8773
8783
if let Some(shutdown_res) = finish_shutdown {
@@ -9593,7 +9603,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9593
9603
} else {
9594
9604
log_trace!(logger, "Failing HTLC with hash {} from our monitor", &htlc_update.payment_hash);
9595
9605
let failure_reason = LocalHTLCFailureReason::ChannelClosed;
9596
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
9606
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(failure_reason.into()) };
9597
9607
let reason = HTLCFailReason::from_failure_code(failure_reason);
9598
9608
self.fail_htlc_backwards_internal(&htlc_update.source, &htlc_update.payment_hash, &reason, receiver);
9599
9609
}
@@ -11687,7 +11697,7 @@ where
11687
11697
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
11688
11698
let data = self.get_htlc_inbound_temp_fail_data(reason);
11689
11699
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
11690
- HTLCDestination::NextHopChannel { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
11700
+ HTLCDestination::NextHopChannel { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id(), reason: Some(reason.into()) }));
11691
11701
}
11692
11702
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
11693
11703
if let Some(channel_ready) = channel_ready_opt {
@@ -11811,7 +11821,7 @@ where
11811
11821
let reason = LocalHTLCFailureReason::PaymentClaimBuffer;
11812
11822
timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(),
11813
11823
HTLCFailReason::reason(reason, htlc_msat_height_data),
11814
- HTLCDestination::FailedPayment { payment_hash: payment_hash.clone() }));
11824
+ HTLCDestination::FailedPayment { payment_hash: payment_hash.clone(), reason: Some(reason) }));
11815
11825
false
11816
11826
} else { true }
11817
11827
});
@@ -14913,7 +14923,7 @@ where
14913
14923
for htlc_source in failed_htlcs.drain(..) {
14914
14924
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
14915
14925
let failure_reason = LocalHTLCFailureReason::ChannelClosed;
14916
- let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
14926
+ let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id, reason: Some(failure_reason.into()) };
14917
14927
let reason = HTLCFailReason::from_failure_code(failure_reason);
14918
14928
channel_manager.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
14919
14929
}
0 commit comments