@@ -56,7 +56,7 @@ use crate::events::{
56
56
InboundChannelFunds, PaymentFailureReason, ReplayEvent,
57
57
};
58
58
use crate::events::{FundingInfo, PaidBolt12Invoice};
59
- use crate::ln::chan_utils::commitment_sat_per_1000_weight_for_type ;
59
+ use crate::ln::chan_utils::selected_commitment_sat_per_1000_weight ;
60
60
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
61
61
// construct one themselves.
62
62
use crate::ln::channel::PendingV2Channel;
@@ -7166,6 +7166,7 @@ where
7166
7166
pub fn maybe_update_chan_fees(&self) {
7167
7167
PersistenceNotifierGuard::optionally_notify(self, || {
7168
7168
let mut should_persist = NotifyOption::SkipPersistNoEvents;
7169
+ let mut feerate_cache = new_hash_map();
7169
7170
7170
7171
let per_peer_state = self.per_peer_state.read().unwrap();
7171
7172
for (_cp_id, peer_state_mutex) in per_peer_state.iter() {
@@ -7174,7 +7175,12 @@ where
7174
7175
for (chan_id, chan) in peer_state.channel_by_id.iter_mut()
7175
7176
.filter_map(|(chan_id, chan)| chan.as_funded_mut().map(|chan| (chan_id, chan)))
7176
7177
{
7177
- let new_feerate = commitment_sat_per_1000_weight_for_type(&self.fee_estimator, chan.funding.get_channel_type());
7178
+ let channel_type = chan.funding.get_channel_type();
7179
+ let new_feerate = feerate_cache.get(channel_type).copied().or_else(|| {
7180
+ let feerate = selected_commitment_sat_per_1000_weight(&self.fee_estimator, &channel_type);
7181
+ feerate_cache.insert(channel_type.clone(), feerate);
7182
+ Some(feerate)
7183
+ }).unwrap();
7178
7184
let chan_needs_persist = self.update_channel_fee(chan_id, chan, new_feerate);
7179
7185
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7180
7186
}
@@ -7212,6 +7218,7 @@ where
7212
7218
let mut handle_errors: Vec<(Result<(), _>, _)> = Vec::new();
7213
7219
let mut timed_out_mpp_htlcs = Vec::new();
7214
7220
let mut pending_peers_awaiting_removal = Vec::new();
7221
+ let mut feerate_cache = new_hash_map();
7215
7222
7216
7223
{
7217
7224
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -7223,7 +7230,12 @@ where
7223
7230
peer_state.channel_by_id.retain(|chan_id, chan| {
7224
7231
match chan.as_funded_mut() {
7225
7232
Some(funded_chan) => {
7226
- let new_feerate = commitment_sat_per_1000_weight_for_type(&self.fee_estimator, funded_chan.funding.get_channel_type());
7233
+ let channel_type = funded_chan.funding.get_channel_type();
7234
+ let new_feerate = feerate_cache.get(channel_type).copied().or_else(|| {
7235
+ let feerate = selected_commitment_sat_per_1000_weight(&self.fee_estimator, &channel_type);
7236
+ feerate_cache.insert(channel_type.clone(), feerate);
7237
+ Some(feerate)
7238
+ }).unwrap();
7227
7239
let chan_needs_persist = self.update_channel_fee(chan_id, funded_chan, new_feerate);
7228
7240
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7229
7241
0 commit comments