2017-04-14 08:29:00 +00:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
2017-04-12 14:27:23 +00:00
|
|
|
// This file is part of go-ethereum.
|
|
|
|
//
|
|
|
|
// go-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// go-ethereum is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-02-25 07:10:30 +00:00
|
|
|
"math/big"
|
2017-04-12 14:27:23 +00:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"unicode"
|
|
|
|
|
2020-11-25 20:00:23 +00:00
|
|
|
"gopkg.in/urfave/cli.v1"
|
2017-04-12 14:27:23 +00:00
|
|
|
|
2021-08-25 20:34:22 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/external"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/scwallet"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/usbwallet"
|
2017-04-12 14:27:23 +00:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2022-03-23 19:57:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2021-02-05 12:51:15 +00:00
|
|
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
2020-08-03 17:40:46 +00:00
|
|
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
2021-06-30 10:57:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2021-01-18 13:36:05 +00:00
|
|
|
"github.com/ethereum/go-ethereum/metrics"
|
2017-04-12 14:27:23 +00:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
"github.com/naoina/toml"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dumpConfigCommand = cli.Command{
|
2017-05-03 12:39:07 +00:00
|
|
|
Action: utils.MigrateFlags(dumpConfig),
|
2017-04-12 14:27:23 +00:00
|
|
|
Name: "dumpconfig",
|
|
|
|
Usage: "Show configuration values",
|
|
|
|
ArgsUsage: "",
|
2021-03-03 14:08:14 +00:00
|
|
|
Flags: append(nodeFlags, rpcFlags...),
|
2017-04-12 14:27:23 +00:00
|
|
|
Category: "MISCELLANEOUS COMMANDS",
|
|
|
|
Description: `The dumpconfig command shows configuration values.`,
|
|
|
|
}
|
|
|
|
|
|
|
|
configFileFlag = cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Usage: "TOML configuration file",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// These settings ensure that TOML keys use the same names as Go struct fields.
|
|
|
|
var tomlSettings = toml.Config{
|
|
|
|
NormFieldName: func(rt reflect.Type, key string) string {
|
|
|
|
return key
|
|
|
|
},
|
|
|
|
FieldToKey: func(rt reflect.Type, field string) string {
|
|
|
|
return field
|
|
|
|
},
|
|
|
|
MissingField: func(rt reflect.Type, field string) error {
|
2021-06-30 10:57:32 +00:00
|
|
|
id := fmt.Sprintf("%s.%s", rt.String(), field)
|
|
|
|
if deprecated(id) {
|
|
|
|
log.Warn("Config field is deprecated and won't have an effect", "name", id)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var link string
|
2017-04-12 14:27:23 +00:00
|
|
|
if unicode.IsUpper(rune(rt.Name()[0])) && rt.PkgPath() != "main" {
|
|
|
|
link = fmt.Sprintf(", see https://godoc.org/%s#%s for available fields", rt.PkgPath(), rt.Name())
|
|
|
|
}
|
|
|
|
return fmt.Errorf("field '%s' is not defined in %s%s", field, rt.String(), link)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type ethstatsConfig struct {
|
|
|
|
URL string `toml:",omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type gethConfig struct {
|
2021-02-05 12:51:15 +00:00
|
|
|
Eth ethconfig.Config
|
2019-11-14 09:04:16 +00:00
|
|
|
Node node.Config
|
|
|
|
Ethstats ethstatsConfig
|
2021-01-18 13:36:05 +00:00
|
|
|
Metrics metrics.Config
|
2017-04-12 14:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig(file string, cfg *gethConfig) error {
|
|
|
|
f, err := os.Open(file)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
err = tomlSettings.NewDecoder(bufio.NewReader(f)).Decode(cfg)
|
|
|
|
// Add file name to errors that have a line number.
|
|
|
|
if _, ok := err.(*toml.LineError); ok {
|
|
|
|
err = errors.New(file + ", " + err.Error())
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultNodeConfig() node.Config {
|
|
|
|
cfg := node.DefaultConfig
|
|
|
|
cfg.Name = clientIdentifier
|
2019-05-08 13:44:28 +00:00
|
|
|
cfg.Version = params.VersionWithCommit(gitCommit, gitDate)
|
2020-01-28 09:37:08 +00:00
|
|
|
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
|
|
|
|
cfg.WSModules = append(cfg.WSModules, "eth")
|
2017-04-12 14:27:23 +00:00
|
|
|
cfg.IPCPath = "geth.ipc"
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:24:36 +00:00
|
|
|
// makeConfigNode loads geth configuration and creates a blank node instance.
|
2017-04-12 14:27:23 +00:00
|
|
|
func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
|
|
|
|
// Load defaults.
|
|
|
|
cfg := gethConfig{
|
2021-02-05 12:51:15 +00:00
|
|
|
Eth: ethconfig.Defaults,
|
2021-01-18 13:36:05 +00:00
|
|
|
Node: defaultNodeConfig(),
|
|
|
|
Metrics: metrics.DefaultConfig,
|
2017-04-12 14:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load config file.
|
|
|
|
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
|
|
|
|
if err := loadConfig(file, &cfg); err != nil {
|
|
|
|
utils.Fatalf("%v", err)
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 14:08:14 +00:00
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
// Apply flags.
|
|
|
|
utils.SetNodeConfig(ctx, &cfg.Node)
|
|
|
|
stack, err := node.New(&cfg.Node)
|
|
|
|
if err != nil {
|
|
|
|
utils.Fatalf("Failed to create the protocol stack: %v", err)
|
|
|
|
}
|
2021-08-25 20:34:22 +00:00
|
|
|
// Node doesn't by default populate account manager backends
|
|
|
|
if err := setAccountManagerBackends(stack); err != nil {
|
|
|
|
utils.Fatalf("Failed to set account manager backends: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
utils.SetEthConfig(ctx, stack, &cfg.Eth)
|
|
|
|
if ctx.GlobalIsSet(utils.EthStatsURLFlag.Name) {
|
|
|
|
cfg.Ethstats.URL = ctx.GlobalString(utils.EthStatsURLFlag.Name)
|
|
|
|
}
|
2021-01-18 13:36:05 +00:00
|
|
|
applyMetricConfig(ctx, &cfg)
|
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
return stack, cfg
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:24:36 +00:00
|
|
|
// makeFullNode loads geth configuration and creates the Ethereum backend.
|
2020-08-03 17:40:46 +00:00
|
|
|
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
|
2017-04-12 14:27:23 +00:00
|
|
|
stack, cfg := makeConfigNode(ctx)
|
2021-10-28 20:18:14 +00:00
|
|
|
if ctx.GlobalIsSet(utils.OverrideArrowGlacierFlag.Name) {
|
|
|
|
cfg.Eth.OverrideArrowGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideArrowGlacierFlag.Name))
|
2021-02-25 07:10:30 +00:00
|
|
|
}
|
all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition
* consensus/beacon, eth: change beacon difficulty to 0
* eth: updates
* all: add terminalBlockDifficulty config, fix rebasing issues
* eth: implemented merge interop spec
* internal/ethapi: update to v1.0.0.alpha.2
This commit updates the code to the new spec, moving payloadId into
it's own object. It also fixes an issue with finalizing an empty blockhash.
It also properly sets the basefee
* all: sync polishes, other fixes + refactors
* core, eth: correct semantics for LeavePoW, EnterPoS
* core: fixed rebasing artifacts
* core: light: performance improvements
* core: use keyed field (f)
* core: eth: fix compilation issues + tests
* eth/catalyst: dbetter error codes
* all: move Merger to consensus/, remove reliance on it in bc
* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS
* core: make mergelogs a function
* core: use InsertChain instead of InsertBlock
* les: drop merger from lightchain object
* consensus: add merger
* core: recoverAncestors in catalyst mode
* core: fix nitpick
* all: removed merger from beacon, use TTD, nitpicks
* consensus: eth: add docstring, removed unnecessary code duplication
* consensus/beacon: better comment
* all: easy to fix nitpicks by karalabe
* consensus/beacon: verify known headers to be sure
* core: comments
* core: eth: don't drop peers who advertise blocks, nitpicks
* core: never add beacon blocks to the future queue
* core: fixed nitpicks
* consensus/beacon: simplify IsTTDReached check
* consensus/beacon: correct IsTTDReached check
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-11-26 11:23:02 +00:00
|
|
|
if ctx.GlobalIsSet(utils.OverrideTerminalTotalDifficulty.Name) {
|
2022-04-13 09:28:23 +00:00
|
|
|
cfg.Eth.OverrideTerminalTotalDifficulty = utils.GlobalBig(ctx, utils.OverrideTerminalTotalDifficulty.Name)
|
2021-04-16 19:29:22 +00:00
|
|
|
}
|
2022-03-23 19:57:32 +00:00
|
|
|
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
|
|
|
|
// Warn users to migrate if they have a legacy freezer format.
|
|
|
|
if eth != nil {
|
|
|
|
firstIdx := uint64(0)
|
|
|
|
// Hack to speed up check for mainnet because we know
|
|
|
|
// the first non-empty block.
|
|
|
|
ghash := rawdb.ReadCanonicalHash(eth.ChainDb(), 0)
|
|
|
|
if cfg.Eth.NetworkId == 1 && ghash == params.MainnetGenesisHash {
|
|
|
|
firstIdx = 46147
|
|
|
|
}
|
|
|
|
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx)
|
|
|
|
if err != nil {
|
2022-03-29 08:40:42 +00:00
|
|
|
log.Error("Failed to check db for legacy receipts", "err", err)
|
|
|
|
} else if isLegacy {
|
2022-03-23 19:57:32 +00:00
|
|
|
log.Warn("Database has receipts with a legacy format. Please run `geth db freezer-migrate`.")
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 14:27:23 +00:00
|
|
|
|
2019-06-12 08:24:24 +00:00
|
|
|
// Configure GraphQL if requested
|
2019-01-21 14:38:13 +00:00
|
|
|
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {
|
2020-08-03 17:40:46 +00:00
|
|
|
utils.RegisterGraphQLService(stack, backend, cfg.Node)
|
2019-01-21 14:38:13 +00:00
|
|
|
}
|
2017-04-12 14:27:23 +00:00
|
|
|
// Add the Ethereum Stats daemon if requested.
|
|
|
|
if cfg.Ethstats.URL != "" {
|
2020-08-03 17:40:46 +00:00
|
|
|
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
|
2017-04-12 14:27:23 +00:00
|
|
|
}
|
2020-08-03 17:40:46 +00:00
|
|
|
return stack, backend
|
2017-04-12 14:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// dumpConfig is the dumpconfig command.
|
|
|
|
func dumpConfig(ctx *cli.Context) error {
|
|
|
|
_, cfg := makeConfigNode(ctx)
|
|
|
|
comment := ""
|
|
|
|
|
|
|
|
if cfg.Eth.Genesis != nil {
|
|
|
|
cfg.Eth.Genesis = nil
|
|
|
|
comment += "# Note: this config doesn't contain the genesis block.\n\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err := tomlSettings.Marshal(&cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-07 08:56:50 +00:00
|
|
|
|
|
|
|
dump := os.Stdout
|
|
|
|
if ctx.NArg() > 0 {
|
|
|
|
dump, err = os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer dump.Close()
|
|
|
|
}
|
|
|
|
dump.WriteString(comment)
|
|
|
|
dump.Write(out)
|
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-01-18 13:36:05 +00:00
|
|
|
|
|
|
|
func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsEnabledFlag.Name) {
|
|
|
|
cfg.Metrics.Enabled = ctx.GlobalBool(utils.MetricsEnabledFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsEnabledExpensiveFlag.Name) {
|
|
|
|
cfg.Metrics.EnabledExpensive = ctx.GlobalBool(utils.MetricsEnabledExpensiveFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsHTTPFlag.Name) {
|
|
|
|
cfg.Metrics.HTTP = ctx.GlobalString(utils.MetricsHTTPFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsPortFlag.Name) {
|
|
|
|
cfg.Metrics.Port = ctx.GlobalInt(utils.MetricsPortFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsEnableInfluxDBFlag.Name) {
|
|
|
|
cfg.Metrics.EnableInfluxDB = ctx.GlobalBool(utils.MetricsEnableInfluxDBFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBEndpointFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBEndpoint = ctx.GlobalString(utils.MetricsInfluxDBEndpointFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBDatabaseFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBDatabase = ctx.GlobalString(utils.MetricsInfluxDBDatabaseFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBUsernameFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBUsername = ctx.GlobalString(utils.MetricsInfluxDBUsernameFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBPasswordFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBPassword = ctx.GlobalString(utils.MetricsInfluxDBPasswordFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBTagsFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBTags = ctx.GlobalString(utils.MetricsInfluxDBTagsFlag.Name)
|
|
|
|
}
|
2021-08-17 16:40:14 +00:00
|
|
|
if ctx.GlobalIsSet(utils.MetricsEnableInfluxDBV2Flag.Name) {
|
|
|
|
cfg.Metrics.EnableInfluxDBV2 = ctx.GlobalBool(utils.MetricsEnableInfluxDBV2Flag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBTokenFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBToken = ctx.GlobalString(utils.MetricsInfluxDBTokenFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBBucketFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBBucket = ctx.GlobalString(utils.MetricsInfluxDBBucketFlag.Name)
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet(utils.MetricsInfluxDBOrganizationFlag.Name) {
|
|
|
|
cfg.Metrics.InfluxDBOrganization = ctx.GlobalString(utils.MetricsInfluxDBOrganizationFlag.Name)
|
|
|
|
}
|
2021-01-18 13:36:05 +00:00
|
|
|
}
|
2021-06-30 10:57:32 +00:00
|
|
|
|
|
|
|
func deprecated(field string) bool {
|
2021-07-06 20:03:09 +00:00
|
|
|
switch field {
|
|
|
|
case "ethconfig.Config.EVMInterpreter":
|
|
|
|
return true
|
|
|
|
case "ethconfig.Config.EWASMInterpreter":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2021-06-30 10:57:32 +00:00
|
|
|
}
|
2021-08-25 20:34:22 +00:00
|
|
|
|
|
|
|
func setAccountManagerBackends(stack *node.Node) error {
|
|
|
|
conf := stack.Config()
|
|
|
|
am := stack.AccountManager()
|
|
|
|
keydir := stack.KeyStoreDir()
|
|
|
|
scryptN := keystore.StandardScryptN
|
|
|
|
scryptP := keystore.StandardScryptP
|
|
|
|
if conf.UseLightweightKDF {
|
|
|
|
scryptN = keystore.LightScryptN
|
|
|
|
scryptP = keystore.LightScryptP
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assemble the supported backends
|
|
|
|
if len(conf.ExternalSigner) > 0 {
|
|
|
|
log.Info("Using external signer", "url", conf.ExternalSigner)
|
|
|
|
if extapi, err := external.NewExternalBackend(conf.ExternalSigner); err == nil {
|
|
|
|
am.AddBackend(extapi)
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("error connecting to external signer: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now, we're using EITHER external signer OR local signers.
|
|
|
|
// If/when we implement some form of lockfile for USB and keystore wallets,
|
|
|
|
// we can have both, but it's very confusing for the user to see the same
|
|
|
|
// accounts in both externally and locally, plus very racey.
|
|
|
|
am.AddBackend(keystore.NewKeyStore(keydir, scryptN, scryptP))
|
|
|
|
if conf.USB {
|
|
|
|
// Start a USB hub for Ledger hardware wallets
|
|
|
|
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start Ledger hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
am.AddBackend(ledgerhub)
|
|
|
|
}
|
|
|
|
// Start a USB hub for Trezor hardware wallets (HID version)
|
|
|
|
if trezorhub, err := usbwallet.NewTrezorHubWithHID(); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start HID Trezor hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
am.AddBackend(trezorhub)
|
|
|
|
}
|
|
|
|
// Start a USB hub for Trezor hardware wallets (WebUSB version)
|
|
|
|
if trezorhub, err := usbwallet.NewTrezorHubWithWebUSB(); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start WebUSB Trezor hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
am.AddBackend(trezorhub)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(conf.SmartCardDaemonPath) > 0 {
|
|
|
|
// Start a smart card hub
|
|
|
|
if schub, err := scwallet.NewHub(conf.SmartCardDaemonPath, scwallet.Scheme, keydir); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
am.AddBackend(schub)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|