Skip to content

Commit 6800d8f

Browse files
committed
Introduce Padding for Blinded Payment Paths
1 parent 047a878 commit 6800d8f

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;
@@ -493,6 +493,10 @@ impl Readable for BlindedPaymentTlvs {
493493
}
494494
}
495495

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

506-
let path = pks.zip(tlvs);
510+
let path = pks.zip(tlvs.map(|tlv| BlindedPathWithPadding { tlvs: tlv, round_off: PAYMENT_PADDING_ROUND_OFF }));
507511

508512
utils::construct_blinded_hops(secp_ctx, path, session_priv)
509513
}

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)