Skip to content

Commit 1e7ca71

Browse files
committed
f remove VariableLengthOnionPacket
1 parent 5c2aea5 commit 1e7ca71

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

lightning/src/ln/msgs.rs

+7-47
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,6 @@ mod fuzzy_internal_msgs {
16701670
use crate::prelude::*;
16711671
use crate::ln::{PaymentPreimage, PaymentSecret};
16721672
use crate::ln::features::BlindedHopFeatures;
1673-
use crate::ln::msgs::VariableLengthOnionPacket;
16741673

16751674
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
16761675
// them from untrusted input):
@@ -1728,7 +1727,7 @@ mod fuzzy_internal_msgs {
17281727
custom_tlvs: Vec<(u64, Vec<u8>)>,
17291728
amt_msat: u64,
17301729
outgoing_cltv_value: u32,
1731-
trampoline_packet: Option<VariableLengthOnionPacket>
1730+
trampoline_packet: Option<crate::onion_message::Packet>
17321731
},
17331732
BlindedForward {
17341733
encrypted_tlvs: Vec<u8>,
@@ -1789,29 +1788,6 @@ impl fmt::Debug for OnionPacket {
17891788
}
17901789
}
17911790

1792-
/// BOLT 4 onion packet including hop data for the next peer.
1793-
#[derive(Clone, Hash, PartialEq, Eq)]
1794-
pub struct VariableLengthOnionPacket {
1795-
/// BOLT 4 version number.
1796-
pub version: u8,
1797-
/// In order to ensure we always return an error on onion decode in compliance with [BOLT
1798-
/// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
1799-
/// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
1800-
/// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
1801-
/// like.
1802-
pub public_key: Result<PublicKey, secp256k1::Error>,
1803-
/// Variable number of bytes encrypted payload for the next hop; 650 by default for Trampoline
1804-
pub(crate) hop_data: Vec<u8>,
1805-
/// HMAC to verify the integrity of hop_data.
1806-
pub hmac: [u8; 32],
1807-
}
1808-
1809-
impl fmt::Debug for VariableLengthOnionPacket {
1810-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1811-
f.write_fmt(format_args!("VariableLengthOnionPacket version {} with hmac {:?}", self.version, &self.hmac[..]))
1812-
}
1813-
}
1814-
18151791
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
18161792
pub(crate) struct OnionErrorPacket {
18171793
// This really should be a constant size slice, but the spec lets these things be up to 128KB?
@@ -2240,23 +2216,6 @@ impl Readable for OnionPacket {
22402216
}
22412217
}
22422218

2243-
// This will be written as the value of a TLV, so when reading, the length of the hop data will be
2244-
// inferred from a ReadableArg containing the total length. The standard hop data for Trampoline
2245-
// onions will prospectively be 650 bytes.
2246-
impl Writeable for VariableLengthOnionPacket {
2247-
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
2248-
self.version.write(w)?;
2249-
match self.public_key {
2250-
Ok(pubkey) => pubkey.write(w)?,
2251-
Err(_) => [0u8;33].write(w)?,
2252-
}
2253-
// don't encode the length of hop_data
2254-
w.write_all(&self.hop_data)?;
2255-
&self.hmac.write(w)?;
2256-
Ok(())
2257-
}
2258-
}
2259-
22602219
impl_writeable_msg!(UpdateAddHTLC, {
22612220
channel_id,
22622221
htlc_id,
@@ -2879,7 +2838,7 @@ mod tests {
28792838
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
28802839
use crate::ln::ChannelId;
28812840
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
2882-
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, VariableLengthOnionPacket};
2841+
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket};
28832842
use crate::ln::msgs::SocketAddress;
28842843
use crate::routing::gossip::{NodeAlias, NodeId};
28852844
use crate::util::ser::{Writeable, Readable, ReadableArgs, Hostname, TransactionU16LenLimited, BigSize};
@@ -2906,6 +2865,7 @@ mod tests {
29062865
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
29072866
#[cfg(feature = "std")]
29082867
use crate::ln::msgs::SocketAddressParseError;
2868+
use crate::onion_message::Packet;
29092869

29102870
#[test]
29112871
fn encoding_channel_reestablish() {
@@ -4180,9 +4140,9 @@ mod tests {
41804140
let compressed_public_key = public_key.serialize();
41814141
assert_eq!(compressed_public_key.len(), 33);
41824142

4183-
let trampoline_packet = VariableLengthOnionPacket {
4143+
let trampoline_packet = Packet {
41844144
version: 0,
4185-
public_key: Ok(public_key),
4145+
public_key,
41864146
hop_data: vec![1; 650], // this should be the standard encoded length
41874147
hmac: [2; 32],
41884148
};
@@ -4222,9 +4182,9 @@ mod tests {
42224182
let compressed_public_key = public_key.serialize();
42234183
assert_eq!(compressed_public_key.len(), 33);
42244184

4225-
let trampoline_packet = VariableLengthOnionPacket {
4185+
let trampoline_packet = Packet {
42264186
version: 0,
4227-
public_key: Ok(public_key),
4187+
public_key,
42284188
hop_data,
42294189
hmac
42304190
};

0 commit comments

Comments
 (0)