Skip to content

Commit 05cec0e

Browse files
committed
Introduce Padding for BlindedMessage Paths.
A note of Compact Blinded Paths: Compact Blinded paths are intended to be as short as possible. So to maintain there compactness, we don't apply padding to them.
1 parent 0971799 commit 05cec0e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::prelude::*;
1717
use bitcoin::hashes::hmac::Hmac;
1818
use bitcoin::hashes::sha256::Hash as Sha256;
1919
use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode, NodeIdLookUp};
20-
use crate::blinded_path::utils;
20+
use crate::blinded_path::utils::{self, WithPadding};
2121
use crate::io;
2222
use crate::io::Cursor;
2323
use crate::ln::channelmanager::PaymentId;
@@ -249,7 +249,6 @@ impl Writeable for ForwardTlvs {
249249
NextMessageHop::NodeId(pubkey) => (Some(pubkey), None),
250250
NextMessageHop::ShortChannelId(scid) => (None, Some(scid)),
251251
};
252-
// TODO: write padding
253252
encode_tlv_stream!(writer, {
254253
(2, short_channel_id, option),
255254
(4, next_node_id, option),
@@ -261,7 +260,6 @@ impl Writeable for ForwardTlvs {
261260

262261
impl Writeable for ReceiveTlvs {
263262
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
264-
// TODO: write padding
265263
encode_tlv_stream!(writer, {
266264
(65537, self.context, option),
267265
});
@@ -459,6 +457,8 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
459457
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
460458
let pks = intermediate_nodes.iter().map(|node| node.node_id)
461459
.chain(core::iter::once(recipient_node_id));
460+
let is_compact = intermediate_nodes.iter().any(|node| node.short_channel_id.is_some());
461+
462462
let tlvs = pks.clone()
463463
.skip(1) // The first node's TLVs contains the next node's pubkey
464464
.zip(intermediate_nodes.iter().map(|node| node.short_channel_id))
@@ -469,8 +469,12 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
469469
.map(|next_hop| ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override: None }))
470470
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs{ context: Some(context) })));
471471

472-
let path = pks.zip(tlvs);
473-
474-
utils::construct_blinded_hops(secp_ctx, path, session_priv)
472+
if is_compact {
473+
let path = pks.zip(tlvs);
474+
utils::construct_blinded_hops(secp_ctx, path, session_priv)
475+
} else {
476+
let path = pks.zip(tlvs.map(|tlv| WithPadding { tlvs: tlv }));
477+
utils::construct_blinded_hops(secp_ctx, path, session_priv)
478+
}
475479
}
476480

0 commit comments

Comments
 (0)