@@ -22,12 +22,24 @@ import (
22
22
"github.com/filecoin-project/lotus/chain/types"
23
23
)
24
24
25
+ const maxLookBackForWait = 120 // one hour of tipsets
26
+
25
27
var (
26
28
ErrMaxResultsReached = xerrors .New ("filter matches too many events, try a more restricted filter" )
27
- ErrRangeInFuture = xerrors .New ("range end is in the future" )
28
29
)
29
30
30
- const maxLookBackForWait = 120 // one hour of tipsets
31
+ type ErrRangeInFuture struct {
32
+ HighestEpoch int
33
+ }
34
+
35
+ func (e * ErrRangeInFuture ) Error () string {
36
+ return fmt .Sprintf ("range end is in the future, highest epoch: %d" , e .HighestEpoch )
37
+ }
38
+
39
+ func (e * ErrRangeInFuture ) Is (target error ) bool {
40
+ _ , ok := target .(* ErrRangeInFuture )
41
+ return ok
42
+ }
31
43
32
44
type executedMessage struct {
33
45
msg types.ChainMsg
@@ -287,7 +299,7 @@ func (si *SqliteIndexer) checkFilterTipsetsIndexed(ctx context.Context, f *Event
287
299
func (si * SqliteIndexer ) checkRangeIndexedStatus (ctx context.Context , minHeight abi.ChainEpoch , maxHeight abi.ChainEpoch ) error {
288
300
head := si .cs .GetHeaviestTipSet ()
289
301
if minHeight > head .Height () || maxHeight > head .Height () {
290
- return ErrRangeInFuture
302
+ return & ErrRangeInFuture { HighestEpoch : int ( head . Height ())}
291
303
}
292
304
293
305
// Find the first non-null round in the range
@@ -305,7 +317,7 @@ func (si *SqliteIndexer) checkRangeIndexedStatus(ctx context.Context, minHeight
305
317
if err != nil {
306
318
return xerrors .Errorf ("failed to find last non-null round: %w" , err )
307
319
}
308
- // If all rounds are null, consider the range valid
320
+ // We should have already rulled out all rounds being null in the startCid check
309
321
if endCid == nil {
310
322
return xerrors .Errorf ("unexpected error finding last non-null round: all rounds are null but start round is not (%d to %d)" , minHeight , maxHeight )
311
323
}
@@ -344,8 +356,7 @@ func (si *SqliteIndexer) findFirstNonNullRound(ctx context.Context, minHeight ab
344
356
// else null round, keep searching
345
357
continue
346
358
}
347
- minHeight = height // Update the minHeight to the found height
348
- return cid , minHeight , nil
359
+ return cid , height , nil
349
360
}
350
361
// All rounds are null
351
362
return nil , 0 , nil
@@ -356,14 +367,13 @@ func (si *SqliteIndexer) findLastNonNullRound(ctx context.Context, maxHeight abi
356
367
for height := maxHeight ; height >= minHeight ; height -- {
357
368
cid , err := si .getTipsetKeyCidByHeight (ctx , height )
358
369
if err == nil {
359
- maxHeight = height // Update the maxHeight to the found height
360
- return cid , maxHeight , nil
370
+ return cid , height , nil
361
371
}
362
372
if ! errors .Is (err , ErrNotFound ) {
363
373
return nil , 0 , xerrors .Errorf ("failed to get tipset key cid for height %d: %w" , height , err )
364
374
}
365
375
}
366
-
376
+ // All rounds are null
367
377
return nil , 0 , nil
368
378
}
369
379
0 commit comments