erigon-pulse/eth/integrity/snap_blocks_read.go
Andrew Ashikhmin ffb6b83c09
(release) RpcDaemon doesn't see recently retired blocks (#9336)
Cherry pick PR #9318

---------

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
2024-01-29 13:49:47 +01:00

47 lines
1.1 KiB
Go

package integrity
import (
"context"
"fmt"
"time"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/log/v3"
)
func SnapBlocksRead(db kv.RoDB, blockReader services.FullBlockReader, ctx context.Context, failFast bool) error {
defer log.Info("[integrity] SnapBlocksRead: done")
logEvery := time.NewTicker(10 * time.Second)
defer logEvery.Stop()
maxBlockNum := blockReader.Snapshots().SegmentsMax()
for i := uint64(0); i < maxBlockNum; i += 10_000 {
if err := db.View(ctx, func(tx kv.Tx) error {
b, err := blockReader.BlockByNumber(ctx, tx, i)
if err != nil {
return err
}
if b == nil {
err := fmt.Errorf("block not found in snapshots: %d\n", i)
if failFast {
return err
}
log.Error("[integrity] SnapBlocksRead", "err", err)
}
return nil
}); err != nil {
return err
}
select {
case <-ctx.Done():
return nil
case <-logEvery.C:
log.Info("[integrity] SnapBlocksRead", "blockNum", fmt.Sprintf("%dK/%dK", i/1000, maxBlockNum/1000))
default:
}
}
return nil
}