Skip to content

Commit a7f74f7

Browse files
cp Integrity check: compare state progress and block progress (#18002)
issue: #17911
1 parent 61d4ffc commit a7f74f7

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package integrity
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/erigontech/erigon/db/kv"
8+
"github.com/erigontech/erigon/turbo/services"
9+
)
10+
11+
func CheckStateProgress(ctx context.Context, db kv.TemporalRoDB, blockReader services.FullBlockReader, failFast bool) (err error) {
12+
// state files should not be ahead of blocks files
13+
tx, err := db.BeginTemporalRo(ctx)
14+
if err != nil {
15+
return err
16+
}
17+
defer tx.Rollback()
18+
19+
stateFileProgress := tx.Debug().DomainFiles(kv.CommitmentDomain).EndRootNum()
20+
21+
txnumReader := blockReader.TxnumReader(ctx)
22+
blockFileProgress, err := txnumReader.Max(tx, blockReader.FrozenBlocks())
23+
if err != nil {
24+
return err
25+
}
26+
27+
if stateFileProgress > blockFileProgress {
28+
return fmt.Errorf("state files progress (%d) is ahead of blocks files progress (%d)", stateFileProgress, blockFileProgress)
29+
}
30+
31+
return nil
32+
}

eth/integrity/integrity_action_type.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ const (
2929
BorEvents Check = "BorEvents"
3030
BorSpans Check = "BorSpans"
3131
BorCheckpoints Check = "BorCheckpoints"
32+
StateProgress Check = "StateProgress" // state files is not ahead of blocks files
3233
Publishable Check = "Publishable"
3334
)
3435

3536
var AllChecks = []Check{
3637
Blocks, HeaderNoGaps, BlocksTxnID, InvertedIndex, HistoryNoSystemTxs, ReceiptsNoDups, BorEvents,
37-
BorSpans, BorCheckpoints, RCacheNoDups, Publishable,
38+
BorSpans, BorCheckpoints, RCacheNoDups, StateProgress, Publishable,
3839
}
3940

4041
var NonDefaultChecks = []Check{}

turbo/app/snapshots_cmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@ func doIntegrity(cliCtx *cli.Context) error {
897897
if err := integrity.CheckRCacheNoDups(ctx, db, blockReader, failFast); err != nil {
898898
return err
899899
}
900+
case integrity.StateProgress:
901+
if err := integrity.CheckStateProgress(ctx, db, blockReader, failFast); err != nil {
902+
return err
903+
}
900904
case integrity.Publishable:
901905
if err := doPublishable(cliCtx); err != nil {
902906
return err

0 commit comments

Comments
 (0)