Merged
Conversation
|
👋 I see @joostjager was un-assigned. |
tankyleo
reviewed
Jul 17, 2025
lightning/src/ln/channelmanager.rs
Outdated
| 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( |
Contributor
There was a problem hiding this comment.
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
}
};
Contributor
There was a problem hiding this comment.
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();
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.
1a9ed0d to
d7790d2
Compare
tankyleo
approved these changes
Jul 17, 2025
elnosh
approved these changes
Jul 18, 2025
Contributor
Author
|
@tankyleo do you think we need another reviewer or is this simple enough to land as-is? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#3884 followups