Skip to content

Commit f32e21e

Browse files
committed
Remove Readable for BlindedPathPadding
Padding serves as filler data with no explicit use case, making it more efficient to ignore it rather than read and discard it. This change simplifies the code by removing unnecessary `Readable` implementation for padding.
1 parent 4d726fc commit f32e21e

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ impl<'a> Writeable for BlindedPaymentTlvsRef<'a> {
520520
impl Readable for BlindedPaymentTlvs {
521521
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
522522
_init_and_read_tlv_stream!(r, {
523-
(1, _padding, option),
523+
// Reasoning: Padding refers to filler data added to a packet to increase
524+
// its size and obscure its actual length. Since padding contains no meaningful
525+
// information, we can safely omit reading it here.
526+
// (1, _padding, option),
524527
(2, scid, option),
525528
(8, next_blinding_override, option),
526529
(10, payment_relay, option),
@@ -530,7 +533,6 @@ impl Readable for BlindedPaymentTlvs {
530533
(65537, payment_context, option),
531534
(65539, authentication, option),
532535
});
533-
let _padding: Option<utils::BlindedPathPadding> = _padding;
534536

535537
if let Some(short_channel_id) = scid {
536538
if payment_secret.is_some() {

lightning/src/blinded_path/utils.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
1818
use super::message::BlindedMessagePath;
1919
use super::{BlindedHop, BlindedPath};
2020
use crate::crypto::streams::ChaChaPolyWriteAdapter;
21-
use crate::ln::msgs::DecodeError;
2221
use crate::ln::onion_utils;
2322
use crate::onion_message::messenger::Destination;
24-
use crate::util::ser::{Readable, Writeable};
25-
26-
use crate::io;
23+
use crate::util::ser::Writeable;
2724

2825
use core::borrow::Borrow;
2926

@@ -201,15 +198,3 @@ fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_rho: [u8; 32]) -> Ve
201198
///
202199
/// For more details, see the [BOLTs Specification - Encrypted Recipient Data](https://github.com/lightning/bolts/blob/8707471dbc23245fb4d84c5f5babac1197f1583e/04-onion-routing.md#inside-encrypted_recipient_data-encrypted_data_tlv).
203200
pub(crate) struct BlindedPathPadding {}
204-
impl Readable for BlindedPathPadding {
205-
#[inline]
206-
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
207-
loop {
208-
let mut buf = [0; 8192];
209-
if reader.read(&mut buf[..])? == 0 {
210-
break;
211-
}
212-
}
213-
Ok(Self {})
214-
}
215-
}

lightning/src/onion_message/packet.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use super::dns_resolution::DNSResolverMessage;
1818
use super::messenger::CustomOnionMessageHandler;
1919
use super::offers::OffersMessage;
2020
use crate::blinded_path::message::{BlindedMessagePath, ForwardTlvs, NextMessageHop, ReceiveTlvs};
21-
use crate::blinded_path::utils::BlindedPathPadding;
2221
use crate::crypto::streams::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter};
2322
use crate::ln::msgs::DecodeError;
2423
use crate::ln::onion_utils;
@@ -336,13 +335,15 @@ pub(crate) enum ControlTlvs {
336335
impl Readable for ControlTlvs {
337336
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
338337
_init_and_read_tlv_stream!(r, {
339-
(1, _padding, option),
338+
// Reasoning: Padding refers to filler data added to a packet to increase
339+
// its size and obscure its actual length. Since padding contains no meaningful
340+
// information, we can safely omit reading it here.
341+
// (1, _padding, option),
340342
(2, short_channel_id, option),
341343
(4, next_node_id, option),
342344
(8, next_blinding_override, option),
343345
(65537, context, option),
344346
});
345-
let _padding: Option<BlindedPathPadding> = _padding;
346347

347348
let next_hop = match (short_channel_id, next_node_id) {
348349
(Some(_), Some(_)) => return Err(DecodeError::InvalidValue),

0 commit comments

Comments
 (0)