Skip to content

Commit d063122

Browse files
committed
ln/refactor: rename OnionDecodeErr err_code to reason
Now that we're not passing BOLT04 error codes around, rename the field accordingly.
1 parent 0a6638f commit d063122

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5975,17 +5975,17 @@ where
59755975
onion_packet.hmac, payment_hash, None, &*self.node_signer
59765976
) {
59775977
Ok(res) => res,
5978-
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
5978+
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, reason }) => {
59795979
let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).to_byte_array();
59805980
// In this scenario, the phantom would have sent us an
59815981
// `update_fail_malformed_htlc`, meaning here we encrypt the error as
59825982
// if it came from us (the second-to-last hop) but contains the sha256
59835983
// of the onion.
5984-
failed_payment!(err_msg, err_code, sha256_of_onion.to_vec(), None);
5984+
failed_payment!(err_msg, reason, sha256_of_onion.to_vec(), None);
59855985
},
5986-
Err(onion_utils::OnionDecodeErr::Relay { err_msg, err_code, shared_secret, .. }) => {
5986+
Err(onion_utils::OnionDecodeErr::Relay { err_msg, reason, shared_secret, .. }) => {
59875987
let phantom_shared_secret = shared_secret.secret_bytes();
5988-
failed_payment!(err_msg, err_code, Vec::new(), Some(phantom_shared_secret));
5988+
failed_payment!(err_msg, reason, Vec::new(), Some(phantom_shared_secret));
59895989
},
59905990
};
59915991
let phantom_shared_secret = next_hop.shared_secret().secret_bytes();

lightning/src/ln/onion_payment.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,11 @@ where
549549
msg.payment_hash, msg.blinding_point, node_signer
550550
) {
551551
Ok(res) => res,
552-
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
553-
return encode_malformed_error(err_msg, err_code);
552+
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, reason }) => {
553+
return encode_malformed_error(err_msg, reason);
554554
},
555-
Err(onion_utils::OnionDecodeErr::Relay { err_msg, err_code, shared_secret, trampoline_shared_secret }) => {
556-
return encode_relay_error(err_msg, err_code, shared_secret.secret_bytes(), trampoline_shared_secret.map(|tss| tss.secret_bytes()), &[0; 0]);
555+
Err(onion_utils::OnionDecodeErr::Relay { err_msg, reason, shared_secret, trampoline_shared_secret }) => {
556+
return encode_relay_error(err_msg, reason, shared_secret.secret_bytes(), trampoline_shared_secret.map(|tss| tss.secret_bytes()), &[0; 0]);
557557
},
558558
};
559559

lightning/src/ln/onion_utils.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,14 +2009,14 @@ impl Hop {
20092009
#[derive(Debug)]
20102010
pub(crate) enum OnionDecodeErr {
20112011
/// The HMAC of the onion packet did not match the hop data.
2012-
Malformed { err_msg: &'static str, err_code: LocalHTLCFailureReason },
2012+
Malformed { err_msg: &'static str, reason: LocalHTLCFailureReason },
20132013
/// We failed to decode the onion payload.
20142014
///
20152015
/// If the payload we failed to decode belonged to a Trampoline onion, following the successful
20162016
/// decoding of the outer onion, the trampoline_shared_secret field should be set.
20172017
Relay {
20182018
err_msg: &'static str,
2019-
err_code: LocalHTLCFailureReason,
2019+
reason: LocalHTLCFailureReason,
20202020
shared_secret: SharedSecret,
20212021
trampoline_shared_secret: Option<SharedSecret>,
20222022
},
@@ -2067,12 +2067,12 @@ where
20672067
return Err(OnionDecodeErr::Malformed {
20682068
err_msg:
20692069
"Final Node OnionHopData provided for us as an intermediary node",
2070-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2070+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
20712071
});
20722072
}
20732073
Err(OnionDecodeErr::Relay {
20742074
err_msg: "Final Node OnionHopData provided for us as an intermediary node",
2075-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2075+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
20762076
shared_secret,
20772077
trampoline_shared_secret: None,
20782078
})
@@ -2167,7 +2167,7 @@ where
21672167
if hop_data.intro_node_blinding_point.is_some() {
21682168
return Err(OnionDecodeErr::Relay {
21692169
err_msg: "Non-final intro node Trampoline onion data provided to us as last hop",
2170-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2170+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
21712171
shared_secret,
21722172
trampoline_shared_secret: Some(SharedSecret::from_bytes(
21732173
trampoline_shared_secret,
@@ -2176,14 +2176,14 @@ where
21762176
}
21772177
Err(OnionDecodeErr::Malformed {
21782178
err_msg: "Non-final Trampoline onion data provided to us as last hop",
2179-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2179+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
21802180
})
21812181
},
21822182
Ok((msgs::InboundTrampolinePayload::BlindedReceive(hop_data), Some(_))) => {
21832183
if hop_data.intro_node_blinding_point.is_some() {
21842184
return Err(OnionDecodeErr::Relay {
21852185
err_msg: "Final Trampoline intro node onion data provided to us as intermediate hop",
2186-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2186+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
21872187
shared_secret,
21882188
trampoline_shared_secret: Some(SharedSecret::from_bytes(
21892189
trampoline_shared_secret,
@@ -2193,13 +2193,13 @@ where
21932193
Err(OnionDecodeErr::Malformed {
21942194
err_msg:
21952195
"Final Trampoline onion data provided to us as intermediate hop",
2196-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2196+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
21972197
})
21982198
},
21992199
Ok((msgs::InboundTrampolinePayload::Forward(_), None)) => {
22002200
Err(OnionDecodeErr::Relay {
22012201
err_msg: "Non-final Trampoline onion data provided to us as last hop",
2202-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2202+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
22032203
shared_secret,
22042204
trampoline_shared_secret: Some(SharedSecret::from_bytes(
22052205
trampoline_shared_secret,
@@ -2210,7 +2210,7 @@ where
22102210
Err(OnionDecodeErr::Relay {
22112211
err_msg:
22122212
"Final Trampoline onion data provided to us as intermediate hop",
2213-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2213+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
22142214
shared_secret,
22152215
trampoline_shared_secret: Some(SharedSecret::from_bytes(
22162216
trampoline_shared_secret,
@@ -2224,12 +2224,12 @@ where
22242224
if blinding_point.is_some() {
22252225
return Err(OnionDecodeErr::Malformed {
22262226
err_msg: "Intermediate Node OnionHopData provided for us as a final node",
2227-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2227+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
22282228
});
22292229
}
22302230
Err(OnionDecodeErr::Relay {
22312231
err_msg: "Intermediate Node OnionHopData provided for us as a final node",
2232-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2232+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
22332233
shared_secret,
22342234
trampoline_shared_secret: None,
22352235
})
@@ -2358,7 +2358,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
23582358
if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &hmac_bytes) {
23592359
return Err(OnionDecodeErr::Malformed {
23602360
err_msg: "HMAC Check failed",
2361-
err_code: LocalHTLCFailureReason::InvalidOnionHMAC,
2361+
reason: LocalHTLCFailureReason::InvalidOnionHMAC,
23622362
});
23632363
}
23642364

@@ -2378,7 +2378,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
23782378
};
23792379
return Err(OnionDecodeErr::Relay {
23802380
err_msg: "Unable to decode our hop data",
2381-
err_code: error_code,
2381+
reason: error_code,
23822382
shared_secret: SharedSecret::from_bytes(shared_secret),
23832383
trampoline_shared_secret: None,
23842384
});
@@ -2388,7 +2388,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
23882388
if let Err(_) = chacha_stream.read_exact(&mut hmac[..]) {
23892389
return Err(OnionDecodeErr::Relay {
23902390
err_msg: "Unable to decode our hop data",
2391-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2391+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
23922392
shared_secret: SharedSecret::from_bytes(shared_secret),
23932393
trampoline_shared_secret: None,
23942394
});

0 commit comments

Comments
 (0)