Skip to content

Commit e810075

Browse files
Make create_blinded_payment_paths methods amount optional.
Useful for creating payment paths for static invoices which are typically amount-less.
1 parent 08d81fb commit e810075

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Router for FuzzRouter {
133133

134134
fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
135135
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
136-
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
136+
_amount_msats: Option<u64>, _secp_ctx: &Secp256k1<T>,
137137
) -> Result<Vec<BlindedPaymentPath>, ()> {
138138
unreachable!()
139139
}

fuzz/src/full_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Router for FuzzRouter {
160160

161161
fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
162162
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
163-
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
163+
_amount_msats: Option<u64>, _secp_ctx: &Secp256k1<T>,
164164
) -> Result<Vec<BlindedPaymentPath>, ()> {
165165
unreachable!()
166166
}

lightning/src/ln/channelmanager.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10182,7 +10182,7 @@ where
1018210182
Ok((payment_hash, payment_secret)) => {
1018310183
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1018410184
let payment_paths = self.create_blinded_payment_paths(
10185-
amount_msats, payment_secret, payment_context
10185+
Some(amount_msats), payment_secret, payment_context
1018610186
)
1018710187
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1018810188

@@ -10489,7 +10489,7 @@ where
1048910489
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1049010490
/// [`Router::create_blinded_payment_paths`].
1049110491
fn create_blinded_payment_paths(
10492-
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
10492+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
1049310493
) -> Result<Vec<BlindedPaymentPath>, ()> {
1049410494
let expanded_key = &self.inbound_payment_key;
1049510495
let entropy = &*self.entropy_source;
@@ -12048,7 +12048,7 @@ where
1204812048
invoice_request: invoice_request.fields(),
1204912049
});
1205012050
let payment_paths = match self.create_blinded_payment_paths(
12051-
amount_msats, payment_secret, payment_context
12051+
Some(amount_msats), payment_secret, payment_context
1205212052
) {
1205312053
Ok(payment_paths) => payment_paths,
1205412054
Err(()) => {

lightning/src/routing/router.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
9595
T: secp256k1::Signing + secp256k1::Verification
9696
> (
9797
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
98-
amount_msats: u64, secp_ctx: &Secp256k1<T>
98+
amount_msats: Option<u64>, secp_ctx: &Secp256k1<T>
9999
) -> Result<Vec<BlindedPaymentPath>, ()> {
100100
// Limit the number of blinded paths that are computed.
101101
const MAX_PAYMENT_PATHS: usize = 3;
@@ -120,9 +120,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
120120

121121
let paths = first_hops.into_iter()
122122
.filter(|details| details.counterparty.features.supports_route_blinding())
123-
.filter(|details| amount_msats <= details.inbound_capacity_msat)
124-
.filter(|details| amount_msats >= details.inbound_htlc_minimum_msat.unwrap_or(0))
125-
.filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(u64::MAX))
123+
.filter(|details| amount_msats.unwrap_or(0) <= details.inbound_capacity_msat)
124+
.filter(|details| amount_msats.unwrap_or(u64::MAX) >= details.inbound_htlc_minimum_msat.unwrap_or(0))
125+
.filter(|details| amount_msats.unwrap_or(0) <= details.inbound_htlc_maximum_msat.unwrap_or(u64::MAX))
126126
// Limit to peers with announced channels unless the recipient is unannounced.
127127
.filter(|details| network_graph
128128
.node(&NodeId::from_pubkey(&details.counterparty.node_id))
@@ -218,7 +218,7 @@ pub trait Router {
218218
T: secp256k1::Signing + secp256k1::Verification
219219
> (
220220
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
221-
amount_msats: u64, secp_ctx: &Secp256k1<T>
221+
amount_msats: Option<u64>, secp_ctx: &Secp256k1<T>
222222
) -> Result<Vec<BlindedPaymentPath>, ()>;
223223
}
224224

lightning/src/util/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a> Router for TestRouter<'a> {
252252
T: secp256k1::Signing + secp256k1::Verification
253253
>(
254254
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
255-
amount_msats: u64, secp_ctx: &Secp256k1<T>,
255+
amount_msats: Option<u64>, secp_ctx: &Secp256k1<T>,
256256
) -> Result<Vec<BlindedPaymentPath>, ()> {
257257
let mut expected_paths = self.next_blinded_payment_paths.lock().unwrap();
258258
if expected_paths.is_empty() {

0 commit comments

Comments
 (0)