eth/downloader: move SyncMode to package eth/ethconfig (#30847)
Lots of packages depend on eth/downloader just for the SyncMode type. Since we have a dedicated package for eth protocol configuration, it makes more sense to define SyncMode there, turning eth/downloader into more of a leaf package.
This commit is contained in:
parent
ae5a16f870
commit
4afab7ef76
|
@ -50,7 +50,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/catalyst"
|
"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/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/eth/filters"
|
"github.com/ethereum/go-ethereum/eth/filters"
|
||||||
"github.com/ethereum/go-ethereum/eth/gasprice"
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
|
@ -1606,7 +1605,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
godebug.SetGCPercent(int(gogc))
|
godebug.SetGCPercent(int(gogc))
|
||||||
|
|
||||||
if ctx.IsSet(SyncTargetFlag.Name) {
|
if ctx.IsSet(SyncTargetFlag.Name) {
|
||||||
cfg.SyncMode = downloader.FullSync // dev sync target forces full sync
|
cfg.SyncMode = ethconfig.FullSync // dev sync target forces full sync
|
||||||
} else if ctx.IsSet(SyncModeFlag.Name) {
|
} else if ctx.IsSet(SyncModeFlag.Name) {
|
||||||
if err = cfg.SyncMode.UnmarshalText([]byte(ctx.String(SyncModeFlag.Name))); err != nil {
|
if err = cfg.SyncMode.UnmarshalText([]byte(ctx.String(SyncModeFlag.Name))); err != nil {
|
||||||
Fatalf("invalid --syncmode flag: %v", err)
|
Fatalf("invalid --syncmode flag: %v", err)
|
||||||
|
@ -1677,7 +1676,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
}
|
}
|
||||||
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
|
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
|
||||||
// If snap-sync is requested, this flag is also required
|
// If snap-sync is requested, this flag is also required
|
||||||
if cfg.SyncMode == downloader.SnapSync {
|
if cfg.SyncMode == ethconfig.SnapSync {
|
||||||
if !ctx.Bool(SnapshotFlag.Name) {
|
if !ctx.Bool(SnapshotFlag.Name) {
|
||||||
log.Warn("Snap sync requested, enabling --snapshot")
|
log.Warn("Snap sync requested, enabling --snapshot")
|
||||||
}
|
}
|
||||||
|
@ -1743,7 +1742,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
if !ctx.IsSet(NetworkIdFlag.Name) {
|
if !ctx.IsSet(NetworkIdFlag.Name) {
|
||||||
cfg.NetworkId = 1337
|
cfg.NetworkId = 1337
|
||||||
}
|
}
|
||||||
cfg.SyncMode = downloader.FullSync
|
cfg.SyncMode = ethconfig.FullSync
|
||||||
// Create new developer account or reuse existing one
|
// Create new developer account or reuse existing one
|
||||||
var (
|
var (
|
||||||
developer accounts.Account
|
developer accounts.Account
|
||||||
|
|
|
@ -424,17 +424,17 @@ func (s *Ethereum) Stop() error {
|
||||||
|
|
||||||
// SyncMode retrieves the current sync mode, either explicitly set, or derived
|
// SyncMode retrieves the current sync mode, either explicitly set, or derived
|
||||||
// from the chain status.
|
// from the chain status.
|
||||||
func (s *Ethereum) SyncMode() downloader.SyncMode {
|
func (s *Ethereum) SyncMode() ethconfig.SyncMode {
|
||||||
// If we're in snap sync mode, return that directly
|
// If we're in snap sync mode, return that directly
|
||||||
if s.handler.snapSync.Load() {
|
if s.handler.snapSync.Load() {
|
||||||
return downloader.SnapSync
|
return ethconfig.SnapSync
|
||||||
}
|
}
|
||||||
// We are probably in full sync, but we might have rewound to before the
|
// 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.
|
// snap sync pivot, check if we should re-enable snap sync.
|
||||||
head := s.blockchain.CurrentBlock()
|
head := s.blockchain.CurrentBlock()
|
||||||
if pivot := rawdb.ReadLastPivotNumber(s.chainDb); pivot != nil {
|
if pivot := rawdb.ReadLastPivotNumber(s.chainDb); pivot != nil {
|
||||||
if head.Number.Uint64() < *pivot {
|
if head.Number.Uint64() < *pivot {
|
||||||
return downloader.SnapSync
|
return ethconfig.SnapSync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We are in a full sync, but the associated head state is missing. To complete
|
// We are in a full sync, but the associated head state is missing. To complete
|
||||||
|
@ -442,8 +442,8 @@ func (s *Ethereum) SyncMode() downloader.SyncMode {
|
||||||
// persistent state is corrupted, just mismatch with the head block.
|
// persistent state is corrupted, just mismatch with the head block.
|
||||||
if !s.blockchain.HasState(head.Root) {
|
if !s.blockchain.HasState(head.Root) {
|
||||||
log.Info("Reenabled snap sync as chain is stateless")
|
log.Info("Reenabled snap sync as chain is stateless")
|
||||||
return downloader.SnapSync
|
return ethconfig.SnapSync
|
||||||
}
|
}
|
||||||
// Nope, we're really full syncing
|
// Nope, we're really full syncing
|
||||||
return downloader.FullSync
|
return ethconfig.FullSync
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"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/internal/version"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
|
@ -918,7 +918,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
|
||||||
// tries to make it import a block. That should be denied as pushing something
|
// 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
|
// into the database directly will conflict with the assumptions of snap sync
|
||||||
// that it has an empty db that it can fill itself.
|
// that it has an empty db that it can fill itself.
|
||||||
if api.eth.SyncMode() != downloader.FullSync {
|
if api.eth.SyncMode() != ethconfig.FullSync {
|
||||||
return api.delayPayloadImport(block), nil
|
return api.delayPayloadImport(block), nil
|
||||||
}
|
}
|
||||||
if !api.eth.BlockChain().HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
|
if !api.eth.BlockChain().HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
|
||||||
|
@ -1031,7 +1031,7 @@ func (api *ConsensusAPI) delayPayloadImport(block *types.Block) engine.PayloadSt
|
||||||
// payload as non-integratable on top of the existing sync. We'll just
|
// 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
|
// have to rely on the beacon client to forcefully update the head with
|
||||||
// a forkchoice update request.
|
// a forkchoice update request.
|
||||||
if api.eth.SyncMode() == downloader.FullSync {
|
if api.eth.SyncMode() == ethconfig.FullSync {
|
||||||
// In full sync mode, failure to import a well-formed block can only mean
|
// 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
|
// that the parent state is missing and the syncer rejected extending the
|
||||||
// current cycle with the new payload.
|
// current cycle with the new payload.
|
||||||
|
|
|
@ -40,7 +40,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"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/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/internal/version"
|
"github.com/ethereum/go-ethereum/internal/version"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
|
@ -452,7 +451,7 @@ func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block)
|
||||||
}
|
}
|
||||||
|
|
||||||
mcfg := miner.DefaultConfig
|
mcfg := miner.DefaultConfig
|
||||||
ethcfg := ðconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
|
ethcfg := ðconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
|
||||||
ethservice, err := eth.New(n, ethcfg)
|
ethservice, err := eth.New(n, ethcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("can't create eth service:", err)
|
t.Fatal("can't create eth service:", err)
|
||||||
|
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"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/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
|
@ -49,7 +48,7 @@ func startSimulatedBeaconEthService(t *testing.T, genesis *core.Genesis, period
|
||||||
t.Fatal("can't create node:", err)
|
t.Fatal("can't create node:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ethcfg := ðconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: miner.DefaultConfig}
|
ethcfg := ðconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: miner.DefaultConfig}
|
||||||
ethservice, err := eth.New(n, ethcfg)
|
ethservice, err := eth.New(n, ethcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("can't create eth service:", err)
|
t.Fatal("can't create eth service:", err)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"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/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
)
|
)
|
||||||
|
@ -62,7 +62,7 @@ func (tester *FullSyncTester) Start() error {
|
||||||
|
|
||||||
// Trigger beacon sync with the provided block hash as trusted
|
// Trigger beacon sync with the provided block hash as trusted
|
||||||
// chain head.
|
// chain head.
|
||||||
err := tester.backend.Downloader().BeaconDevSync(downloader.FullSync, tester.target, tester.closed)
|
err := tester.backend.Downloader().BeaconDevSync(ethconfig.FullSync, tester.target, tester.closed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Failed to trigger beacon sync", "err", err)
|
log.Info("Failed to trigger beacon sync", "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -198,9 +199,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
|
||||||
var chainHead *types.Header
|
var chainHead *types.Header
|
||||||
|
|
||||||
switch d.getMode() {
|
switch d.getMode() {
|
||||||
case FullSync:
|
case ethconfig.FullSync:
|
||||||
chainHead = d.blockchain.CurrentBlock()
|
chainHead = d.blockchain.CurrentBlock()
|
||||||
case SnapSync:
|
case ethconfig.SnapSync:
|
||||||
chainHead = d.blockchain.CurrentSnapBlock()
|
chainHead = d.blockchain.CurrentSnapBlock()
|
||||||
default:
|
default:
|
||||||
panic("unknown sync mode")
|
panic("unknown sync mode")
|
||||||
|
@ -218,9 +219,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
|
||||||
}
|
}
|
||||||
var linked bool
|
var linked bool
|
||||||
switch d.getMode() {
|
switch d.getMode() {
|
||||||
case FullSync:
|
case ethconfig.FullSync:
|
||||||
linked = d.blockchain.HasBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
linked = d.blockchain.HasBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
||||||
case SnapSync:
|
case ethconfig.SnapSync:
|
||||||
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
||||||
default:
|
default:
|
||||||
panic("unknown sync mode")
|
panic("unknown sync mode")
|
||||||
|
@ -253,9 +254,9 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
|
||||||
|
|
||||||
var known bool
|
var known bool
|
||||||
switch d.getMode() {
|
switch d.getMode() {
|
||||||
case FullSync:
|
case ethconfig.FullSync:
|
||||||
known = d.blockchain.HasBlock(h.Hash(), n)
|
known = d.blockchain.HasBlock(h.Hash(), n)
|
||||||
case SnapSync:
|
case ethconfig.SnapSync:
|
||||||
known = d.blockchain.HasFastBlock(h.Hash(), n)
|
known = d.blockchain.HasFastBlock(h.Hash(), n)
|
||||||
default:
|
default:
|
||||||
panic("unknown sync mode")
|
panic("unknown sync mode")
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
@ -69,6 +70,17 @@ var (
|
||||||
errNoPivotHeader = errors.New("pivot header is not found")
|
errNoPivotHeader = errors.New("pivot header is not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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.
|
// peerDropFn is a callback type for dropping a peer detected as malicious.
|
||||||
type peerDropFn func(id string)
|
type peerDropFn func(id string)
|
||||||
|
|
||||||
|
@ -230,9 +242,9 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
|
||||||
current := uint64(0)
|
current := uint64(0)
|
||||||
mode := d.getMode()
|
mode := d.getMode()
|
||||||
switch mode {
|
switch mode {
|
||||||
case FullSync:
|
case ethconfig.FullSync:
|
||||||
current = d.blockchain.CurrentBlock().Number.Uint64()
|
current = d.blockchain.CurrentBlock().Number.Uint64()
|
||||||
case SnapSync:
|
case ethconfig.SnapSync:
|
||||||
current = d.blockchain.CurrentSnapBlock().Number.Uint64()
|
current = d.blockchain.CurrentSnapBlock().Number.Uint64()
|
||||||
default:
|
default:
|
||||||
log.Error("Unknown downloader mode", "mode", mode)
|
log.Error("Unknown downloader mode", "mode", mode)
|
||||||
|
@ -326,7 +338,7 @@ func (d *Downloader) synchronise(mode SyncMode, beaconPing chan struct{}) error
|
||||||
if d.notified.CompareAndSwap(false, true) {
|
if d.notified.CompareAndSwap(false, true) {
|
||||||
log.Info("Block synchronisation started")
|
log.Info("Block synchronisation started")
|
||||||
}
|
}
|
||||||
if mode == SnapSync {
|
if mode == ethconfig.SnapSync {
|
||||||
// Snap sync will directly modify the persistent state, making the entire
|
// Snap sync will directly modify the persistent state, making the entire
|
||||||
// trie database unusable until the state is fully synced. To prevent any
|
// trie database unusable until the state is fully synced. To prevent any
|
||||||
// subsequent state reads, explicitly disable the trie database and state
|
// subsequent state reads, explicitly disable the trie database and state
|
||||||
|
@ -434,7 +446,7 @@ func (d *Downloader) syncToHead() (err error) {
|
||||||
// threshold (i.e. new chain). In that case we won't really snap sync
|
// threshold (i.e. new chain). In that case we won't really snap sync
|
||||||
// anyway, but still need a valid pivot block to avoid some code hitting
|
// anyway, but still need a valid pivot block to avoid some code hitting
|
||||||
// nil panics on access.
|
// nil panics on access.
|
||||||
if mode == SnapSync && pivot == nil {
|
if mode == ethconfig.SnapSync && pivot == nil {
|
||||||
pivot = d.blockchain.CurrentBlock()
|
pivot = d.blockchain.CurrentBlock()
|
||||||
}
|
}
|
||||||
height := latest.Number.Uint64()
|
height := latest.Number.Uint64()
|
||||||
|
@ -452,7 +464,7 @@ func (d *Downloader) syncToHead() (err error) {
|
||||||
d.syncStatsLock.Unlock()
|
d.syncStatsLock.Unlock()
|
||||||
|
|
||||||
// Ensure our origin point is below any snap sync pivot point
|
// Ensure our origin point is below any snap sync pivot point
|
||||||
if mode == SnapSync {
|
if mode == ethconfig.SnapSync {
|
||||||
if height <= uint64(fsMinFullBlocks) {
|
if height <= uint64(fsMinFullBlocks) {
|
||||||
origin = 0
|
origin = 0
|
||||||
} else {
|
} else {
|
||||||
|
@ -466,10 +478,10 @@ func (d *Downloader) syncToHead() (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.committed.Store(true)
|
d.committed.Store(true)
|
||||||
if mode == SnapSync && pivot.Number.Uint64() != 0 {
|
if mode == ethconfig.SnapSync && pivot.Number.Uint64() != 0 {
|
||||||
d.committed.Store(false)
|
d.committed.Store(false)
|
||||||
}
|
}
|
||||||
if mode == SnapSync {
|
if mode == ethconfig.SnapSync {
|
||||||
// Set the ancient data limitation. If we are running snap sync, all block
|
// 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
|
// 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
|
// recent data will be written to the active database and will wait for the
|
||||||
|
@ -523,13 +535,13 @@ func (d *Downloader) syncToHead() (err error) {
|
||||||
func() error { return d.fetchReceipts(origin + 1) }, // Receipts are retrieved during snap sync
|
func() error { return d.fetchReceipts(origin + 1) }, // Receipts are retrieved during snap sync
|
||||||
func() error { return d.processHeaders(origin + 1) },
|
func() error { return d.processHeaders(origin + 1) },
|
||||||
}
|
}
|
||||||
if mode == SnapSync {
|
if mode == ethconfig.SnapSync {
|
||||||
d.pivotLock.Lock()
|
d.pivotLock.Lock()
|
||||||
d.pivotHeader = pivot
|
d.pivotHeader = pivot
|
||||||
d.pivotLock.Unlock()
|
d.pivotLock.Unlock()
|
||||||
|
|
||||||
fetchers = append(fetchers, func() error { return d.processSnapSyncContent() })
|
fetchers = append(fetchers, func() error { return d.processSnapSyncContent() })
|
||||||
} else if mode == FullSync {
|
} else if mode == ethconfig.FullSync {
|
||||||
fetchers = append(fetchers, func() error { return d.processFullSyncContent() })
|
fetchers = append(fetchers, func() error { return d.processFullSyncContent() })
|
||||||
}
|
}
|
||||||
return d.spawnSync(fetchers)
|
return d.spawnSync(fetchers)
|
||||||
|
@ -676,7 +688,7 @@ func (d *Downloader) processHeaders(origin uint64) error {
|
||||||
chunkHashes := hashes[:limit]
|
chunkHashes := hashes[:limit]
|
||||||
|
|
||||||
// In case of header only syncing, validate the chunk immediately
|
// In case of header only syncing, validate the chunk immediately
|
||||||
if mode == SnapSync {
|
if mode == ethconfig.SnapSync {
|
||||||
// Although the received headers might be all valid, a legacy
|
// Although the received headers might be all valid, a legacy
|
||||||
// PoW/PoA sync must not accept post-merge headers. Make sure
|
// PoW/PoA sync must not accept post-merge headers. Make sure
|
||||||
// that any transition is rejected at this point.
|
// that any transition is rejected at this point.
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/prque"
|
"github.com/ethereum/go-ethereum/common/prque"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
"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/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
@ -180,7 +181,7 @@ func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
|
||||||
defer q.lock.Unlock()
|
defer q.lock.Unlock()
|
||||||
|
|
||||||
q.closed = false
|
q.closed = false
|
||||||
q.mode = FullSync
|
q.mode = ethconfig.FullSync
|
||||||
|
|
||||||
q.headerHead = common.Hash{}
|
q.headerHead = common.Hash{}
|
||||||
q.headerPendPool = make(map[string]*fetchRequest)
|
q.headerPendPool = make(map[string]*fetchRequest)
|
||||||
|
@ -328,7 +329,7 @@ func (q *queue) Schedule(headers []*types.Header, hashes []common.Hash, from uin
|
||||||
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
|
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||||
}
|
}
|
||||||
// Queue for receipt retrieval
|
// Queue for receipt retrieval
|
||||||
if q.mode == SnapSync && !header.EmptyReceipts() {
|
if q.mode == ethconfig.SnapSync && !header.EmptyReceipts() {
|
||||||
if _, ok := q.receiptTaskPool[hash]; ok {
|
if _, ok := q.receiptTaskPool[hash]; ok {
|
||||||
log.Warn("Header already scheduled for receipt fetch", "number", header.Number, "hash", hash)
|
log.Warn("Header already scheduled for receipt fetch", "number", header.Number, "hash", hash)
|
||||||
} else {
|
} else {
|
||||||
|
@ -523,7 +524,7 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
|
||||||
// we can ask the resultcache if this header is within the
|
// we can ask the resultcache if this header is within the
|
||||||
// "prioritized" segment of blocks. If it is not, we need to throttle
|
// "prioritized" segment of blocks. If it is not, we need to throttle
|
||||||
|
|
||||||
stale, throttle, item, err := q.resultCache.AddFetch(header, q.mode == SnapSync)
|
stale, throttle, item, err := q.resultCache.AddFetch(header, q.mode == ethconfig.SnapSync)
|
||||||
if stale {
|
if stale {
|
||||||
// Don't put back in the task queue, this item has already been
|
// Don't put back in the task queue, this item has already been
|
||||||
// delivered upstream
|
// delivered upstream
|
||||||
|
|
|
@ -29,7 +29,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
|
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
|
"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/eth/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
@ -49,7 +48,7 @@ var FullNodeGPO = gasprice.Config{
|
||||||
|
|
||||||
// Defaults contains default settings for use on the Ethereum main net.
|
// Defaults contains default settings for use on the Ethereum main net.
|
||||||
var Defaults = Config{
|
var Defaults = Config{
|
||||||
SyncMode: downloader.SnapSync,
|
SyncMode: SnapSync,
|
||||||
NetworkId: 0, // enable auto configuration of networkID == chainID
|
NetworkId: 0, // enable auto configuration of networkID == chainID
|
||||||
TxLookupLimit: 2350000,
|
TxLookupLimit: 2350000,
|
||||||
TransactionHistory: 2350000,
|
TransactionHistory: 2350000,
|
||||||
|
@ -80,7 +79,7 @@ type Config struct {
|
||||||
// Network ID separates blockchains on the peer-to-peer networking level. When left
|
// Network ID separates blockchains on the peer-to-peer networking level. When left
|
||||||
// zero, the chain ID is used as network ID.
|
// zero, the chain ID is used as network ID.
|
||||||
NetworkId uint64
|
NetworkId uint64
|
||||||
SyncMode downloader.SyncMode
|
SyncMode SyncMode
|
||||||
|
|
||||||
// This can be set to list of enrtree:// URLs which will be queried for
|
// This can be set to list of enrtree:// URLs which will be queried for
|
||||||
// nodes to connect to.
|
// nodes to connect to.
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
|
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
|
"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/eth/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +18,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Genesis *core.Genesis `toml:",omitempty"`
|
Genesis *core.Genesis `toml:",omitempty"`
|
||||||
NetworkId uint64
|
NetworkId uint64
|
||||||
SyncMode downloader.SyncMode
|
SyncMode SyncMode
|
||||||
EthDiscoveryURLs []string
|
EthDiscoveryURLs []string
|
||||||
SnapDiscoveryURLs []string
|
SnapDiscoveryURLs []string
|
||||||
NoPruning bool
|
NoPruning bool
|
||||||
|
@ -95,7 +94,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Genesis *core.Genesis `toml:",omitempty"`
|
Genesis *core.Genesis `toml:",omitempty"`
|
||||||
NetworkId *uint64
|
NetworkId *uint64
|
||||||
SyncMode *downloader.SyncMode
|
SyncMode *SyncMode
|
||||||
EthDiscoveryURLs []string
|
EthDiscoveryURLs []string
|
||||||
SnapDiscoveryURLs []string
|
SnapDiscoveryURLs []string
|
||||||
NoPruning *bool
|
NoPruning *bool
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// 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/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package downloader
|
package ethconfig
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"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/fetcher"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
||||||
|
@ -87,7 +88,7 @@ type handlerConfig struct {
|
||||||
Chain *core.BlockChain // Blockchain to serve data from
|
Chain *core.BlockChain // Blockchain to serve data from
|
||||||
TxPool txPool // Transaction pool to propagate from
|
TxPool txPool // Transaction pool to propagate from
|
||||||
Network uint64 // Network identifier to advertise
|
Network uint64 // Network identifier to advertise
|
||||||
Sync downloader.SyncMode // Whether to snap or full sync
|
Sync ethconfig.SyncMode // Whether to snap or full sync
|
||||||
BloomCache uint64 // Megabytes to alloc for snap sync bloom
|
BloomCache uint64 // Megabytes to alloc for snap sync bloom
|
||||||
EventMux *event.TypeMux // Legacy event mux, deprecate for `feed`
|
EventMux *event.TypeMux // Legacy event mux, deprecate for `feed`
|
||||||
RequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges
|
RequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges
|
||||||
|
@ -145,7 +146,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
|
||||||
handlerDoneCh: make(chan struct{}),
|
handlerDoneCh: make(chan struct{}),
|
||||||
handlerStartCh: make(chan struct{}),
|
handlerStartCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
if config.Sync == downloader.FullSync {
|
if config.Sync == ethconfig.FullSync {
|
||||||
// The database seems empty as the current block is the genesis. Yet the snap
|
// 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.
|
// block is ahead, so snap sync was enabled for this node at a certain point.
|
||||||
// The scenarios where this can happen is
|
// The scenarios where this can happen is
|
||||||
|
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
@ -109,7 +109,7 @@ func testForkIDSplit(t *testing.T, protocol uint) {
|
||||||
Chain: chainNoFork,
|
Chain: chainNoFork,
|
||||||
TxPool: newTestTxPool(),
|
TxPool: newTestTxPool(),
|
||||||
Network: 1,
|
Network: 1,
|
||||||
Sync: downloader.FullSync,
|
Sync: ethconfig.FullSync,
|
||||||
BloomCache: 1,
|
BloomCache: 1,
|
||||||
})
|
})
|
||||||
ethProFork, _ = newHandler(&handlerConfig{
|
ethProFork, _ = newHandler(&handlerConfig{
|
||||||
|
@ -117,7 +117,7 @@ func testForkIDSplit(t *testing.T, protocol uint) {
|
||||||
Chain: chainProFork,
|
Chain: chainProFork,
|
||||||
TxPool: newTestTxPool(),
|
TxPool: newTestTxPool(),
|
||||||
Network: 1,
|
Network: 1,
|
||||||
Sync: downloader.FullSync,
|
Sync: ethconfig.FullSync,
|
||||||
BloomCache: 1,
|
BloomCache: 1,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"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/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
@ -164,7 +164,7 @@ func newTestHandlerWithBlocks(blocks int) *testHandler {
|
||||||
Chain: chain,
|
Chain: chain,
|
||||||
TxPool: txpool,
|
TxPool: txpool,
|
||||||
Network: 1,
|
Network: 1,
|
||||||
Sync: downloader.SnapSync,
|
Sync: ethconfig.SnapSync,
|
||||||
BloomCache: 1,
|
BloomCache: 1,
|
||||||
})
|
})
|
||||||
handler.Start(1000)
|
handler.Start(1000)
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
@ -85,7 +85,7 @@ func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) {
|
||||||
time.Sleep(250 * time.Millisecond)
|
time.Sleep(250 * time.Millisecond)
|
||||||
|
|
||||||
// Check that snap sync was disabled
|
// Check that snap sync was disabled
|
||||||
if err := empty.handler.downloader.BeaconSync(downloader.SnapSync, full.chain.CurrentBlock(), nil); err != nil {
|
if err := empty.handler.downloader.BeaconSync(ethconfig.SnapSync, full.chain.CurrentBlock(), nil); err != nil {
|
||||||
t.Fatal("sync failed:", err)
|
t.Fatal("sync failed:", err)
|
||||||
}
|
}
|
||||||
empty.handler.enableSyncedFeatures()
|
empty.handler.enableSyncedFeatures()
|
||||||
|
|
|
@ -26,7 +26,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/catalyst"
|
"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/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/eth/filters"
|
"github.com/ethereum/go-ethereum/eth/filters"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
|
@ -85,7 +84,7 @@ func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config,
|
||||||
GasLimit: ethconfig.Defaults.Miner.GasCeil,
|
GasLimit: ethconfig.Defaults.Miner.GasCeil,
|
||||||
Alloc: alloc,
|
Alloc: alloc,
|
||||||
}
|
}
|
||||||
ethConf.SyncMode = downloader.FullSync
|
ethConf.SyncMode = ethconfig.FullSync
|
||||||
ethConf.TxPool.NoLocals = true
|
ethConf.TxPool.NoLocals = true
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
|
|
Loading…
Reference in New Issue