Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RpcDaemon doesn't see recently retired blocks #9318

Merged
merged 17 commits into from
Jan 29, 2024
16 changes: 13 additions & 3 deletions erigon-lib/kv/remotedbserver/remotedbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,27 @@ func (s *KvServer) SendStateChanges(_ context.Context, sc *remote.StateChangeBat
s.stateChangeStreams.Pub(sc)
}

func (s *KvServer) Snapshots(_ context.Context, _ *remote.SnapshotsRequest) (*remote.SnapshotsReply, error) {
func (s *KvServer) Snapshots(_ context.Context, _ *remote.SnapshotsRequest) (reply *remote.SnapshotsReply, err error) {
defer func() {
if rec := recover(); rec != nil {
err = fmt.Errorf("%v, %s", rec, dbg.Stack())
}
}()
if s.blockSnapshots == nil || reflect.ValueOf(s.blockSnapshots).IsNil() { // nolint
return &remote.SnapshotsReply{BlocksFiles: []string{}, HistoryFiles: []string{}}, nil
}

blockFiles := s.blockSnapshots.Files()
if s.borSnapshots != nil {
if s.borSnapshots != nil && !reflect.ValueOf(s.borSnapshots).IsNil() { // nolint
blockFiles = append(blockFiles, s.borSnapshots.Files()...)
}

return &remote.SnapshotsReply{BlocksFiles: blockFiles, HistoryFiles: s.historySnapshots.Files()}, nil
reply = &remote.SnapshotsReply{BlocksFiles: blockFiles}
if s.historySnapshots != nil && !reflect.ValueOf(s.historySnapshots).IsNil() { // nolint
reply.HistoryFiles = s.historySnapshots.Files()
}

return reply, nil
}

type StateChangePubSub struct {
Expand Down
46 changes: 46 additions & 0 deletions eth/integrity/snap_blocks_read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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
}
7 changes: 6 additions & 1 deletion turbo/app/snapshots_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/metrics"
"github.com/ledgerwatch/erigon/eth/integrity"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli/v2"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -223,10 +224,14 @@ func doIntegrity(cliCtx *cli.Context) error {
defer agg.Close()

blockReader, _ := blockRetire.IO()
if err := blockReader.(*freezeblocks.BlockReader).IntegrityTxnID(false); err != nil {
if err := integrity.SnapBlocksRead(chainDB, blockReader, ctx, false); err != nil {
return err
}

//if err := blockReader.(*freezeblocks.BlockReader).IntegrityTxnID(false); err != nil {
// return err
//}

//if err := integrity.E3HistoryNoSystemTxs(ctx, chainDB, agg); err != nil {
// return err
//}
Expand Down
Loading