Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static invoice creation utils to ChannelManager #3408

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Router for FuzzRouter {

fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
_amount_msats: Option<u64>, _secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedPaymentPath>, ()> {
unreachable!()
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Router for FuzzRouter {

fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
_amount_msats: Option<u64>, _secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedPaymentPath>, ()> {
unreachable!()
}
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9748,7 +9748,7 @@ where
Ok((payment_hash, payment_secret)) => {
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
let payment_paths = self.create_blinded_payment_paths(
amount_msats, payment_secret, payment_context
Some(amount_msats), payment_secret, payment_context
)
.map_err(|_| Bolt12SemanticError::MissingPaths)?;

Expand Down Expand Up @@ -10055,7 +10055,7 @@ where
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
/// [`Router::create_blinded_payment_paths`].
fn create_blinded_payment_paths(
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
) -> Result<Vec<BlindedPaymentPath>, ()> {
let secp_ctx = &self.secp_ctx;

Expand Down Expand Up @@ -11585,7 +11585,7 @@ where
invoice_request: invoice_request.fields(),
});
let payment_paths = match self.create_blinded_payment_paths(
amount_msats, payment_secret, payment_context
Some(amount_msats), payment_secret, payment_context
) {
Ok(payment_paths) => payment_paths,
Err(()) => {
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
T: secp256k1::Signing + secp256k1::Verification
> (
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
amount_msats: u64, secp_ctx: &Secp256k1<T>
amount_msats: Option<u64>, secp_ctx: &Secp256k1<T>
) -> Result<Vec<BlindedPaymentPath>, ()> {
// Limit the number of blinded paths that are computed.
const MAX_PAYMENT_PATHS: usize = 3;
Expand All @@ -104,6 +104,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
// recipient's node_id.
const MIN_PEER_CHANNELS: usize = 3;

const DEFAULT_AMT_MSAT: u64 = 100_000_000;
let amount_msats = amount_msats.unwrap_or(DEFAULT_AMT_MSAT);
Comment on lines +107 to +108
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining this amount?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was chosen pretty arbitrarily lol. Input welcome on it. I'm guessing async receivers are mostly doing p2p payments and this amount is about $100 USD right now. I think the main constraint is that we don't want to exceed the recipient's channel capacity, and they may only have 1 channel with their LSP. Another option would be to not filter channels by capacity/{min,max}_htlc if no amount is provided.


let has_one_peer = first_hops
.first()
.map(|details| details.counterparty.node_id)
Expand Down Expand Up @@ -218,7 +221,7 @@ pub trait Router {
T: secp256k1::Signing + secp256k1::Verification
> (
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
amount_msats: u64, secp_ctx: &Secp256k1<T>
amount_msats: Option<u64>, secp_ctx: &Secp256k1<T>
) -> Result<Vec<BlindedPaymentPath>, ()>;
}

Expand Down
2 changes: 1 addition & 1 deletion lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'a> Router for TestRouter<'a> {
T: secp256k1::Signing + secp256k1::Verification
>(
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
amount_msats: u64, secp_ctx: &Secp256k1<T>,
amount_msats: Option<u64>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedPaymentPath>, ()> {
let mut expected_paths = self.next_blinded_payment_paths.lock().unwrap();
if expected_paths.is_empty() {
Expand Down