Skip to content

Commit 1c776a9

Browse files
Add init_features to list_channels filter callback
Useful to filter for channel peers that support a specific feature, in this case the hold_htlc feature, in upcoming commits.
1 parent b9f5fd6 commit 1c776a9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,9 @@ where
40864086
Ok(temporary_channel_id)
40874087
}
40884088

4089-
fn list_funded_channels_with_filter<Fn: FnMut(&(&ChannelId, &Channel<SP>)) -> bool + Copy>(
4089+
fn list_funded_channels_with_filter<
4090+
Fn: FnMut(&(&InitFeatures, &ChannelId, &Channel<SP>)) -> bool + Copy,
4091+
>(
40904092
&self, f: Fn,
40914093
) -> Vec<ChannelDetails> {
40924094
// Allocate our best estimate of the number of channels we have in the `res`
@@ -4102,9 +4104,13 @@ where
41024104
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
41034105
let peer_state = &mut *peer_state_lock;
41044106
// Only `Channels` in the `Channel::Funded` phase can be considered funded.
4105-
let filtered_chan_by_id =
4106-
peer_state.channel_by_id.iter().filter(|(_, chan)| chan.is_funded()).filter(f);
4107-
res.extend(filtered_chan_by_id.map(|(_channel_id, channel)| {
4107+
let filtered_chan_by_id = peer_state
4108+
.channel_by_id
4109+
.iter()
4110+
.map(|(cid, c)| (&peer_state.latest_features, cid, c))
4111+
.filter(|(_, _, chan)| chan.is_funded())
4112+
.filter(f);
4113+
res.extend(filtered_chan_by_id.map(|(_, _channel_id, channel)| {
41084114
ChannelDetails::from_channel(
41094115
channel,
41104116
best_block_height,
@@ -4156,7 +4162,7 @@ where
41564162
// Note we use is_live here instead of usable which leads to somewhat confused
41574163
// internal/external nomenclature, but that's ok cause that's probably what the user
41584164
// really wanted anyway.
4159-
self.list_funded_channels_with_filter(|&(_, ref channel)| channel.context().is_live())
4165+
self.list_funded_channels_with_filter(|&(_, _, ref channel)| channel.context().is_live())
41604166
}
41614167

41624168
/// Gets the list of channels we have with a given counterparty, in random order.

0 commit comments

Comments
 (0)