-
Notifications
You must be signed in to change notification settings - Fork 417
#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
#3884 followups #3938
Conversation
👋 I see @joostjager was un-assigned. |
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( |
There was a problem hiding this comment.
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
}
};
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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.
1a9ed0d
to
d7790d2
Compare
@tankyleo do you think we need another reviewer or is this simple enough to land as-is? |
#3884 followups