Skip to content

Commit 7a72560

Browse files
committed
Change sort_and_filter_channels return type to a Box containing an
iterator
1 parent 997c2fe commit 7a72560

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lightning-invoice/src/utils.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ where
241241
for PhantomRouteHints { channels, phantom_scid, real_node_pubkey } in phantom_route_hints {
242242
log_trace!(logger, "Generating phantom route hints for node {}",
243243
log_pubkey!(real_node_pubkey));
244-
let mut route_hints = sort_and_filter_channels(channels, amt_msat, &logger);
244+
let mut route_hints: Vec<RouteHint> = sort_and_filter_channels(channels, amt_msat, &logger).collect();
245245

246246
// If we have any public channel, the route hints from `sort_and_filter_channels` will be
247247
// empty. In that case we create a RouteHint on which we will push a single hop with the
@@ -585,8 +585,13 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
585585
/// * Sorted by lowest inbound capacity if an online channel with the minimum amount requested exists,
586586
/// otherwise sort by highest inbound capacity to give the payment the best chance of succeeding.
587587
fn sort_and_filter_channels<L: Deref>(
588-
channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Option<u64>, logger: &L
589-
) -> Vec<RouteHint> where L::Target: Logger {
588+
channels: Vec<ChannelDetails>,
589+
min_inbound_capacity_msat: Option<u64>,
590+
logger: &L,
591+
) -> Box<dyn Iterator<Item = RouteHint>>
592+
where
593+
L::Target: Logger,
594+
{
590595
let mut filtered_channels: HashMap<PublicKey, ChannelDetails> = HashMap::new();
591596
let min_inbound_capacity = min_inbound_capacity_msat.unwrap_or(0);
592597
let mut min_capacity_channel_exists = false;
@@ -612,7 +617,7 @@ fn sort_and_filter_channels<L: Deref>(
612617
// look at the public channels instead.
613618
log_trace!(logger, "Not including channels in invoice route hints on account of public channel {}",
614619
log_bytes!(channel.channel_id));
615-
return vec![]
620+
return Box::new(vec![].into_iter());
616621
}
617622
}
618623

@@ -672,7 +677,7 @@ fn sort_and_filter_channels<L: Deref>(
672677
}
673678
}
674679

675-
let route_hint_from_channel = |channel: ChannelDetails| {
680+
fn route_hint_from_channel(channel: ChannelDetails) -> RouteHint {
676681
let forwarding_info = channel.counterparty.forwarding_info.as_ref().unwrap();
677682
RouteHint(vec![RouteHintHop {
678683
src_node_id: channel.counterparty.node_id,
@@ -734,7 +739,8 @@ fn sort_and_filter_channels<L: Deref>(
734739
} else {
735740
b.inbound_capacity_msat.cmp(&a.inbound_capacity_msat)
736741
}});
737-
eligible_channels.into_iter().take(3).map(route_hint_from_channel).collect::<Vec<RouteHint>>()
742+
743+
Box::new(eligible_channels.into_iter().take(3).map(route_hint_from_channel))
738744
}
739745

740746
/// prefer_current_channel chooses a channel to use for route hints between a currently selected and candidate

0 commit comments

Comments
 (0)