Skip to content

Commit 649b021

Browse files
valentinewallacetnull
authored andcommitted
Make create_blinded_payment_paths methods amount optional.
Useful for creating payment paths for static invoices which are typically amount-less.
1 parent f6e2196 commit 649b021

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10143,7 +10143,7 @@ where
1014310143
Ok((payment_hash, payment_secret)) => {
1014410144
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1014510145
let payment_paths = self.create_blinded_payment_paths(
10146-
amount_msats, payment_secret, payment_context
10146+
Some(amount_msats), payment_secret, payment_context
1014710147
)
1014810148
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1014910149

@@ -10450,7 +10450,7 @@ where
1045010450
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1045110451
/// [`Router::create_blinded_payment_paths`].
1045210452
fn create_blinded_payment_paths(
10453-
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
10453+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
1045410454
) -> Result<Vec<BlindedPaymentPath>, ()> {
1045510455
let expanded_key = &self.inbound_payment_key;
1045610456
let entropy = &*self.entropy_source;
@@ -12004,7 +12004,7 @@ where
1200412004
invoice_request: invoice_request.fields(),
1200512005
});
1200612006
let payment_paths = match self.create_blinded_payment_paths(
12007-
amount_msats, payment_secret, payment_context
12007+
Some(amount_msats), payment_secret, payment_context
1200812008
) {
1200912009
Ok(payment_paths) => payment_paths,
1201012010
Err(()) => {

lightning/src/routing/router.rs

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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)