Skip to content

Commit 5506d3d

Browse files
committed
Refactor onion_utils to encrypt/decrypt OnionErrorPacket types
Prepares for extending OnionErrorPacket with attribution data.
1 parent 43de15e commit 5506d3d

File tree

2 files changed

+100
-71
lines changed

2 files changed

+100
-71
lines changed

lightning/src/ln/onion_route_tests.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ln::msgs::{
2828
OutboundOnionPayload, OutboundTrampolinePayload, MessageSendEvent,
2929
};
3030
use crate::ln::wire::Encode;
31-
use crate::util::ser::{Writeable, Writer, BigSize};
31+
use crate::util::ser::{BigSize, VecWriter, Writeable, Writer};
3232
use crate::util::test_utils;
3333
use crate::util::config::{UserConfig, ChannelConfig, MaxDustHTLCExposure};
3434
use crate::util::errors::APIError;
@@ -49,6 +49,8 @@ use crate::blinded_path::BlindedHop;
4949
use crate::ln::functional_test_utils::*;
5050
use crate::ln::onion_utils::{construct_trampoline_onion_keys, construct_trampoline_onion_packet};
5151

52+
use super::msgs::OnionErrorPacket;
53+
5254
fn run_onion_failure_test<F1,F2>(_name: &str, test_case: u8, nodes: &Vec<Node>, route: &Route, payment_hash: &PaymentHash, payment_secret: &PaymentSecret, callback_msg: F1, callback_node: F2, expected_retryable: bool, expected_error_code: Option<u16>, expected_channel_update: Option<NetworkUpdate>, expected_short_channel_id: Option<u64>, expected_htlc_destination: Option<HTLCDestination>)
5355
where F1: for <'a> FnMut(&'a mut msgs::UpdateAddHTLC),
5456
F2: FnMut(),
@@ -670,8 +672,12 @@ fn test_onion_failure() {
670672
let mut hmac = HmacEngine::<Sha256>::new(&um);
671673
hmac.input(&decoded_err_packet.encode()[32..]);
672674
decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
673-
msg.reason = onion_utils::encrypt_failure_packet(
674-
&onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
675+
let mut onion_error = OnionErrorPacket{
676+
data: decoded_err_packet.encode(),
677+
};
678+
onion_utils::crypt_failure_packet(
679+
&onion_keys[1].shared_secret.as_ref(), &mut onion_error);
680+
msg.reason = onion_error;
675681
}, || nodes[2].node.fail_htlc_backwards(&payment_hash), false, None,
676682
Some(NetworkUpdate::NodeFailure { node_id: route.paths[0].hops[1].pubkey, is_permanent: true }),
677683
Some(channels[1].0.contents.short_channel_id), None);
@@ -693,8 +699,12 @@ fn test_onion_failure() {
693699
let mut hmac = HmacEngine::<Sha256>::new(&um);
694700
hmac.input(&decoded_err_packet.encode()[32..]);
695701
decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
696-
msg.reason = onion_utils::encrypt_failure_packet(
697-
&onion_keys[0].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
702+
let mut onion_error = OnionErrorPacket{
703+
data: decoded_err_packet.encode(),
704+
};
705+
onion_utils::crypt_failure_packet(
706+
&onion_keys[0].shared_secret.as_ref(), &mut onion_error);
707+
msg.reason = onion_error;
698708
}, || {}, true, Some(0x1000|7),
699709
Some(NetworkUpdate::ChannelFailure {
700710
short_channel_id: channels[1].0.contents.short_channel_id,
@@ -717,8 +727,12 @@ fn test_onion_failure() {
717727
let mut hmac = HmacEngine::<Sha256>::new(&um);
718728
hmac.input(&decoded_err_packet.encode()[32..]);
719729
decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
720-
msg.reason = onion_utils::encrypt_failure_packet(
721-
&onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
730+
let mut onion_error = OnionErrorPacket{
731+
data: decoded_err_packet.encode(),
732+
};
733+
onion_utils::crypt_failure_packet(
734+
&onion_keys[1].shared_secret.as_ref(), &mut onion_error);
735+
msg.reason = onion_error;
722736
}, || nodes[2].node.fail_htlc_backwards(&payment_hash), true, Some(0x1000|7),
723737
Some(NetworkUpdate::ChannelFailure {
724738
short_channel_id: channels[1].0.contents.short_channel_id,

lightning/src/ln/onion_utils.rs

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::types::payment::{PaymentHash, PaymentPreimage};
2222
use crate::util::errors::{self, APIError};
2323
use crate::util::logger::Logger;
2424
use crate::util::ser::{LengthCalculatingWriter, Readable, ReadableArgs, Writeable, Writer};
25+
use super::msgs::OnionErrorPacket;
2526

2627
use bitcoin::hashes::cmp::fixed_time_eq;
2728
use bitcoin::hashes::hmac::{Hmac, HmacEngine};
@@ -869,23 +870,22 @@ fn construct_onion_packet_with_init_noise<HD: Writeable, P: Packet>(
869870
Ok(P::new(onion_keys.first().unwrap().ephemeral_pubkey, packet_data, hmac_res))
870871
}
871872

872-
/// Encrypts a failure packet. raw_packet can either be a
873-
/// msgs::DecodedOnionErrorPacket.encode() result or a msgs::OnionErrorPacket.data element.
874-
pub(super) fn encrypt_failure_packet(
875-
shared_secret: &[u8], raw_packet: &[u8],
876-
) -> msgs::OnionErrorPacket {
873+
/// Encrypts/decrypts a failure packet.
874+
pub(super) fn crypt_failure_packet(
875+
shared_secret: &[u8], packet: &mut OnionErrorPacket
876+
) {
877877
let ammag = gen_ammag_from_shared_secret(&shared_secret);
878+
process_chacha(&ammag, &mut packet.data);
879+
}
878880

879-
let mut packet_crypted = Vec::with_capacity(raw_packet.len());
880-
packet_crypted.resize(raw_packet.len(), 0);
881-
let mut chacha = ChaCha20::new(&ammag, &[0u8; 8]);
882-
chacha.process(&raw_packet, &mut packet_crypted[..]);
883-
msgs::OnionErrorPacket { data: packet_crypted }
881+
pub(super) fn process_chacha(key: &[u8; 32], packet: &mut [u8]) {
882+
let mut chacha = ChaCha20::new(key, &[0u8; 8]);
883+
chacha.process_in_place(packet);
884884
}
885885

886886
pub(super) fn build_failure_packet(
887-
shared_secret: &[u8], failure_type: u16, failure_data: &[u8],
888-
) -> msgs::DecodedOnionErrorPacket {
887+
shared_secret: &[u8], failure_type: u16, failure_data: &[u8]
888+
) -> OnionErrorPacket {
889889
assert_eq!(shared_secret.len(), 32);
890890
assert!(failure_data.len() <= 256 - 2);
891891

@@ -909,15 +909,20 @@ pub(super) fn build_failure_packet(
909909
hmac.input(&packet.encode()[32..]);
910910
packet.hmac = Hmac::from_engine(hmac).to_byte_array();
911911

912-
packet
912+
913+
OnionErrorPacket {
914+
data: packet.encode(),
915+
}
913916
}
914917

915918
#[cfg(test)]
916919
pub(super) fn build_first_hop_failure_packet(
917920
shared_secret: &[u8], failure_type: u16, failure_data: &[u8],
918921
) -> msgs::OnionErrorPacket {
919-
let failure_packet = build_failure_packet(shared_secret, failure_type, failure_data);
920-
encrypt_failure_packet(shared_secret, &failure_packet.encode()[..])
922+
let mut failure_packet = build_failure_packet(shared_secret, failure_type, failure_data);
923+
crypt_failure_packet(shared_secret, &mut failure_packet);
924+
925+
failure_packet
921926
}
922927

923928
pub(crate) struct DecodedOnionFailure {
@@ -932,17 +937,18 @@ pub(crate) struct DecodedOnionFailure {
932937
}
933938

934939
/// Decrypt the error packet in-place.
935-
fn decrypt_onion_error_packet(packet: &mut Vec<u8>, shared_secret: SharedSecret) {
936-
let ammag = gen_ammag_from_shared_secret(shared_secret.as_ref());
937-
let mut chacha = ChaCha20::new(&ammag, &[0u8; 8]);
938-
chacha.process_in_place(packet);
940+
fn decrypt_onion_error_packet(
941+
packet: &mut OnionErrorPacket, shared_secret: SharedSecret,
942+
) {
943+
// Decrypt the packet.
944+
crypt_failure_packet(shared_secret.as_ref(), packet);
939945
}
940946

941947
/// Process failure we got back from upstream on a payment we sent (implying htlc_source is an
942948
/// OutboundRoute).
943949
#[inline]
944950
pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
945-
secp_ctx: &Secp256k1<T>, logger: &L, htlc_source: &HTLCSource, mut encrypted_packet: Vec<u8>,
951+
secp_ctx: &Secp256k1<T>, logger: &L, htlc_source: &HTLCSource, mut encrypted_packet: OnionErrorPacket,
946952
) -> DecodedOnionFailure
947953
where
948954
L::Target: Logger,
@@ -1019,7 +1025,7 @@ where
10191025
// back correctly.
10201026
decrypt_onion_error_packet(&mut encrypted_packet, shared_secret);
10211027
let err_packet = msgs::DecodedOnionErrorPacket::read(&mut Cursor::new(
1022-
&encrypted_packet,
1028+
&encrypted_packet.data,
10231029
))
10241030
.unwrap();
10251031
error_code_ret = Some(u16::from_be_bytes(
@@ -1046,14 +1052,14 @@ where
10461052

10471053
let um = gen_um_from_shared_secret(shared_secret.as_ref());
10481054
let mut hmac = HmacEngine::<Sha256>::new(&um);
1049-
hmac.input(&encrypted_packet[32..]);
1055+
hmac.input(&encrypted_packet.data[32..]);
10501056

1051-
if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &encrypted_packet[..32]) {
1057+
if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &encrypted_packet.data[..32]) {
10521058
return;
10531059
}
10541060

10551061
let err_packet =
1056-
match msgs::DecodedOnionErrorPacket::read(&mut Cursor::new(&encrypted_packet)) {
1062+
match msgs::DecodedOnionErrorPacket::read(&mut Cursor::new(&encrypted_packet.data)) {
10571063
Ok(p) => p,
10581064
Err(_) => {
10591065
log_warn!(logger, "Unreadable failure from {}", route_hop.pubkey);
@@ -1258,11 +1264,11 @@ where
12581264
}
12591265
}
12601266

1261-
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
1267+
#[derive(Clone)]// See Channel::revoke_and_ack for why, tl;dr: Rust bug
12621268
#[cfg_attr(test, derive(PartialEq))]
12631269
pub(super) struct HTLCFailReason(HTLCFailReasonRepr);
12641270

1265-
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
1271+
#[derive(Clone)]// See Channel::revoke_and_ack for why, tl;dr: Rust bug
12661272
#[cfg_attr(test, derive(PartialEq))]
12671273
enum HTLCFailReasonRepr {
12681274
LightningError { err: msgs::OnionErrorPacket },
@@ -1361,26 +1367,32 @@ impl HTLCFailReason {
13611367
match self.0 {
13621368
HTLCFailReasonRepr::Reason { ref failure_code, ref data } => {
13631369
if let Some(phantom_ss) = phantom_shared_secret {
1364-
let phantom_packet =
1365-
build_failure_packet(phantom_ss, *failure_code, &data[..]).encode();
1366-
let encrypted_phantom_packet =
1367-
encrypt_failure_packet(phantom_ss, &phantom_packet);
1368-
encrypt_failure_packet(
1370+
let mut packet =
1371+
build_failure_packet(phantom_ss, *failure_code, &data[..]);
1372+
crypt_failure_packet(phantom_ss, &mut packet);
1373+
crypt_failure_packet(
13691374
incoming_packet_shared_secret,
1370-
&encrypted_phantom_packet.data[..],
1371-
)
1375+
&mut packet
1376+
);
1377+
1378+
packet
13721379
} else {
1373-
let packet = build_failure_packet(
1380+
let mut packet = build_failure_packet(
13741381
incoming_packet_shared_secret,
13751382
*failure_code,
13761383
&data[..],
1377-
)
1378-
.encode();
1379-
encrypt_failure_packet(incoming_packet_shared_secret, &packet)
1384+
);
1385+
crypt_failure_packet(incoming_packet_shared_secret, &mut packet);
1386+
1387+
packet
13801388
}
13811389
},
13821390
HTLCFailReasonRepr::LightningError { ref err } => {
1383-
encrypt_failure_packet(incoming_packet_shared_secret, &err.data)
1391+
let mut err = err.clone();
1392+
1393+
crypt_failure_packet(incoming_packet_shared_secret, &mut err);
1394+
1395+
err
13841396
},
13851397
}
13861398
}
@@ -1393,7 +1405,7 @@ impl HTLCFailReason {
13931405
{
13941406
match self.0 {
13951407
HTLCFailReasonRepr::LightningError { ref err } => {
1396-
process_onion_failure(secp_ctx, logger, &htlc_source, err.data.clone())
1408+
process_onion_failure(secp_ctx, logger, &htlc_source, err.clone())
13971409
},
13981410
#[allow(unused)]
13991411
HTLCFailReasonRepr::Reason { ref failure_code, ref data, .. } => {
@@ -2124,45 +2136,45 @@ mod tests {
21242136
// Returning Errors test vectors from BOLT 4
21252137

21262138
let onion_keys = build_test_onion_keys();
2127-
let onion_error =
2139+
let mut onion_error =
21282140
super::build_failure_packet(onion_keys[4].shared_secret.as_ref(), 0x2002, &[0; 0]);
21292141
let hex = "4c2fc8bc08510334b6833ad9c3e79cd1b52ae59dfe5c2a4b23ead50f09f7ee0b0002200200fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
2130-
assert_eq!(onion_error.encode(), <Vec<u8>>::from_hex(hex).unwrap());
2142+
assert_eq!(onion_error.data, <Vec<u8>>::from_hex(hex).unwrap());
21312143

2132-
let onion_packet_1 = super::encrypt_failure_packet(
2144+
super::crypt_failure_packet(
21332145
onion_keys[4].shared_secret.as_ref(),
2134-
&onion_error.encode()[..],
2146+
&mut onion_error,
21352147
);
21362148
let hex = "a5e6bd0c74cb347f10cce367f949098f2457d14c046fd8a22cb96efb30b0fdcda8cb9168b50f2fd45edd73c1b0c8b33002df376801ff58aaa94000bf8a86f92620f343baef38a580102395ae3abf9128d1047a0736ff9b83d456740ebbb4aeb3aa9737f18fb4afb4aa074fb26c4d702f42968888550a3bded8c05247e045b866baef0499f079fdaeef6538f31d44deafffdfd3afa2fb4ca9082b8f1c465371a9894dd8c243fb4847e004f5256b3e90e2edde4c9fb3082ddfe4d1e734cacd96ef0706bf63c9984e22dc98851bcccd1c3494351feb458c9c6af41c0044bea3c47552b1d992ae542b17a2d0bba1a096c78d169034ecb55b6e3a7263c26017f033031228833c1daefc0dedb8cf7c3e37c9c37ebfe42f3225c326e8bcfd338804c145b16e34e4";
2137-
assert_eq!(onion_packet_1.data, <Vec<u8>>::from_hex(hex).unwrap());
2149+
assert_eq!(onion_error.data, <Vec<u8>>::from_hex(hex).unwrap());
21382150

2139-
let onion_packet_2 = super::encrypt_failure_packet(
2151+
super::crypt_failure_packet(
21402152
onion_keys[3].shared_secret.as_ref(),
2141-
&onion_packet_1.data[..],
2153+
&mut onion_error,
21422154
);
21432155
let hex = "c49a1ce81680f78f5f2000cda36268de34a3f0a0662f55b4e837c83a8773c22aa081bab1616a0011585323930fa5b9fae0c85770a2279ff59ec427ad1bbff9001c0cd1497004bd2a0f68b50704cf6d6a4bf3c8b6a0833399a24b3456961ba00736785112594f65b6b2d44d9f5ea4e49b5e1ec2af978cbe31c67114440ac51a62081df0ed46d4a3df295da0b0fe25c0115019f03f15ec86fabb4c852f83449e812f141a9395b3f70b766ebbd4ec2fae2b6955bd8f32684c15abfe8fd3a6261e52650e8807a92158d9f1463261a925e4bfba44bd20b166d532f0017185c3a6ac7957adefe45559e3072c8dc35abeba835a8cb01a71a15c736911126f27d46a36168ca5ef7dccd4e2886212602b181463e0dd30185c96348f9743a02aca8ec27c0b90dca270";
2144-
assert_eq!(onion_packet_2.data, <Vec<u8>>::from_hex(hex).unwrap());
2156+
assert_eq!(onion_error.data, <Vec<u8>>::from_hex(hex).unwrap());
21452157

2146-
let onion_packet_3 = super::encrypt_failure_packet(
2158+
super::crypt_failure_packet(
21472159
onion_keys[2].shared_secret.as_ref(),
2148-
&onion_packet_2.data[..],
2160+
&mut onion_error,
21492161
);
21502162
let hex = "a5d3e8634cfe78b2307d87c6d90be6fe7855b4f2cc9b1dfb19e92e4b79103f61ff9ac25f412ddfb7466e74f81b3e545563cdd8f5524dae873de61d7bdfccd496af2584930d2b566b4f8d3881f8c043df92224f38cf094cfc09d92655989531524593ec6d6caec1863bdfaa79229b5020acc034cd6deeea1021c50586947b9b8e6faa83b81fbfa6133c0af5d6b07c017f7158fa94f0d206baf12dda6b68f785b773b360fd0497e16cc402d779c8d48d0fa6315536ef0660f3f4e1865f5b38ea49c7da4fd959de4e83ff3ab686f059a45c65ba2af4a6a79166aa0f496bf04d06987b6d2ea205bdb0d347718b9aeff5b61dfff344993a275b79717cd815b6ad4c0beb568c4ac9c36ff1c315ec1119a1993c4b61e6eaa0375e0aaf738ac691abd3263bf937e3";
2151-
assert_eq!(onion_packet_3.data, <Vec<u8>>::from_hex(hex).unwrap());
2163+
assert_eq!(onion_error.data, <Vec<u8>>::from_hex(hex).unwrap());
21522164

2153-
let onion_packet_4 = super::encrypt_failure_packet(
2165+
super::crypt_failure_packet(
21542166
onion_keys[1].shared_secret.as_ref(),
2155-
&onion_packet_3.data[..],
2167+
&mut onion_error,
21562168
);
21572169
let hex = "aac3200c4968f56b21f53e5e374e3a2383ad2b1b6501bbcc45abc31e59b26881b7dfadbb56ec8dae8857add94e6702fb4c3a4de22e2e669e1ed926b04447fc73034bb730f4932acd62727b75348a648a1128744657ca6a4e713b9b646c3ca66cac02cdab44dd3439890ef3aaf61708714f7375349b8da541b2548d452d84de7084bb95b3ac2345201d624d31f4d52078aa0fa05a88b4e20202bd2b86ac5b52919ea305a8949de95e935eed0319cf3cf19ebea61d76ba92532497fcdc9411d06bcd4275094d0a4a3c5d3a945e43305a5a9256e333e1f64dbca5fcd4e03a39b9012d197506e06f29339dfee3331995b21615337ae060233d39befea925cc262873e0530408e6990f1cbd233a150ef7b004ff6166c70c68d9f8c853c1abca640b8660db2921";
2158-
assert_eq!(onion_packet_4.data, <Vec<u8>>::from_hex(hex).unwrap());
2170+
assert_eq!(onion_error.data, <Vec<u8>>::from_hex(hex).unwrap());
21592171

2160-
let onion_packet_5 = super::encrypt_failure_packet(
2172+
super::crypt_failure_packet(
21612173
onion_keys[0].shared_secret.as_ref(),
2162-
&onion_packet_4.data[..],
2174+
&mut onion_error,
21632175
);
21642176
let hex = "9c5add3963fc7f6ed7f148623c84134b5647e1306419dbe2174e523fa9e2fbed3a06a19f899145610741c83ad40b7712aefaddec8c6baf7325d92ea4ca4d1df8bce517f7e54554608bf2bd8071a4f52a7a2f7ffbb1413edad81eeea5785aa9d990f2865dc23b4bc3c301a94eec4eabebca66be5cf638f693ec256aec514620cc28ee4a94bd9565bc4d4962b9d3641d4278fb319ed2b84de5b665f307a2db0f7fbb757366067d88c50f7e829138fde4f78d39b5b5802f1b92a8a820865af5cc79f9f30bc3f461c66af95d13e5e1f0381c184572a91dee1c849048a647a1158cf884064deddbf1b0b88dfe2f791428d0ba0f6fb2f04e14081f69165ae66d9297c118f0907705c9c4954a199bae0bb96fad763d690e7daa6cfda59ba7f2c8d11448b604d12d";
2165-
assert_eq!(onion_packet_5.data, <Vec<u8>>::from_hex(hex).unwrap());
2177+
assert_eq!(onion_error.data, <Vec<u8>>::from_hex(hex).unwrap());
21662178

21672179
let logger: Arc<TestLogger> = Arc::new(TestLogger::new());
21682180
let ctx_full = Secp256k1::new();
@@ -2176,7 +2188,7 @@ mod tests {
21762188

21772189
// Assert that the original failure can be retrieved and that all hmacs check out.
21782190
let decrypted_failure =
2179-
process_onion_failure(&ctx_full, &logger, &htlc_source, onion_packet_5.data);
2191+
process_onion_failure(&ctx_full, &logger, &htlc_source, onion_error);
21802192

21812193
assert_eq!(decrypted_failure.onion_error_code, Some(0x2002));
21822194
}
@@ -2185,10 +2197,11 @@ mod tests {
21852197
fn test_non_attributable_failure_packet_onion() {
21862198
// Create a failure packet with bogus data.
21872199
let packet = vec![1u8; 292];
2200+
let mut onion_error_packet = OnionErrorPacket {data: packet};
21882201

21892202
// In the current protocol, it is unfortunately not possible to identify the failure source.
21902203
let logger: TestLogger = TestLogger::new();
2191-
let decrypted_failure = test_failure_attribution(&logger, &packet);
2204+
let decrypted_failure = test_failure_attribution(&logger, onion_error_packet);
21922205
assert_eq!(decrypted_failure.short_channel_id, None);
21932206

21942207
logger.assert_log_contains(
@@ -2213,11 +2226,12 @@ mod tests {
22132226
let hmac = Hmac::from_engine(hmac).to_byte_array();
22142227
packet[..32].copy_from_slice(&hmac);
22152228

2216-
let packet = encrypt_failure_packet(shared_secret, &packet);
2229+
let mut onion_error_packet = OnionErrorPacket {data: packet.to_vec()};
2230+
crypt_failure_packet(shared_secret, &mut onion_error_packet);
22172231

22182232
// For the unreadable failure, it is still expected that the failing channel can be identified.
22192233
let logger: TestLogger = TestLogger::new();
2220-
let decrypted_failure = test_failure_attribution(&logger, &packet.data);
2234+
let decrypted_failure = test_failure_attribution(&logger, onion_error_packet);
22212235
assert_eq!(decrypted_failure.short_channel_id, Some(0));
22222236

22232237
logger.assert_log_contains("lightning::ln::onion_utils", "Unreadable failure", 1);
@@ -2238,10 +2252,11 @@ mod tests {
22382252
hmac.input(&packet.encode()[32..]);
22392253
packet.hmac = Hmac::from_engine(hmac).to_byte_array();
22402254

2241-
let packet = encrypt_failure_packet(shared_secret, &packet.encode()[..]);
2255+
let mut onion_error_packet = OnionErrorPacket {data: packet.encode()};
2256+
crypt_failure_packet(shared_secret, &mut onion_error_packet);
22422257

22432258
let logger = TestLogger::new();
2244-
let decrypted_failure = test_failure_attribution(&logger, &packet.data);
2259+
let decrypted_failure = test_failure_attribution(&logger, onion_error_packet);
22452260
assert_eq!(decrypted_failure.short_channel_id, Some(0));
22462261

22472262
logger.assert_log_contains(
@@ -2251,7 +2266,7 @@ mod tests {
22512266
);
22522267
}
22532268

2254-
fn test_failure_attribution(logger: &TestLogger, packet: &[u8]) -> DecodedOnionFailure {
2269+
fn test_failure_attribution(logger: &TestLogger, packet: OnionErrorPacket) -> DecodedOnionFailure {
22552270
let ctx_full = Secp256k1::new();
22562271
let path = build_test_path();
22572272
let htlc_source = HTLCSource::OutboundRoute {
@@ -2262,7 +2277,7 @@ mod tests {
22622277
};
22632278

22642279
let decrypted_failure =
2265-
process_onion_failure(&ctx_full, &logger, &htlc_source, packet.into());
2280+
process_onion_failure(&ctx_full, &logger, &htlc_source, packet);
22662281

22672282
decrypted_failure
22682283
}

0 commit comments

Comments
 (0)