Skip to content

Commit

Permalink
Also update the fee rate cache in sync_wallets
Browse files Browse the repository at this point in the history
.. which we previously omitted.
  • Loading branch information
tnull committed Jun 11, 2024
1 parent c641eaf commit 27623e0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,8 @@ impl Node {
}
}

/// Manually sync the LDK and BDK wallets with the current chain state.
/// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate
/// cache.
///
/// **Note:** The wallets are regularly synced in the background, which is configurable via
/// [`Config::onchain_wallet_sync_interval_secs`] and [`Config::wallet_sync_interval_secs`].
Expand All @@ -1091,6 +1092,7 @@ impl Node {
let archive_cman = Arc::clone(&self.channel_manager);
let sync_cmon = Arc::clone(&self.chain_monitor);
let archive_cmon = Arc::clone(&self.chain_monitor);
let fee_estimator = Arc::clone(&self.fee_estimator);
let sync_sweeper = Arc::clone(&self.output_sweeper);
let sync_logger = Arc::clone(&self.logger);
let confirmables = vec![
Expand All @@ -1099,6 +1101,8 @@ impl Node {
&*sync_sweeper as &(dyn Confirm + Sync + Send),
];
let sync_wallet_timestamp = Arc::clone(&self.latest_wallet_sync_timestamp);
let sync_fee_rate_update_timestamp =
Arc::clone(&self.latest_fee_rate_cache_update_timestamp);
let sync_onchain_wallet_timestamp = Arc::clone(&self.latest_onchain_wallet_sync_timestamp);
let sync_monitor_archival_height = Arc::clone(&self.latest_channel_monitor_archival_height);

Expand All @@ -1125,6 +1129,26 @@ impl Node {
},
};

let now = Instant::now();
match fee_estimator.update_fee_estimates().await {
Ok(()) => {
log_info!(
sync_logger,
"Fee rate cache update finished in {}ms.",
now.elapsed().as_millis()
);
let unix_time_secs_opt = SystemTime::now()
.duration_since(UNIX_EPOCH)
.ok()
.map(|d| d.as_secs());
*sync_fee_rate_update_timestamp.write().unwrap() = unix_time_secs_opt;
},
Err(e) => {
log_error!(sync_logger, "Fee rate cache update failed: {}", e,);
return Err(e);
},
}

let now = Instant::now();
match tx_sync.sync(confirmables).await {
Ok(()) => {
Expand Down

0 comments on commit 27623e0

Please sign in to comment.