33
44use std:: {
55 collections:: VecDeque ,
6- time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ,
6+ time:: { Duration , SystemTime , UNIX_EPOCH } ,
77} ;
88
9- use crate :: agent:: unaggregated_receipts:: UnaggregatedReceipts ;
9+ use crate :: { agent:: unaggregated_receipts:: UnaggregatedReceipts , backoff :: BackoffInfo } ;
1010
1111use super :: { AllocationStats , DefaultFromExtra , DurationInfo } ;
1212
@@ -84,31 +84,6 @@ impl BufferInfo {
8484 }
8585}
8686
87- #[ derive( Debug , Clone ) ]
88- pub struct BackoffInfo {
89- failed_ravs_count : u32 ,
90- failed_rav_backoff_time : Instant ,
91- }
92-
93- impl BackoffInfo {
94- pub fn ok ( & mut self ) {
95- self . failed_ravs_count = 0 ;
96- }
97-
98- pub fn fail ( & mut self ) {
99- // backoff = max(100ms * 2 ^ retries, 60s)
100- self . failed_rav_backoff_time = Instant :: now ( )
101- + ( Duration :: from_millis ( 100 ) * 2u32 . pow ( self . failed_ravs_count ) )
102- . min ( Duration :: from_secs ( 60 ) ) ;
103- self . failed_ravs_count += 1 ;
104- }
105-
106- pub fn in_backoff ( & self ) -> bool {
107- let now = Instant :: now ( ) ;
108- now < self . failed_rav_backoff_time
109- }
110- }
111-
11287impl DefaultFromExtra < DurationInfo > for SenderFeeStats {
11388 fn default_from_extra ( extra : & DurationInfo ) -> Self {
11489 SenderFeeStats {
@@ -121,15 +96,6 @@ impl DefaultFromExtra<DurationInfo> for SenderFeeStats {
12196 }
12297}
12398
124- impl Default for BackoffInfo {
125- fn default ( ) -> Self {
126- Self {
127- failed_ravs_count : 0 ,
128- failed_rav_backoff_time : Instant :: now ( ) ,
129- }
130- }
131- }
132-
13399impl AllocationStats < UnaggregatedReceipts > for SenderFeeStats {
134100 fn update ( & mut self , v : UnaggregatedReceipts ) {
135101 self . total_fee = v. value ;
0 commit comments