Skip to content

Commit

Permalink
f liquidity check for offer-based amount
Browse files Browse the repository at this point in the history
This commit uses the offer.amount() when amount_msats 
is not provided.
  • Loading branch information
slanesuke committed Jul 15, 2024
1 parent 954bb1c commit 0dca193
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use crate::ln::wire::Encode;
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
use crate::offers::invoice_error::InvoiceError;
use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
use crate::offers::offer::{Offer, OfferBuilder};
use crate::offers::offer::{Offer, OfferBuilder, Amount};
use crate::offers::parse::Bolt12SemanticError;
use crate::offers::refund::{Refund, RefundBuilder};
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
Expand Down Expand Up @@ -8820,9 +8820,19 @@ where
let invoice_request = builder.build_and_sign()?;

let total_liquidity: u64 = self.list_usable_channels().iter().map(|channel| channel.next_outbound_htlc_limit_msat).sum();
if invoice_request.amount_msats() > Some(total_liquidity) {
log_error!(self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
return Err(Bolt12SemanticError::InsufficientLiquidity);
let total_amount_msats = match invoice_request.amount_msats() {
Some(amount_msats) => Some(amount_msats),
None => match offer.amount() {
Some(Amount::Bitcoin { amount_msats }) => Some(amount_msats),
_ => None,
},
};

if let Some(amount) = total_amount_msats {
if amount > total_liquidity {
log_error!(self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
return Err(Bolt12SemanticError::InsufficientLiquidity);
}
}

let context = OffersContext::OutboundPayment { payment_id };
Expand Down

0 comments on commit 0dca193

Please sign in to comment.