From 890e2efca2111c790c6d5eb55e29981816ee1fe9 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 8 Dec 2022 21:40:43 +0800 Subject: [PATCH] eth, cmd: remove syncTarget from eth config (#26330) --syncTarget is a feature for development purpose in post-merge world. Previously it's added into eth.Config. But it turns out that's a stupid idea. - syncTarget is a block object, which is hard to be put in config file(large) - syncTarget is just a dev feature, doesn't make too much sense to add it in config file So I remove it from the eth config object. And it also fixes the #26328 --- cmd/geth/config.go | 8 ++++++- cmd/utils/flags.go | 44 +++++++++++++++---------------------- eth/ethconfig/config.go | 5 ----- eth/ethconfig/gen_config.go | 7 ------ 4 files changed, 25 insertions(+), 39 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index e15302544c..e61de4b21e 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/scwallet" "github.com/ethereum/go-ethereum/accounts/usbwallet" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/internal/flags" @@ -165,7 +166,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { cfg.Eth.OverrideTerminalTotalDifficultyPassed = &override } - backend, _ := utils.RegisterEthService(stack, &cfg.Eth) + backend, eth := utils.RegisterEthService(stack, &cfg.Eth) // Configure log filter RPC API. filterSystem := utils.RegisterFilterAPI(stack, backend, &cfg.Eth) @@ -179,6 +180,11 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { if cfg.Ethstats.URL != "" { utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL) } + + // Configure full-sync tester service if requested + if ctx.IsSet(utils.SyncTargetFlag.Name) && cfg.Eth.SyncMode == downloader.FullSync { + utils.RegisterFullSyncTester(stack, eth, ctx.Path(utils.SyncTargetFlag.Name)) + } return stack, backend } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5c0d984cbf..cb7ff910d0 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1880,25 +1880,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { cfg.EthDiscoveryURLs = SplitAndTrim(urls) } } - if ctx.IsSet(SyncTargetFlag.Name) { - path := ctx.Path(SyncTargetFlag.Name) - if path == "" { - Fatalf("Failed to resolve file path") - } - blob, err := os.ReadFile(path) - if err != nil { - Fatalf("Failed to read block file: %v", err) - } - rlpBlob, err := hexutil.Decode(string(bytes.TrimRight(blob, "\r\n"))) - if err != nil { - Fatalf("Failed to decode block blob: %v", err) - } - var block types.Block - if err := rlp.DecodeBytes(rlpBlob, &block); err != nil { - Fatalf("Failed to decode block: %v", err) - } - cfg.SyncTarget = &block - } // Override any default configs for hard coded networks. switch { case ctx.Bool(MainnetFlag.Name): @@ -2052,13 +2033,6 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend Fatalf("Failed to register the Engine API service: %v", err) } stack.RegisterAPIs(tracers.APIs(backend.APIBackend)) - - // Register the auxiliary full-sync tester service in case the sync - // target is configured. - if cfg.SyncTarget != nil && cfg.SyncMode == downloader.FullSync { - ethcatalyst.RegisterFullSyncTester(stack, backend, cfg.SyncTarget) - log.Info("Registered full-sync tester", "number", cfg.SyncTarget.NumberU64(), "hash", cfg.SyncTarget.Hash()) - } return backend.APIBackend, backend } @@ -2090,6 +2064,24 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf return filterSystem } +// RegisterFullSyncTester adds the full-sync tester service into node. +func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, path string) { + blob, err := os.ReadFile(path) + if err != nil { + Fatalf("Failed to read block file: %v", err) + } + rlpBlob, err := hexutil.Decode(string(bytes.TrimRight(blob, "\r\n"))) + if err != nil { + Fatalf("Failed to decode block blob: %v", err) + } + var block types.Block + if err := rlp.DecodeBytes(rlpBlob, &block); err != nil { + Fatalf("Failed to decode block: %v", err) + } + ethcatalyst.RegisterFullSyncTester(stack, eth, &block) + log.Info("Registered full-sync tester", "number", block.NumberU64(), "hash", block.Hash()) +} + func SetupMetrics(ctx *cli.Context) { if metrics.Enabled { log.Info("Enabling metrics collection") diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index e9651d041c..7560633932 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -32,7 +32,6 @@ import ( "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/txpool" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/ethdb" @@ -212,10 +211,6 @@ type Config struct { // OverrideTerminalTotalDifficultyPassed (TODO: remove after the fork) OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` - - // SyncTarget defines the target block of sync. It's only used for - // development purposes. - SyncTarget *types.Block } // CreateConsensusEngine creates a consensus engine for the given chain configuration. diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index a3dcf5a12f..514facde0a 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/txpool" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/miner" @@ -64,7 +63,6 @@ func (c Config) MarshalTOML() (interface{}, error) { CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` - FullSyncTarget *types.Block } var enc Config enc.Genesis = c.Genesis @@ -111,7 +109,6 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.CheckpointOracle = c.CheckpointOracle enc.OverrideTerminalTotalDifficulty = c.OverrideTerminalTotalDifficulty enc.OverrideTerminalTotalDifficultyPassed = c.OverrideTerminalTotalDifficultyPassed - enc.FullSyncTarget = c.SyncTarget return &enc, nil } @@ -162,7 +159,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` - FullSyncTarget *types.Block } var dec Config if err := unmarshal(&dec); err != nil { @@ -300,8 +296,5 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideTerminalTotalDifficultyPassed != nil { c.OverrideTerminalTotalDifficultyPassed = dec.OverrideTerminalTotalDifficultyPassed } - if dec.FullSyncTarget != nil { - c.SyncTarget = dec.FullSyncTarget - } return nil }