@@ -87,6 +87,8 @@ use crate::util::string::UntrustedString;
8787use crate::util::ser::{BigSize, FixedLengthReader, LengthReadable, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter};
8888use crate::util::logger::{Level, Logger, WithContext};
8989use crate::util::errors::APIError;
90+ use super::onion_payment::invalid_payment_err_data;
91+
9092#[cfg(async_payments)] use {
9193 crate::offers::offer::Amount,
9294 crate::offers::static_invoice::{DEFAULT_RELATIVE_EXPIRY as STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY, StaticInvoice, StaticInvoiceBuilder},
@@ -6262,10 +6264,7 @@ where
62626264 macro_rules! fail_htlc {
62636265 ($htlc: expr, $payment_hash: expr) => {
62646266 debug_assert!(!committed_to_claimable);
6265- let mut htlc_msat_height_data = $htlc.value.to_be_bytes().to_vec();
6266- htlc_msat_height_data.extend_from_slice(
6267- &self.best_block.read().unwrap().height.to_be_bytes(),
6268- );
6267+ let err_data = invalid_payment_err_data($htlc.value, self.best_block.read().unwrap().height);
62696268 failed_forwards.push((HTLCSource::PreviousHopData(HTLCPreviousHopData {
62706269 short_channel_id: $htlc.prev_hop.short_channel_id,
62716270 user_channel_id: $htlc.prev_hop.user_channel_id,
@@ -6278,7 +6277,7 @@ where
62786277 blinded_failure,
62796278 cltv_expiry: Some(cltv_expiry),
62806279 }), payment_hash,
6281- HTLCFailReason::reason(0x4000 | 15, htlc_msat_height_data ),
6280+ HTLCFailReason::reason(0x4000 | 15, err_data ),
62826281 HTLCDestination::FailedPayment { payment_hash: $payment_hash },
62836282 ));
62846283 continue 'next_forwardable_htlc;
@@ -7231,10 +7230,9 @@ where
72317230 }
72327231 } else {
72337232 for htlc in sources {
7234- let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
7235- htlc_msat_height_data.extend_from_slice(&self.best_block.read().unwrap().height.to_be_bytes());
7233+ let err_data = invalid_payment_err_data(htlc.value, self.best_block.read().unwrap().height);
72367234 let source = HTLCSource::PreviousHopData(htlc.prev_hop);
7237- let reason = HTLCFailReason::reason(0x4000 | 15, htlc_msat_height_data );
7235+ let reason = HTLCFailReason::reason(0x4000 | 15, err_data );
72387236 let receiver = HTLCDestination::FailedPayment { payment_hash };
72397237 self.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
72407238 }
@@ -11822,11 +11820,8 @@ where
1182211820 // number of blocks we generally consider it to take to do a commitment update,
1182311821 // just give up on it and fail the HTLC.
1182411822 if height >= htlc.cltv_expiry - HTLC_FAIL_BACK_BUFFER {
11825- let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
11826- htlc_msat_height_data.extend_from_slice(&height.to_be_bytes());
11827-
1182811823 timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(),
11829- HTLCFailReason::reason(0x4000 | 15, htlc_msat_height_data ),
11824+ HTLCFailReason::reason(0x4000 | 15, invalid_payment_err_data(htlc.value, height) ),
1183011825 HTLCDestination::FailedPayment { payment_hash: payment_hash.clone() }));
1183111826 false
1183211827 } else { true }
0 commit comments