Skip to content

Commit 0a6638f

Browse files
committed
ln/refactor: rename InboundHTLCErr err_code/reason
Now that we're passing around more than a BOLT04 error code, rename the field accordingly.
1 parent e99ec2b commit 0a6638f

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,7 +4502,7 @@ where
45024502
next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>,
45034503
) -> PendingHTLCStatus {
45044504
macro_rules! return_err {
4505-
($msg: expr, $err_code: expr, $data: expr) => {
4505+
($msg: expr, $reason: expr, $data: expr) => {
45064506
{
45074507
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id), Some(msg.payment_hash));
45084508
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
@@ -4516,7 +4516,7 @@ where
45164516
}
45174517
))
45184518
}
4519-
let failure = HTLCFailReason::reason($err_code, $data.to_vec())
4519+
let failure = HTLCFailReason::reason($reason, $data.to_vec())
45204520
.get_encrypted_failure_packet(&shared_secret, &None);
45214521
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
45224522
channel_id: msg.channel_id,
@@ -4543,19 +4543,19 @@ where
45434543
// delay) once they've sent us a commitment_signed!
45444544
PendingHTLCStatus::Forward(info)
45454545
},
4546-
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
4546+
Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason , &err_data)
45474547
}
45484548
},
45494549
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
45504550
match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
45514551
Ok(info) => PendingHTLCStatus::Forward(info),
4552-
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
4552+
Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
45534553
}
45544554
},
45554555
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
45564556
match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
45574557
Ok(info) => PendingHTLCStatus::Forward(info),
4558-
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
4558+
Err(InboundHTLCErr { reason, err_data, msg }) => return_err!(msg, reason, &err_data)
45594559
}
45604560
}
45614561
}
@@ -5923,7 +5923,7 @@ where
59235923
}) => {
59245924
let cltv_expiry = routing.incoming_cltv_expiry();
59255925
macro_rules! failure_handler {
5926-
($msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr, $next_hop_unknown: expr) => {
5926+
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr, $next_hop_unknown: expr) => {
59275927
let logger = WithContext::from(&self.logger, forwarding_counterparty, Some(prev_channel_id), Some(payment_hash));
59285928
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
59295929

@@ -5947,23 +5947,23 @@ where
59475947
};
59485948

59495949
failed_forwards.push((htlc_source, payment_hash,
5950-
HTLCFailReason::reason($err_code, $err_data),
5950+
HTLCFailReason::reason($reason, $err_data),
59515951
reason
59525952
));
59535953
continue;
59545954
}
59555955
}
59565956
macro_rules! fail_forward {
5957-
($msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
5957+
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr) => {
59585958
{
5959-
failure_handler!($msg, $err_code, $err_data, $phantom_ss, true);
5959+
failure_handler!($msg, $reason, $err_data, $phantom_ss, true);
59605960
}
59615961
}
59625962
}
59635963
macro_rules! failed_payment {
5964-
($msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
5964+
($msg: expr, $reason: expr, $err_data: expr, $phantom_ss: expr) => {
59655965
{
5966-
failure_handler!($msg, $err_code, $err_data, $phantom_ss, false);
5966+
failure_handler!($msg, $reason, $err_data, $phantom_ss, false);
59675967
}
59685968
}
59695969
}
@@ -5999,7 +5999,7 @@ where
59995999
prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
60006000
prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)]
60016001
)),
6002-
Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
6002+
Err(InboundHTLCErr { reason, err_data, msg }) => failed_payment!(msg, reason, err_data, Some(phantom_shared_secret))
60036003
}
60046004
} else {
60056005
fail_forward!(format!("Unknown short channel id {} for forward HTLC", short_chan_id),
@@ -15972,12 +15972,12 @@ mod tests {
1597215972
// Check that if the amount we received + the penultimate hop extra fee is less than the sender
1597315973
// intended amount, we fail the payment.
1597415974
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
15975-
if let Err(crate::ln::channelmanager::InboundHTLCErr { err_code, .. }) =
15975+
if let Err(crate::ln::channelmanager::InboundHTLCErr { reason, .. }) =
1597615976
create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1597715977
sender_intended_amt_msat - extra_fee_msat - 1, 42, None, true, Some(extra_fee_msat),
1597815978
current_height)
1597915979
{
15980-
assert_eq!(err_code, LocalHTLCFailureReason::FinalIncorrectHTLCAmount);
15980+
assert_eq!(reason, LocalHTLCFailureReason::FinalIncorrectHTLCAmount);
1598115981
} else { panic!(); }
1598215982

1598315983
// If amt_received + extra_fee is equal to the sender intended amount, we're fine.

lightning/src/ln/onion_payment.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use core::ops::Deref;
2929
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
3030
pub struct InboundHTLCErr {
3131
/// BOLT 4 error code.
32-
pub err_code: LocalHTLCFailureReason,
32+
pub reason: LocalHTLCFailureReason,
3333
/// Data attached to this error.
3434
pub err_data: Vec<u8>,
3535
/// Error message text.
@@ -110,7 +110,7 @@ pub(super) fn create_fwd_pending_htlc_info(
110110
// unreachable right now since we checked it in `decode_update_add_htlc_onion`.
111111
InboundHTLCErr {
112112
msg: "Underflow calculating outbound amount or cltv value for blinded forward",
113-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
113+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
114114
err_data: vec![0; 32],
115115
}
116116
})?;
@@ -120,13 +120,13 @@ pub(super) fn create_fwd_pending_htlc_info(
120120
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } =>
121121
return Err(InboundHTLCErr {
122122
msg: "Final Node OnionHopData provided for us as an intermediary node",
123-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
123+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
124124
err_data: Vec::new(),
125125
}),
126126
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } =>
127127
return Err(InboundHTLCErr {
128128
msg: "Final Node OnionHopData provided for us as an intermediary node",
129-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
129+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
130130
err_data: Vec::new(),
131131
}),
132132
onion_utils::Hop::TrampolineForward { next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
@@ -152,7 +152,7 @@ pub(super) fn create_fwd_pending_htlc_info(
152152
// unreachable right now since we checked it in `decode_update_add_htlc_onion`.
153153
InboundHTLCErr {
154154
msg: "Underflow calculating outbound amount or cltv value for blinded forward",
155-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
155+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
156156
err_data: vec![0; 32],
157157
}
158158
})?;
@@ -199,7 +199,7 @@ pub(super) fn create_fwd_pending_htlc_info(
199199
Some(Ok(pubkey)) => pubkey,
200200
_ => return Err(InboundHTLCErr {
201201
msg: "Missing next Trampoline hop pubkey from intermediate Trampoline forwarding data",
202-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
202+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
203203
err_data: Vec::new(),
204204
}),
205205
};
@@ -263,7 +263,7 @@ pub(super) fn create_recv_pending_htlc_info(
263263
)
264264
.map_err(|()| {
265265
InboundHTLCErr {
266-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
266+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
267267
err_data: vec![0; 32],
268268
msg: "Amount or cltv_expiry violated blinded payment constraints",
269269
}
@@ -293,7 +293,7 @@ pub(super) fn create_recv_pending_htlc_info(
293293
)
294294
.map_err(|()| {
295295
InboundHTLCErr {
296-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
296+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
297297
err_data: vec![0; 32],
298298
msg: "Amount or cltv_expiry violated blinded payment constraints within Trampoline onion",
299299
}
@@ -305,21 +305,21 @@ pub(super) fn create_recv_pending_htlc_info(
305305
},
306306
onion_utils::Hop::Forward { .. } => {
307307
return Err(InboundHTLCErr {
308-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
308+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
309309
err_data: Vec::new(),
310310
msg: "Got non final data with an HMAC of 0",
311311
})
312312
},
313313
onion_utils::Hop::BlindedForward { .. } => {
314314
return Err(InboundHTLCErr {
315-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
315+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
316316
err_data: vec![0; 32],
317317
msg: "Got blinded non final data with an HMAC of 0",
318318
})
319319
},
320320
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
321321
return Err(InboundHTLCErr {
322-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
322+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
323323
err_data: Vec::new(),
324324
msg: "Got Trampoline non final data with an HMAC of 0",
325325
})
@@ -329,7 +329,7 @@ pub(super) fn create_recv_pending_htlc_info(
329329
if onion_cltv_expiry > cltv_expiry {
330330
return Err(InboundHTLCErr {
331331
msg: "Upstream node set CLTV to less than the CLTV set by the sender",
332-
err_code: LocalHTLCFailureReason::FinalIncorrectCLTVExpiry,
332+
reason: LocalHTLCFailureReason::FinalIncorrectCLTVExpiry,
333333
err_data: cltv_expiry.to_be_bytes().to_vec()
334334
})
335335
}
@@ -342,7 +342,7 @@ pub(super) fn create_recv_pending_htlc_info(
342342
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
343343
if cltv_expiry <= current_height + HTLC_FAIL_BACK_BUFFER + 1 {
344344
return Err(InboundHTLCErr {
345-
err_code: LocalHTLCFailureReason::IncorrectPaymentDetails,
345+
reason: LocalHTLCFailureReason::IncorrectPaymentDetails,
346346
err_data: invalid_payment_err_data(amt_msat, current_height),
347347
msg: "The final CLTV expiry is too soon to handle",
348348
});
@@ -352,7 +352,7 @@ pub(super) fn create_recv_pending_htlc_info(
352352
amt_msat.saturating_add(counterparty_skimmed_fee_msat.unwrap_or(0)))
353353
{
354354
return Err(InboundHTLCErr {
355-
err_code: LocalHTLCFailureReason::FinalIncorrectHTLCAmount,
355+
reason: LocalHTLCFailureReason::FinalIncorrectHTLCAmount,
356356
err_data: amt_msat.to_be_bytes().to_vec(),
357357
msg: "Upstream node sent less than we were supposed to receive in payment",
358358
});
@@ -367,7 +367,7 @@ pub(super) fn create_recv_pending_htlc_info(
367367
let hashed_preimage = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
368368
if hashed_preimage != payment_hash {
369369
return Err(InboundHTLCErr {
370-
err_code: LocalHTLCFailureReason::IncorrectPaymentDetails,
370+
reason: LocalHTLCFailureReason::IncorrectPaymentDetails,
371371
err_data: invalid_payment_err_data(amt_msat, current_height),
372372
msg: "Payment preimage didn't match payment hash",
373373
});
@@ -395,7 +395,7 @@ pub(super) fn create_recv_pending_htlc_info(
395395
}
396396
} else {
397397
return Err(InboundHTLCErr {
398-
err_code: LocalHTLCFailureReason::RequiredNodeFeature,
398+
reason: LocalHTLCFailureReason::RequiredNodeFeature,
399399
err_data: Vec::new(),
400400
msg: "We require payment_secrets",
401401
});
@@ -431,12 +431,12 @@ where
431431
let (hop, next_packet_details_opt) =
432432
decode_incoming_update_add_htlc_onion(msg, node_signer, logger, secp_ctx
433433
).map_err(|(msg, failure_reason)| {
434-
let (err_code, err_data) = match msg {
434+
let (reason, err_data) = match msg {
435435
HTLCFailureMsg::Malformed(_) => (failure_reason, Vec::new()),
436436
HTLCFailureMsg::Relay(r) => (LocalHTLCFailureReason::InvalidOnionPayload, r.reason),
437437
};
438438
let msg = "Failed to decode update add htlc onion";
439-
InboundHTLCErr { msg, err_code, err_data }
439+
InboundHTLCErr { msg, reason, err_data }
440440
})?;
441441
Ok(match hop {
442442
onion_utils::Hop::Forward { shared_secret, .. } |
@@ -448,17 +448,17 @@ where
448448
// Forward should always include the next hop details
449449
None => return Err(InboundHTLCErr {
450450
msg: "Failed to decode update add htlc onion",
451-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
451+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
452452
err_data: Vec::new(),
453453
}),
454454
};
455455

456-
if let Err((err_msg, err_code)) = check_incoming_htlc_cltv(
456+
if let Err((err_msg, reason)) = check_incoming_htlc_cltv(
457457
cur_height, outgoing_cltv_value, msg.cltv_expiry,
458458
) {
459459
return Err(InboundHTLCErr {
460460
msg: err_msg,
461-
err_code,
461+
reason,
462462
err_data: Vec::new(),
463463
});
464464
}

0 commit comments

Comments
 (0)