Skip to content

Commit fa44185

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 a9d73c2 commit fa44185

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

lightning/src/blinded_path/mod.rs

+6-5
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

+5-3
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

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
1414
use crate::blinded_path::{BlindedHop, BlindedPath};
1515
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
1616
use crate::ln::PaymentHash;
17-
use crate::ln::channelmanager::{ChannelDetails, PaymentId};
17+
use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA};
1818
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
1919
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2020
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
@@ -134,7 +134,8 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
134134
})
135135
.map(|forward_node| {
136136
BlindedPath::new_for_payment(
137-
&[forward_node], recipient, tlvs.clone(), u64::MAX, &*self.entropy_source, secp_ctx
137+
&[forward_node], recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
138+
&*self.entropy_source, secp_ctx
138139
)
139140
})
140141
.take(MAX_PAYMENT_PATHS)
@@ -144,8 +145,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
144145
Ok(paths) if !paths.is_empty() => Ok(paths),
145146
_ => {
146147
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
147-
BlindedPath::one_hop_for_payment(recipient, tlvs, &*self.entropy_source, secp_ctx)
148-
.map(|path| vec![path])
148+
BlindedPath::one_hop_for_payment(
149+
recipient, tlvs, MIN_FINAL_CLTV_EXPIRY_DELTA, &*self.entropy_source, secp_ctx
150+
).map(|path| vec![path])
149151
} else {
150152
Err(())
151153
}

0 commit comments

Comments
 (0)