Skip to content

Commit 17b4036

Browse files
committed
f remove VariableLengthOnionPacket
1 parent 4897700 commit 17b4036

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

lightning/src/ln/msgs.rs

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,6 @@ mod fuzzy_internal_msgs {
16901690
use crate::ln::{PaymentPreimage, PaymentSecret};
16911691
use crate::ln::features::BlindedHopFeatures;
16921692
use super::FinalOnionHopData;
1693-
use crate::ln::msgs::VariableLengthOnionPacket;
16941693

16951694
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
16961695
// them from untrusted input):
@@ -1741,7 +1740,7 @@ mod fuzzy_internal_msgs {
17411740
custom_tlvs: Vec<(u64, Vec<u8>)>,
17421741
sender_intended_htlc_amt_msat: u64,
17431742
cltv_expiry_height: u32,
1744-
trampoline_packet: Option<VariableLengthOnionPacket>
1743+
trampoline_packet: Option<crate::onion_message::Packet>
17451744
},
17461745
BlindedForward {
17471746
encrypted_tlvs: Vec<u8>,
@@ -1802,29 +1801,6 @@ impl fmt::Debug for OnionPacket {
18021801
}
18031802
}
18041803

1805-
/// BOLT 4 onion packet including hop data for the next peer.
1806-
#[derive(Clone, Hash, PartialEq, Eq)]
1807-
pub struct VariableLengthOnionPacket {
1808-
/// BOLT 4 version number.
1809-
pub version: u8,
1810-
/// In order to ensure we always return an error on onion decode in compliance with [BOLT
1811-
/// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
1812-
/// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
1813-
/// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
1814-
/// like.
1815-
pub public_key: Result<PublicKey, secp256k1::Error>,
1816-
/// Variable number of bytes encrypted payload for the next hop; 650 by default for Trampoline
1817-
pub(crate) hop_data: Vec<u8>,
1818-
/// HMAC to verify the integrity of hop_data.
1819-
pub hmac: [u8; 32],
1820-
}
1821-
1822-
impl fmt::Debug for VariableLengthOnionPacket {
1823-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1824-
f.write_fmt(format_args!("VariableLengthOnionPacket version {} with hmac {:?}", self.version, &self.hmac[..]))
1825-
}
1826-
}
1827-
18281804
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
18291805
pub(crate) struct OnionErrorPacket {
18301806
// This really should be a constant size slice, but the spec lets these things be up to 128KB?
@@ -2253,23 +2229,6 @@ impl Readable for OnionPacket {
22532229
}
22542230
}
22552231

2256-
// This will be written as the value of a TLV, so when reading, the length of the hop data will be
2257-
// inferred from a ReadableArg containing the total length. The standard hop data for Trampoline
2258-
// onions will prospectively be 650 bytes.
2259-
impl Writeable for VariableLengthOnionPacket {
2260-
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
2261-
self.version.write(w)?;
2262-
match self.public_key {
2263-
Ok(pubkey) => pubkey.write(w)?,
2264-
Err(_) => [0u8;33].write(w)?,
2265-
}
2266-
// don't encode the length of hop_data
2267-
w.write_all(&self.hop_data)?;
2268-
&self.hmac.write(w)?;
2269-
Ok(())
2270-
}
2271-
}
2272-
22732232
impl_writeable_msg!(UpdateAddHTLC, {
22742233
channel_id,
22752234
htlc_id,
@@ -2900,7 +2859,7 @@ mod tests {
29002859
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
29012860
use crate::ln::ChannelId;
29022861
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
2903-
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, VariableLengthOnionPacket};
2862+
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket};
29042863
use crate::ln::msgs::SocketAddress;
29052864
use crate::routing::gossip::{NodeAlias, NodeId};
29062865
use crate::util::ser::{Writeable, Readable, ReadableArgs, Hostname, TransactionU16LenLimited, BigSize};
@@ -2927,6 +2886,7 @@ mod tests {
29272886
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
29282887
#[cfg(feature = "std")]
29292888
use crate::ln::msgs::SocketAddressParseError;
2889+
use crate::onion_message::Packet;
29302890

29312891
#[test]
29322892
fn encoding_channel_reestablish() {
@@ -4201,9 +4161,9 @@ mod tests {
42014161
let compressed_public_key = public_key.serialize();
42024162
assert_eq!(compressed_public_key.len(), 33);
42034163

4204-
let trampoline_packet = VariableLengthOnionPacket {
4164+
let trampoline_packet = Packet {
42054165
version: 0,
4206-
public_key: Ok(public_key),
4166+
public_key,
42074167
hop_data: vec![1; 650], // this should be the standard encoded length
42084168
hmac: [2; 32],
42094169
};
@@ -4243,9 +4203,9 @@ mod tests {
42434203
let compressed_public_key = public_key.serialize();
42444204
assert_eq!(compressed_public_key.len(), 33);
42454205

4246-
let trampoline_packet = VariableLengthOnionPacket {
4206+
let trampoline_packet = Packet {
42474207
version: 0,
4248-
public_key: Ok(public_key),
4208+
public_key,
42494209
hop_data,
42504210
hmac
42514211
};

0 commit comments

Comments
 (0)