File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
packages/adapters/eth/src/failover Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -94,16 +94,17 @@ impl ErrorTracker {
94
94
mempool_drop_threshold : usize ,
95
95
mempool_drop_window : Duration ,
96
96
) -> bool {
97
- let now = Instant :: now ( ) ;
98
97
let failure_window = self . mempool_drop_window . read ( ) . await ;
98
+ let cutoff = Instant :: now ( ) - mempool_drop_window;
99
99
100
- // Count entries within the time window
101
- let valid_entries_count = failure_window
100
+ // Since entries are ordered by timestamp, we can iterate from the back
101
+ // and stop as soon as we find an entry outside the time window
102
+ failure_window
102
103
. iter ( )
103
- . filter ( | & timestamp| now . duration_since ( * timestamp ) <= mempool_drop_window )
104
- . count ( ) ;
105
-
106
- valid_entries_count >= mempool_drop_threshold
104
+ . rev ( )
105
+ . take_while ( | & & timestamp| timestamp >= cutoff )
106
+ . count ( )
107
+ >= mempool_drop_threshold
107
108
}
108
109
109
110
pub async fn note_mempool_drop (
You can’t perform that action at this time.
0 commit comments