11use crate :: logger:: { log_error, log_trace, Logger } ;
2- use crate :: Error ;
2+ use crate :: { Config , Error } ;
33
44use lightning:: chain:: chaininterface:: {
55 ConfirmationTarget , FeeEstimator , FEERATE_FLOOR_SATS_PER_KW ,
@@ -8,28 +8,30 @@ use lightning::chain::chaininterface::{
88use bdk:: FeeRate ;
99use esplora_client:: AsyncClient as EsploraClient ;
1010
11+ use bitcoin:: Network ;
1112use bitcoin:: blockdata:: weight:: Weight ;
1213
1314use std:: collections:: HashMap ;
1415use std:: ops:: Deref ;
15- use std:: sync:: RwLock ;
16+ use std:: sync:: { Arc , RwLock } ;
1617
1718pub ( crate ) struct OnchainFeeEstimator < L : Deref >
1819where
1920 L :: Target : Logger ,
2021{
2122 fee_rate_cache : RwLock < HashMap < ConfirmationTarget , FeeRate > > ,
2223 esplora_client : EsploraClient ,
24+ config : Arc < Config > ,
2325 logger : L ,
2426}
2527
2628impl < L : Deref > OnchainFeeEstimator < L >
2729where
2830 L :: Target : Logger ,
2931{
30- pub ( crate ) fn new ( esplora_client : EsploraClient , logger : L ) -> Self {
32+ pub ( crate ) fn new ( esplora_client : EsploraClient , config : Arc < Config > , logger : L ) -> Self {
3133 let fee_rate_cache = RwLock :: new ( HashMap :: new ( ) ) ;
32- Self { fee_rate_cache, esplora_client, logger }
34+ Self { fee_rate_cache, esplora_client, config , logger }
3335 }
3436
3537 pub ( crate ) async fn update_fee_estimates ( & self ) -> Result < ( ) , Error > {
6163 Error :: FeerateEstimationUpdateFailed
6264 } ) ?;
6365
66+ if estimates. is_empty ( ) && self . config . network == Network :: Bitcoin {
67+ // Ensure we fail if we didn't receive any estimates.
68+ log_error ! (
69+ self . logger,
70+ "Failed to retrieve fee rate estimates for {:?}: empty fee estimates are dissallowed on Mainnet." ,
71+ target,
72+ ) ;
73+ return Err ( Error :: FeerateEstimationUpdateFailed ) ;
74+ }
75+
6476 let converted_estimates = esplora_client:: convert_fee_rate ( num_blocks, estimates)
6577 . map_err ( |e| {
6678 log_error ! (
0 commit comments