Skip to content

Commit b6cc8c2

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 e16e4e3 commit b6cc8c2

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
@@ -4039,7 +4039,9 @@ where
40394039
Ok(temporary_channel_id)
40404040
}
40414041

4042-
fn list_funded_channels_with_filter<Fn: FnMut(&(&ChannelId, &Channel<SP>)) -> bool + Copy>(
4042+
fn list_funded_channels_with_filter<
4043+
Fn: FnMut(&(&InitFeatures, &ChannelId, &Channel<SP>)) -> bool + Copy,
4044+
>(
40434045
&self, f: Fn,
40444046
) -> Vec<ChannelDetails> {
40454047
// Allocate our best estimate of the number of channels we have in the `res`
@@ -4055,9 +4057,13 @@ where
40554057
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
40564058
let peer_state = &mut *peer_state_lock;
40574059
// Only `Channels` in the `Channel::Funded` phase can be considered funded.
4058-
let filtered_chan_by_id =
4059-
peer_state.channel_by_id.iter().filter(|(_, chan)| chan.is_funded()).filter(f);
4060-
res.extend(filtered_chan_by_id.map(|(_channel_id, channel)| {
4060+
let filtered_chan_by_id = peer_state
4061+
.channel_by_id
4062+
.iter()
4063+
.map(|(cid, c)| (&peer_state.latest_features, cid, c))
4064+
.filter(|(_, _, chan)| chan.is_funded())
4065+
.filter(f);
4066+
res.extend(filtered_chan_by_id.map(|(_, _channel_id, channel)| {
40614067
ChannelDetails::from_channel(
40624068
channel,
40634069
best_block_height,
@@ -4109,7 +4115,7 @@ where
41094115
// Note we use is_live here instead of usable which leads to somewhat confused
41104116
// internal/external nomenclature, but that's ok cause that's probably what the user
41114117
// really wanted anyway.
4112-
self.list_funded_channels_with_filter(|&(_, ref channel)| channel.context().is_live())
4118+
self.list_funded_channels_with_filter(|&(_, _, ref channel)| channel.context().is_live())
41134119
}
41144120

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

0 commit comments

Comments
 (0)