Skip to content

Commit 5d6881f

Browse files
committed
Introduce Padding for BlindedPaymentPaths
1 parent 8ad34ef commit 5d6881f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lightning/src/blinded_path/payment.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
1414
use bitcoin::secp256k1::ecdh::SharedSecret;
1515
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1616

17-
use crate::blinded_path::utils;
17+
use crate::blinded_path::utils::{self, BlindedPathWithPadding};
1818
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
1919
use crate::crypto::streams::ChaChaPolyReadAdapter;
2020
use crate::io;
@@ -560,6 +560,10 @@ impl Readable for BlindedPaymentTlvs {
560560
}
561561
}
562562

563+
/// Represents the padding round off size (in bytes) that
564+
/// is used to pad payment bilnded path's [`BlindedHop`]
565+
pub(crate) const PAYMENT_PADDING_ROUND_OFF: usize = 30;
566+
563567
/// Construct blinded payment hops for the given `intermediate_nodes` and payee info.
564568
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
565569
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
@@ -572,7 +576,9 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
572576
.map(|node| BlindedPaymentTlvsRef::Forward(&node.tlvs))
573577
.chain(core::iter::once(BlindedPaymentTlvsRef::Receive(&payee_tlvs)));
574578

575-
let path = pks.zip(tlvs);
579+
let path = pks.zip(
580+
tlvs.map(|tlv| BlindedPathWithPadding { tlvs: tlv, round_off: PAYMENT_PADDING_ROUND_OFF }),
581+
);
576582

577583
utils::construct_blinded_hops(secp_ctx, path, session_priv)
578584
}

lightning/src/ln/blinded_payment_tests.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
353353
let mut route_params = get_blinded_route_parameters(amt_msat, payment_secret, 1, 1_0000_0000,
354354
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
355355
&[&chan_upd_1_2, &chan_upd_2_3], &chanmon_cfgs[3].keys_manager);
356-
route_params.payment_params.max_path_length = 17;
356+
route_params.payment_params.max_path_length = 16;
357357

358358
let route = get_route(&nodes[0], &route_params).unwrap();
359359
node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
@@ -878,6 +878,8 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
878878
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2],
879879
&chanmon_cfgs[2].keys_manager);
880880

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

0 commit comments

Comments
 (0)