Skip to content

Commit a63e344

Browse files
Optimize dedup_decode_update_add_htlcs
No need to iterate through all entries in the map, we can instead pull out the specific entry that we want.
1 parent 748965b commit a63e344

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17119,28 +17119,32 @@ fn dedup_decode_update_add_htlcs<L: Deref>(
1711917119
) where
1712017120
L::Target: Logger,
1712117121
{
17122-
decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
17123-
update_add_htlcs.retain(|update_add| {
17124-
let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias
17125-
&& update_add.htlc_id == prev_hop_data.htlc_id;
17126-
if matches {
17127-
let logger = WithContext::from(
17128-
logger,
17129-
prev_hop_data.counterparty_node_id,
17130-
Some(update_add.channel_id),
17131-
Some(update_add.payment_hash),
17132-
);
17133-
log_info!(
17134-
logger,
17135-
"Removing pending to-decode HTLC with id {}: {}",
17136-
update_add.htlc_id,
17137-
removal_reason
17138-
);
17122+
match decode_update_add_htlcs.entry(prev_hop_data.prev_outbound_scid_alias) {
17123+
hash_map::Entry::Occupied(mut update_add_htlcs) => {
17124+
update_add_htlcs.get_mut().retain(|update_add| {
17125+
let matches = update_add.htlc_id == prev_hop_data.htlc_id;
17126+
if matches {
17127+
let logger = WithContext::from(
17128+
logger,
17129+
prev_hop_data.counterparty_node_id,
17130+
Some(update_add.channel_id),
17131+
Some(update_add.payment_hash),
17132+
);
17133+
log_info!(
17134+
logger,
17135+
"Removing pending to-decode HTLC with id {}: {}",
17136+
update_add.htlc_id,
17137+
removal_reason
17138+
);
17139+
}
17140+
!matches
17141+
});
17142+
if update_add_htlcs.get().is_empty() {
17143+
update_add_htlcs.remove();
1713917144
}
17140-
!matches
17141-
});
17142-
!update_add_htlcs.is_empty()
17143-
});
17145+
},
17146+
_ => {},
17147+
}
1714417148
}
1714517149

1714617150
// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the

0 commit comments

Comments
 (0)