Skip to content

Commit 37925db

Browse files
committed
Introduce Padding for blinded payment paths
1. Introducing the padding increase the Tlvs size and hence reduced the max path length of payment paths. 2. This leads to reducing the max path length from 18 -> 17 in `forward_checks_failure` which is accounted for in this commit.
1 parent 1eac6cd commit 37925db

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1515

1616
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
17-
use crate::blinded_path::utils;
17+
use crate::blinded_path::utils::{self, WithPadding};
1818
use crate::crypto::streams::ChaChaPolyReadAdapter;
1919
use crate::io;
2020
use crate::io::Cursor;
@@ -86,6 +86,7 @@ pub(crate) enum BlindedPaymentTlvs {
8686
}
8787

8888
// Used to include forward and receive TLVs in the same iterator for encoding.
89+
#[derive(Clone)]
8990
enum BlindedPaymentTlvsRef<'a> {
9091
Forward(&'a ForwardTlvs),
9192
Receive(&'a ReceiveTlvs),
@@ -226,7 +227,6 @@ impl Writeable for ReceiveTlvs {
226227

227228
impl<'a> Writeable for BlindedPaymentTlvsRef<'a> {
228229
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
229-
// TODO: write padding
230230
match self {
231231
Self::Forward(tlvs) => tlvs.write(w)?,
232232
Self::Receive(tlvs) => tlvs.write(w)?,
@@ -278,7 +278,15 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
278278
.chain(core::iter::once(&payee_node_id));
279279
let tlvs = intermediate_nodes.iter().map(|node| BlindedPaymentTlvsRef::Forward(&node.tlvs))
280280
.chain(core::iter::once(BlindedPaymentTlvsRef::Receive(&payee_tlvs)));
281-
utils::construct_blinded_hops(secp_ctx, pks, tlvs, session_priv)
281+
282+
let max_length = tlvs.clone()
283+
.map(|tlv| tlv.serialized_length())
284+
.max()
285+
.unwrap_or(0);
286+
287+
let length_tlvs = tlvs.map(|tlvs| WithPadding { max_length, tlvs });
288+
289+
utils::construct_blinded_hops(secp_ctx, pks, length_tlvs, session_priv)
282290
}
283291

284292
// Advance the blinded onion payment path by one hop, so make the second hop into the new

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
289289
let mut route_params = get_blinded_route_parameters(amt_msat, payment_secret, 1, 1_0000_0000,
290290
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
291291
&[&chan_upd_1_2, &chan_upd_2_3], &chanmon_cfgs[3].keys_manager);
292-
route_params.payment_params.max_path_length = 18;
292+
route_params.payment_params.max_path_length = 17;
293293

294294
let route = get_route(&nodes[0], &route_params).unwrap();
295295
node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));

0 commit comments

Comments
 (0)