Skip to content

Commit 31b8d54

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 f0317b8 commit 31b8d54

1 file changed

Lines changed: 25 additions & 21 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17106,28 +17106,32 @@ fn dedup_decode_update_add_htlcs<L: Deref>(
1710617106
) where
1710717107
L::Target: Logger,
1710817108
{
17109-
decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
17110-
update_add_htlcs.retain(|update_add| {
17111-
let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias
17112-
&& update_add.htlc_id == prev_hop_data.htlc_id;
17113-
if matches {
17114-
let logger = WithContext::from(
17115-
logger,
17116-
prev_hop_data.counterparty_node_id,
17117-
Some(update_add.channel_id),
17118-
Some(update_add.payment_hash),
17119-
);
17120-
log_info!(
17121-
logger,
17122-
"Removing pending to-decode HTLC with id {}: {}",
17123-
update_add.htlc_id,
17124-
removal_reason
17125-
);
17109+
match decode_update_add_htlcs.entry(prev_hop_data.prev_outbound_scid_alias) {
17110+
hash_map::Entry::Occupied(mut update_add_htlcs) => {
17111+
update_add_htlcs.get_mut().retain(|update_add| {
17112+
let matches = update_add.htlc_id == prev_hop_data.htlc_id;
17113+
if matches {
17114+
let logger = WithContext::from(
17115+
logger,
17116+
prev_hop_data.counterparty_node_id,
17117+
Some(update_add.channel_id),
17118+
Some(update_add.payment_hash),
17119+
);
17120+
log_info!(
17121+
logger,
17122+
"Removing pending to-decode HTLC with id {}: {}",
17123+
update_add.htlc_id,
17124+
removal_reason
17125+
);
17126+
}
17127+
!matches
17128+
});
17129+
if update_add_htlcs.get().is_empty() {
17130+
update_add_htlcs.remove();
1712617131
}
17127-
!matches
17128-
});
17129-
!update_add_htlcs.is_empty()
17130-
});
17132+
},
17133+
_ => {},
17134+
}
1713117135
}
1713217136

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

0 commit comments

Comments
 (0)