Skip to content

Commit ec7a361

Browse files
wire --erigondb.domain.steps-in-frozen-file for stage_exec and seg retire (#21025)
## Summary Wire the existing `--erigondb.domain.steps-in-frozen-file` flag into two more entry points so the domain-only merge cap can be overridden when running these tools directly: - **`integration stage_exec`** — registers the flag and applies it via `AggOpts.ErigondbDomainStepsInFrozenFile` when constructing the aggregator singleton. - **`erigon seg retire`** — registers the flag on the `seg retire` subcommand and applies it via a new `Aggregator.SetErigondbDomainStepsInFrozenFile` runtime setter (the aggregator is constructed via `openAgg` here, so the override is applied post-construction, before any merge work begins). History/inverted-index merges are unaffected — the flag still only adjusts the domain merge cap, matching the main `erigon` binary's behavior. Both commits cherry-picked from the `explores_3` exploration branch. ## Test plan - [x] `make erigon integration` builds clean - [x] `make lint` reports 0 issues - [ ] Manual smoke: run `integration stage_exec --erigondb.domain.steps-in-frozen-file=Inf` and `erigon seg retire --erigondb.domain.steps-in-frozen-file=64` against a test datadir, confirm the override-log line fires and merges respect the new cap
1 parent a81cc87 commit ec7a361

4 files changed

Lines changed: 68 additions & 6 deletions

File tree

cmd/integration/commands/flags.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ var (
4848

4949
dbWriteMap bool
5050

51-
chainTipMode bool
52-
clearCommitment bool
53-
resume bool
54-
noHistory bool
55-
syncCfg = ethconfig.Defaults.Sync
51+
chainTipMode bool
52+
clearCommitment bool
53+
resume bool
54+
noHistory bool
55+
erigondbDomainStepsInFrozenFile string
56+
syncCfg = ethconfig.Defaults.Sync
5657
)
5758

5859
func must(err error) {
@@ -203,6 +204,12 @@ func withChaosMonkey(cmd *cobra.Command) {
203204
cmd.Flags().BoolVar(&syncCfg.ChaosMonkey, utils.ChaosMonkeyFlag.Name, utils.ChaosMonkeyFlag.Value, utils.ChaosMonkeyFlag.Usage)
204205
}
205206

207+
func withErigondbDomainStepsInFrozenFile(cmd *cobra.Command) {
208+
cmd.Flags().StringVar(&erigondbDomainStepsInFrozenFile,
209+
utils.ErigondbDomainStepsInFrozenFileFlag.Name, "",
210+
utils.ErigondbDomainStepsInFrozenFileFlag.Usage)
211+
}
212+
206213
// withStageBase applies flags common to most stage commands: config, datadir, chain, chaos monkey, heimdall, unwind.
207214
func withStageBase(cmd *cobra.Command) {
208215
withConfig(cmd)

cmd/integration/commands/stages.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"runtime"
2626
"slices"
27+
"strconv"
2728
"strings"
2829
"sync"
2930
"time"
@@ -36,11 +37,13 @@ import (
3637
"golang.org/x/sync/semaphore"
3738

3839
"github.com/erigontech/erigon/cl/clparams"
40+
"github.com/erigontech/erigon/cmd/utils"
3941
"github.com/erigontech/erigon/common"
4042
"github.com/erigontech/erigon/common/dbg"
4143
"github.com/erigontech/erigon/common/dir"
4244
"github.com/erigontech/erigon/common/estimate"
4345
"github.com/erigontech/erigon/common/log/v3"
46+
"github.com/erigontech/erigon/db/config3"
4447
"github.com/erigontech/erigon/db/datadir"
4548
"github.com/erigontech/erigon/db/fromdb"
4649
"github.com/erigontech/erigon/db/integrity"
@@ -322,6 +325,7 @@ func init() {
322325
withPruneTo(cmdStageExec)
323326
withTraceFlags(cmdStageExec)
324327
withChainTipMode(cmdStageExec)
328+
withErigondbDomainStepsInFrozenFile(cmdStageExec)
325329
rootCmd.AddCommand(cmdStageExec)
326330

327331
withStageBase(cmdStageExecReplay)
@@ -1073,7 +1077,28 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl
10731077
if erigonDBSettings, err = dbstate.ResolveErigonDBSettings(dirs, logger, false); err != nil {
10741078
return
10751079
}
1076-
_aggSingleton = dbstate.New(dirs).Logger(logger).WithErigonDBSettings(erigonDBSettings).MustOpen(ctx, db)
1080+
aggOpts := dbstate.New(dirs).Logger(logger).WithErigonDBSettings(erigonDBSettings)
1081+
if erigondbDomainStepsInFrozenFile != "" {
1082+
var v uint64
1083+
if strings.EqualFold(erigondbDomainStepsInFrozenFile, "inf") {
1084+
v = config3.UnboundedDomainMerge
1085+
} else {
1086+
parsed, perr := strconv.ParseUint(erigondbDomainStepsInFrozenFile, 10, 64)
1087+
if perr != nil || parsed == 0 {
1088+
err = fmt.Errorf("invalid --%s value %q: must be a positive integer or \"Inf\"",
1089+
utils.ErigondbDomainStepsInFrozenFileFlag.Name, erigondbDomainStepsInFrozenFile)
1090+
return
1091+
}
1092+
v = parsed
1093+
}
1094+
stepsStr := "Inf"
1095+
if v != config3.UnboundedDomainMerge {
1096+
stepsStr = fmt.Sprintf("%d", v)
1097+
}
1098+
logger.Info("domain merge cap overridden", "steps_in_frozen_file", stepsStr)
1099+
aggOpts = aggOpts.ErigondbDomainStepsInFrozenFile(v)
1100+
}
1101+
_aggSingleton = aggOpts.MustOpen(ctx, db)
10771102

10781103
_aggSingleton.SetProduceMod(snapCfg.ProduceE3)
10791104
_aggSingleton.SetFrozenBlocksProvider(blockReader)

cmd/utils/app/snapshots_cmd.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ var snapshotCommand = cli.Command{
189189
Usage: "create snapshots from the specified block number",
190190
Flags: joinFlags([]cli.Flag{
191191
&utils.DataDirFlag,
192+
&utils.ErigondbDomainStepsInFrozenFileFlag,
192193
}),
193194
},
194195
{
@@ -3192,6 +3193,27 @@ func doRetireCommand(cliCtx *cli.Context, dirs datadir.Dirs) error {
31923193
defer br.MadvNormal().DisableReadAhead()
31933194
defer agg.MadvNormal().DisableReadAhead()
31943195

3196+
if cliCtx.IsSet(utils.ErigondbDomainStepsInFrozenFileFlag.Name) {
3197+
s := cliCtx.String(utils.ErigondbDomainStepsInFrozenFileFlag.Name)
3198+
var v uint64
3199+
if strings.EqualFold(s, "inf") {
3200+
v = config3.UnboundedDomainMerge
3201+
} else {
3202+
parsed, perr := strconv.ParseUint(s, 10, 64)
3203+
if perr != nil || parsed == 0 {
3204+
return fmt.Errorf("invalid --%s value %q: must be a positive integer or \"Inf\"",
3205+
utils.ErigondbDomainStepsInFrozenFileFlag.Name, s)
3206+
}
3207+
v = parsed
3208+
}
3209+
stepsStr := "Inf"
3210+
if v != config3.UnboundedDomainMerge {
3211+
stepsStr = fmt.Sprintf("%d", v)
3212+
}
3213+
logger.Info("domain merge cap overridden", "steps_in_frozen_file", stepsStr)
3214+
agg.SetErigondbDomainStepsInFrozenFile(v)
3215+
}
3216+
31953217
blockSnapBuildSema := semaphore.NewWeighted(int64(runtime.NumCPU()))
31963218
agg.SetSnapshotBuildSema(blockSnapBuildSema)
31973219

db/state/aggregator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ func (a *Aggregator) Dirs() datadir.Dirs { return a.dirs }
273273
func (a *Aggregator) StepsInFrozenFile() uint64 { return a.stepsInFrozenFile.Load() }
274274
func (a *Aggregator) Logger() log.Logger { return a.logger }
275275

276+
// SetErigondbDomainStepsInFrozenFile applies a domain-only merge cap override at runtime.
277+
// Intended for one-shot tools (e.g. `erigon seg retire`) that construct the aggregator
278+
// via openAgg and need to override the cap after construction. Must be called before any
279+
// merge work begins.
280+
func (a *Aggregator) SetErigondbDomainStepsInFrozenFile(steps uint64) {
281+
a.erigondbDomainStepsInFrozenFile = steps
282+
}
283+
276284
func (a *Aggregator) ForTestReplaceKeysInValues(domain kv.Domain, v bool) {
277285
a.d[domain].ReplaceKeysInValues = v
278286
}

0 commit comments

Comments
 (0)