Skip to content

Commit 987f78c

Browse files
authored
Merge pull request #333 from tnull/2024-07-request-fees-once
2 parents 8e5dbfe + caa4d22 commit 987f78c

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

src/fee_estimator.rs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ where
3737
}
3838

3939
pub(crate) async fn update_fee_estimates(&self) -> Result<(), Error> {
40+
let estimates = tokio::time::timeout(
41+
Duration::from_secs(FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS),
42+
self.esplora_client.get_fee_estimates(),
43+
)
44+
.await
45+
.map_err(|e| {
46+
log_error!(self.logger, "Updating fee rate estimates timed out: {}", e);
47+
Error::FeerateEstimationUpdateTimeout
48+
})?
49+
.map_err(|e| {
50+
log_error!(self.logger, "Failed to retrieve fee rate estimates: {}", e);
51+
Error::FeerateEstimationUpdateFailed
52+
})?;
53+
54+
if estimates.is_empty() && self.config.network == Network::Bitcoin {
55+
// Ensure we fail if we didn't receive any estimates.
56+
log_error!(
57+
self.logger,
58+
"Failed to retrieve fee rate estimates: empty fee estimates are dissallowed on Mainnet.",
59+
);
60+
return Err(Error::FeerateEstimationUpdateFailed);
61+
}
62+
4063
let confirmation_targets = vec![
4164
ConfirmationTarget::OnChainSweep,
4265
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
@@ -57,42 +80,8 @@ where
5780
ConfirmationTarget::OutputSpendingFee => 12,
5881
};
5982

60-
let estimates = tokio::time::timeout(
61-
Duration::from_secs(FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS),
62-
self.esplora_client.get_fee_estimates(),
63-
)
64-
.await
65-
.map_err(|e| {
66-
log_error!(
67-
self.logger,
68-
"Updating fee rate estimates for {:?} timed out: {}",
69-
target,
70-
e
71-
);
72-
Error::FeerateEstimationUpdateTimeout
73-
})?
74-
.map_err(|e| {
75-
log_error!(
76-
self.logger,
77-
"Failed to retrieve fee rate estimates for {:?}: {}",
78-
target,
79-
e
80-
);
81-
Error::FeerateEstimationUpdateFailed
82-
})?;
83-
84-
if estimates.is_empty() && self.config.network == Network::Bitcoin {
85-
// Ensure we fail if we didn't receive any estimates.
86-
log_error!(
87-
self.logger,
88-
"Failed to retrieve fee rate estimates for {:?}: empty fee estimates are dissallowed on Mainnet.",
89-
target,
90-
);
91-
return Err(Error::FeerateEstimationUpdateFailed);
92-
}
93-
94-
let converted_estimates = esplora_client::convert_fee_rate(num_blocks, estimates)
95-
.map_err(|e| {
83+
let converted_estimates =
84+
esplora_client::convert_fee_rate(num_blocks, estimates.clone()).map_err(|e| {
9685
log_error!(
9786
self.logger,
9887
"Failed to convert fee rate estimates for {:?}: {}",

0 commit comments

Comments
 (0)