Skip to content

Commit e81641a

Browse files
committed
Introduce Padding for Blinded Payment Paths
1 parent d30a395 commit e81641a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::hashes::hmac::Hmac;
1313
use bitcoin::hashes::sha256::Hash as Sha256;
1414
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1515

16-
use crate::blinded_path::utils;
16+
use crate::blinded_path::utils::{self, BlindedPathWithPadding};
1717
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
1818
use crate::crypto::streams::ChaChaPolyReadAdapter;
1919
use crate::io;
@@ -546,6 +546,10 @@ impl Readable for BlindedPaymentTlvs {
546546
}
547547
}
548548

549+
/// Represents the padding round off size (in bytes) that
550+
/// is used to pad payment bilnded path's [`BlindedHop`]
551+
pub(crate) const PAYMENT_PADDING_ROUND_OFF: usize = 30;
552+
549553
/// Construct blinded payment hops for the given `intermediate_nodes` and payee info.
550554
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
551555
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
@@ -558,7 +562,9 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
558562
.map(|node| BlindedPaymentTlvsRef::Forward(&node.tlvs))
559563
.chain(core::iter::once(BlindedPaymentTlvsRef::Receive(&payee_tlvs)));
560564

561-
let path = pks.zip(tlvs);
565+
let path = pks.zip(
566+
tlvs.map(|tlv| BlindedPathWithPadding { tlvs: tlv, round_off: PAYMENT_PADDING_ROUND_OFF }),
567+
);
562568

563569
utils::construct_blinded_hops(secp_ctx, path, session_priv)
564570
}

lightning/src/ln/blinded_payment_tests.rs

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

351351
let route = get_route(&nodes[0], &route_params).unwrap();
352352
node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
@@ -861,6 +861,8 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
861861
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2],
862862
&chanmon_cfgs[2].keys_manager);
863863

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

0 commit comments

Comments
 (0)