Skip to content

Commit b34443f

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 8ab96f0 commit b34443f

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
@@ -10152,7 +10152,7 @@ where
1015210152
Ok((payment_hash, payment_secret)) => {
1015310153
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1015410154
let payment_paths = self.create_blinded_payment_paths(
10155-
amount_msats, payment_secret, payment_context
10155+
Some(amount_msats), payment_secret, payment_context
1015610156
)
1015710157
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1015810158

@@ -10459,7 +10459,7 @@ where
1045910459
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1046010460
/// [`Router::create_blinded_payment_paths`].
1046110461
fn create_blinded_payment_paths(
10462-
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
10462+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
1046310463
) -> Result<Vec<BlindedPaymentPath>, ()> {
1046410464
let expanded_key = &self.inbound_payment_key;
1046510465
let entropy = &*self.entropy_source;
@@ -12030,7 +12030,7 @@ where
1203012030
invoice_request: invoice_request.fields(),
1203112031
});
1203212032
let payment_paths = match self.create_blinded_payment_paths(
12033-
amount_msats, payment_secret, payment_context
12033+
Some(amount_msats), payment_secret, payment_context
1203412034
) {
1203512035
Ok(payment_paths) => payment_paths,
1203612036
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)