This commit is contained in:
Alex Sharov 2021-06-19 13:32:35 +07:00 committed by GitHub
parent 54dc77af40
commit de24b427bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 80 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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

View File

@ -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)

View File

@ -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,