Revert "eth/downloader: move SyncMode to package eth/ethconfig (#30847)"

This reverts commit 4afab7ef76.
This commit is contained in:
Pratik Patil 2025-05-02 14:43:27 +05:30
parent 09d6a731b9
commit 6e34cc4f2c
No known key found for this signature in database
GPG key ID: AFDCA496554874B3
17 changed files with 55 additions and 65 deletions

View file

@ -54,6 +54,7 @@ import (
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/eth/gasprice"
@ -1722,7 +1723,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
godebug.SetGCPercent(int(gogc))
if ctx.IsSet(SyncTargetFlag.Name) {
cfg.SyncMode = ethconfig.FullSync // dev sync target forces full sync
cfg.SyncMode = downloader.FullSync // dev sync target forces full sync
} else if ctx.IsSet(SyncModeFlag.Name) {
value := ctx.String(SyncModeFlag.Name)
if err = cfg.SyncMode.UnmarshalText([]byte(value)); err != nil {
@ -1825,7 +1826,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
// If snap-sync is requested, this flag is also required
if cfg.SyncMode == ethconfig.SnapSync {
if cfg.SyncMode == downloader.SnapSync {
if !ctx.Bool(SnapshotFlag.Name) {
log.Warn("Snap sync requested, enabling --snapshot")
}
@ -1897,7 +1898,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
}
cfg.SyncMode = ethconfig.FullSync
cfg.SyncMode = downloader.FullSync
// Create new developer account or reuse existing one
var (
developer accounts.Account

View file

@ -966,17 +966,17 @@ func (s *Ethereum) SetBlockchain(blockchain *core.BlockChain) {
// SyncMode retrieves the current sync mode, either explicitly set, or derived
// from the chain status.
func (s *Ethereum) SyncMode() ethconfig.SyncMode {
func (s *Ethereum) SyncMode() downloader.SyncMode {
// If we're in snap sync mode, return that directly
if s.handler.snapSync.Load() {
return ethconfig.SnapSync
return downloader.SnapSync
}
// We are probably in full sync, but we might have rewound to before the
// snap sync pivot, check if we should re-enable snap sync.
head := s.blockchain.CurrentBlock()
if pivot := rawdb.ReadLastPivotNumber(s.chainDb); pivot != nil {
if head.Number.Uint64() < *pivot {
return ethconfig.SnapSync
return downloader.SnapSync
}
}
// We are in a full sync, but the associated head state is missing. To complete
@ -984,8 +984,8 @@ func (s *Ethereum) SyncMode() ethconfig.SyncMode {
// persistent state is corrupted, just mismatch with the head block.
if !s.blockchain.HasState(head.Root) {
log.Info("Reenabled snap sync as chain is stateless")
return ethconfig.SnapSync
return downloader.SnapSync
}
// Nope, we're really full syncing
return ethconfig.FullSync
return downloader.FullSync
}

View file

@ -34,7 +34,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/internal/version"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner"
@ -925,7 +925,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
// tries to make it import a block. That should be denied as pushing something
// into the database directly will conflict with the assumptions of snap sync
// that it has an empty db that it can fill itself.
if api.eth.SyncMode() != ethconfig.FullSync {
if api.eth.SyncMode() != downloader.FullSync {
return api.delayPayloadImport(block), nil
}
if !api.eth.BlockChain().HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
@ -1038,7 +1038,7 @@ func (api *ConsensusAPI) delayPayloadImport(block *types.Block) engine.PayloadSt
// payload as non-integratable on top of the existing sync. We'll just
// have to rely on the beacon client to forcefully update the head with
// a forkchoice update request.
if api.eth.SyncMode() == ethconfig.FullSync {
if api.eth.SyncMode() == downloader.FullSync {
// In full sync mode, failure to import a well-formed block can only mean
// that the parent state is missing and the syncer rejected extending the
// current cycle with the new payload.

View file

@ -40,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/version"
"github.com/ethereum/go-ethereum/miner"
@ -453,7 +454,7 @@ func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block)
mcfg := miner.DefaultConfig
mcfg.Etherbase = testAddr
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
ethservice, err := eth.New(n, ethcfg)
if err != nil {
t.Fatal("can't create eth service:", err)

View file

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node"
@ -49,7 +50,7 @@ func startSimulatedBeaconEthService(t *testing.T, genesis *core.Genesis, period
t.Fatal("can't create node:", err)
}
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: miner.DefaultConfig}
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: miner.DefaultConfig}
ethservice, err := eth.New(n, ethcfg)
if err != nil {
t.Fatal("can't create eth service:", err)

View file

@ -22,7 +22,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
)
@ -64,7 +64,7 @@ func (tester *FullSyncTester) Start() error {
// Trigger beacon sync with the provided block hash as trusted
// chain head.
err := tester.backend.Downloader().BeaconDevSync(ethconfig.FullSync, tester.target, tester.closed)
err := tester.backend.Downloader().BeaconDevSync(downloader.FullSync, tester.target, tester.closed)
if err != nil {
log.Info("Failed to trigger beacon sync", "err", err)
}

View file

@ -24,7 +24,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/log"
)
@ -200,9 +199,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
var chainHead *types.Header
switch d.getMode() {
case ethconfig.FullSync:
case FullSync:
chainHead = d.blockchain.CurrentBlock()
case ethconfig.SnapSync:
case SnapSync:
chainHead = d.blockchain.CurrentSnapBlock()
default:
chainHead = d.lightchain.CurrentHeader()
@ -222,9 +221,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
var linked bool
switch d.getMode() {
case ethconfig.FullSync:
case FullSync:
linked = d.blockchain.HasBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
case ethconfig.SnapSync:
case SnapSync:
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
default:
linked = d.blockchain.HasHeader(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
@ -260,9 +259,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
var known bool
switch d.getMode() {
case ethconfig.FullSync:
case FullSync:
known = d.blockchain.HasBlock(h.Hash(), n)
case ethconfig.SnapSync:
case SnapSync:
known = d.blockchain.HasFastBlock(h.Hash(), n)
default:
known = d.lightchain.HasHeader(h.Hash(), n)

View file

@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/downloader/whitelist"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
@ -84,17 +83,6 @@ var (
ErrMergeTransition = errors.New("legacy sync reached the merge")
)
// SyncMode defines the sync method of the downloader.
// Deprecated: use ethconfig.SyncMode instead
type SyncMode = ethconfig.SyncMode
const (
// Deprecated: use ethconfig.FullSync
FullSync = ethconfig.FullSync
// Deprecated: use ethconfig.SnapSync
SnapSync = ethconfig.SnapSync
)
// peerDropFn is a callback type for dropping a peer detected as malicious.
type peerDropFn func(id string)
@ -279,11 +267,10 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
current := uint64(0)
mode := d.getMode()
switch {
case d.blockchain != nil && mode == ethconfig.FullSync:
switch mode {
case FullSync:
current = d.blockchain.CurrentBlock().Number.Uint64()
case d.blockchain != nil && mode == ethconfig.SnapSync:
case SnapSync:
current = d.blockchain.CurrentSnapBlock().Number.Uint64()
case d.lightchain != nil:
current = d.lightchain.CurrentHeader().Number.Uint64()
@ -431,7 +418,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
if d.notified.CompareAndSwap(false, true) {
log.Info("Block synchronisation started")
}
if mode == ethconfig.SnapSync {
if mode == SnapSync {
// Snap sync will directly modify the persistent state, making the entire
// trie database unusable until the state is fully synced. To prevent any
// 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 *
// threshold (i.e. new chain). In that case we won't really fast sync
// anyway, but still need a valid pivot block to avoid some code hitting
// nil panics on access.
if mode == ethconfig.SnapSync && pivot == nil {
if mode == SnapSync && pivot == nil {
pivot = d.blockchain.CurrentBlock()
}
@ -599,7 +586,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
d.syncStatsLock.Unlock()
// Ensure our origin point is below any snap sync pivot point
if mode == ethconfig.SnapSync {
if mode == SnapSync {
if height <= uint64(fsMinFullBlocks) {
origin = 0
} else {
@ -614,10 +601,10 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
}
d.committed.Store(true)
if mode == ethconfig.SnapSync && pivot.Number.Uint64() != 0 {
if mode == SnapSync && pivot.Number.Uint64() != 0 {
d.committed.Store(false)
}
if mode == ethconfig.SnapSync {
if mode == SnapSync {
// Set the ancient data limitation. If we are running snap sync, all block
// data older than ancientLimit will be written to the ancient store. More
// 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 *
func() error { return d.processHeaders(origin+1, td, ttd, beaconMode) },
}
if mode == ethconfig.SnapSync {
if mode == SnapSync {
d.pivotLock.Lock()
d.pivotHeader = pivot
d.pivotLock.Unlock()
fetchers = append(fetchers, func() error { return d.processSnapSyncContent() })
} else if mode == ethconfig.FullSync {
} else if mode == FullSync {
fetchers = append(fetchers, func() error { return d.processFullSyncContent(ttd, beaconMode) })
}
@ -1453,7 +1440,7 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
chunkHashes := hashes[:limit]
// In case of header only syncing, validate the chunk immediately
if mode == ethconfig.SnapSync {
if mode == SnapSync {
// Although the received headers might be all valid, a legacy
// PoW/PoA sync must not accept post-merge headers. Make sure
// that any transition is rejected at this point.

View file

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package ethconfig
package downloader
import "fmt"

View file

@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
@ -185,7 +184,7 @@ func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
defer q.lock.Unlock()
q.closed = false
q.mode = ethconfig.FullSync
q.mode = FullSync
q.headerHead = common.Hash{}
q.headerPendPool = make(map[string]*fetchRequest)
@ -335,7 +334,7 @@ func (q *queue) Schedule(headers []*types.Header, hashes []common.Hash, from uin
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
}
// Queue for receipt retrieval
if q.mode == ethconfig.SnapSync && !header.EmptyReceipts() {
if q.mode == SnapSync && !header.EmptyReceipts() {
if _, ok := q.receiptTaskPool[hash]; ok {
log.Warn("Header already scheduled for receipt fetch", "number", header.Number, "hash", hash)
} else {
@ -541,7 +540,7 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
// we can ask the resultcache if this header is within the
// "prioritized" segment of blocks. If it is not, we need to throttle
stale, throttle, item, err := q.resultCache.AddFetch(header, q.mode == ethconfig.SnapSync)
stale, throttle, item, err := q.resultCache.AddFetch(header, q.mode == SnapSync)
if stale {
// Don't put back in the task queue, this item has already been
// delivered upstream

View file

@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/internal/ethapi"
@ -55,7 +56,7 @@ var FullNodeGPO = gasprice.Config{
// Defaults contains default settings for use on the Ethereum main net.
var Defaults = Config{
SyncMode: FullSync,
SyncMode: downloader.SnapSync,
NetworkId: 0, // enable auto configuration of networkID == chainID
TxLookupLimit: 2350000,
TransactionHistory: 2350000,
@ -87,7 +88,7 @@ type Config struct {
// Network ID separates blockchains on the peer-to-peer networking level. When left
// zero, the chain ID is used as network ID.
NetworkId uint64
SyncMode SyncMode
SyncMode downloader.SyncMode
// HistoryMode configures chain history retention.
HistoryMode HistoryMode

View file

@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/miner"
)
@ -19,7 +20,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
type Config struct {
Genesis *core.Genesis `toml:",omitempty"`
NetworkId uint64
SyncMode SyncMode
SyncMode downloader.SyncMode
HistoryMode HistoryMode
EthDiscoveryURLs []string
SnapDiscoveryURLs []string
@ -137,7 +138,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
type Config struct {
Genesis *core.Genesis `toml:",omitempty"`
NetworkId *uint64
SyncMode *SyncMode
SyncMode *downloader.SyncMode
HistoryMode *HistoryMode
EthDiscoveryURLs []string
SnapDiscoveryURLs []string

View file

@ -33,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/fetcher"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
@ -169,7 +168,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
handlerDoneCh: make(chan struct{}),
handlerStartCh: make(chan struct{}),
}
if config.Sync == ethconfig.FullSync {
if config.Sync == downloader.FullSync {
// The database seems empty as the current block is the genesis. Yet the snap
// block is ahead, so snap sync was enabled for this node at a certain point.
// The scenarios where this can happen is

View file

@ -29,7 +29,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p"
@ -114,7 +114,7 @@ func testForkIDSplit(t *testing.T, protocol uint) {
Chain: chainNoFork,
TxPool: newTestTxPool(),
Network: 1,
Sync: ethconfig.FullSync,
Sync: downloader.FullSync,
BloomCache: 1,
})
ethProFork, _ = newHandler(&handlerConfig{
@ -122,7 +122,7 @@ func testForkIDSplit(t *testing.T, protocol uint) {
Chain: chainProFork,
TxPool: newTestTxPool(),
Network: 1,
Sync: ethconfig.FullSync,
Sync: downloader.FullSync,
BloomCache: 1,
})
)

View file

@ -29,7 +29,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
@ -181,7 +181,7 @@ func newTestHandlerWithBlocks(blocks int) *testHandler {
Chain: chain,
TxPool: txpool,
Network: 1,
Sync: ethconfig.SnapSync,
Sync: downloader.SnapSync,
BloomCache: 1,
})
handler.Start(1000)

View file

@ -20,7 +20,7 @@ import (
"testing"
"time"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
"github.com/ethereum/go-ethereum/p2p"
@ -86,7 +86,7 @@ func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) {
time.Sleep(250 * time.Millisecond)
// Check that snap sync was disabled
if err := empty.handler.downloader.BeaconSync(ethconfig.SnapSync, full.chain.CurrentBlock(), nil); err != nil {
if err := empty.handler.downloader.BeaconSync(downloader.SnapSync, full.chain.CurrentBlock(), nil); err != nil {
t.Fatal("sync failed:", err)
}
time.Sleep(time.Second * 5) // Downloader internally has to wait a timer (3s) to be expired before exiting

View file

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/ethclient"
@ -84,7 +85,7 @@ func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config,
GasLimit: ethconfig.Defaults.Miner.GasCeil,
Alloc: alloc,
}
ethConf.SyncMode = ethconfig.FullSync
ethConf.SyncMode = downloader.FullSync
ethConf.TxPool.NoLocals = true
for _, option := range options {