Skip to content

Commit

Permalink
refactor(exporter): make el payload exporter less stingy, report unse…
Browse files Browse the repository at this point in the history
…en blocks in bigtable
  • Loading branch information
invis-bitfly committed Jan 15, 2025
1 parent 5c40cb5 commit e97224b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions backend/pkg/exporter/modules/execution_payloads_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"context"
"database/sql"
"fmt"
"maps"
"math/big"
"slices"
"sync"
"time"

Expand Down Expand Up @@ -120,7 +122,6 @@ func (d *executionPayloadsExporter) maintainTable() (err error) {
ctx, abortProcessing := context.WithCancel(context.Background())
defer abortProcessing() // to kill the errgroup if something goes wrong
group, _ := errgroup.WithContext(ctx)

// coroutine to process the blocks
group.Go(func() error {
var block *types.Eth1BlockIndexed
Expand Down Expand Up @@ -171,6 +172,10 @@ func (d *executionPayloadsExporter) maintainTable() (err error) {
// sanity checks: check if any block hashes are 0x0000000000000000000000000000000000000000000000000000000000000000 or duplicate, check if count matches expected
seen := make(map[string]bool)
emptyBlockHash := bytes.Repeat([]byte{0}, 32)
unseenBlockNumbers := make(map[uint64]bool)
for i := minBlock; i <= maxBlock; i++ {
unseenBlockNumbers[i] = true
}
err = error(nil)
counter := 0
for _, r := range resData {
Expand All @@ -195,13 +200,21 @@ func (d *executionPayloadsExporter) maintainTable() (err error) {
counter++
}
seen[string(r.BlockHash)] = true
if _, ok := unseenBlockNumbers[r.BlockNumber]; !ok {
err = fmt.Errorf("error processing blocks: block number %v is not in the unseen map", r.BlockNumber)
log.Error(err, "error processing blocks", 0)
counter++
}
delete(unseenBlockNumbers, r.BlockNumber) // noop in case it doesn't exist
}

if err != nil {
return err
}

if uint64(len(resData)) != maxBlock-minBlock+1 {
return fmt.Errorf("error processing blocks: expected %v blocks, got %v", maxBlock-minBlock+1, len(resData))
u := slices.Collect(maps.Keys(unseenBlockNumbers))
if len(u) > 0 && slices.Min(u) < maxBlock-10 { // we are fine with the last 10 blocks being missing, the indexer might not have caught up yet
return fmt.Errorf("error processing blocks: expected %v blocks, got %v, unseen map: %v", maxBlock-minBlock+1, len(resData), maps.Keys(unseenBlockNumbers))
}

// update the execution_payloads table
Expand Down

0 comments on commit e97224b

Please sign in to comment.