Skip to content

Commit e09f0df

Browse files
committed
Introduce Padding for Blinded Payment Paths
1 parent e612363 commit e09f0df

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
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, BlindedPathWithPadding};
1818
use crate::crypto::streams::ChaChaPolyReadAdapter;
1919
use crate::io;
2020
use crate::io::Cursor;
@@ -495,6 +495,10 @@ impl Readable for BlindedPaymentTlvs {
495495
}
496496
}
497497

498+
/// Represents the padding round off size (in bytes) that
499+
/// is used to pad payment bilnded path's [`BlindedHop`]
500+
pub(crate) const PAYMENT_PADDING_ROUND_OFF: usize = 35;
501+
498502
/// Construct blinded payment hops for the given `intermediate_nodes` and payee info.
499503
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
500504
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[PaymentForwardNode],
@@ -505,7 +509,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
505509
let tlvs = intermediate_nodes.iter().map(|node| BlindedPaymentTlvsRef::Forward(&node.tlvs))
506510
.chain(core::iter::once(BlindedPaymentTlvsRef::Receive(&payee_tlvs)));
507511

508-
let path = pks.zip(tlvs);
512+
let path = pks.zip(tlvs.map(|tlv| BlindedPathWithPadding { tlvs: tlv, round_off: PAYMENT_PADDING_ROUND_OFF }));
509513

510514
utils::construct_blinded_hops(secp_ctx, path, session_priv)
511515
}

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
317317
let mut route_params = get_blinded_route_parameters(amt_msat, payment_secret, 1, 1_0000_0000,
318318
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
319319
&[&chan_upd_1_2, &chan_upd_2_3], &chanmon_cfgs[3].keys_manager);
320-
route_params.payment_params.max_path_length = 17;
320+
route_params.payment_params.max_path_length = 16;
321321

322322
let route = get_route(&nodes[0], &route_params).unwrap();
323323
node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
@@ -841,6 +841,8 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
841841
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2],
842842
&chanmon_cfgs[2].keys_manager);
843843

844+
route_params.payment_params.max_path_length = 17;
845+
844846
let route = if check == ReceiveCheckFail::ProcessPendingHTLCsCheck {
845847
let mut route = get_route(&nodes[0], &route_params).unwrap();
846848
// Set the final CLTV expiry too low to trigger the failure in process_pending_htlc_forwards.

0 commit comments

Comments
 (0)