Replace testnet flags with one chain option (#1686)

* Replace testnet flags with one chain option

* Update README.md

* Update README.md

* Update README.md

* Update config.go

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
ledgerwatch 2021-04-08 08:39:40 +01:00 committed by GitHub
parent dda138e8b7
commit acea6548a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 138 additions and 134 deletions

View File

@ -1,6 +1,8 @@
# Turbo-Geth
Turbo-Geth is a fork of [Go-Ethereum](https://github.com/ethereum/go-ethereum) with focus on performance. [![CircleCI](https://circleci.com/gh/ledgerwatch/turbo-geth.svg?style=svg)](https://circleci.com/gh/ledgerwatch/turbo-geth)
Turbo-Geth is a fork of [Go-Ethereum](https://github.com/ethereum/go-ethereum) with focus on performance.
![Build status](https://github.com/ledgerwatch/turbo-geth/actions/workflows/ci.yml/badge.svg)
<!--ts-->
- [System Requirements](#system-requirements)
@ -63,10 +65,10 @@ If you would like to give turbo-geth a try, but do not have spare 2Tb on your dr
> git clone --recurse-submodules -j8 https://github.com/ledgerwatch/turbo-geth.git
> cd turbo-geth
> make tg
> ./build/bin/tg --datadir goerli --goerli
> ./build/bin/tg --datadir goerli --chain goerli
```
Please note the `--datadir` option that allows you to store turbo-geth files in a non-default location, in this example, in `goerli` subdirectory of the current directory.
Please note the `--datadir` option that allows you to store turbo-geth files in a non-default location, in this example, in `goerli` subdirectory of the current directory. Name of the directory `--datadir` does not have to match the name if the chain in `--chain`.
### Mining

View File

@ -22,7 +22,6 @@ import (
"fmt"
"io"
"math/big"
"os"
"path"
"path/filepath"
"strconv"
@ -109,37 +108,18 @@ var (
}
NetworkIdFlag = cli.Uint64Flag{
Name: "networkid",
Usage: "Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli instead)",
Usage: "Explicitly set network id (integer)(For testnets: use --chain <testnet_name> instead)",
Value: ethconfig.Defaults.NetworkID,
}
MainnetFlag = cli.BoolFlag{
Name: "mainnet",
Usage: "Ethereum mainnet",
}
GoerliFlag = cli.BoolFlag{
Name: "goerli",
Usage: "Görli network: pre-configured proof-of-authority test network",
}
YoloV3Flag = cli.BoolFlag{
Name: "yolov3",
Usage: "YOLOv3 network: pre-configured proof-of-authority shortlived test network.",
}
RinkebyFlag = cli.BoolFlag{
Name: "rinkeby",
Usage: "Rinkeby network: pre-configured proof-of-authority test network",
}
RopstenFlag = cli.BoolFlag{
Name: "ropsten",
Usage: "Ropsten network: pre-configured proof-of-work test network",
}
DeveloperFlag = cli.BoolFlag{
Name: "dev",
Usage: "Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled",
}
DeveloperPeriodFlag = cli.IntFlag{
Name: "dev.period",
Usage: "Block period to use in developer mode (0 = mine only if transaction pending)",
}
ChainFlag = cli.StringFlag{
Name: "chain",
Usage: "Name of the testnet to join",
Value: params.MainnetChainName,
}
IdentityFlag = cli.StringFlag{
Name: "identity",
Usage: "Custom node name",
@ -625,35 +605,6 @@ var (
var MetricFlags = []cli.Flag{MetricsEnabledFlag, MetricsEnabledExpensiveFlag, MetricsHTTPFlag, MetricsPortFlag}
// MakeDataDir retrieves the currently requested data directory, terminating
// if none (or the empty string) is specified. If the node is starting a testnet,
// then a subdirectory of the specified datadir will be used.
func MakeDataDir(ctx *cli.Context) string {
if path := ctx.GlobalString(DataDirFlag.Name); path != "" {
if ctx.GlobalBool(RopstenFlag.Name) {
// Maintain compatibility with older Geth configurations storing the
// Ropsten database in `testnet` instead of `ropsten`.
legacyPath := filepath.Join(path, "testnet")
if _, err := os.Stat(legacyPath); !os.IsNotExist(err) {
return legacyPath
}
return filepath.Join(path, "ropsten")
}
if ctx.GlobalBool(RinkebyFlag.Name) {
return filepath.Join(path, "rinkeby")
}
if ctx.GlobalBool(GoerliFlag.Name) {
return filepath.Join(path, "goerli")
}
if ctx.GlobalBool(YoloV3Flag.Name) {
return filepath.Join(path, "yolo-v3")
}
return path
}
Fatalf("Cannot determine default data directory, please set manually (--datadir)")
return ""
}
// setNodeKey creates a node key from set command line flags, either loading it
// from a file or as a specified hex value. If neither flags were provided, this
// method returns nil and an emphemeral key is to be generated.
@ -696,19 +647,24 @@ func setNodeUserIdentCobra(f *pflag.FlagSet, cfg *node.Config) {
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls := params.MainnetBootnodes
switch {
case ctx.GlobalIsSet(BootnodesFlag.Name):
if ctx.GlobalIsSet(BootnodesFlag.Name) {
urls = SplitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
case ctx.GlobalBool(RopstenFlag.Name):
urls = params.RopstenBootnodes
case ctx.GlobalBool(RinkebyFlag.Name):
urls = params.RinkebyBootnodes
case ctx.GlobalBool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.GlobalBool(YoloV3Flag.Name):
urls = params.YoloV3Bootnodes
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
} else {
chain := ctx.GlobalString(ChainFlag.Name)
switch chain {
case params.RopstenChainName:
urls = params.RopstenBootnodes
case params.RinkebyChainName:
urls = params.RinkebyBootnodes
case params.GoerliChainName:
urls = params.GoerliBootnodes
case params.YoloV3ChainName:
urls = params.YoloV3Bootnodes
default:
if cfg.BootstrapNodes != nil {
return // already set, don't apply defaults.
}
}
}
cfg.BootstrapNodes = make([]*enode.Node, 0, len(urls))
@ -728,19 +684,25 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
urls := params.MainnetBootnodes
switch {
case ctx.GlobalIsSet(BootnodesFlag.Name):
if ctx.GlobalIsSet(BootnodesFlag.Name) {
urls = SplitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
case ctx.GlobalBool(RopstenFlag.Name):
urls = params.RopstenBootnodes
case ctx.GlobalBool(RinkebyFlag.Name):
urls = params.RinkebyBootnodes
case ctx.GlobalBool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.GlobalBool(YoloV3Flag.Name):
urls = params.YoloV3Bootnodes
case cfg.BootstrapNodesV5 != nil:
return // already set, don't apply defaults.
} else {
chain := ctx.GlobalString(ChainFlag.Name)
switch chain {
case params.RopstenChainName:
urls = params.RopstenBootnodes
case params.RinkebyChainName:
urls = params.RinkebyBootnodes
case params.GoerliChainName:
urls = params.GoerliBootnodes
case params.YoloV3ChainName:
urls = params.YoloV3Bootnodes
default:
if cfg.BootstrapNodesV5 != nil {
return // already set, don't apply defaults.
}
}
}
cfg.BootstrapNodesV5 = make([]*enode.Node, 0, len(urls))
@ -851,7 +813,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
cfg.NetRestrict = list
}
if ctx.GlobalBool(DeveloperFlag.Name) {
if ctx.GlobalString(ChainFlag.Name) == params.DevChainName {
// --dev mode can't use p2p networking.
cfg.MaxPeers = 0
cfg.ListenAddr = ":0"
@ -874,39 +836,52 @@ func SetNodeConfigCobra(cmd *cobra.Command, cfg *node.Config) {
}
func setDataDir(ctx *cli.Context, cfg *node.Config) {
switch {
case ctx.GlobalIsSet(DataDirFlag.Name):
if ctx.GlobalIsSet(DataDirFlag.Name) {
cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
case ctx.GlobalBool(DeveloperFlag.Name):
cfg.DataDir = "" // unless explicitly requested, use memory databases
case ctx.GlobalBool(RinkebyFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
case ctx.GlobalBool(GoerliFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
case ctx.GlobalBool(YoloV3Flag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "yolo-v3")
} else {
chain := ctx.GlobalString(ChainFlag.Name)
switch chain {
case params.RinkebyChainName:
if cfg.DataDir == node.DefaultDataDir() {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
}
case params.GoerliChainName:
if cfg.DataDir == node.DefaultDataDir() {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
}
case params.YoloV3ChainName:
if cfg.DataDir == node.DefaultDataDir() {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "yolo-v3")
}
}
}
}
func setDataDirCobra(f *pflag.FlagSet, cfg *node.Config) {
dirname, err := f.GetString(DataDirFlag.Name)
if err != nil {
panic(err)
}
dev := f.Bool(DeveloperFlag.Name, false, DeveloperFlag.Usage)
rinkeby := f.Bool(RinkebyFlag.Name, false, RinkebyFlag.Usage)
goerli := f.Bool(GoerliFlag.Name, false, GoerliFlag.Usage)
yolov3 := f.Bool(YoloV3Flag.Name, false, YoloV3Flag.Usage)
switch {
case dirname != "":
chain := f.String(ChainFlag.Name, ChainFlag.Value, ChainFlag.Usage)
if dirname != "" {
cfg.DataDir = dirname
case dev != nil:
cfg.DataDir = "" // unless explicitly requested, use memory databases
case rinkeby != nil && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
case goerli != nil && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
case yolov3 != nil && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "yolo-v3")
} else if chain != nil {
switch *chain {
case params.DevChainName:
cfg.DataDir = "" // unless explicitly requested, use memory databases
case params.RinkebyChainName:
if cfg.DataDir == node.DefaultDataDir() {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
}
case params.GoerliChainName:
if cfg.DataDir == node.DefaultDataDir() {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
}
case params.YoloV3ChainName:
if cfg.DataDir == node.DefaultDataDir() {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "yolo-v3")
}
}
}
}
@ -1147,8 +1122,6 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// Avoid conflicting network flags
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV3Flag)
CheckExclusive(ctx, MinerSigningKeyFlag, MinerEtherbaseFlag)
setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO)
@ -1225,37 +1198,38 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
}
// Override any default configs for hard coded networks.
switch {
case ctx.GlobalBool(MainnetFlag.Name):
chain := ctx.GlobalString(ChainFlag.Name)
switch chain {
case params.MainnetChainName:
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkID = 1
}
cfg.Genesis = core.DefaultGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
case ctx.GlobalBool(RopstenFlag.Name):
case params.RopstenChainName:
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkID = 3
}
cfg.Genesis = core.DefaultRopstenGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.RopstenGenesisHash)
case ctx.GlobalBool(RinkebyFlag.Name):
case params.RinkebyChainName:
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkID = 4
}
cfg.Genesis = core.DefaultRinkebyGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.RinkebyGenesisHash)
case ctx.GlobalBool(GoerliFlag.Name):
case params.GoerliChainName:
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkID = 5
}
cfg.Genesis = core.DefaultGoerliGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.GoerliGenesisHash)
case ctx.GlobalBool(YoloV3Flag.Name):
case params.YoloV3ChainName:
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkID = new(big.Int).SetBytes([]byte("yolov3x")).Uint64() // "yolov3x"
}
cfg.Genesis = core.DefaultYoloV3GenesisBlock()
case ctx.GlobalBool(DeveloperFlag.Name):
case params.DevChainName:
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkID = 1337
}
@ -1343,16 +1317,17 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) *ethdb.ObjectDatabase
func MakeGenesis(ctx *cli.Context) *core.Genesis {
var genesis *core.Genesis
switch {
case ctx.GlobalBool(RopstenFlag.Name):
chain := ctx.GlobalString(ChainFlag.Name)
switch chain {
case params.RopstenChainName:
genesis = core.DefaultRopstenGenesisBlock()
case ctx.GlobalBool(RinkebyFlag.Name):
case params.RinkebyChainName:
genesis = core.DefaultRinkebyGenesisBlock()
case ctx.GlobalBool(GoerliFlag.Name):
case params.GoerliChainName:
genesis = core.DefaultGoerliGenesisBlock()
case ctx.GlobalBool(YoloV3Flag.Name):
case params.YoloV3ChainName:
genesis = core.DefaultYoloV3GenesisBlock()
case ctx.GlobalBool(DeveloperFlag.Name):
case params.DevChainName:
Fatalf("Developer chains are ephemeral")
}
return genesis

View File

@ -25,6 +25,15 @@ import (
"github.com/ledgerwatch/turbo-geth/crypto"
)
const (
MainnetChainName = "mainnet"
RopstenChainName = "ropsten"
RinkebyChainName = "rinkeby"
GoerliChainName = "goerli"
YoloV3ChainName = "yolov3"
DevChainName = "dev"
)
// Genesis hashes to enforce below configs on.
var (
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
@ -239,6 +248,24 @@ var (
},
}
// MainnetChainConfig is the chain parameters to run a PoW dev net to test turbo-geth mining
TurboMineChainConfig = &ChainConfig{
ChainID: new(big.Int).SetBytes([]byte("turbo-mine")),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
Ethash: new(EthashConfig),
}
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Ethash consensus.
//

View File

@ -45,10 +45,7 @@ var DefaultFlags = []cli.Flag{
utils.NodeKeyFileFlag,
utils.NodeKeyHexFlag,
utils.DNSDiscoveryFlag,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.YoloV3Flag,
utils.ChainFlag,
utils.VMEnableDebugFlag,
utils.NetworkIdFlag,
utils.FakePoWFlag,

View File

@ -125,26 +125,29 @@ func makeConfigNode(config *node.Config) *node.Node {
// This function should be called before launching devp2p stack.
func prepare(ctx *cli.Context) {
// If we're running a known preset, log it for convenience.
switch {
case ctx.GlobalIsSet(utils.RopstenFlag.Name):
chain := ctx.GlobalString(utils.ChainFlag.Name)
switch chain {
case params.RopstenChainName:
log.Info("Starting Turbo-Geth on Ropsten testnet...")
case ctx.GlobalIsSet(utils.RinkebyFlag.Name):
case params.RinkebyChainName:
log.Info("Starting Turbo-Geth on Rinkeby testnet...")
case ctx.GlobalIsSet(utils.GoerliFlag.Name):
case params.GoerliChainName:
log.Info("Starting Turbo-Geth on Görli testnet...")
case ctx.GlobalIsSet(utils.DeveloperFlag.Name):
case params.DevChainName:
log.Info("Starting Turbo-Geth in ephemeral dev mode...")
case !ctx.GlobalIsSet(utils.NetworkIdFlag.Name):
log.Info("Starting Turbo-Geth on Ethereum mainnet...")
default:
if !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
log.Info("Starting Turbo-Geth on Ethereum mainnet...")
}
}
// If we're a full node on mainnet without --cache specified, bump default cache allowance
if !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
// Make sure we're not on any supported preconfigured testnet either
if !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
if chain != params.RopstenChainName && chain != params.RinkebyChainName && chain != params.GoerliChainName && chain != params.DevChainName {
// Nope, we're really on mainnet. Bump that cache up!
log.Info("Bumping default cache on mainnet", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 4096)
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(4096)) //nolint:errcheck