Skip to content

Commit daae398

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 8e47178 commit daae398

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
@@ -5974,17 +5974,17 @@ where
59745974
onion_packet.hmac, payment_hash, None, &*self.node_signer
59755975
) {
59765976
Ok(res) => res,
5977-
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
5977+
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, reason }) => {
59785978
let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).to_byte_array();
59795979
// In this scenario, the phantom would have sent us an
59805980
// `update_fail_malformed_htlc`, meaning here we encrypt the error as
59815981
// if it came from us (the second-to-last hop) but contains the sha256
59825982
// of the onion.
5983-
failed_payment!(err_msg, err_code, sha256_of_onion.to_vec(), None);
5983+
failed_payment!(err_msg, reason, sha256_of_onion.to_vec(), None);
59845984
},
5985-
Err(onion_utils::OnionDecodeErr::Relay { err_msg, err_code, shared_secret, .. }) => {
5985+
Err(onion_utils::OnionDecodeErr::Relay { err_msg, reason, shared_secret, .. }) => {
59865986
let phantom_shared_secret = shared_secret.secret_bytes();
5987-
failed_payment!(err_msg, err_code, Vec::new(), Some(phantom_shared_secret));
5987+
failed_payment!(err_msg, reason, Vec::new(), Some(phantom_shared_secret));
59885988
},
59895989
};
59905990
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
@@ -1986,14 +1986,14 @@ impl Hop {
19861986
#[derive(Debug)]
19871987
pub(crate) enum OnionDecodeErr {
19881988
/// The HMAC of the onion packet did not match the hop data.
1989-
Malformed { err_msg: &'static str, err_code: LocalHTLCFailureReason },
1989+
Malformed { err_msg: &'static str, reason: LocalHTLCFailureReason },
19901990
/// We failed to decode the onion payload.
19911991
///
19921992
/// If the payload we failed to decode belonged to a Trampoline onion, following the successful
19931993
/// decoding of the outer onion, the trampoline_shared_secret field should be set.
19941994
Relay {
19951995
err_msg: &'static str,
1996-
err_code: LocalHTLCFailureReason,
1996+
reason: LocalHTLCFailureReason,
19971997
shared_secret: SharedSecret,
19981998
trampoline_shared_secret: Option<SharedSecret>,
19991999
},
@@ -2044,12 +2044,12 @@ where
20442044
return Err(OnionDecodeErr::Malformed {
20452045
err_msg:
20462046
"Final Node OnionHopData provided for us as an intermediary node",
2047-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2047+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
20482048
});
20492049
}
20502050
Err(OnionDecodeErr::Relay {
20512051
err_msg: "Final Node OnionHopData provided for us as an intermediary node",
2052-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2052+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
20532053
shared_secret,
20542054
trampoline_shared_secret: None,
20552055
})
@@ -2144,7 +2144,7 @@ where
21442144
if hop_data.intro_node_blinding_point.is_some() {
21452145
return Err(OnionDecodeErr::Relay {
21462146
err_msg: "Non-final intro node Trampoline onion data provided to us as last hop",
2147-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2147+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
21482148
shared_secret,
21492149
trampoline_shared_secret: Some(SharedSecret::from_bytes(
21502150
trampoline_shared_secret,
@@ -2153,14 +2153,14 @@ where
21532153
}
21542154
Err(OnionDecodeErr::Malformed {
21552155
err_msg: "Non-final Trampoline onion data provided to us as last hop",
2156-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2156+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
21572157
})
21582158
},
21592159
Ok((msgs::InboundTrampolinePayload::BlindedReceive(hop_data), Some(_))) => {
21602160
if hop_data.intro_node_blinding_point.is_some() {
21612161
return Err(OnionDecodeErr::Relay {
21622162
err_msg: "Final Trampoline intro node onion data provided to us as intermediate hop",
2163-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2163+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
21642164
shared_secret,
21652165
trampoline_shared_secret: Some(SharedSecret::from_bytes(
21662166
trampoline_shared_secret,
@@ -2170,13 +2170,13 @@ where
21702170
Err(OnionDecodeErr::Malformed {
21712171
err_msg:
21722172
"Final Trampoline onion data provided to us as intermediate hop",
2173-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2173+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
21742174
})
21752175
},
21762176
Ok((msgs::InboundTrampolinePayload::Forward(_), None)) => {
21772177
Err(OnionDecodeErr::Relay {
21782178
err_msg: "Non-final Trampoline onion data provided to us as last hop",
2179-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2179+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
21802180
shared_secret,
21812181
trampoline_shared_secret: Some(SharedSecret::from_bytes(
21822182
trampoline_shared_secret,
@@ -2187,7 +2187,7 @@ where
21872187
Err(OnionDecodeErr::Relay {
21882188
err_msg:
21892189
"Final Trampoline onion data provided to us as intermediate hop",
2190-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2190+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
21912191
shared_secret,
21922192
trampoline_shared_secret: Some(SharedSecret::from_bytes(
21932193
trampoline_shared_secret,
@@ -2201,12 +2201,12 @@ where
22012201
if blinding_point.is_some() {
22022202
return Err(OnionDecodeErr::Malformed {
22032203
err_msg: "Intermediate Node OnionHopData provided for us as a final node",
2204-
err_code: LocalHTLCFailureReason::InvalidOnionBlinding,
2204+
reason: LocalHTLCFailureReason::InvalidOnionBlinding,
22052205
});
22062206
}
22072207
Err(OnionDecodeErr::Relay {
22082208
err_msg: "Intermediate Node OnionHopData provided for us as a final node",
2209-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2209+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
22102210
shared_secret,
22112211
trampoline_shared_secret: None,
22122212
})
@@ -2329,7 +2329,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
23292329
if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &hmac_bytes) {
23302330
return Err(OnionDecodeErr::Malformed {
23312331
err_msg: "HMAC Check failed",
2332-
err_code: LocalHTLCFailureReason::InvalidOnionHMAC,
2332+
reason: LocalHTLCFailureReason::InvalidOnionHMAC,
23332333
});
23342334
}
23352335

@@ -2349,7 +2349,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
23492349
};
23502350
return Err(OnionDecodeErr::Relay {
23512351
err_msg: "Unable to decode our hop data",
2352-
err_code: error_code,
2352+
reason: error_code,
23532353
shared_secret: SharedSecret::from_bytes(shared_secret),
23542354
trampoline_shared_secret: None,
23552355
});
@@ -2359,7 +2359,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
23592359
if let Err(_) = chacha_stream.read_exact(&mut hmac[..]) {
23602360
return Err(OnionDecodeErr::Relay {
23612361
err_msg: "Unable to decode our hop data",
2362-
err_code: LocalHTLCFailureReason::InvalidOnionPayload,
2362+
reason: LocalHTLCFailureReason::InvalidOnionPayload,
23632363
shared_secret: SharedSecret::from_bytes(shared_secret),
23642364
trampoline_shared_secret: None,
23652365
});

0 commit comments

Comments
 (0)