@@ -43,11 +43,18 @@ pub struct Frontier {
4343
4444 /// Tracks the average transaction mass throughout the mempool's lifespan using a decayed weighting mechanism
4545 average_transaction_mass : f64 ,
46+
47+ target_time_per_block_seconds : f64 ,
4648}
4749
48- impl Default for Frontier {
49- fn default ( ) -> Self {
50- Self { search_tree : Default :: default ( ) , total_mass : Default :: default ( ) , average_transaction_mass : INITIAL_AVG_MASS }
50+ impl Frontier {
51+ pub fn new ( target_time_per_block_seconds : f64 ) -> Self {
52+ Self {
53+ search_tree : Default :: default ( ) ,
54+ total_mass : Default :: default ( ) ,
55+ average_transaction_mass : INITIAL_AVG_MASS ,
56+ target_time_per_block_seconds,
57+ }
5158 }
5259}
5360
@@ -229,7 +236,7 @@ impl Frontier {
229236 let bps = args. network_blocks_per_second as f64 ;
230237 let mut mass_per_block = args. maximum_mass_per_block as f64 ;
231238 let mut inclusion_interval = average_transaction_mass / ( mass_per_block * bps) ;
232- let mut estimator = FeerateEstimator :: new ( self . total_weight ( ) , inclusion_interval) ;
239+ let mut estimator = FeerateEstimator :: new ( self . total_weight ( ) , inclusion_interval, self . target_time_per_block_seconds ) ;
233240
234241 // Search for better estimators by possibly removing extremely high outliers
235242 let mut down_iter = self . search_tree . descending_iter ( ) . peekable ( ) ;
@@ -250,7 +257,7 @@ impl Frontier {
250257
251258 // Compute the weight up to, and excluding, current key (which translates to zero weight if peek() is none)
252259 let prefix_weight = down_iter. peek ( ) . map ( |key| self . search_tree . prefix_weight ( key) ) . unwrap_or_default ( ) ;
253- let pending_estimator = FeerateEstimator :: new ( prefix_weight, inclusion_interval) ;
260+ let pending_estimator = FeerateEstimator :: new ( prefix_weight, inclusion_interval, self . target_time_per_block_seconds ) ;
254261
255262 // Test the pending estimator vs. the current one
256263 if pending_estimator. feerate_to_time ( 1.0 ) < estimator. feerate_to_time ( 1.0 ) {
@@ -294,7 +301,7 @@ mod tests {
294301 map. insert ( key. tx . id ( ) , key) ;
295302 }
296303
297- let mut frontier = Frontier :: default ( ) ;
304+ let mut frontier = Frontier :: new ( 1.0 ) ;
298305 for item in map. values ( ) . cloned ( ) {
299306 frontier. insert ( item) . then_some ( ( ) ) . unwrap ( ) ;
300307 }
@@ -314,7 +321,7 @@ mod tests {
314321 map. insert ( key. tx . id ( ) , key) ;
315322 }
316323
317- let mut frontier = Frontier :: default ( ) ;
324+ let mut frontier = Frontier :: new ( 1.0 ) ;
318325 for item in map. values ( ) . cloned ( ) {
319326 frontier. insert ( item) . then_some ( ( ) ) . unwrap ( ) ;
320327 }
@@ -348,7 +355,7 @@ mod tests {
348355 }
349356
350357 let len = cap / 2 ;
351- let mut frontier = Frontier :: default ( ) ;
358+ let mut frontier = Frontier :: new ( 1.0 ) ;
352359 for item in map. values ( ) . take ( len) . cloned ( ) {
353360 frontier. insert ( item) . then_some ( ( ) ) . unwrap ( ) ;
354361 }
@@ -402,7 +409,7 @@ mod tests {
402409 }
403410
404411 for len in [ 0 , 1 , 10 , 100 , 200 , 300 , 500 , 750 , cap / 2 , ( cap * 2 ) / 3 , ( cap * 4 ) / 5 , ( cap * 5 ) / 6 , cap] {
405- let mut frontier = Frontier :: default ( ) ;
412+ let mut frontier = Frontier :: new ( 1.0 ) ;
406413 for item in map. values ( ) . take ( len) . cloned ( ) {
407414 frontier. insert ( item) . then_some ( ( ) ) . unwrap ( ) ;
408415 }
@@ -444,7 +451,7 @@ mod tests {
444451 for len in [ 0 , 1 , 10 , 100 , 200 , 300 , 500 , 750 , cap / 2 , ( cap * 2 ) / 3 , ( cap * 4 ) / 5 , ( cap * 5 ) / 6 , cap] {
445452 println ! ( ) ;
446453 println ! ( "Testing a frontier with {} txs..." , len. min( cap) ) ;
447- let mut frontier = Frontier :: default ( ) ;
454+ let mut frontier = Frontier :: new ( 1.0 ) ;
448455 for item in map. values ( ) . take ( len) . cloned ( ) {
449456 frontier. insert ( item) . then_some ( ( ) ) . unwrap ( ) ;
450457 }
@@ -477,7 +484,7 @@ mod tests {
477484 const HIGH_FEERATE : f64 = 1000.0 ;
478485
479486 let cap = 20_000 ;
480- let mut frontier = Frontier :: default ( ) ;
487+ let mut frontier = Frontier :: new ( 1.0 ) ;
481488 for i in 0 ..cap as u64 {
482489 let ( mass, fee) = if i < 200 {
483490 let mass = 1650 ;
@@ -533,7 +540,7 @@ mod tests {
533540
534541 // All lens make for less than block capacity (given the mass used)
535542 for len in [ 0 , 1 , 10 , 100 , 200 , 250 , 300 ] {
536- let mut frontier = Frontier :: default ( ) ;
543+ let mut frontier = Frontier :: new ( 1.0 ) ;
537544 for item in map. values ( ) . take ( len) . cloned ( ) {
538545 frontier. insert ( item) . then_some ( ( ) ) . unwrap ( ) ;
539546 }
0 commit comments