diff --git a/cmd/efsn/config.go b/cmd/efsn/config.go index 9d2a5678..b14f63af 100644 --- a/cmd/efsn/config.go +++ b/cmd/efsn/config.go @@ -30,7 +30,6 @@ import ( "github.com/FusionFoundation/efsn/cmd/utils" "github.com/FusionFoundation/efsn/dashboard" "github.com/FusionFoundation/efsn/eth" - "github.com/FusionFoundation/efsn/eth/downloader" "github.com/FusionFoundation/efsn/node" "github.com/FusionFoundation/efsn/params" whisper "github.com/FusionFoundation/efsn/whisper/whisperv6" @@ -138,11 +137,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { utils.SetShhConfig(ctx, stack, &cfg.Shh) utils.SetDashboardConfig(ctx, &cfg.Dashboard) - // Disable fast sync mode - if cfg.Eth.SyncMode == downloader.FastSync { - cfg.Eth.SyncMode = downloader.FullSync - } - // set to archival mode by default // necessary to get ticket state back cfg.Eth.NoPruning = true diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 1b6f978f..243f5691 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1138,6 +1138,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { if ctx.GlobalIsSet(SyncModeFlag.Name) { cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) + if cfg.SyncMode == downloader.FastSync && downloader.FastSyncSupported() == false { + log.Warn("SetEthConfig: 'fast' sync mode is not supported, change to 'full' sync mode.") + cfg.SyncMode = downloader.FullSync + } } if ctx.GlobalIsSet(LightServFlag.Name) { cfg.LightServ = ctx.GlobalInt(LightServFlag.Name) @@ -1251,6 +1255,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { if gen := ctx.GlobalInt(TrieCacheGenFlag.Name); gen > 0 { state.MaxTrieCacheGen = uint16(gen) } + log.Info("SetEthConfig finished", "NetworkId", cfg.NetworkId, "SyncMode", cfg.SyncMode, "NoPruning", cfg.NoPruning) } // SetDashboardConfig applies dashboard related command line flags to the config. diff --git a/eth/config.go b/eth/config.go index edf4971c..561ff7de 100644 --- a/eth/config.go +++ b/eth/config.go @@ -35,7 +35,7 @@ import ( // DefaultConfig contains default settings for use on the Ethereum main net. var DefaultConfig = Config{ - SyncMode: downloader.FastSync, + SyncMode: downloader.DefaultSyncMode(), Ethash: ethash.Config{ CacheDir: "ethash", CachesInMem: 2, diff --git a/eth/downloader/modes.go b/eth/downloader/modes.go index 8ecdf91f..fe4b9a8b 100644 --- a/eth/downloader/modes.go +++ b/eth/downloader/modes.go @@ -27,6 +27,17 @@ const ( LightSync // Download only the headers and terminate afterwards ) +func FastSyncSupported() bool { + return false +} + +func DefaultSyncMode() SyncMode { + if FastSyncSupported() { + return FastSync + } + return FullSync +} + func (mode SyncMode) IsValid() bool { return mode >= FullSync && mode <= LightSync } diff --git a/eth/sync.go b/eth/sync.go index ddb4cc09..035a60f4 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -176,23 +176,25 @@ func (pm *ProtocolManager) synchronise(peer *peer) { } // Otherwise try to sync with the downloader mode := downloader.FullSync - if atomic.LoadUint32(&pm.fastSync) == 1 { - // Fast sync was explicitly requested, and explicitly granted - mode = downloader.FastSync - } else if currentBlock.NumberU64() == 0 && pm.blockchain.CurrentFastBlock().NumberU64() > 0 { - // The database seems empty as the current block is the genesis. Yet the fast - // block is ahead, so fast sync was enabled for this node at a certain point. - // The only scenario where this can happen is if the user manually (or via a - // bad block) rolled back a fast sync node below the sync point. In this case - // however it's safe to reenable fast sync. - atomic.StoreUint32(&pm.fastSync, 1) - mode = downloader.FastSync - } + if downloader.FastSyncSupported() { + if atomic.LoadUint32(&pm.fastSync) == 1 { + // Fast sync was explicitly requested, and explicitly granted + mode = downloader.FastSync + } else if currentBlock.NumberU64() == 0 && pm.blockchain.CurrentFastBlock().NumberU64() > 0 { + // The database seems empty as the current block is the genesis. Yet the fast + // block is ahead, so fast sync was enabled for this node at a certain point. + // The only scenario where this can happen is if the user manually (or via a + // bad block) rolled back a fast sync node below the sync point. In this case + // however it's safe to reenable fast sync. + atomic.StoreUint32(&pm.fastSync, 1) + mode = downloader.FastSync + } - if mode == downloader.FastSync { - // Make sure the peer's total difficulty we are synchronizing is higher. - if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 { - return + if mode == downloader.FastSync { + // Make sure the peer's total difficulty we are synchronizing is higher. + if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 { + return + } } }