@@ -1069,18 +1069,26 @@ export class BaseProvider extends Provider implements EnsProvider {
1069
1069
if ( ! event . _inflight ) {
1070
1070
event . _inflight = true ;
1071
1071
1072
- // Filter from the last known event; due to load-balancing
1072
+ // This is the first filter for this event, so we want to
1073
+ // restrict events to events that happened no earlier than now
1074
+ if ( event . _lastBlockNumber === - 2 ) {
1075
+ event . _lastBlockNumber = blockNumber - 1 ;
1076
+ }
1077
+
1078
+ // Filter from the last *known* event; due to load-balancing
1073
1079
// and some nodes returning updated block numbers before
1074
1080
// indexing events, a logs result with 0 entries cannot be
1075
1081
// trusted and we must retry a range which includes it again
1076
1082
const filter = event . filter ;
1077
1083
filter . fromBlock = event . _lastBlockNumber + 1 ;
1078
1084
filter . toBlock = blockNumber ;
1079
1085
1080
- // Prevent fitler ranges from growing too wild
1081
- if ( filter . toBlock - this . _maxFilterBlockRange > filter . fromBlock ) {
1082
- filter . fromBlock = filter . toBlock - this . _maxFilterBlockRange ;
1083
- }
1086
+ // Prevent fitler ranges from growing too wild, since it is quite
1087
+ // likely there just haven't been any events to move the lastBlockNumber.
1088
+ const minFromBlock = filter . toBlock - this . _maxFilterBlockRange ;
1089
+ if ( minFromBlock > filter . fromBlock ) { filter . fromBlock = minFromBlock ; }
1090
+
1091
+ if ( filter . fromBlock < 0 ) { filter . fromBlock = 0 ; }
1084
1092
1085
1093
const runner = this . getLogs ( filter ) . then ( ( logs ) => {
1086
1094
// Allow the next getLogs
0 commit comments