Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/utils/app/snapshots_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import (
"github.com/erigontech/erigon/db/rawdb/blockio"
"github.com/erigontech/erigon/db/recsplit"
"github.com/erigontech/erigon/db/seg"
"github.com/erigontech/erigon/db/services"
"github.com/erigontech/erigon/db/snapshotsync"
"github.com/erigontech/erigon/db/snapshotsync/freezeblocks"
"github.com/erigontech/erigon/db/snaptype"
Expand Down Expand Up @@ -2962,6 +2963,11 @@ func doRetireCommand(cliCtx *cli.Context, dirs datadir.Dirs) error {
if err != nil {
return err
}
maxCollatable, err := services.MaxCollatableTxNum(ctx, tx, blockReader)
if err != nil {
return err
}
lastTxNum = min(lastTxNum, maxCollatable)
return nil
}); err != nil {
return err
Expand Down
33 changes: 33 additions & 0 deletions db/services/snapshot_progress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.

package services

import (
"context"

"github.com/erigontech/erigon/db/kv"
)

// MaxCollatableTxNum returns the upper bound txNum that state collation may
// target without running ahead of block snapshot files. Callers of
// Aggregator.BuildFiles / BuildFilesInBackground must cap their target txNum
// by this value — otherwise state files may advance past block files, an
// unrecoverable state that requires manual `erigon seg rm-state --latest` to
// release.
func MaxCollatableTxNum(ctx context.Context, tx kv.Tx, blockReader FullBlockReader) (uint64, error) {
return blockReader.TxnumReader().Max(ctx, tx, blockReader.FrozenBlocks())
}
7 changes: 6 additions & 1 deletion execution/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/erigontech/erigon/db/rawdb"
"github.com/erigontech/erigon/db/rawdb/rawdbhelpers"
"github.com/erigontech/erigon/db/rawdb/rawtemporaldb"
"github.com/erigontech/erigon/db/services"
dbstate "github.com/erigontech/erigon/db/state"
"github.com/erigontech/erigon/db/state/execctx"
"github.com/erigontech/erigon/execution/commitment"
Expand Down Expand Up @@ -141,7 +142,11 @@ func ExecV3(ctx context.Context,
}

if execStage.SyncMode() == stages.ModeApplyingBlocks {
agg.BuildFilesInBackground(initialTxNum)
maxCollatable, err := services.MaxCollatableTxNum(ctx, applyTx, cfg.blockReader)
if err != nil {
return err
}
agg.BuildFilesInBackground(min(initialTxNum, maxCollatable))
}

var (
Expand Down
Loading