Skip to content

Commit 954bb1c

Browse files
committed
Abort if insufficient liquidity in pay_for_offer
This commit introduces a check to abort early if there's insufficient liquidity when fulfilling the payment in `pay_for_offer`
1 parent 4bd4f19 commit 954bb1c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8816,8 +8816,15 @@ where
88168816
None => builder,
88178817
Some(payer_note) => builder.payer_note(payer_note),
88188818
};
8819+
88198820
let invoice_request = builder.build_and_sign()?;
88208821

8822+
let total_liquidity: u64 = self.list_usable_channels().iter().map(|channel| channel.next_outbound_htlc_limit_msat).sum();
8823+
if invoice_request.amount_msats() > Some(total_liquidity) {
8824+
log_error!(self.logger, "Insufficient liquidity for payment with payment id: {}", payment_id);
8825+
return Err(Bolt12SemanticError::InsufficientLiquidity);
8826+
}
8827+
88218828
let context = OffersContext::OutboundPayment { payment_id };
88228829
let reply_path = self.create_blinded_path(context).map_err(|_| Bolt12SemanticError::MissingPaths)?;
88238830

lightning/src/offers/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ pub enum Bolt12SemanticError {
193193
UnexpectedPaymentHash,
194194
/// A signature was expected but was missing.
195195
MissingSignature,
196+
/// There is insufficient liquidity to complete the payment.
197+
InsufficientLiquidity,
196198
}
197199

198200
impl From<bech32::Error> for Bolt12ParseError {

0 commit comments

Comments
 (0)