@@ -15,9 +15,7 @@ import (
1515// SyncIndexers is a special index that includes multiple indexes,
1616// which stay in sync when blocks are added.
1717type SyncIndexers struct {
18- indexers []blockdao.BlockIndexer
19- startHeights []uint64 // start height of each indexer, which will be determined when the indexer is started
20- minStartHeight uint64 // minimum start height of all indexers
18+ indexers []blockdao.BlockIndexer
2119}
2220
2321// NewSyncIndexers creates a new SyncIndexers
@@ -33,7 +31,7 @@ func (ig *SyncIndexers) Start(ctx context.Context) error {
3331 return err
3432 }
3533 }
36- return ig . initStartHeight ()
34+ return nil
3735}
3836
3937// Stop stops the indexer group
@@ -48,11 +46,7 @@ func (ig *SyncIndexers) Stop(ctx context.Context) error {
4846
4947// PutBlock puts a block into the indexers in the group
5048func (ig * SyncIndexers ) PutBlock (ctx context.Context , blk * block.Block ) error {
51- for i , indexer := range ig .indexers {
52- // check if the block is higher than the indexer's start height
53- if blk .Height () < ig .startHeights [i ] {
54- continue
55- }
49+ for _ , indexer := range ig .indexers {
5650 // check if the block is higher than the indexer's height
5751 height , err := indexer .Height ()
5852 if err != nil {
@@ -79,11 +73,6 @@ func (ig *SyncIndexers) DeleteTipBlock(ctx context.Context, blk *block.Block) er
7973 return nil
8074}
8175
82- // StartHeight returns the minimum start height of the indexers in the group
83- func (ig * SyncIndexers ) StartHeight () uint64 {
84- return ig .minStartHeight
85- }
86-
8776// Height returns the minimum height of the indexers in the group
8877func (ig * SyncIndexers ) Height () (uint64 , error ) {
8978 var height uint64
@@ -98,28 +87,3 @@ func (ig *SyncIndexers) Height() (uint64, error) {
9887 }
9988 return height , nil
10089}
101-
102- // initStartHeight initializes the start height of the indexers in the group
103- // for every indexer, the start height is the maximum of tipheight+1 and startheight
104- func (ig * SyncIndexers ) initStartHeight () error {
105- ig .minStartHeight = 0
106- ig .startHeights = make ([]uint64 , len (ig .indexers ))
107- for i , indexer := range ig .indexers {
108- tipHeight , err := indexer .Height ()
109- if err != nil {
110- return err
111- }
112- indexStartHeight := tipHeight + 1
113- if indexerWithStart , ok := indexer .(blockdao.BlockIndexerWithStart ); ok {
114- startHeight := indexerWithStart .StartHeight ()
115- if startHeight > indexStartHeight {
116- indexStartHeight = startHeight
117- }
118- }
119- ig .startHeights [i ] = indexStartHeight
120- if i == 0 || indexStartHeight < ig .minStartHeight {
121- ig .minStartHeight = indexStartHeight
122- }
123- }
124- return nil
125- }
0 commit comments