Skip to content

Commit 15f20db

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 44570fd commit 15f20db

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
@@ -506,7 +506,10 @@ impl<'a> Writeable for BlindedPaymentTlvsRef<'a> {
506506
impl Readable for BlindedPaymentTlvs {
507507
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
508508
_init_and_read_tlv_stream!(r, {
509-
(1, _padding, option),
509+
// Reasoning: Padding refers to filler data added to a packet to increase
510+
// its size and obscure its actual length. Since padding contains no meaningful
511+
// information, we can safely omit reading it here.
512+
// (1, _padding, option),
510513
(2, scid, option),
511514
(8, next_blinding_override, option),
512515
(10, payment_relay, option),
@@ -516,7 +519,6 @@ impl Readable for BlindedPaymentTlvs {
516519
(65537, payment_context, option),
517520
(65539, authentication, option),
518521
});
519-
let _padding: Option<utils::BlindedPathPadding> = _padding;
520522

521523
if let Some(short_channel_id) = scid {
522524
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
@@ -13,7 +13,6 @@ use bitcoin::secp256k1::PublicKey;
1313
use bitcoin::secp256k1::ecdh::SharedSecret;
1414

1515
use crate::blinded_path::message::{BlindedMessagePath, ForwardTlvs, NextMessageHop, ReceiveTlvs};
16-
use crate::blinded_path::utils::BlindedPathPadding;
1716
use crate::ln::msgs::DecodeError;
1817
use crate::ln::onion_utils;
1918
#[cfg(async_payments)]
@@ -342,13 +341,15 @@ pub(crate) enum ControlTlvs {
342341
impl Readable for ControlTlvs {
343342
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
344343
_init_and_read_tlv_stream!(r, {
345-
(1, _padding, option),
344+
// Reasoning: Padding refers to filler data added to a packet to increase
345+
// its size and obscure its actual length. Since padding contains no meaningful
346+
// information, we can safely omit reading it here.
347+
// (1, _padding, option),
346348
(2, short_channel_id, option),
347349
(4, next_node_id, option),
348350
(8, next_blinding_override, option),
349351
(65537, context, option),
350352
});
351-
let _padding: Option<BlindedPathPadding> = _padding;
352353

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

0 commit comments

Comments
 (0)