Skip to content

Commit 1ab7b8b

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 560150d commit 1ab7b8b

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
@@ -4030,7 +4030,9 @@ where
40304030
Ok(temporary_channel_id)
40314031
}
40324032

4033-
fn list_funded_channels_with_filter<Fn: FnMut(&(&ChannelId, &Channel<SP>)) -> bool + Copy>(
4033+
fn list_funded_channels_with_filter<
4034+
Fn: FnMut(&(&InitFeatures, &ChannelId, &Channel<SP>)) -> bool + Copy,
4035+
>(
40344036
&self, f: Fn,
40354037
) -> Vec<ChannelDetails> {
40364038
// Allocate our best estimate of the number of channels we have in the `res`
@@ -4046,9 +4048,13 @@ where
40464048
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
40474049
let peer_state = &mut *peer_state_lock;
40484050
// Only `Channels` in the `Channel::Funded` phase can be considered funded.
4049-
let filtered_chan_by_id =
4050-
peer_state.channel_by_id.iter().filter(|(_, chan)| chan.is_funded()).filter(f);
4051-
res.extend(filtered_chan_by_id.map(|(_channel_id, channel)| {
4051+
let filtered_chan_by_id = peer_state
4052+
.channel_by_id
4053+
.iter()
4054+
.map(|(cid, c)| (&peer_state.latest_features, cid, c))
4055+
.filter(|(_, _, chan)| chan.is_funded())
4056+
.filter(f);
4057+
res.extend(filtered_chan_by_id.map(|(_, _channel_id, channel)| {
40524058
ChannelDetails::from_channel(
40534059
channel,
40544060
best_block_height,
@@ -4100,7 +4106,7 @@ where
41004106
// Note we use is_live here instead of usable which leads to somewhat confused
41014107
// internal/external nomenclature, but that's ok cause that's probably what the user
41024108
// really wanted anyway.
4103-
self.list_funded_channels_with_filter(|&(_, ref channel)| channel.context().is_live())
4109+
self.list_funded_channels_with_filter(|&(_, _, ref channel)| channel.context().is_live())
41044110
}
41054111

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

0 commit comments

Comments
 (0)