diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index e04361f7d..c82a58e37 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -827,7 +827,7 @@ func newSync(ctx context.Context, db ethdb.RwKV) (ethdb.StorageMode, consensus.E var sync *stagedsync.State if err := db.View(context.Background(), func(tx ethdb.Tx) (err error) { - sync, err = st.Prepare(nil, chainConfig, engine, vmConfig, nil, tx, "integration_test", sm, tmpdir, 0, ctx.Done(), nil, nil, false, nil, nil) + sync, err = st.Prepare(vmConfig, nil, tx, sm, ctx.Done(), false, nil, nil) if err != nil { return nil } diff --git a/cmd/integration/commands/state_stages.go b/cmd/integration/commands/state_stages.go index 14d5ecdd5..3c9b805da 100644 --- a/cmd/integration/commands/state_stages.go +++ b/cmd/integration/commands/state_stages.go @@ -308,7 +308,7 @@ func syncBySmallSteps(db ethdb.RwKV, miningConfig params.MiningConfig, ctx conte miningConfig.Etherbase = nextBlock.Header().Coinbase miningConfig.ExtraData = nextBlock.Header().Extra - miningStages, err := mining.Prepare(nil, chainConfig, engine, vmConfig, ethdb.NewObjectDatabase(db), tx, "integration_test", sm, tmpDir, batchSize, quit, nil, txPool, false, miningWorld, nil) + miningStages, err := mining.Prepare(vmConfig, ethdb.NewObjectDatabase(db), tx, sm, quit, false, miningWorld, nil) if err != nil { panic(err) } diff --git a/eth/stagedsync/stagebuilder.go b/eth/stagedsync/stagebuilder.go index ea5fc8bb4..b0c8fa744 100644 --- a/eth/stagedsync/stagebuilder.go +++ b/eth/stagedsync/stagebuilder.go @@ -4,17 +4,11 @@ import ( "fmt" "strings" - "github.com/c2h5oh/datasize" - "github.com/ledgerwatch/erigon/consensus" - "github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/core/types" - "github.com/ledgerwatch/erigon/core/vm" "github.com/ledgerwatch/erigon/eth/stagedsync/stages" "github.com/ledgerwatch/erigon/ethdb" - "github.com/ledgerwatch/erigon/params" "github.com/ledgerwatch/erigon/turbo/shards" "github.com/ledgerwatch/erigon/turbo/snapshotsync" - "github.com/ledgerwatch/erigon/turbo/stages/bodydownload" ) type ChainEventNotifier interface { @@ -27,28 +21,12 @@ type ChainEventNotifier interface { // StageParameters contains the stage that stages receives at runtime when initializes. // Then the stage can use it to receive different useful functions. type StageParameters struct { - d DownloaderGlue - ChainConfig *params.ChainConfig - vmConfig *vm.Config - Engine consensus.Engine - DB ethdb.Database - // TX is a current transaction that staged sync runs in. It contains all the latest changes that DB has. - // It can be used for both reading and writing. - pid string - BatchSize datasize.ByteSize // Batch size for the execution stage - storageMode ethdb.StorageMode - TmpDir string + DB ethdb.Database // QuitCh is a channel that is closed. This channel is useful to listen to when // the stage can take significant time and gracefully shutdown at Ctrl+C. - QuitCh <-chan struct{} - headersFetchers []func() error - txPool *core.TxPool - prefetchedBlocks *bodydownload.PrefetchedBlocks - stateReaderBuilder StateReaderBuilder - stateWriterBuilder StateWriterBuilder - notifier ChainEventNotifier - InitialCycle bool - mining *MiningCfg + QuitCh <-chan struct{} + InitialCycle bool + mining *MiningCfg snapshotsDir string btClient *snapshotsync.Client diff --git a/eth/stagedsync/stagedsync.go b/eth/stagedsync/stagedsync.go index 5ff4238e7..4d68121e7 100644 --- a/eth/stagedsync/stagedsync.go +++ b/eth/stagedsync/stagedsync.go @@ -1,12 +1,8 @@ package stagedsync import ( - "github.com/c2h5oh/datasize" - "github.com/ledgerwatch/erigon/consensus" - "github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/core/vm" "github.com/ledgerwatch/erigon/ethdb" - "github.com/ledgerwatch/erigon/params" "github.com/ledgerwatch/erigon/turbo/shards" "github.com/ledgerwatch/erigon/turbo/snapshotsync" "github.com/ledgerwatch/erigon/turbo/stages/bodydownload" @@ -46,32 +42,15 @@ func New(stages StageBuilders, unwindOrder UnwindOrder, params OptionalParameter } func (stagedSync *StagedSync) Prepare( - d DownloaderGlue, - chainConfig *params.ChainConfig, - engine consensus.Engine, vmConfig *vm.Config, db ethdb.Database, tx ethdb.Tx, - pid string, storageMode ethdb.StorageMode, - tmpdir string, - batchSize datasize.ByteSize, quitCh <-chan struct{}, - headersFetchers []func() error, - txPool *core.TxPool, initialCycle bool, miningConfig *MiningCfg, accumulator *shards.Accumulator, ) (*State, error) { - var readerBuilder StateReaderBuilder - if stagedSync.params.StateReaderBuilder != nil { - readerBuilder = stagedSync.params.StateReaderBuilder - } - - var writerBuilder StateWriterBuilder - if stagedSync.params.StateWriterBuilder != nil { - writerBuilder = stagedSync.params.StateWriterBuilder - } if vmConfig == nil { vmConfig = &vm.Config{} @@ -80,28 +59,14 @@ func (stagedSync *StagedSync) Prepare( stages := stagedSync.stageBuilders.Build( StageParameters{ - d: d, - ChainConfig: chainConfig, - Engine: engine, - vmConfig: vmConfig, - DB: db, - pid: pid, - storageMode: storageMode, - TmpDir: tmpdir, - QuitCh: quitCh, - headersFetchers: headersFetchers, - txPool: txPool, - BatchSize: batchSize, - prefetchedBlocks: stagedSync.PrefetchedBlocks, - stateReaderBuilder: readerBuilder, - stateWriterBuilder: writerBuilder, - notifier: stagedSync.Notifier, - InitialCycle: initialCycle, - mining: miningConfig, - snapshotsDir: stagedSync.params.SnapshotDir, - btClient: stagedSync.params.TorrentClient, - SnapshotBuilder: stagedSync.params.SnapshotMigrator, - Accumulator: accumulator, + DB: db, + QuitCh: quitCh, + InitialCycle: initialCycle, + mining: miningConfig, + snapshotsDir: stagedSync.params.SnapshotDir, + btClient: stagedSync.params.TorrentClient, + SnapshotBuilder: stagedSync.params.SnapshotMigrator, + Accumulator: accumulator, }, ) state := NewState(stages) diff --git a/turbo/stages/stageloop.go b/turbo/stages/stageloop.go index 3505f1451..2226d432d 100644 --- a/turbo/stages/stageloop.go +++ b/turbo/stages/stageloop.go @@ -146,7 +146,7 @@ func StageLoopStep( return err } - st, err1 := sync.Prepare(nil, chainConfig, nil, &vm.Config{}, ethdb.NewObjectDatabase(db), nil, "downloader", sm, ".", 512*datasize.MB, ctx.Done(), nil, nil, initialCycle, nil, accumulator) + st, err1 := sync.Prepare(&vm.Config{}, ethdb.NewObjectDatabase(db), nil, sm, ctx.Done(), initialCycle, nil, accumulator) if err1 != nil { return fmt.Errorf("prepare staged sync: %w", err1) } @@ -226,19 +226,11 @@ func MiningStep(ctx context.Context, kv ethdb.RwKV, mining *stagedsync.StagedSyn } defer tx.Rollback() miningState, err := mining.Prepare( - nil, - nil, - nil, nil, nil, tx, - "", ethdb.DefaultStorageMode, - ".", - 0, ctx.Done(), - nil, - nil, false, stagedsync.StageMiningCfg(true), nil,