Skip to content

Commit 5978c85

Browse files
committed
Only enforce successful fee rate cache updates on mainnet
This behavior mirrors what we do in the Esplora case: we only enforce successful fee rate updates on mainnet. On regtest/signet/testnet we will just skip (i.e. return `Ok(())`) if we fail to retrieve the updates (e.g., when bitcoind's `estimatesmartfee` isn't sufficiently populated) and will either keep previously-retrieved values or worst case fallback to the fallback defaults.
1 parent 0814b13 commit 5978c85

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/chain/mod.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,34 +841,32 @@ impl ChainSource {
841841
Self::BitcoindRpc {
842842
bitcoind_rpc_client,
843843
fee_estimator,
844+
config,
844845
kv_store,
845846
logger,
846847
node_metrics,
847848
..
848849
} => {
849850
macro_rules! get_fee_rate_update {
850851
($estimation_fut: expr) => {{
851-
tokio::time::timeout(
852+
let update_res = tokio::time::timeout(
852853
Duration::from_secs(FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS),
853854
$estimation_fut,
854855
)
855856
.await
856857
.map_err(|e| {
857858
log_error!(logger, "Updating fee rate estimates timed out: {}", e);
858859
Error::FeerateEstimationUpdateTimeout
859-
})?
860-
.map_err(|e| {
861-
log_error!(logger, "Failed to retrieve fee rate estimates: {}", e);
862-
Error::FeerateEstimationUpdateFailed
863-
})?
860+
})?;
861+
update_res
864862
}};
865863
}
866864
let confirmation_targets = get_all_conf_targets();
867865

868866
let mut new_fee_rate_cache = HashMap::with_capacity(10);
869867
let now = Instant::now();
870868
for target in confirmation_targets {
871-
let fee_rate = match target {
869+
let fee_rate_update_res = match target {
872870
ConfirmationTarget::Lightning(
873871
LdkConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
874872
) => {
@@ -903,6 +901,24 @@ impl ChainSource {
903901
},
904902
};
905903

904+
let fee_rate = match (fee_rate_update_res, config.network) {
905+
(Ok(rate), _) => rate,
906+
(Err(e), Network::Bitcoin) => {
907+
// Strictly fail on mainnet.
908+
log_error!(logger, "Failed to retrieve fee rate estimates: {}", e);
909+
return Err(Error::FeerateEstimationUpdateFailed);
910+
},
911+
(Err(e), _) => {
912+
// On regtest/testnet/signet we just skip, which will have us falling back to defaults.
913+
log_error!(
914+
logger,
915+
"Failed to retrieve fee rate estimates: {}. Falling back to defaults.",
916+
e,
917+
);
918+
return Ok(());
919+
},
920+
};
921+
906922
// LDK 0.0.118 introduced changes to the `ConfirmationTarget` semantics that
907923
// require some post-estimation adjustments to the fee rates, which we do here.
908924
let adjusted_fee_rate = apply_post_estimation_adjustments(target, fee_rate);

0 commit comments

Comments
 (0)