From 5444e70038fd5655e3ff13415c62cb188b16168a Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sat, 31 Jul 2021 12:25:56 +0700 Subject: [PATCH] allow to run stages once if --nodiscover (#2470) --- cmd/integration/commands/stages.go | 3 ++- eth/backend.go | 3 ++- eth/stagedsync/stage_headers.go | 8 ++++++++ turbo/stages/mock_sentry.go | 1 + turbo/stages/stageloop.go | 5 ++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index 9025364b289..59a88dd5edc 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -25,6 +25,7 @@ import ( "github.com/ledgerwatch/erigon/ethdb/privateapi" "github.com/ledgerwatch/erigon/ethdb/prune" "github.com/ledgerwatch/erigon/migrations" + "github.com/ledgerwatch/erigon/p2p" "github.com/ledgerwatch/erigon/params" stages2 "github.com/ledgerwatch/erigon/turbo/stages" "github.com/ledgerwatch/erigon/turbo/txpool" @@ -940,7 +941,7 @@ func newSync(ctx context.Context, db kv.RwDB, miningConfig *params.MiningConfig) cfg.Miner = *miningConfig } - sync, err := stages2.NewStagedSync2(context.Background(), logger, db, cfg, + sync, err := stages2.NewStagedSync(context.Background(), logger, db, p2p.Config{}, cfg, downloadServer, tmpdir, txPool, diff --git a/eth/backend.go b/eth/backend.go index 67a51c06136..e80649c6c60 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -428,10 +428,11 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere backend.txPoolP2PServer.TxFetcher = fetcher.NewTxFetcher(backend.txPool.Has, backend.txPool.AddRemotes, fetchTx) config.BodyDownloadTimeoutSeconds = 30 - backend.stagedSync, err = stages2.NewStagedSync2( + backend.stagedSync, err = stages2.NewStagedSync( backend.downloadCtx, backend.logger, backend.chainKV, + stack.Config().P2P, *config, backend.downloadServer, tmpdir, diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index 5ddd4a4390a..dff92690a46 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -32,6 +32,7 @@ type HeadersCfg struct { announceNewHashes func(context.Context, []headerdownload.Announce) penalize func(context.Context, []headerdownload.PenaltyItem) batchSize datasize.ByteSize + noP2PDiscovery bool } func StageHeadersCfg( @@ -42,6 +43,7 @@ func StageHeadersCfg( announceNewHashes func(context.Context, []headerdownload.Announce), penalize func(context.Context, []headerdownload.PenaltyItem), batchSize datasize.ByteSize, + noP2PDiscovery bool, ) HeadersCfg { return HeadersCfg{ db: db, @@ -51,6 +53,7 @@ func StageHeadersCfg( announceNewHashes: announceNewHashes, penalize: penalize, batchSize: batchSize, + noP2PDiscovery: noP2PDiscovery, } } @@ -101,6 +104,11 @@ func HeadersForward( return nil } + // Allow other stages to run 1 cycle if no network available + if initialCycle && cfg.noP2PDiscovery { + return nil + } + log.Info(fmt.Sprintf("[%s] Waiting for headers...", logPrefix), "from", headerProgress) localTd, err := rawdb.ReadTd(tx, hash, headerProgress) diff --git a/turbo/stages/mock_sentry.go b/turbo/stages/mock_sentry.go index c1b8827a1e1..9faba4c7c07 100644 --- a/turbo/stages/mock_sentry.go +++ b/turbo/stages/mock_sentry.go @@ -241,6 +241,7 @@ func MockWithEverything(t *testing.T, gspec *core.Genesis, key *ecdsa.PrivateKey propagateNewBlockHashes, penalize, cfg.BatchSize, + false, ), stagedsync.StageBlockHashesCfg(mock.DB, mock.tmpdir), stagedsync.StageSnapshotHeadersCfg(mock.DB, ethconfig.Snapshot{Enabled: false}, nil, nil, mock.Log), diff --git a/turbo/stages/stageloop.go b/turbo/stages/stageloop.go index 1f8b587e91f..56a8bde7c26 100644 --- a/turbo/stages/stageloop.go +++ b/turbo/stages/stageloop.go @@ -18,6 +18,7 @@ import ( "github.com/ledgerwatch/erigon/eth/ethconfig" "github.com/ledgerwatch/erigon/eth/stagedsync" "github.com/ledgerwatch/erigon/eth/stagedsync/stages" + "github.com/ledgerwatch/erigon/p2p" "github.com/ledgerwatch/erigon/turbo/shards" "github.com/ledgerwatch/erigon/turbo/snapshotsync" "github.com/ledgerwatch/erigon/turbo/stages/headerdownload" @@ -194,10 +195,11 @@ func MiningStep(ctx context.Context, kv kv.RwDB, mining *stagedsync.Sync) (err e return nil } -func NewStagedSync2( +func NewStagedSync( ctx context.Context, logger log.Logger, db kv.RwDB, + p2pCfg p2p.Config, cfg ethconfig.Config, controlServer *download.ControlServerImpl, tmpdir string, @@ -220,6 +222,7 @@ func NewStagedSync2( controlServer.PropagateNewBlockHashes, controlServer.Penalize, cfg.BatchSize, + p2pCfg.NoDiscovery, ), stagedsync.StageBlockHashesCfg(db, tmpdir), stagedsync.StageSnapshotHeadersCfg(db, cfg.Snapshot, client, snapshotMigrator, logger),