Skip to content

Commit 6267be4

Browse files
Parameterize BlindedPath::new_for_payment by min final CLTV delta.
Currently we are not including this value in the aggregated CLTV delta, which is wrong.
1 parent 51d9ee3 commit 6267be4

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ impl BlindedPath {
8585

8686
/// Create a one-hop blinded path for a payment.
8787
pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
88-
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, entropy_source: &ES,
89-
secp_ctx: &Secp256k1<T>
88+
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
89+
entropy_source: &ES, secp_ctx: &Secp256k1<T>
9090
) -> Result<(BlindedPayInfo, Self), ()> {
9191
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
9292
// be in relation to a specific channel.
9393
let htlc_maximum_msat = u64::max_value();
9494
Self::new_for_payment(
95-
&[], payee_node_id, payee_tlvs, htlc_maximum_msat, entropy_source, secp_ctx
95+
&[], payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
96+
entropy_source, secp_ctx
9697
)
9798
}
9899

@@ -107,8 +108,8 @@ impl BlindedPath {
107108
// TODO: make all payloads the same size with padding + add dummy hops
108109
pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
109110
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
110-
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, entropy_source: &ES,
111-
secp_ctx: &Secp256k1<T>
111+
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
112+
entropy_source: &ES, secp_ctx: &Secp256k1<T>
112113
) -> Result<(BlindedPayInfo, Self), ()> {
113114
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
114115
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn blinded_payment_path(
6161
let mut secp_ctx = Secp256k1::new();
6262
BlindedPath::new_for_payment(
6363
&intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs,
64-
channel_upds.last().unwrap().htlc_maximum_msat, keys_manager, &secp_ctx
64+
channel_upds.last().unwrap().htlc_maximum_msat, TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx
6565
).unwrap()
6666
}
6767

@@ -100,7 +100,8 @@ fn do_one_hop_blinded_path(success: bool) {
100100
};
101101
let mut secp_ctx = Secp256k1::new();
102102
let blinded_path = BlindedPath::one_hop_for_payment(
103-
nodes[1].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[1].keys_manager, &secp_ctx
103+
nodes[1].node.get_our_node_id(), payee_tlvs, TEST_FINAL_CLTV as u16,
104+
&chanmon_cfgs[1].keys_manager, &secp_ctx
104105
).unwrap();
105106

106107
let route_params = RouteParameters::from_payment_params_and_value(
@@ -141,7 +142,8 @@ fn mpp_to_one_hop_blinded_path() {
141142
},
142143
};
143144
let blinded_path = BlindedPath::one_hop_for_payment(
144-
nodes[3].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[3].keys_manager, &secp_ctx
145+
nodes[3].node.get_our_node_id(), payee_tlvs, TEST_FINAL_CLTV as u16,
146+
&chanmon_cfgs[3].keys_manager, &secp_ctx
145147
).unwrap();
146148

147149
let bolt12_features =

lightning/src/routing/router.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
1616
use crate::blinded_path::{BlindedHop, BlindedPath};
1717
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
1818
use crate::ln::PaymentHash;
19-
use crate::ln::channelmanager::{ChannelDetails, PaymentId};
19+
use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA};
2020
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
2121
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2222
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
@@ -139,7 +139,8 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
139139
})
140140
.map(|forward_node| {
141141
BlindedPath::new_for_payment(
142-
&[forward_node], recipient, tlvs.clone(), u64::MAX, entropy_source, secp_ctx
142+
&[forward_node], recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
143+
entropy_source, secp_ctx
143144
)
144145
})
145146
.take(MAX_PAYMENT_PATHS)
@@ -149,8 +150,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
149150
Ok(paths) if !paths.is_empty() => Ok(paths),
150151
_ => {
151152
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
152-
BlindedPath::one_hop_for_payment(recipient, tlvs, entropy_source, secp_ctx)
153-
.map(|path| vec![path])
153+
BlindedPath::one_hop_for_payment(
154+
recipient, tlvs, MIN_FINAL_CLTV_EXPIRY_DELTA, entropy_source, secp_ctx
155+
).map(|path| vec![path])
154156
} else {
155157
Err(())
156158
}

0 commit comments

Comments
 (0)