Skip to content

Commit 95a5ab9

Browse files
Rename InboundOnionErr to InboundHTLCErr.
The prior name seems to reference onion decode errors specifically, when in fact the error contents are generic failure codes for any error that occurs during HTLC receipt.
1 parent be134d1 commit 95a5ab9

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFea
4848
#[cfg(any(feature = "_test_utils", test))]
4949
use crate::ln::features::Bolt11InvoiceFeatures;
5050
use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
51-
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundOnionErr, NextPacketDetails};
51+
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
5252
use crate::ln::msgs;
5353
use crate::ln::onion_utils;
5454
use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
@@ -3245,14 +3245,14 @@ where
32453245
// delay) once they've send us a commitment_signed!
32463246
PendingHTLCStatus::Forward(info)
32473247
},
3248-
Err(InboundOnionErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
3248+
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
32493249
}
32503250
},
32513251
onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
32523252
match create_fwd_pending_htlc_info(msg, next_hop_data, next_hop_hmac,
32533253
new_packet_bytes, shared_secret, next_packet_pubkey_opt) {
32543254
Ok(info) => PendingHTLCStatus::Forward(info),
3255-
Err(InboundOnionErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
3255+
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
32563256
}
32573257
}
32583258
}
@@ -4309,7 +4309,7 @@ where
43094309
current_height, self.default_configuration.accept_mpp_keysend)
43104310
{
43114311
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id, vec![(info, prev_htlc_id)])),
4312-
Err(InboundOnionErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
4312+
Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
43134313
}
43144314
},
43154315
_ => panic!(),
@@ -6011,10 +6011,10 @@ where
60116011
let per_peer_state = self.per_peer_state.read().unwrap();
60126012
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
60136013
.ok_or_else(|| {
6014-
let err_str = format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id);
6014+
let err_str = format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id);
60156015
log_error!(logger, "{}", err_str);
60166016

6017-
APIError::ChannelUnavailable { err: err_str }
6017+
APIError::ChannelUnavailable { err: err_str }
60186018
})?;
60196019
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
60206020
let peer_state = &mut *peer_state_lock;
@@ -12139,7 +12139,7 @@ mod tests {
1213912139
// Check that if the amount we received + the penultimate hop extra fee is less than the sender
1214012140
// intended amount, we fail the payment.
1214112141
let current_height: u32 = node[0].node.best_block.read().unwrap().height();
12142-
if let Err(crate::ln::channelmanager::InboundOnionErr { err_code, .. }) =
12142+
if let Err(crate::ln::channelmanager::InboundHTLCErr { err_code, .. }) =
1214312143
create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1214412144
sender_intended_amt_msat - extra_fee_msat - 1, 42, None, true, Some(extra_fee_msat),
1214512145
current_height, node[0].node.default_configuration.accept_mpp_keysend)

lightning/src/ln/onion_payment.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::ops::Deref;
2525

2626
/// Invalid inbound onion payment.
2727
#[derive(Debug)]
28-
pub struct InboundOnionErr {
28+
pub struct InboundHTLCErr {
2929
/// BOLT 4 error code.
3030
pub err_code: u16,
3131
/// Data attached to this error.
@@ -63,7 +63,7 @@ pub(super) fn create_fwd_pending_htlc_info(
6363
msg: &msgs::UpdateAddHTLC, hop_data: msgs::InboundOnionPayload, hop_hmac: [u8; 32],
6464
new_packet_bytes: [u8; onion_utils::ONION_DATA_LEN], shared_secret: [u8; 32],
6565
next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>
66-
) -> Result<PendingHTLCInfo, InboundOnionErr> {
66+
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
6767
debug_assert!(next_packet_pubkey_opt.is_some());
6868
let outgoing_packet = msgs::OnionPacket {
6969
version: 0,
@@ -85,7 +85,7 @@ pub(super) fn create_fwd_pending_htlc_info(
8585
).map_err(|()| {
8686
// We should be returning malformed here if `msg.blinding_point` is set, but this is
8787
// unreachable right now since we checked it in `decode_update_add_htlc_onion`.
88-
InboundOnionErr {
88+
InboundHTLCErr {
8989
msg: "Underflow calculating outbound amount or cltv value for blinded forward",
9090
err_code: INVALID_ONION_BLINDING,
9191
err_data: vec![0; 32],
@@ -94,7 +94,7 @@ pub(super) fn create_fwd_pending_htlc_info(
9494
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(intro_node_blinding_point))
9595
},
9696
msgs::InboundOnionPayload::Receive { .. } | msgs::InboundOnionPayload::BlindedReceive { .. } =>
97-
return Err(InboundOnionErr {
97+
return Err(InboundHTLCErr {
9898
msg: "Final Node OnionHopData provided for us as an intermediary node",
9999
err_code: 0x4000 | 22,
100100
err_data: Vec::new(),
@@ -120,7 +120,7 @@ pub(super) fn create_recv_pending_htlc_info(
120120
hop_data: msgs::InboundOnionPayload, shared_secret: [u8; 32], payment_hash: PaymentHash,
121121
amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>, allow_underpay: bool,
122122
counterparty_skimmed_fee_msat: Option<u64>, current_height: u32, accept_mpp_keysend: bool,
123-
) -> Result<PendingHTLCInfo, InboundOnionErr> {
123+
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
124124
let (
125125
payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, outgoing_cltv_value,
126126
payment_metadata, requires_blinded_error
@@ -136,7 +136,7 @@ pub(super) fn create_recv_pending_htlc_info(
136136
} => {
137137
check_blinded_payment_constraints(amt_msat, cltv_expiry, &payment_constraints)
138138
.map_err(|()| {
139-
InboundOnionErr {
139+
InboundHTLCErr {
140140
err_code: INVALID_ONION_BLINDING,
141141
err_data: vec![0; 32],
142142
msg: "Amount or cltv_expiry violated blinded payment constraints",
@@ -147,14 +147,14 @@ pub(super) fn create_recv_pending_htlc_info(
147147
intro_node_blinding_point.is_none())
148148
}
149149
msgs::InboundOnionPayload::Forward { .. } => {
150-
return Err(InboundOnionErr {
150+
return Err(InboundHTLCErr {
151151
err_code: 0x4000|22,
152152
err_data: Vec::new(),
153153
msg: "Got non final data with an HMAC of 0",
154154
})
155155
},
156156
msgs::InboundOnionPayload::BlindedForward { .. } => {
157-
return Err(InboundOnionErr {
157+
return Err(InboundHTLCErr {
158158
err_code: INVALID_ONION_BLINDING,
159159
err_data: vec![0; 32],
160160
msg: "Got blinded non final data with an HMAC of 0",
@@ -163,7 +163,7 @@ pub(super) fn create_recv_pending_htlc_info(
163163
};
164164
// final_incorrect_cltv_expiry
165165
if outgoing_cltv_value > cltv_expiry {
166-
return Err(InboundOnionErr {
166+
return Err(InboundHTLCErr {
167167
msg: "Upstream node set CLTV to less than the CLTV set by the sender",
168168
err_code: 18,
169169
err_data: cltv_expiry.to_be_bytes().to_vec()
@@ -180,7 +180,7 @@ pub(super) fn create_recv_pending_htlc_info(
180180
let mut err_data = Vec::with_capacity(12);
181181
err_data.extend_from_slice(&amt_msat.to_be_bytes());
182182
err_data.extend_from_slice(&current_height.to_be_bytes());
183-
return Err(InboundOnionErr {
183+
return Err(InboundHTLCErr {
184184
err_code: 0x4000 | 15, err_data,
185185
msg: "The final CLTV expiry is too soon to handle",
186186
});
@@ -189,7 +189,7 @@ pub(super) fn create_recv_pending_htlc_info(
189189
(allow_underpay && onion_amt_msat >
190190
amt_msat.saturating_add(counterparty_skimmed_fee_msat.unwrap_or(0)))
191191
{
192-
return Err(InboundOnionErr {
192+
return Err(InboundHTLCErr {
193193
err_code: 19,
194194
err_data: amt_msat.to_be_bytes().to_vec(),
195195
msg: "Upstream node sent less than we were supposed to receive in payment",
@@ -204,14 +204,14 @@ pub(super) fn create_recv_pending_htlc_info(
204204
// time discrepancies due to a hash collision with X.
205205
let hashed_preimage = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
206206
if hashed_preimage != payment_hash {
207-
return Err(InboundOnionErr {
207+
return Err(InboundHTLCErr {
208208
err_code: 0x4000|22,
209209
err_data: Vec::new(),
210210
msg: "Payment preimage didn't match payment hash",
211211
});
212212
}
213213
if !accept_mpp_keysend && payment_data.is_some() {
214-
return Err(InboundOnionErr {
214+
return Err(InboundHTLCErr {
215215
err_code: 0x4000|22,
216216
err_data: Vec::new(),
217217
msg: "We don't support MPP keysend payments",
@@ -234,7 +234,7 @@ pub(super) fn create_recv_pending_htlc_info(
234234
requires_blinded_error,
235235
}
236236
} else {
237-
return Err(InboundOnionErr {
237+
return Err(InboundHTLCErr {
238238
err_code: 0x4000|0x2000|3,
239239
err_data: Vec::new(),
240240
msg: "We require payment_secrets",
@@ -263,7 +263,7 @@ pub(super) fn create_recv_pending_htlc_info(
263263
pub fn peel_payment_onion<NS: Deref, L: Deref, T: secp256k1::Verification>(
264264
msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1<T>,
265265
cur_height: u32, accept_mpp_keysend: bool, allow_skimmed_fees: bool,
266-
) -> Result<PendingHTLCInfo, InboundOnionErr>
266+
) -> Result<PendingHTLCInfo, InboundHTLCErr>
267267
where
268268
NS::Target: NodeSigner,
269269
L::Target: Logger,
@@ -276,7 +276,7 @@ where
276276
HTLCFailureMsg::Relay(r) => (0x4000 | 22, r.reason.data),
277277
};
278278
let msg = "Failed to decode update add htlc onion";
279-
InboundOnionErr { msg, err_code, err_data }
279+
InboundHTLCErr { msg, err_code, err_data }
280280
})?;
281281
Ok(match hop {
282282
onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
@@ -285,7 +285,7 @@ where
285285
} = match next_packet_details_opt {
286286
Some(next_packet_details) => next_packet_details,
287287
// Forward should always include the next hop details
288-
None => return Err(InboundOnionErr {
288+
None => return Err(InboundHTLCErr {
289289
msg: "Failed to decode update add htlc onion",
290290
err_code: 0x4000 | 22,
291291
err_data: Vec::new(),
@@ -295,7 +295,7 @@ where
295295
if let Err((err_msg, code)) = check_incoming_htlc_cltv(
296296
cur_height, outgoing_cltv_value, msg.cltv_expiry
297297
) {
298-
return Err(InboundOnionErr {
298+
return Err(InboundHTLCErr {
299299
msg: err_msg,
300300
err_code: code,
301301
err_data: Vec::new(),

0 commit comments

Comments
 (0)