Skip to content

Commit e268b80

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 6da0b98 commit e268b80

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/chain/mod.rs

Lines changed: 34 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,35 @@ 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), n) if n == Network::Regtest || n == Network::Signet => {
912+
// On regtest/signet we just fall back to the usual 1 sat/vb == 250
913+
// sat/kwu default.
914+
log_error!(
915+
logger,
916+
"Failed to retrieve fee rate estimates: {}. Falling back to default of 1 sat/vb.",
917+
e,
918+
);
919+
FeeRate::from_sat_per_kwu(250)
920+
},
921+
(Err(e), _) => {
922+
// On testnet `estimatesmartfee` can be unreliable so we just skip in
923+
// case of a failure, which will have us falling back to defaults.
924+
log_error!(
925+
logger,
926+
"Failed to retrieve fee rate estimates: {}. Falling back to defaults.",
927+
e,
928+
);
929+
return Ok(());
930+
},
931+
};
932+
906933
// LDK 0.0.118 introduced changes to the `ConfirmationTarget` semantics that
907934
// require some post-estimation adjustments to the fee rates, which we do here.
908935
let adjusted_fee_rate = apply_post_estimation_adjustments(target, fee_rate);

0 commit comments

Comments
 (0)