Skip to content

Commit 6e34cc4

Browse files
Revert "eth/downloader: move SyncMode to package eth/ethconfig (ethereum#30847)"
This reverts commit 4afab7e.
1 parent 09d6a73 commit 6e34cc4

File tree

17 files changed

+55
-65
lines changed

17 files changed

+55
-65
lines changed

cmd/utils/flags.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
"github.com/ethereum/go-ethereum/crypto/kzg4844"
5555
"github.com/ethereum/go-ethereum/eth"
5656
"github.com/ethereum/go-ethereum/eth/catalyst"
57+
"github.com/ethereum/go-ethereum/eth/downloader"
5758
"github.com/ethereum/go-ethereum/eth/ethconfig"
5859
"github.com/ethereum/go-ethereum/eth/filters"
5960
"github.com/ethereum/go-ethereum/eth/gasprice"
@@ -1722,7 +1723,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17221723
godebug.SetGCPercent(int(gogc))
17231724

17241725
if ctx.IsSet(SyncTargetFlag.Name) {
1725-
cfg.SyncMode = ethconfig.FullSync // dev sync target forces full sync
1726+
cfg.SyncMode = downloader.FullSync // dev sync target forces full sync
17261727
} else if ctx.IsSet(SyncModeFlag.Name) {
17271728
value := ctx.String(SyncModeFlag.Name)
17281729
if err = cfg.SyncMode.UnmarshalText([]byte(value)); err != nil {
@@ -1825,7 +1826,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18251826
}
18261827
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
18271828
// If snap-sync is requested, this flag is also required
1828-
if cfg.SyncMode == ethconfig.SnapSync {
1829+
if cfg.SyncMode == downloader.SnapSync {
18291830
if !ctx.Bool(SnapshotFlag.Name) {
18301831
log.Warn("Snap sync requested, enabling --snapshot")
18311832
}
@@ -1897,7 +1898,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18971898
if !ctx.IsSet(NetworkIdFlag.Name) {
18981899
cfg.NetworkId = 1337
18991900
}
1900-
cfg.SyncMode = ethconfig.FullSync
1901+
cfg.SyncMode = downloader.FullSync
19011902
// Create new developer account or reuse existing one
19021903
var (
19031904
developer accounts.Account

eth/backend.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -966,26 +966,26 @@ func (s *Ethereum) SetBlockchain(blockchain *core.BlockChain) {
966966

967967
// SyncMode retrieves the current sync mode, either explicitly set, or derived
968968
// from the chain status.
969-
func (s *Ethereum) SyncMode() ethconfig.SyncMode {
969+
func (s *Ethereum) SyncMode() downloader.SyncMode {
970970
// If we're in snap sync mode, return that directly
971971
if s.handler.snapSync.Load() {
972-
return ethconfig.SnapSync
972+
return downloader.SnapSync
973973
}
974974
// We are probably in full sync, but we might have rewound to before the
975975
// snap sync pivot, check if we should re-enable snap sync.
976976
head := s.blockchain.CurrentBlock()
977977
if pivot := rawdb.ReadLastPivotNumber(s.chainDb); pivot != nil {
978978
if head.Number.Uint64() < *pivot {
979-
return ethconfig.SnapSync
979+
return downloader.SnapSync
980980
}
981981
}
982982
// We are in a full sync, but the associated head state is missing. To complete
983983
// the head state, forcefully rerun the snap sync. Note it doesn't mean the
984984
// persistent state is corrupted, just mismatch with the head block.
985985
if !s.blockchain.HasState(head.Root) {
986986
log.Info("Reenabled snap sync as chain is stateless")
987-
return ethconfig.SnapSync
987+
return downloader.SnapSync
988988
}
989989
// Nope, we're really full syncing
990-
return ethconfig.FullSync
990+
return downloader.FullSync
991991
}

eth/catalyst/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/ethereum/go-ethereum/core/types"
3535
"github.com/ethereum/go-ethereum/core/vm"
3636
"github.com/ethereum/go-ethereum/eth"
37-
"github.com/ethereum/go-ethereum/eth/ethconfig"
37+
"github.com/ethereum/go-ethereum/eth/downloader"
3838
"github.com/ethereum/go-ethereum/internal/version"
3939
"github.com/ethereum/go-ethereum/log"
4040
"github.com/ethereum/go-ethereum/miner"
@@ -925,7 +925,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
925925
// tries to make it import a block. That should be denied as pushing something
926926
// into the database directly will conflict with the assumptions of snap sync
927927
// that it has an empty db that it can fill itself.
928-
if api.eth.SyncMode() != ethconfig.FullSync {
928+
if api.eth.SyncMode() != downloader.FullSync {
929929
return api.delayPayloadImport(block), nil
930930
}
931931
if !api.eth.BlockChain().HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
@@ -1038,7 +1038,7 @@ func (api *ConsensusAPI) delayPayloadImport(block *types.Block) engine.PayloadSt
10381038
// payload as non-integratable on top of the existing sync. We'll just
10391039
// have to rely on the beacon client to forcefully update the head with
10401040
// a forkchoice update request.
1041-
if api.eth.SyncMode() == ethconfig.FullSync {
1041+
if api.eth.SyncMode() == downloader.FullSync {
10421042
// In full sync mode, failure to import a well-formed block can only mean
10431043
// that the parent state is missing and the syncer rejected extending the
10441044
// current cycle with the new payload.

eth/catalyst/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/crypto"
4141
"github.com/ethereum/go-ethereum/crypto/kzg4844"
4242
"github.com/ethereum/go-ethereum/eth"
43+
"github.com/ethereum/go-ethereum/eth/downloader"
4344
"github.com/ethereum/go-ethereum/eth/ethconfig"
4445
"github.com/ethereum/go-ethereum/internal/version"
4546
"github.com/ethereum/go-ethereum/miner"
@@ -453,7 +454,7 @@ func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block)
453454

454455
mcfg := miner.DefaultConfig
455456
mcfg.Etherbase = testAddr
456-
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
457+
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
457458
ethservice, err := eth.New(n, ethcfg)
458459
if err != nil {
459460
t.Fatal("can't create eth service:", err)

eth/catalyst/simulated_beacon_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/core/types"
2929
"github.com/ethereum/go-ethereum/crypto"
3030
"github.com/ethereum/go-ethereum/eth"
31+
"github.com/ethereum/go-ethereum/eth/downloader"
3132
"github.com/ethereum/go-ethereum/eth/ethconfig"
3233
"github.com/ethereum/go-ethereum/miner"
3334
"github.com/ethereum/go-ethereum/node"
@@ -49,7 +50,7 @@ func startSimulatedBeaconEthService(t *testing.T, genesis *core.Genesis, period
4950
t.Fatal("can't create node:", err)
5051
}
5152

52-
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: miner.DefaultConfig}
53+
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: miner.DefaultConfig}
5354
ethservice, err := eth.New(n, ethcfg)
5455
if err != nil {
5556
t.Fatal("can't create eth service:", err)

eth/catalyst/tester.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/eth"
25-
"github.com/ethereum/go-ethereum/eth/ethconfig"
25+
"github.com/ethereum/go-ethereum/eth/downloader"
2626
"github.com/ethereum/go-ethereum/log"
2727
"github.com/ethereum/go-ethereum/node"
2828
)
@@ -64,7 +64,7 @@ func (tester *FullSyncTester) Start() error {
6464

6565
// Trigger beacon sync with the provided block hash as trusted
6666
// chain head.
67-
err := tester.backend.Downloader().BeaconDevSync(ethconfig.FullSync, tester.target, tester.closed)
67+
err := tester.backend.Downloader().BeaconDevSync(downloader.FullSync, tester.target, tester.closed)
6868
if err != nil {
6969
log.Info("Failed to trigger beacon sync", "err", err)
7070
}

eth/downloader/beaconsync.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/ethereum/go-ethereum/common"
2525
"github.com/ethereum/go-ethereum/core/rawdb"
2626
"github.com/ethereum/go-ethereum/core/types"
27-
"github.com/ethereum/go-ethereum/eth/ethconfig"
2827
"github.com/ethereum/go-ethereum/log"
2928
)
3029

@@ -200,9 +199,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
200199
var chainHead *types.Header
201200

202201
switch d.getMode() {
203-
case ethconfig.FullSync:
202+
case FullSync:
204203
chainHead = d.blockchain.CurrentBlock()
205-
case ethconfig.SnapSync:
204+
case SnapSync:
206205
chainHead = d.blockchain.CurrentSnapBlock()
207206
default:
208207
chainHead = d.lightchain.CurrentHeader()
@@ -222,9 +221,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
222221

223222
var linked bool
224223
switch d.getMode() {
225-
case ethconfig.FullSync:
224+
case FullSync:
226225
linked = d.blockchain.HasBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
227-
case ethconfig.SnapSync:
226+
case SnapSync:
228227
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
229228
default:
230229
linked = d.blockchain.HasHeader(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
@@ -260,9 +259,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
260259
var known bool
261260

262261
switch d.getMode() {
263-
case ethconfig.FullSync:
262+
case FullSync:
264263
known = d.blockchain.HasBlock(h.Hash(), n)
265-
case ethconfig.SnapSync:
264+
case SnapSync:
266265
known = d.blockchain.HasFastBlock(h.Hash(), n)
267266
default:
268267
known = d.lightchain.HasHeader(h.Hash(), n)

eth/downloader/bor_downloader.go

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/ethereum/go-ethereum/core/state/snapshot"
3232
"github.com/ethereum/go-ethereum/core/types"
3333
"github.com/ethereum/go-ethereum/eth/downloader/whitelist"
34-
"github.com/ethereum/go-ethereum/eth/ethconfig"
3534
"github.com/ethereum/go-ethereum/eth/protocols/snap"
3635
"github.com/ethereum/go-ethereum/ethdb"
3736
"github.com/ethereum/go-ethereum/event"
@@ -84,17 +83,6 @@ var (
8483
ErrMergeTransition = errors.New("legacy sync reached the merge")
8584
)
8685

87-
// SyncMode defines the sync method of the downloader.
88-
// Deprecated: use ethconfig.SyncMode instead
89-
type SyncMode = ethconfig.SyncMode
90-
91-
const (
92-
// Deprecated: use ethconfig.FullSync
93-
FullSync = ethconfig.FullSync
94-
// Deprecated: use ethconfig.SnapSync
95-
SnapSync = ethconfig.SnapSync
96-
)
97-
9886
// peerDropFn is a callback type for dropping a peer detected as malicious.
9987
type peerDropFn func(id string)
10088

@@ -279,11 +267,10 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
279267

280268
current := uint64(0)
281269
mode := d.getMode()
282-
283-
switch {
284-
case d.blockchain != nil && mode == ethconfig.FullSync:
270+
switch mode {
271+
case FullSync:
285272
current = d.blockchain.CurrentBlock().Number.Uint64()
286-
case d.blockchain != nil && mode == ethconfig.SnapSync:
273+
case SnapSync:
287274
current = d.blockchain.CurrentSnapBlock().Number.Uint64()
288275
case d.lightchain != nil:
289276
current = d.lightchain.CurrentHeader().Number.Uint64()
@@ -431,7 +418,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
431418
if d.notified.CompareAndSwap(false, true) {
432419
log.Info("Block synchronisation started")
433420
}
434-
if mode == ethconfig.SnapSync {
421+
if mode == SnapSync {
435422
// Snap sync will directly modify the persistent state, making the entire
436423
// trie database unusable until the state is fully synced. To prevent any
437424
// subsequent state reads, explicitly disable the trie database and state
@@ -569,7 +556,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
569556
// threshold (i.e. new chain). In that case we won't really fast sync
570557
// anyway, but still need a valid pivot block to avoid some code hitting
571558
// nil panics on access.
572-
if mode == ethconfig.SnapSync && pivot == nil {
559+
if mode == SnapSync && pivot == nil {
573560
pivot = d.blockchain.CurrentBlock()
574561
}
575562

@@ -599,7 +586,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
599586
d.syncStatsLock.Unlock()
600587

601588
// Ensure our origin point is below any snap sync pivot point
602-
if mode == ethconfig.SnapSync {
589+
if mode == SnapSync {
603590
if height <= uint64(fsMinFullBlocks) {
604591
origin = 0
605592
} else {
@@ -614,10 +601,10 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
614601
}
615602

616603
d.committed.Store(true)
617-
if mode == ethconfig.SnapSync && pivot.Number.Uint64() != 0 {
604+
if mode == SnapSync && pivot.Number.Uint64() != 0 {
618605
d.committed.Store(false)
619606
}
620-
if mode == ethconfig.SnapSync {
607+
if mode == SnapSync {
621608
// Set the ancient data limitation. If we are running snap sync, all block
622609
// data older than ancientLimit will be written to the ancient store. More
623610
// recent data will be written to the active database and will wait for the
@@ -694,13 +681,13 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
694681
func() error { return d.processHeaders(origin+1, td, ttd, beaconMode) },
695682
}
696683

697-
if mode == ethconfig.SnapSync {
684+
if mode == SnapSync {
698685
d.pivotLock.Lock()
699686
d.pivotHeader = pivot
700687
d.pivotLock.Unlock()
701688

702689
fetchers = append(fetchers, func() error { return d.processSnapSyncContent() })
703-
} else if mode == ethconfig.FullSync {
690+
} else if mode == FullSync {
704691
fetchers = append(fetchers, func() error { return d.processFullSyncContent(ttd, beaconMode) })
705692
}
706693

@@ -1453,7 +1440,7 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
14531440
chunkHashes := hashes[:limit]
14541441

14551442
// In case of header only syncing, validate the chunk immediately
1456-
if mode == ethconfig.SnapSync {
1443+
if mode == SnapSync {
14571444
// Although the received headers might be all valid, a legacy
14581445
// PoW/PoA sync must not accept post-merge headers. Make sure
14591446
// that any transition is rejected at this point.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
package ethconfig
17+
package downloader
1818

1919
import "fmt"
2020

eth/downloader/queue.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/ethereum/go-ethereum/common/prque"
3131
"github.com/ethereum/go-ethereum/core/types"
3232
"github.com/ethereum/go-ethereum/crypto/kzg4844"
33-
"github.com/ethereum/go-ethereum/eth/ethconfig"
3433
"github.com/ethereum/go-ethereum/log"
3534
"github.com/ethereum/go-ethereum/metrics"
3635
"github.com/ethereum/go-ethereum/params"
@@ -185,7 +184,7 @@ func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
185184
defer q.lock.Unlock()
186185

187186
q.closed = false
188-
q.mode = ethconfig.FullSync
187+
q.mode = FullSync
189188

190189
q.headerHead = common.Hash{}
191190
q.headerPendPool = make(map[string]*fetchRequest)
@@ -335,7 +334,7 @@ func (q *queue) Schedule(headers []*types.Header, hashes []common.Hash, from uin
335334
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
336335
}
337336
// Queue for receipt retrieval
338-
if q.mode == ethconfig.SnapSync && !header.EmptyReceipts() {
337+
if q.mode == SnapSync && !header.EmptyReceipts() {
339338
if _, ok := q.receiptTaskPool[hash]; ok {
340339
log.Warn("Header already scheduled for receipt fetch", "number", header.Number, "hash", hash)
341340
} else {
@@ -541,7 +540,7 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
541540
// we can ask the resultcache if this header is within the
542541
// "prioritized" segment of blocks. If it is not, we need to throttle
543542

544-
stale, throttle, item, err := q.resultCache.AddFetch(header, q.mode == ethconfig.SnapSync)
543+
stale, throttle, item, err := q.resultCache.AddFetch(header, q.mode == SnapSync)
545544
if stale {
546545
// Don't put back in the task queue, this item has already been
547546
// delivered upstream

0 commit comments

Comments
 (0)