Skip to content

Commit

Permalink
feat: expose node method to update fee estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jun 24, 2024
1 parent 6797574 commit e1afe31
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ interface Node {
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
[Throws=NodeError]
void update_fee_estimates();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
void remove_payment([ByRef]PaymentId payment_id);
Expand Down
42 changes: 42 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,48 @@ impl Node {
}
}

/// Alby: update fee estimates separately rather than doing a full sync
pub fn update_fee_estimates(&self) -> Result<(), Error> {
let rt_lock = self.runtime.read().unwrap();
if rt_lock.is_none() {
return Err(Error::NotRunning);
}

let fee_estimator = Arc::clone(&self.fee_estimator);
let sync_logger = Arc::clone(&self.logger);
let sync_fee_rate_update_timestamp =
Arc::clone(&self.latest_fee_rate_cache_update_timestamp);

tokio::task::block_in_place(move || {
tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(
async move {
let now = Instant::now();
// We don't add an additional timeout here, as
// `FeeEstimator::update_fee_estimates` already returns after a timeout.
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;
Ok(())
},
Err(e) => {
log_error!(sync_logger, "Fee rate cache update failed: {}", e,);
return Err(e);
},
}
},
)
})
}

/// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate
/// cache.
///
Expand Down

0 comments on commit e1afe31

Please sign in to comment.