Skip to content

Commit ffb6b83

Browse files
(release) RpcDaemon doesn't see recently retired blocks (#9336)
Cherry pick PR #9318 --------- Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
1 parent 9f1cd65 commit ffb6b83

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

erigon-lib/kv/remotedbserver/remotedbserver.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,27 @@ func (s *KvServer) SendStateChanges(_ context.Context, sc *remote.StateChangeBat
458458
s.stateChangeStreams.Pub(sc)
459459
}
460460

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

466471
blockFiles := s.blockSnapshots.Files()
467-
if s.borSnapshots != nil {
472+
if s.borSnapshots != nil && !reflect.ValueOf(s.borSnapshots).IsNil() { // nolint
468473
blockFiles = append(blockFiles, s.borSnapshots.Files()...)
469474
}
470475

471-
return &remote.SnapshotsReply{BlocksFiles: blockFiles, HistoryFiles: s.historySnapshots.Files()}, nil
476+
reply = &remote.SnapshotsReply{BlocksFiles: blockFiles}
477+
if s.historySnapshots != nil && !reflect.ValueOf(s.historySnapshots).IsNil() { // nolint
478+
reply.HistoryFiles = s.historySnapshots.Files()
479+
}
480+
481+
return reply, nil
472482
}
473483

474484
type StateChangePubSub struct {

eth/integrity/snap_blocks_read.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package integrity
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
"github.com/ledgerwatch/erigon-lib/kv"
9+
"github.com/ledgerwatch/erigon/turbo/services"
10+
"github.com/ledgerwatch/log/v3"
11+
)
12+
13+
func SnapBlocksRead(db kv.RoDB, blockReader services.FullBlockReader, ctx context.Context, failFast bool) error {
14+
defer log.Info("[integrity] SnapBlocksRead: done")
15+
logEvery := time.NewTicker(10 * time.Second)
16+
defer logEvery.Stop()
17+
18+
maxBlockNum := blockReader.Snapshots().SegmentsMax()
19+
for i := uint64(0); i < maxBlockNum; i += 10_000 {
20+
if err := db.View(ctx, func(tx kv.Tx) error {
21+
b, err := blockReader.BlockByNumber(ctx, tx, i)
22+
if err != nil {
23+
return err
24+
}
25+
if b == nil {
26+
err := fmt.Errorf("block not found in snapshots: %d\n", i)
27+
if failFast {
28+
return err
29+
}
30+
log.Error("[integrity] SnapBlocksRead", "err", err)
31+
}
32+
return nil
33+
}); err != nil {
34+
return err
35+
}
36+
37+
select {
38+
case <-ctx.Done():
39+
return nil
40+
case <-logEvery.C:
41+
log.Info("[integrity] SnapBlocksRead", "blockNum", fmt.Sprintf("%dK/%dK", i/1000, maxBlockNum/1000))
42+
default:
43+
}
44+
}
45+
return nil
46+
}

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
const (
3434
VersionMajor = 2 // Major version component of the current release
3535
VersionMinor = 57 // Minor version component of the current release
36-
VersionMicro = 1 // Patch version component of the current release
36+
VersionMicro = 2 // Patch version component of the current release
3737
VersionModifier = "" // Modifier component of the current release
3838
VersionKeyCreated = "ErigonVersionCreated"
3939
VersionKeyFinished = "ErigonVersionFinished"

turbo/app/snapshots_cmd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/ledgerwatch/erigon-lib/common/dbg"
2020
"github.com/ledgerwatch/erigon-lib/common/dir"
2121
"github.com/ledgerwatch/erigon-lib/metrics"
22+
"github.com/ledgerwatch/erigon/eth/integrity"
2223
"github.com/ledgerwatch/log/v3"
2324
"github.com/urfave/cli/v2"
2425
"golang.org/x/sync/semaphore"
@@ -223,10 +224,14 @@ func doIntegrity(cliCtx *cli.Context) error {
223224
defer agg.Close()
224225

225226
blockReader, _ := blockRetire.IO()
226-
if err := blockReader.(*freezeblocks.BlockReader).IntegrityTxnID(false); err != nil {
227+
if err := integrity.SnapBlocksRead(chainDB, blockReader, ctx, false); err != nil {
227228
return err
228229
}
229230

231+
//if err := blockReader.(*freezeblocks.BlockReader).IntegrityTxnID(false); err != nil {
232+
// return err
233+
//}
234+
230235
//if err := integrity.E3HistoryNoSystemTxs(ctx, chainDB, agg); err != nil {
231236
// return err
232237
//}

0 commit comments

Comments
 (0)