@@ -13,6 +13,7 @@ import (
1313 "github.com/fystack/multichain-indexer/pkg/events"
1414 "github.com/fystack/multichain-indexer/pkg/infra"
1515 "github.com/fystack/multichain-indexer/pkg/store/blockstore"
16+ "github.com/fystack/multichain-indexer/pkg/store/catchupstore"
1617 "github.com/fystack/multichain-indexer/pkg/store/pubkeystore"
1718)
1819
@@ -36,6 +37,7 @@ func NewCatchupWorker(
3637 cfg config.ChainConfig ,
3738 kv infra.KVStore ,
3839 blockStore blockstore.Store ,
40+ catchupStore catchupstore.Store ,
3941 emitter events.Emitter ,
4042 pubkeyStore pubkeystore.Store ,
4143 failedChan chan FailedBlockEvent ,
@@ -47,6 +49,7 @@ func NewCatchupWorker(
4749 cfg ,
4850 kv ,
4951 blockStore ,
52+ catchupStore ,
5053 emitter ,
5154 pubkeyStore ,
5255 ModeCatchup ,
@@ -116,26 +119,22 @@ func (cw *CatchupWorker) runCatchup() {
116119}
117120
118121func (cw * CatchupWorker ) loadCatchupProgress () []blockstore.CatchupRange {
119- registry := status .EnsureStatusRegistry (cw .statusRegistry )
120-
121122 // Load existing catchup ranges from the store. The catchup worker only loads
122123 // ranges; creating new ranges is the responsibility of the regular worker
123124 // (via determineStartingBlock or skipAheadIfLagging).
124- progress , err := cw .blockStore . GetCatchupProgress ( cw .chain .GetNetworkInternalCode ())
125+ progress , err := cw .catchupStore . GetProgress ( cw . ctx , cw .chain .GetNetworkInternalCode ())
125126 if err != nil {
126127 cw .logger .Warn ("Failed to load catchup progress" ,
127128 "chain" , cw .chain .GetName (),
128129 "error" , err ,
129130 )
130- registry .SetCatchupRanges (cw .chain .GetName (), nil )
131131 return nil
132132 }
133133
134134 cw .logger .Info ("Loaded catchup progress" ,
135135 "chain" , cw .chain .GetName (),
136136 "progress_ranges" , len (progress ),
137137 )
138- registry .SetCatchupRanges (cw .chain .GetName (), progress )
139138 return progress
140139}
141140
@@ -319,14 +318,13 @@ func (cw *CatchupWorker) processRange(r blockstore.CatchupRange, workerID int) e
319318func (cw * CatchupWorker ) saveProgress (r blockstore.CatchupRange , current uint64 ) {
320319 cw .progressMu .Lock ()
321320 defer cw .progressMu .Unlock ()
322- registry := status .EnsureStatusRegistry (cw .statusRegistry )
323321 cw .logger .Debug ("Saving catchup progress" ,
324322 "chain" , cw .chain .GetName (),
325323 "range" , fmt .Sprintf ("%d-%d" , r .Start , r .End ),
326324 "current" , current ,
327325 )
328326 current = min (current , r .End )
329- if err := cw .blockStore . SaveCatchupProgress ( cw .chain .GetNetworkInternalCode (), r .Start , r .End , current ); err != nil {
327+ if err := cw .catchupStore . SaveProgress ( cw . ctx , cw .chain .GetNetworkInternalCode (), r .Start , r .End , current ); err != nil {
330328 cw .logger .Warn ("Failed to save catchup progress" ,
331329 "chain" , cw .chain .GetName (),
332330 "range" , fmt .Sprintf ("%d-%d" , r .Start , r .End ),
@@ -335,11 +333,6 @@ func (cw *CatchupWorker) saveProgress(r blockstore.CatchupRange, current uint64)
335333 )
336334 return
337335 }
338- registry .UpsertCatchupRanges (cw .chain .GetName (), []blockstore.CatchupRange {{
339- Start : r .Start ,
340- End : r .End ,
341- Current : current ,
342- }})
343336 for i := range cw .blockRanges {
344337 if cw .blockRanges [i ].Start == r .Start && cw .blockRanges [i ].End == r .End {
345338 cw .blockRanges [i ].Current = current
@@ -351,23 +344,20 @@ func (cw *CatchupWorker) saveProgress(r blockstore.CatchupRange, current uint64)
351344func (cw * CatchupWorker ) completeRange (r blockstore.CatchupRange ) error {
352345 cw .progressMu .Lock ()
353346 defer cw .progressMu .Unlock ()
354- registry := status .EnsureStatusRegistry (cw .statusRegistry )
355347
356348 cw .logger .Info ("Completing catchup range" ,
357349 "chain" , cw .chain .GetName (),
358350 "range" , fmt .Sprintf ("%d-%d" , r .Start , r .End ),
359351 )
360352
361- if err := cw .blockStore . DeleteCatchupRange ( cw .chain .GetNetworkInternalCode (), r .Start , r .End ); err != nil {
353+ if err := cw .catchupStore . DeleteRange ( cw . ctx , cw .chain .GetNetworkInternalCode (), r .Start , r .End ); err != nil {
362354 cw .logger .Warn ("Failed to delete catchup range" ,
363355 "chain" , cw .chain .GetName (),
364356 "range" , fmt .Sprintf ("%d-%d" , r .Start , r .End ),
365357 "error" , err ,
366358 )
367359 return err
368360 }
369- registry .DeleteCatchupRange (cw .chain .GetName (), r .Start , r .End )
370-
371361 // Remove from local ranges
372362 for i , existing := range cw .blockRanges {
373363 if existing .Start == r .Start && existing .End == r .End {
@@ -406,15 +396,12 @@ func (cw *CatchupWorker) Close() error {
406396 )
407397 }
408398
409- if err := cw .blockStore . SaveCatchupRanges ( cw .chain .GetNetworkInternalCode (), rangesToSave ); err != nil {
399+ if err := cw .catchupStore . SaveRanges ( cw . ctx , cw .chain .GetNetworkInternalCode (), rangesToSave ); err != nil {
410400 cw .logger .Error ("Failed to batch save progress on close" ,
411401 "chain" , cw .chain .GetName (),
412402 "ranges" , len (rangesToSave ),
413403 "error" , err ,
414404 )
415- } else {
416- registry := status .EnsureStatusRegistry (cw .statusRegistry )
417- registry .UpsertCatchupRanges (cw .chain .GetName (), rangesToSave )
418405 }
419406
420407 return nil
0 commit comments