Skip to content

#3884 followups #3938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2025
Merged

Conversation

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jul 17, 2025

👋 I see @joostjager was un-assigned.
If you'd like another reviewer assignment, please click here.

let new_feerate = commitment_sat_per_1000_weight_for_type(&self.fee_estimator, chan.funding.get_channel_type());
let chan_needs_persist = self.update_channel_fee(chan_id, chan, new_feerate);
let channel_type = chan.funding.get_channel_type();
let new_feerate = feerate_cache.entry(channel_type.clone()).or_insert(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider using this snippet below to clone once for each channel type, instead of cloning for every channel ?

								let new_feerate = match feerate_cache.get(channel_type) {
									Some(feerate) => {
										*feerate
									}
									None => {
										let feerate = selected_commitment_sat_per_1000_weight(&self.fee_estimator, &channel_type);
										feerate_cache.insert(channel_type.clone(), feerate);
										feerate
									}
								};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned it up some more below:

					let new_feerate = feerate_cache.get(channel_type).copied().or_else(|| {
						let feerate = selected_commitment_sat_per_1000_weight(&self.fee_estimator, &channel_type);
						feerate_cache.insert(channel_type.clone(), feerate);
						Some(feerate)
					}).unwrap();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👌

Add a cache by channel type for the cases where we're updating many
channels at a time, to minimize calls to the fee estimator. We can't
move this check out of the loop without duplicating the logic in
holder_preferred_commitment_sat_per_1000_weight_for_type, so we settle
for a cache to prevent duplicate queries.
@carlaKC carlaKC force-pushed the 3789-offchain-followups branch from 1a9ed0d to d7790d2 Compare July 17, 2025 19:40
@tankyleo tankyleo requested review from TheBlueMatt and removed request for joostjager July 17, 2025 21:38
@carlaKC
Copy link
Contributor Author

carlaKC commented Jul 18, 2025

@tankyleo do you think we need another reviewer or is this simple enough to land as-is?
(in the spirit of 1-reviewer PRs)

@TheBlueMatt TheBlueMatt merged commit 1e34de0 into lightningdevkit:main Jul 18, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants