Skip to content

Commit

Permalink
set initial inexing block via genesis if no blobs exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Mar 19, 2024
1 parent 972db87 commit 79f1b2b
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/blobstorage/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,40 @@ func InitFromConfig(ctx context.Context, i *Indexer, cfg *Config) (err error) {

func (i *Indexer) Start() error {
i.wg.Add(1)

go i.eventLoop(i.ctx, i.latestIndexedBlockNumber)

return nil
}

func (i *Indexer) setInitialIndexingBlock(
ctx context.Context,
) error {
// get most recently processed block height from the DB
latest, err := i.blobHashRepo.FindLatestBlockID()
if err != nil {
return err
}

// if its non-zero ,we use that. if it is zero, it means we havent
// processed any blobs, so we should get the state variables below.
if latest != 0 {
i.latestIndexedBlockNumber = latest

return nil
}

// and then start from the genesis height.
stateVars, err := i.taikoL1.GetStateVariables(nil)
if err != nil {
return err
}

i.latestIndexedBlockNumber = stateVars.A.GenesisHeight - 1

return nil
}

// eventLoop runs on an interval ticker, every N seconds we will check
// the latest processed block, and the latest header, and filter every block in between
// for BlockProposed events, if we are not already filtering. This lets us avoid
Expand Down Expand Up @@ -143,13 +172,10 @@ func (i *Indexer) withRetry(f func() error) error {
}

func (i *Indexer) filter(ctx context.Context) error {
n, err := i.blobHashRepo.FindLatestBlockID()
if err != nil {
if err := i.setInitialIndexingBlock(i.ctx); err != nil {
return err
}

i.latestIndexedBlockNumber = n

// get the latest header
header, err := i.ethClient.HeaderByNumber(i.ctx, nil)
if err != nil {
Expand Down

0 comments on commit 79f1b2b

Please sign in to comment.