Skip to content

Commit feeab19

Browse files
Add util to gather channels that support htlc_hold
Returns a list of channels where our counterparty supports InitFeatures::supports_htlc_hold, or an error if there are none. Useful for sending async payments to StaticInvoices.
1 parent 38685db commit feeab19

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,9 +4087,9 @@ where
40874087
}
40884088

40894089
fn list_funded_channels_with_filter<
4090-
Fn: FnMut(&(&InitFeatures, &ChannelId, &Channel<SP>)) -> bool + Copy,
4090+
Fn: FnMut(&(&InitFeatures, &ChannelId, &Channel<SP>)) -> bool,
40914091
>(
4092-
&self, f: Fn,
4092+
&self, mut f: Fn,
40934093
) -> Vec<ChannelDetails> {
40944094
// Allocate our best estimate of the number of channels we have in the `res`
40954095
// Vec. Sadly the `short_to_chan_info` map doesn't cover channels without
@@ -4109,7 +4109,7 @@ where
41094109
.iter()
41104110
.map(|(cid, c)| (&peer_state.latest_features, cid, c))
41114111
.filter(|(_, _, chan)| chan.is_funded())
4112-
.filter(f);
4112+
.filter(|v| f(v));
41134113
res.extend(filtered_chan_by_id.map(|(_, _channel_id, channel)| {
41144114
ChannelDetails::from_channel(
41154115
channel,
@@ -5503,6 +5503,28 @@ where
55035503
res
55045504
}
55055505

5506+
/// Returns a list of channels where our counterparty supports
5507+
/// [`InitFeatures::supports_htlc_hold`], or an error if there are none or we are configured not
5508+
/// to hold HTLCs at our next-hop channel counterparty. Useful for sending async payments to
5509+
/// [`StaticInvoice`]s.
5510+
fn hold_htlc_channels(&self) -> Result<Vec<ChannelDetails>, ()> {
5511+
let should_send_async = self.config.read().unwrap().hold_outbound_htlcs_at_next_hop;
5512+
if !should_send_async {
5513+
return Err(());
5514+
}
5515+
5516+
let hold_htlc_channels =
5517+
self.list_funded_channels_with_filter(|&(init_features, _, ref channel)| {
5518+
init_features.supports_htlc_hold() && channel.context().is_live()
5519+
});
5520+
5521+
if hold_htlc_channels.is_empty() {
5522+
Err(())
5523+
} else {
5524+
Ok(hold_htlc_channels)
5525+
}
5526+
}
5527+
55065528
fn send_payment_for_static_invoice(
55075529
&self, payment_id: PaymentId,
55085530
) -> Result<(), Bolt12PaymentError> {

0 commit comments

Comments
 (0)