@@ -3,6 +3,8 @@ use crate::tx::UnsignedTransaction;
33use crate :: { Network , fake_sign} ;
44use ic_btc_interface:: { MillisatoshiPerByte , Satoshi } ;
55use std:: cmp:: max;
6+ #[ cfg( test) ]
7+ mod tests;
68
79pub trait FeeEstimator {
810 const DUST_LIMIT : u64 ;
@@ -14,6 +16,15 @@ pub trait FeeEstimator {
1416 fn estimate_median_fee (
1517 & self ,
1618 fee_percentiles : & [ MillisatoshiPerByte ] ,
19+ ) -> Option < MillisatoshiPerByte > {
20+ self . estimate_nth_fee ( fee_percentiles, 50 )
21+ }
22+
23+ /// Estimate the n-th percentile fees (n < 100) based on the given fee percentiles (slice of fee rates in milli base unit per vbyte/byte).
24+ fn estimate_nth_fee (
25+ & self ,
26+ fee_percentiles : & [ MillisatoshiPerByte ] ,
27+ nth : usize ,
1728 ) -> Option < MillisatoshiPerByte > ;
1829
1930 /// Evaluate the fee necessary to cover the minter's cycles consumption.
@@ -90,19 +101,20 @@ impl FeeEstimator for BitcoinFeeEstimator {
90101
91102 const MIN_RELAY_FEE_RATE_INCREASE : MillisatoshiPerByte = 1_000 ;
92103
93- fn estimate_median_fee (
104+ fn estimate_nth_fee (
94105 & self ,
95106 fee_percentiles : & [ MillisatoshiPerByte ] ,
107+ nth : usize ,
96108 ) -> Option < MillisatoshiPerByte > {
97109 /// The default fee we use on regtest networks.
98110 const DEFAULT_REGTEST_FEE : MillisatoshiPerByte = 5_000 ;
99111
100112 let median_fee = match & self . network {
101113 Network :: Mainnet | Network :: Testnet => {
102- if fee_percentiles. len ( ) < 100 {
114+ if fee_percentiles. len ( ) < 100 || nth >= 100 {
103115 return None ;
104116 }
105- Some ( fee_percentiles[ 50 ] )
117+ Some ( fee_percentiles[ nth ] )
106118 }
107119 Network :: Regtest => Some ( DEFAULT_REGTEST_FEE ) ,
108120 } ;
0 commit comments