Skip to content

Commit

Permalink
Merge pull request #40 from getAlby/fix/ldk-fixes
Browse files Browse the repository at this point in the history
Fix: LDK fixes
  • Loading branch information
rolznz authored Jul 30, 2024
2 parents 34f562a + 857b4ad commit c75e244
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
61 changes: 25 additions & 36 deletions src/fee_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {:?}: {}",
Expand Down

0 comments on commit c75e244

Please sign in to comment.