@@ -52,14 +52,6 @@ pub trait FeeEstimator {
5252 fn get_est_sat_per_1000_weight ( & self , confirmation_target : ConfirmationTarget ) -> u32 ;
5353}
5454
55- // We need `FeeEstimator` implemented so that in some places where we only have a shared
56- // reference to a `Deref` to a `FeeEstimator`, we can still wrap it.
57- impl < D : Deref > FeeEstimator for D where D :: Target : FeeEstimator {
58- fn get_est_sat_per_1000_weight ( & self , confirmation_target : ConfirmationTarget ) -> u32 {
59- ( * * self ) . get_est_sat_per_1000_weight ( confirmation_target)
60- }
61- }
62-
6355/// Minimum relay fee as required by bitcoin network mempool policy.
6456pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT : u64 = 4000 ;
6557/// Minimum feerate that takes a sane approach to bitcoind weight-to-vbytes rounding.
@@ -68,18 +60,19 @@ pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;
6860pub const FEERATE_FLOOR_SATS_PER_KW : u32 = 253 ;
6961
7062/// Wraps a `Deref` to a `FeeEstimator` so that any fee estimations provided by it
71- /// are bounded below by `FEERATE_FLOOR_SATS_PER_KW` (253 sats/KW)
63+ /// are bounded below by `FEERATE_FLOOR_SATS_PER_KW` (253 sats/KW).
64+ ///
65+ /// Note that this does *not* implement [`FeeEstimator`] to make it harder to accidentally mix the
66+ /// two.
7267pub ( crate ) struct LowerBoundedFeeEstimator < F : Deref > ( pub F ) where F :: Target : FeeEstimator ;
7368
7469impl < F : Deref > LowerBoundedFeeEstimator < F > where F :: Target : FeeEstimator {
7570 /// Creates a new `LowerBoundedFeeEstimator` which wraps the provided fee_estimator
7671 pub fn new ( fee_estimator : F ) -> Self {
7772 LowerBoundedFeeEstimator ( fee_estimator)
7873 }
79- }
8074
81- impl < F : Deref > FeeEstimator for LowerBoundedFeeEstimator < F > where F :: Target : FeeEstimator {
82- fn get_est_sat_per_1000_weight ( & self , confirmation_target : ConfirmationTarget ) -> u32 {
75+ pub fn bounded_sat_per_1000_weight ( & self , confirmation_target : ConfirmationTarget ) -> u32 {
8376 cmp:: max (
8477 self . 0 . get_est_sat_per_1000_weight ( confirmation_target) ,
8578 FEERATE_FLOOR_SATS_PER_KW ,
@@ -107,7 +100,7 @@ mod tests {
107100 let test_fee_estimator = & TestFeeEstimator { sat_per_kw } ;
108101 let fee_estimator = LowerBoundedFeeEstimator :: new ( test_fee_estimator) ;
109102
110- assert_eq ! ( fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) , FEERATE_FLOOR_SATS_PER_KW ) ;
103+ assert_eq ! ( fee_estimator. bounded_sat_per_1000_weight ( ConfirmationTarget :: Background ) , FEERATE_FLOOR_SATS_PER_KW ) ;
111104 }
112105
113106 #[ test]
@@ -116,6 +109,6 @@ mod tests {
116109 let test_fee_estimator = & TestFeeEstimator { sat_per_kw } ;
117110 let fee_estimator = LowerBoundedFeeEstimator :: new ( test_fee_estimator) ;
118111
119- assert_eq ! ( fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) , sat_per_kw) ;
112+ assert_eq ! ( fee_estimator. bounded_sat_per_1000_weight ( ConfirmationTarget :: Background ) , sat_per_kw) ;
120113 }
121114}
0 commit comments