diff --git a/eth/integrity/commitment_progress_check.go b/eth/integrity/commitment_progress_check.go new file mode 100644 index 00000000000..2784dc9c45d --- /dev/null +++ b/eth/integrity/commitment_progress_check.go @@ -0,0 +1,32 @@ +package integrity + +import ( + "context" + "fmt" + + "github.com/erigontech/erigon/db/kv" + "github.com/erigontech/erigon/turbo/services" +) + +func CheckStateProgress(ctx context.Context, db kv.TemporalRoDB, blockReader services.FullBlockReader, failFast bool) (err error) { + // state files should not be ahead of blocks files + tx, err := db.BeginTemporalRo(ctx) + if err != nil { + return err + } + defer tx.Rollback() + + stateFileProgress := tx.Debug().DomainFiles(kv.CommitmentDomain).EndRootNum() + + txnumReader := blockReader.TxnumReader(ctx) + blockFileProgress, err := txnumReader.Max(tx, blockReader.FrozenBlocks()) + if err != nil { + return err + } + + if stateFileProgress > blockFileProgress { + return fmt.Errorf("state files progress (%d) is ahead of blocks files progress (%d)", stateFileProgress, blockFileProgress) + } + + return nil +} diff --git a/eth/integrity/integrity_action_type.go b/eth/integrity/integrity_action_type.go index d8cdc17411f..564f1ca656b 100644 --- a/eth/integrity/integrity_action_type.go +++ b/eth/integrity/integrity_action_type.go @@ -29,12 +29,13 @@ const ( BorEvents Check = "BorEvents" BorSpans Check = "BorSpans" BorCheckpoints Check = "BorCheckpoints" + StateProgress Check = "StateProgress" // state files is not ahead of blocks files Publishable Check = "Publishable" ) var AllChecks = []Check{ Blocks, HeaderNoGaps, BlocksTxnID, InvertedIndex, HistoryNoSystemTxs, ReceiptsNoDups, BorEvents, - BorSpans, BorCheckpoints, RCacheNoDups, Publishable, + BorSpans, BorCheckpoints, RCacheNoDups, StateProgress, Publishable, } var NonDefaultChecks = []Check{} diff --git a/turbo/app/snapshots_cmd.go b/turbo/app/snapshots_cmd.go index 982fb56b94d..33924531e0f 100644 --- a/turbo/app/snapshots_cmd.go +++ b/turbo/app/snapshots_cmd.go @@ -897,6 +897,10 @@ func doIntegrity(cliCtx *cli.Context) error { if err := integrity.CheckRCacheNoDups(ctx, db, blockReader, failFast); err != nil { return err } + case integrity.StateProgress: + if err := integrity.CheckStateProgress(ctx, db, blockReader, failFast); err != nil { + return err + } case integrity.Publishable: if err := doPublishable(cliCtx); err != nil { return err