diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 830d40119..5cff3a6b5 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -145,7 +145,7 @@ interface OnchainPayment { [Throws=NodeError] Address new_address(); [Throws=NodeError] - Txid send_to_address([ByRef]Address address, u64 amount_msat); + Txid send_to_address([ByRef]Address address, u64 amount_sats); [Throws=NodeError] Txid send_all_to_address([ByRef]Address address); }; diff --git a/src/fee_estimator.rs b/src/fee_estimator.rs index f1fa7e43b..329cc6e42 100644 --- a/src/fee_estimator.rs +++ b/src/fee_estimator.rs @@ -37,6 +37,29 @@ where } pub(crate) async fn update_fee_estimates(&self) -> Result<(), Error> { + let estimates = tokio::time::timeout( + Duration::from_secs(FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS), + self.esplora_client.get_fee_estimates(), + ) + .await + .map_err(|e| { + log_error!(self.logger, "Updating fee rate estimates timed out: {}", e); + Error::FeerateEstimationUpdateTimeout + })? + .map_err(|e| { + log_error!(self.logger, "Failed to retrieve fee rate estimates: {}", e); + Error::FeerateEstimationUpdateFailed + })?; + + if estimates.is_empty() && self.config.network == Network::Bitcoin { + // Ensure we fail if we didn't receive any estimates. + log_error!( + self.logger, + "Failed to retrieve fee rate estimates: empty fee estimates are dissallowed on Mainnet.", + ); + return Err(Error::FeerateEstimationUpdateFailed); + } + let confirmation_targets = vec![ ConfirmationTarget::OnChainSweep, ConfirmationTarget::MinAllowedAnchorChannelRemoteFee, @@ -57,42 +80,8 @@ where ConfirmationTarget::OutputSpendingFee => 12, }; - let estimates = tokio::time::timeout( - Duration::from_secs(FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS), - self.esplora_client.get_fee_estimates(), - ) - .await - .map_err(|e| { - log_error!( - self.logger, - "Updating fee rate estimates for {:?} timed out: {}", - target, - e - ); - Error::FeerateEstimationUpdateTimeout - })? - .map_err(|e| { - log_error!( - self.logger, - "Failed to retrieve fee rate estimates for {:?}: {}", - target, - e - ); - Error::FeerateEstimationUpdateFailed - })?; - - if estimates.is_empty() && self.config.network == Network::Bitcoin { - // Ensure we fail if we didn't receive any estimates. - log_error!( - self.logger, - "Failed to retrieve fee rate estimates for {:?}: empty fee estimates are dissallowed on Mainnet.", - target, - ); - return Err(Error::FeerateEstimationUpdateFailed); - } - - let converted_estimates = esplora_client::convert_fee_rate(num_blocks, estimates) - .map_err(|e| { + let converted_estimates = + esplora_client::convert_fee_rate(num_blocks, estimates.clone()).map_err(|e| { log_error!( self.logger, "Failed to convert fee rate estimates for {:?}: {}",