@@ -65,7 +65,7 @@ use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXP
65
65
use crate::offers::invoice_error::InvoiceError;
66
66
use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
67
67
use crate::offers::nonce::Nonce;
68
- use crate::offers::offer::{Offer, OfferBuilder};
68
+ use crate::offers::offer::{Amount, Offer, OfferBuilder};
69
69
use crate::offers::parse::Bolt12SemanticError;
70
70
use crate::offers::refund::{Refund, RefundBuilder};
71
71
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
@@ -9020,6 +9020,22 @@ where
9020
9020
let reply_paths = self.create_blinded_paths(context)
9021
9021
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
9022
9022
9023
+ let total_liquidity: u64 = self.list_usable_channels().iter().map(|channel| channel.next_outbound_htlc_limit_msat).sum();
9024
+ let total_amount_msats = match invoice_request.amount_msats() {
9025
+ Some(amount_msats) => Some(amount_msats),
9026
+ None => match offer.amount() {
9027
+ Some(Amount::Bitcoin { amount_msats }) => Some(amount_msats),
9028
+ _ => None,
9029
+ },
9030
+ };
9031
+
9032
+ if let Some(amount) = total_amount_msats {
9033
+ if amount > total_liquidity {
9034
+ log_error!(self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
9035
+ return Err(Bolt12SemanticError::InsufficientLiquidity);
9036
+ }
9037
+ }
9038
+
9023
9039
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9024
9040
9025
9041
let expiration = StaleExpiration::TimerTicks(1);
0 commit comments