Skip to content

Commit

Permalink
Rename constant to DefaultStepSize (#12928)
Browse files Browse the repository at this point in the history
I always forget that constant name when I need to check the value, let's
rename it to something more direct.

I think we could also rename/move the package "config3" to some other
place with global constants, but no idea of good place.
  • Loading branch information
wmitsuda authored Nov 30, 2024
1 parent a0889a7 commit 3b6a6ce
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func runCmd(ctx *cli.Context) error {
} else {
genesisConfig = new(types.Genesis)
}
agg, err := state2.NewAggregator(context.Background(), datadir.New(os.TempDir()), config3.HistoryV3AggregationStep, db, log.New())
agg, err := state2.NewAggregator(context.Background(), datadir.New(os.TempDir()), config3.DefaultStepSize, db, log.New())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func aggregateResultsFromStateTests(
MustOpen()
defer _db.Close()

agg, err := libstate.NewAggregator(context.Background(), dirs, config3.HistoryV3AggregationStep, _db, log.New())
agg, err := libstate.NewAggregator(context.Background(), dirs, config3.DefaultStepSize, _db, log.New())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl
blockReader := freezeblocks.NewBlockReader(_allSnapshotsSingleton, _allBorSnapshotsSingleton, _heimdallStoreSingleton, _bridgeStoreSingleton)

txNums := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, blockReader))
_aggSingleton, err = libstate.NewAggregator(ctx, dirs, config3.HistoryV3AggregationStep, db, logger)
_aggSingleton, err = libstate.NewAggregator(ctx, dirs, config3.DefaultStepSize, db, logger)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
blockReader = freezeblocks.NewBlockReader(allSnapshots, allBorSnapshots, heimdallStore, bridgeStore)
txNumsReader := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, blockReader))

agg, err := libstate.NewAggregator(ctx, cfg.Dirs, config3.HistoryV3AggregationStep, db, logger)
agg, err := libstate.NewAggregator(ctx, cfg.Dirs, config3.DefaultStepSize, db, logger)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("create aggregator: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func GenesisToBlock(g *types.Genesis, dirs datadir.Dirs, logger log.Logger) (*ty
genesisTmpDB := mdbx.New(kv.TemporaryDB, logger).InMem(dirs.DataDir).MapSize(2 * datasize.GB).GrowthStep(1 * datasize.MB).MustOpen()
defer genesisTmpDB.Close()

agg, err := state2.NewAggregator(context.Background(), dirs, config3.HistoryV3AggregationStep, genesisTmpDB, logger)
agg, err := state2.NewAggregator(context.Background(), dirs, config3.DefaultStepSize, genesisTmpDB, logger)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/rawdbhelpers/rawdbhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func IdxStepsCountV3(tx kv.Tx) float64 {
fstTxNum := binary.BigEndian.Uint64(fst)
lstTxNum := binary.BigEndian.Uint64(lst)

return float64(lstTxNum-fstTxNum) / float64(config3.HistoryV3AggregationStep)
return float64(lstTxNum-fstTxNum) / float64(config3.DefaultStepSize)
}
return 0
}
4 changes: 2 additions & 2 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func Execute(code, input []byte, cfg *Config, tempdir string) ([]byte, *state.In
if !externalState {
db := memdb.NewStateDB(tempdir)
defer db.Close()
agg, err := state3.NewAggregator(context.Background(), datadir.New(tempdir), config3.HistoryV3AggregationStep, db, log.New())
agg, err := state3.NewAggregator(context.Background(), datadir.New(tempdir), config3.DefaultStepSize, db, log.New())
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func Create(input []byte, cfg *Config, blockNr uint64) ([]byte, libcommon.Addres

db := memdb.NewStateDB(tmp)
defer db.Close()
agg, err := state3.NewAggregator(context.Background(), datadir.New(tmp), config3.HistoryV3AggregationStep, db, log.New())
agg, err := state3.NewAggregator(context.Background(), datadir.New(tmp), config3.DefaultStepSize, db, log.New())
if err != nil {
return nil, [20]byte{}, 0, err
}
Expand Down
5 changes: 2 additions & 3 deletions erigon-lib/config3/config3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package config3

// AggregationStep number of transactions in smallest static file
const HistoryV3AggregationStep = 1_562_500 // = 100M / 64. Dividers: 2, 5, 10, 20, 50, 100, 500
// const HistoryV3AggregationStep = 1_562_500 / 10
// Default number of transactions (txNums) in one "step". One static file can have [1, 64] steps.
const DefaultStepSize = 1_562_500 // = 100M / 64. Dividers: 2, 5, 10, 20, 50, 100, 500

const EnableHistoryV4InTest = true

Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/temporal/temporaltest/kv_temporal_testdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewTestDB(tb testing.TB, dirs datadir.Dirs) (db kv.RwDB, agg *state.Aggrega
}

var err error
agg, err = state.NewAggregator(context.Background(), dirs, config3.HistoryV3AggregationStep, db, log.New())
agg, err = state.NewAggregator(context.Background(), dirs, config3.DefaultStepSize, db, log.New())
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/state/files_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (files visibleFiles) LatestMergedRange() MergeRange {
return MergeRange{}
}
for i := len(files) - 1; i >= 0; i-- {
shardSize := (files[i].endTxNum - files[i].startTxNum) / config3.HistoryV3AggregationStep
shardSize := (files[i].endTxNum - files[i].startTxNum) / config3.DefaultStepSize
if shardSize > 2 {
return MergeRange{from: files[i].startTxNum, to: files[i].endTxNum}
}
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ func setUpBlockReader(ctx context.Context, db kv.RwDB, dirs datadir.Dirs, snConf
}
}
blockReader := freezeblocks.NewBlockReader(allSnapshots, allBorSnapshots, heimdallStore, bridgeStore)
agg, err := libstate.NewAggregator(ctx, dirs, config3.HistoryV3AggregationStep, db, logger)
agg, err := libstate.NewAggregator(ctx, dirs, config3.DefaultStepSize, db, logger)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *Progress) Log(suffix string, rs *state.StateV3, in *state.QueueWithRetr
//"workers", p.workersCount,
"buf", fmt.Sprintf("%s/%s", common.ByteCount(sizeEstimate), common.ByteCount(p.commitThreshold)),
"stepsInDB", fmt.Sprintf("%.2f", idxStepsAmountInDB),
"step", fmt.Sprintf("%.1f", float64(outTxNum)/float64(config3.HistoryV3AggregationStep)),
"step", fmt.Sprintf("%.1f", float64(outTxNum)/float64(config3.DefaultStepSize)),
"inMem", inMemExec,
"alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys),
)
Expand Down
2 changes: 1 addition & 1 deletion turbo/app/snapshots_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ func dbCfg(label kv.Label, path string) mdbx.MdbxOpts {
Accede(true) // integration tool: open db without creation and without blocking erigon
}
func openAgg(ctx context.Context, dirs datadir.Dirs, chainDB kv.RwDB, logger log.Logger) *libstate.Aggregator {
agg, err := libstate.NewAggregator(ctx, dirs, config3.HistoryV3AggregationStep, chainDB, logger)
agg, err := libstate.NewAggregator(ctx, dirs, config3.DefaultStepSize, chainDB, logger)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions turbo/app/squeeze_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func squeezeStorage(ctx context.Context, dirs datadir.Dirs, logger log.Logger) e
ac := agg.BeginFilesRo()
defer ac.Close()

aggOld, err := state.NewAggregator(ctx, dirsOld, config3.HistoryV3AggregationStep, db, logger)
aggOld, err := state.NewAggregator(ctx, dirsOld, config3.DefaultStepSize, db, logger)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func squeezeStorage(ctx context.Context, dirs datadir.Dirs, logger log.Logger) e
func squeezeCode(ctx context.Context, dirs datadir.Dirs, logger log.Logger) error {
db := dbCfg(kv.ChainDB, dirs.Chaindata).MustOpen()
defer db.Close()
agg, err := state.NewAggregator(ctx, dirs, config3.HistoryV3AggregationStep, db, logger)
agg, err := state.NewAggregator(ctx, dirs, config3.DefaultStepSize, db, logger)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions turbo/snapshotsync/snapshotsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ func getMinimumBlocksToDownload(tx kv.Tx, blockReader blockReader, minStep uint6
frozenBlocks := blockReader.Snapshots().SegmentsMax()
minToDownload := uint64(math.MaxUint64)
minStepToDownload := uint64(math.MaxUint32)
stateTxNum := minStep * config3.HistoryV3AggregationStep
stateTxNum := minStep * config3.DefaultStepSize
if err := blockReader.IterateFrozenBodies(func(blockNum, baseTxNum, txAmount uint64) error {
if blockNum == historyPruneTo {
minStepToDownload = (baseTxNum - (config3.HistoryV3AggregationStep - 1)) / config3.HistoryV3AggregationStep
if baseTxNum < (config3.HistoryV3AggregationStep - 1) {
minStepToDownload = (baseTxNum - (config3.DefaultStepSize - 1)) / config3.DefaultStepSize
if baseTxNum < (config3.DefaultStepSize - 1) {
minStepToDownload = 0
}
}
Expand Down

0 comments on commit 3b6a6ce

Please sign in to comment.