mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
Added script to generate config.toml fromstart.sh (#518)
* added go and bash script to get config out of start.sh and updated flagset.go * changed 'requiredblocks' flag back to 'eth.requiredblocks' * updated script * changed 'requiredblocks' flag back to 'eth.requiredblocks' * updated tests, and removed requiredblocks from json and hcl * addressed comments
This commit is contained in:
parent
2a677a5aff
commit
77db80cc91
14 changed files with 779 additions and 16 deletions
|
|
@ -12,7 +12,7 @@ syncmode = "full"
|
|||
# snapshot = true
|
||||
# ethstats = ""
|
||||
|
||||
# [requiredblocks]
|
||||
# ["eth.requiredblocks"]
|
||||
|
||||
[p2p]
|
||||
# maxpeers = 1
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ gcmode = "full"
|
|||
snapshot = true
|
||||
ethstats = ""
|
||||
|
||||
["eth.requiredblocks"]
|
||||
|
||||
[p2p]
|
||||
maxpeers = 30
|
||||
maxpendpeers = 50
|
||||
|
|
|
|||
1
go.mod
1
go.mod
|
|
@ -122,6 +122,7 @@ require (
|
|||
github.com/mitchellh/pointerstructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.0 // indirect
|
||||
github.com/opentracing/opentracing-go v1.1.0 // indirect
|
||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/posener/complete v1.1.1 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -401,6 +401,8 @@ github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mo
|
|||
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE=
|
||||
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
||||
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||
github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
|
||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
|
||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@ func (f *Flagset) Help() string {
|
|||
return str + strings.Join(items, "\n\n")
|
||||
}
|
||||
|
||||
func (f *Flagset) GetAllFlags() []string {
|
||||
flags := []string{}
|
||||
for _, flag := range f.flags {
|
||||
flags = append(flags, flag.Name)
|
||||
}
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
// MarkDown implements cli.MarkDown interface
|
||||
func (f *Flagset) MarkDown() string {
|
||||
if len(f.flags) == 0 {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func TestFlags(t *testing.T) {
|
|||
"--dev.period", "2",
|
||||
"--datadir", "./data",
|
||||
"--maxpeers", "30",
|
||||
"--requiredblocks", "a=b",
|
||||
"--eth.requiredblocks", "a=b",
|
||||
"--http.api", "eth,web3,bor",
|
||||
}
|
||||
err := c.extractFlags(args)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ type Config struct {
|
|||
Identity string `hcl:"identity,optional" toml:"identity,optional"`
|
||||
|
||||
// RequiredBlocks is a list of required (block number, hash) pairs to accept
|
||||
RequiredBlocks map[string]string `hcl:"requiredblocks,optional" toml:"requiredblocks,optional"`
|
||||
RequiredBlocks map[string]string `hcl:"eth.requiredblocks,optional" toml:"eth.requiredblocks,optional"`
|
||||
|
||||
// LogLevel is the level of the logs to put out
|
||||
LogLevel string `hcl:"log-level,optional" toml:"log-level,optional"`
|
||||
|
|
|
|||
|
|
@ -108,9 +108,6 @@ func TestConfigLoadFile(t *testing.T) {
|
|||
|
||||
assert.Equal(t, config, &Config{
|
||||
DataDir: "./data",
|
||||
RequiredBlocks: map[string]string{
|
||||
"a": "b",
|
||||
},
|
||||
P2P: &P2PConfig{
|
||||
MaxPeers: 30,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ func (c *Command) Flags() *flagset.Flagset {
|
|||
Default: c.cliConfig.GcMode,
|
||||
})
|
||||
f.MapStringFlag(&flagset.MapStringFlag{
|
||||
Name: "requiredblocks",
|
||||
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
|
||||
Name: "eth.requiredblocks",
|
||||
Usage: "Comma separated block number-to-hash mappings to require for peering (<number>=<hash>)",
|
||||
Value: &c.cliConfig.RequiredBlocks,
|
||||
})
|
||||
f.BoolFlag(&flagset.BoolFlag{
|
||||
|
|
|
|||
4
internal/cli/server/testdata/test.hcl
vendored
4
internal/cli/server/testdata/test.hcl
vendored
|
|
@ -1,9 +1,5 @@
|
|||
datadir = "./data"
|
||||
|
||||
requiredblocks = {
|
||||
a = "b"
|
||||
}
|
||||
|
||||
p2p {
|
||||
maxpeers = 30
|
||||
}
|
||||
|
|
|
|||
3
internal/cli/server/testdata/test.json
vendored
3
internal/cli/server/testdata/test.json
vendored
|
|
@ -1,8 +1,5 @@
|
|||
{
|
||||
"datadir": "./data",
|
||||
"requiredblocks": {
|
||||
"a": "b"
|
||||
},
|
||||
"p2p": {
|
||||
"maxpeers": 30
|
||||
},
|
||||
|
|
|
|||
2
internal/cli/server/testdata/test.toml
vendored
2
internal/cli/server/testdata/test.toml
vendored
|
|
@ -1,6 +1,6 @@
|
|||
datadir = "./data"
|
||||
|
||||
[requiredblocks]
|
||||
["eth.requiredblocks"]
|
||||
a = "b"
|
||||
|
||||
[p2p]
|
||||
|
|
|
|||
672
scripts/getconfig.go
Normal file
672
scripts/getconfig.go
Normal file
|
|
@ -0,0 +1,672 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pelletier/go-toml"
|
||||
|
||||
"github.com/ethereum/go-ethereum/internal/cli/server"
|
||||
)
|
||||
|
||||
// YesFV: Both, Flags and their values has changed
|
||||
// YesF: Only the Flag has changed, not their value
|
||||
var flagMap = map[string][]string{
|
||||
"networkid": {"notABoolFlag", "YesFV"},
|
||||
"miner.gastarget": {"notABoolFlag", "No"},
|
||||
"pprof": {"BoolFlag", "No"},
|
||||
"pprof.port": {"notABoolFlag", "No"},
|
||||
"pprof.addr": {"notABoolFlag", "No"},
|
||||
"pprof.memprofilerate": {"notABoolFlag", "No"},
|
||||
"pprof.blockprofilerate": {"notABoolFlag", "No"},
|
||||
"pprof.cpuprofile": {"notABoolFlag", "No"},
|
||||
"jsonrpc.corsdomain": {"notABoolFlag", "YesF"},
|
||||
"jsonrpc.vhosts": {"notABoolFlag", "YesF"},
|
||||
"http.modules": {"notABoolFlag", "YesF"},
|
||||
"ws.modules": {"notABoolFlag", "YesF"},
|
||||
"config": {"notABoolFlag", "No"},
|
||||
"datadir.ancient": {"notABoolFlag", "No"},
|
||||
"datadir.minfreedisk": {"notABoolFlag", "No"},
|
||||
"usb": {"BoolFlag", "No"},
|
||||
"pcscdpath": {"notABoolFlag", "No"},
|
||||
"mainnet": {"BoolFlag", "No"},
|
||||
"goerli": {"BoolFlag", "No"},
|
||||
"bor-mumbai": {"BoolFlag", "No"},
|
||||
"bor-mainnet": {"BoolFlag", "No"},
|
||||
"rinkeby": {"BoolFlag", "No"},
|
||||
"ropsten": {"BoolFlag", "No"},
|
||||
"sepolia": {"BoolFlag", "No"},
|
||||
"kiln": {"BoolFlag", "No"},
|
||||
"exitwhensynced": {"BoolFlag", "No"},
|
||||
"light.serve": {"notABoolFlag", "No"},
|
||||
"light.ingress": {"notABoolFlag", "No"},
|
||||
"light.egress": {"notABoolFlag", "No"},
|
||||
"light.maxpeers": {"notABoolFlag", "No"},
|
||||
"ulc.servers": {"notABoolFlag", "No"},
|
||||
"ulc.fraction": {"notABoolFlag", "No"},
|
||||
"ulc.onlyannounce": {"BoolFlag", "No"},
|
||||
"light.nopruning": {"BoolFlag", "No"},
|
||||
"light.nosyncserve": {"BoolFlag", "No"},
|
||||
"dev.gaslimit": {"notABoolFlag", "No"},
|
||||
"ethash.cachedir": {"notABoolFlag", "No"},
|
||||
"ethash.cachesinmem": {"notABoolFlag", "No"},
|
||||
"ethash.cachesondisk": {"notABoolFlag", "No"},
|
||||
"ethash.cacheslockmmap": {"BoolFlag", "No"},
|
||||
"ethash.dagdir": {"notABoolFlag", "No"},
|
||||
"ethash.dagsinmem": {"notABoolFlag", "No"},
|
||||
"ethash.dagsondisk": {"notABoolFlag", "No"},
|
||||
"ethash.dagslockmmap": {"BoolFlag", "No"},
|
||||
"fdlimit": {"notABoolFlag", "No"},
|
||||
"signer": {"notABoolFlag", "No"},
|
||||
"authrpc.jwtsecret": {"notABoolFlag", "No"},
|
||||
"authrpc.addr": {"notABoolFlag", "No"},
|
||||
"authrpc.port": {"notABoolFlag", "No"},
|
||||
"authrpc.vhosts": {"notABoolFlag", "No"},
|
||||
"graphql.corsdomain": {"notABoolFlag", "No"},
|
||||
"graphql.vhosts": {"notABoolFlag", "No"},
|
||||
"rpc.evmtimeout": {"notABoolFlag", "No"},
|
||||
"rpc.allow-unprotected-txs": {"BoolFlag", "No"},
|
||||
"jspath": {"notABoolFlag", "No"},
|
||||
"exec": {"notABoolFlag", "No"},
|
||||
"preload": {"notABoolFlag", "No"},
|
||||
"discovery.dns": {"notABoolFlag", "No"},
|
||||
"netrestrict": {"notABoolFlag", "No"},
|
||||
"nodekey": {"notABoolFlag", "No"},
|
||||
"nodekeyhex": {"notABoolFlag", "No"},
|
||||
"miner.threads": {"notABoolFlag", "No"},
|
||||
"miner.notify": {"notABoolFlag", "No"},
|
||||
"miner.notify.full": {"BoolFlag", "No"},
|
||||
"miner.recommit": {"notABoolFlag", "No"},
|
||||
"miner.noverify": {"BoolFlag", "No"},
|
||||
"vmdebug": {"BoolFlag", "No"},
|
||||
"fakepow": {"BoolFlag", "No"},
|
||||
"nocompaction": {"BoolFlag", "No"},
|
||||
"metrics.addr": {"notABoolFlag", "No"},
|
||||
"metrics.port": {"notABoolFlag", "No"},
|
||||
"whitelist": {"notABoolFlag", "No"},
|
||||
"snapshot": {"BoolFlag", "YesF"},
|
||||
"bloomfilter.size": {"notABoolFlag", "No"},
|
||||
"bor.logs": {"BoolFlag", "No"},
|
||||
"override.arrowglacier": {"notABoolFlag", "No"},
|
||||
"override.terminaltotaldifficulty": {"notABoolFlag", "No"},
|
||||
"verbosity": {"notABoolFlag", "YesFV"},
|
||||
"ws.origins": {"notABoolFlag", "YesF"},
|
||||
}
|
||||
|
||||
// map from cli flags to corresponding toml tags
|
||||
var nameTagMap = map[string]string{
|
||||
"chain": "chain",
|
||||
"identity": "identity",
|
||||
"log-level": "log-level",
|
||||
"datadir": "datadir",
|
||||
"keystore": "keystore",
|
||||
"syncmode": "syncmode",
|
||||
"gcmode": "gcmode",
|
||||
"eth.requiredblocks": "eth.requiredblocks",
|
||||
"0-snapshot": "snapshot",
|
||||
"url": "bor.heimdall",
|
||||
"bor.without": "bor.withoutheimdall",
|
||||
"grpc-address": "bor.heimdallgRPC",
|
||||
"locals": "txpool.locals",
|
||||
"nolocals": "txpool.nolocals",
|
||||
"journal": "txpool.journal",
|
||||
"rejournal": "txpool.rejournal",
|
||||
"pricelimit": "txpool.pricelimit",
|
||||
"pricebump": "txpool.pricebump",
|
||||
"accountslots": "txpool.accountslots",
|
||||
"globalslots": "txpool.globalslots",
|
||||
"accountqueue": "txpool.accountqueue",
|
||||
"globalqueue": "txpool.globalqueue",
|
||||
"lifetime": "txpool.lifetime",
|
||||
"mine": "mine",
|
||||
"etherbase": "miner.etherbase",
|
||||
"extradata": "miner.extradata",
|
||||
"gaslimit": "miner.gaslimit",
|
||||
"gasprice": "miner.gasprice",
|
||||
"ethstats": "ethstats",
|
||||
"blocks": "gpo.blocks",
|
||||
"percentile": "gpo.percentile",
|
||||
"maxprice": "gpo.maxprice",
|
||||
"ignoreprice": "gpo.ignoreprice",
|
||||
"cache": "cache",
|
||||
"1-database": "cache.database",
|
||||
"trie": "cache.trie",
|
||||
"trie.journal": "cache.journal",
|
||||
"trie.rejournal": "cache.rejournal",
|
||||
"gc": "cache.gc",
|
||||
"1-snapshot": "cache.snapshot",
|
||||
"noprefetch": "cache.noprefetch",
|
||||
"preimages": "cache.preimages",
|
||||
"txlookuplimit": "txlookuplimit",
|
||||
"gascap": "rpc.gascap",
|
||||
"txfeecap": "rpc.txfeecap",
|
||||
"ipcdisable": "ipcdisable",
|
||||
"ipcpath": "ipcpath",
|
||||
"1-corsdomain": "http.corsdomain",
|
||||
"1-vhosts": "http.vhosts",
|
||||
"2-corsdomain": "ws.corsdomain",
|
||||
"2-vhosts": "ws.vhosts",
|
||||
"3-corsdomain": "graphql.corsdomain",
|
||||
"3-vhosts": "graphql.vhosts",
|
||||
"1-enabled": "http",
|
||||
"1-host": "http.addr",
|
||||
"1-port": "http.port",
|
||||
"1-prefix": "http.rpcprefix",
|
||||
"1-api": "http.api",
|
||||
"2-enabled": "ws",
|
||||
"2-host": "ws.addr",
|
||||
"2-port": "ws.port",
|
||||
"2-prefix": "ws.rpcprefix",
|
||||
"2-api": "ws.api",
|
||||
"3-enabled": "graphql",
|
||||
"bind": "bind",
|
||||
"0-port": "port",
|
||||
"bootnodes": "bootnodes",
|
||||
"maxpeers": "maxpeers",
|
||||
"maxpendpeers": "maxpendpeers",
|
||||
"nat": "nat",
|
||||
"nodiscover": "nodiscover",
|
||||
"v5disc": "v5disc",
|
||||
"metrics": "metrics",
|
||||
"expensive": "metrics.expensive",
|
||||
"influxdb": "metrics.influxdb",
|
||||
"endpoint": "metrics.influxdb.endpoint",
|
||||
"0-database": "metrics.influxdb.database",
|
||||
"username": "metrics.influxdb.username",
|
||||
"0-password": "metrics.influxdb.password",
|
||||
"tags": "metrics.influxdb.tags",
|
||||
"prometheus-addr": "metrics.prometheus-addr",
|
||||
"opencollector-endpoint": "metrics.opencollector-endpoint",
|
||||
"influxdbv2": "metrics.influxdbv2",
|
||||
"token": "metrics.influxdb.token",
|
||||
"bucket": "metrics.influxdb.bucket",
|
||||
"organization": "metrics.influxdb.organization",
|
||||
"unlock": "unlock",
|
||||
"1-password": "password",
|
||||
"allow-insecure-unlock": "allow-insecure-unlock",
|
||||
"lightkdf": "lightkdf",
|
||||
"disable-bor-wallet": "disable-bor-wallet",
|
||||
"addr": "grpc.addr",
|
||||
"dev": "dev",
|
||||
"period": "dev.period",
|
||||
}
|
||||
|
||||
var removedFlagsAndValues = map[string]string{}
|
||||
|
||||
var replacedFlagsMapFlagAndValue = map[string]map[string]map[string]string{
|
||||
"networkid": {
|
||||
"flag": {
|
||||
"networkid": "chain",
|
||||
},
|
||||
"value": {
|
||||
"'137'": "mainnet",
|
||||
"137": "mainnet",
|
||||
"'80001'": "mumbai",
|
||||
"80001": "mumbai",
|
||||
},
|
||||
},
|
||||
"verbosity": {
|
||||
"flag": {
|
||||
"verbosity": "log-level",
|
||||
},
|
||||
"value": {
|
||||
"0": "SILENT",
|
||||
"1": "ERROR",
|
||||
"2": "WARN",
|
||||
"3": "INFO",
|
||||
"4": "DEBUG",
|
||||
"5": "DETAIL",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var replacedFlagsMapFlag = map[string]string{
|
||||
"ws.origins": "ws.corsdomain",
|
||||
}
|
||||
|
||||
var currentBoolFlags = []string{
|
||||
"snapshot",
|
||||
"bor.withoutheimdall",
|
||||
"txpool.nolocals",
|
||||
"mine",
|
||||
"cache.noprefetch",
|
||||
"cache.preimages",
|
||||
"ipcdisable",
|
||||
"http",
|
||||
"ws",
|
||||
"graphql",
|
||||
"nodiscover",
|
||||
"v5disc",
|
||||
"metrics",
|
||||
"metrics.expensive",
|
||||
"metrics.influxdb",
|
||||
"metrics.influxdbv2",
|
||||
"allow-insecure-unlock",
|
||||
"lightkdf",
|
||||
"disable-bor-wallet",
|
||||
"dev",
|
||||
}
|
||||
|
||||
func contains(s []string, str string) (bool, int) {
|
||||
for ind, v := range s {
|
||||
if v == str || v == "-"+str || v == "--"+str {
|
||||
return true, ind
|
||||
}
|
||||
}
|
||||
|
||||
return false, -1
|
||||
}
|
||||
|
||||
func indexOf(s []string, str string) int {
|
||||
for k, v := range s {
|
||||
if v == str || v == "-"+str || v == "--"+str {
|
||||
return k
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func remove1(s []string, idx int) []string {
|
||||
removedFlagsAndValues[s[idx]] = ""
|
||||
return append(s[:idx], s[idx+1:]...)
|
||||
}
|
||||
|
||||
func remove2(s []string, idx int) []string {
|
||||
removedFlagsAndValues[s[idx]] = s[idx+1]
|
||||
return append(s[:idx], s[idx+2:]...)
|
||||
}
|
||||
|
||||
func checkFlag(allFlags []string, checkFlags []string) []string {
|
||||
outOfDateFlags := []string{}
|
||||
|
||||
for _, flag := range checkFlags {
|
||||
t1, _ := contains(allFlags, flag)
|
||||
if !t1 {
|
||||
outOfDateFlags = append(outOfDateFlags, flag)
|
||||
}
|
||||
}
|
||||
|
||||
return outOfDateFlags
|
||||
}
|
||||
|
||||
func checkFileExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
fmt.Println("WARN: File does not exist", path)
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func writeTempStaticJSON(path string) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var conf interface{}
|
||||
if err := json.Unmarshal(data, &conf); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
temparr := []string{}
|
||||
for _, item := range conf.([]interface{}) {
|
||||
temparr = append(temparr, item.(string))
|
||||
}
|
||||
|
||||
// write to a temp file
|
||||
err = os.WriteFile("./tempStaticNodes.json", []byte(strings.Join(temparr, "\", \"")), 0600)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeTempStaticTrustedTOML(path string) {
|
||||
data, err := toml.LoadFile(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if data.Has("Node.P2P.StaticNodes") {
|
||||
temparr := []string{}
|
||||
for _, item := range data.Get("Node.P2P.StaticNodes").([]interface{}) {
|
||||
temparr = append(temparr, item.(string))
|
||||
}
|
||||
|
||||
err = os.WriteFile("./tempStaticNodes.toml", []byte(strings.Join(temparr, "\", \"")), 0600)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if data.Has("Node.P2P.TrustedNodes") {
|
||||
temparr := []string{}
|
||||
for _, item := range data.Get("Node.P2P.TrustedNodes").([]interface{}) {
|
||||
temparr = append(temparr, item.(string))
|
||||
}
|
||||
|
||||
err = os.WriteFile("./tempTrustedNodes.toml", []byte(strings.Join(temparr, "\", \"")), 0600)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getStaticTrustedNodes(args []string) {
|
||||
// if config flag is passed, it should be only a .toml file
|
||||
t1, t2 := contains(args, "config")
|
||||
// nolint: nestif
|
||||
if t1 {
|
||||
path := args[t2+1]
|
||||
if !checkFileExists(path) {
|
||||
return
|
||||
}
|
||||
|
||||
if path[len(path)-4:] == "toml" {
|
||||
writeTempStaticTrustedTOML(path)
|
||||
} else {
|
||||
fmt.Println("only TOML config file is supported through CLI")
|
||||
}
|
||||
} else {
|
||||
path := "~/.bor/data/bor/static-nodes.json"
|
||||
if !checkFileExists(path) {
|
||||
return
|
||||
}
|
||||
writeTempStaticJSON(path)
|
||||
}
|
||||
}
|
||||
|
||||
func getFlagsToCheck(args []string) []string {
|
||||
flagsToCheck := []string{}
|
||||
|
||||
for _, item := range args {
|
||||
if strings.HasPrefix(item, "-") {
|
||||
if item[1] == '-' {
|
||||
temp := item[2:]
|
||||
flagsToCheck = append(flagsToCheck, temp)
|
||||
} else {
|
||||
temp := item[1:]
|
||||
flagsToCheck = append(flagsToCheck, temp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flagsToCheck
|
||||
}
|
||||
|
||||
func getFlagType(flag string) string {
|
||||
return flagMap[flag][0]
|
||||
}
|
||||
|
||||
func updateArgsClean(args []string, outOfDateFlags []string) []string {
|
||||
updatedArgs := []string{}
|
||||
updatedArgs = append(updatedArgs, args...)
|
||||
|
||||
// iterate through outOfDateFlags and remove the flags from updatedArgs along with their value (if any)
|
||||
for _, item := range outOfDateFlags {
|
||||
idx := indexOf(updatedArgs, item)
|
||||
|
||||
if getFlagType(item) == "BoolFlag" {
|
||||
// remove the element at index idx
|
||||
updatedArgs = remove1(updatedArgs, idx)
|
||||
} else {
|
||||
// remove the element at index idx and idx + 1
|
||||
updatedArgs = remove2(updatedArgs, idx)
|
||||
}
|
||||
}
|
||||
|
||||
return updatedArgs
|
||||
}
|
||||
|
||||
func updateArgsAdd(args []string) []string {
|
||||
for flag, value := range removedFlagsAndValues {
|
||||
if strings.HasPrefix(flag, "--") {
|
||||
flag = flag[2:]
|
||||
} else {
|
||||
flag = flag[1:]
|
||||
}
|
||||
|
||||
if flagMap[flag][1] == "YesFV" {
|
||||
temp := "--" + replacedFlagsMapFlagAndValue[flag]["flag"][flag] + " " + replacedFlagsMapFlagAndValue[flag]["value"][value]
|
||||
args = append(args, temp)
|
||||
} else if flagMap[flag][1] == "YesF" {
|
||||
temp := "--" + replacedFlagsMapFlag[flag] + " " + value
|
||||
args = append(args, temp)
|
||||
}
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func handleGRPC(args []string, updatedArgs []string) []string {
|
||||
var newUpdatedArgs []string
|
||||
|
||||
var addr string
|
||||
|
||||
var port string
|
||||
|
||||
newUpdatedArgs = append(newUpdatedArgs, updatedArgs...)
|
||||
|
||||
for i, val := range args {
|
||||
if strings.Contains(val, "pprof.addr") && strings.Contains(val, "-") {
|
||||
addr = args[i+1]
|
||||
}
|
||||
|
||||
if strings.Contains(val, "pprof.port") && strings.Contains(val, "-") {
|
||||
port = args[i+1]
|
||||
}
|
||||
}
|
||||
|
||||
newUpdatedArgs = append(newUpdatedArgs, "--grpc.addr")
|
||||
newUpdatedArgs = append(newUpdatedArgs, addr+":"+port)
|
||||
|
||||
return newUpdatedArgs
|
||||
}
|
||||
|
||||
func dumpFlags(args []string) {
|
||||
err := os.WriteFile("./temp", []byte(strings.Join(args, " ")), 0600)
|
||||
if err != nil {
|
||||
fmt.Println("Error in WriteFile")
|
||||
} else {
|
||||
fmt.Println("WriteFile Done")
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: gocognit
|
||||
func commentFlags(path string, updatedArgs []string) {
|
||||
const cache = "[cache]"
|
||||
|
||||
const telemetry = "[telemetry]"
|
||||
|
||||
// snapshot: "[cache]"
|
||||
cacheFlag := 0
|
||||
|
||||
// corsdomain, vhosts, enabled, host, api, port, prefix: "[p2p]", " [jsonrpc.http]", " [jsonrpc.ws]", " [jsonrpc.graphql]"
|
||||
p2pHttpWsGraphFlag := -1
|
||||
|
||||
// database: "[telemetry]", "[cache]"
|
||||
databaseFlag := -1
|
||||
|
||||
// password: "[telemetry]", "[accounts]"
|
||||
passwordFlag := -1
|
||||
|
||||
ignoreLineFlag := false
|
||||
|
||||
input, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
lines := strings.Split(string(input), "\n")
|
||||
|
||||
var newLines []string
|
||||
newLines = append(newLines, lines...)
|
||||
|
||||
for i, line := range lines {
|
||||
if line == cache {
|
||||
cacheFlag += 1
|
||||
}
|
||||
|
||||
if line == "[p2p]" || line == " [jsonrpc.http]" || line == " [jsonrpc.ws]" || line == " [jsonrpc.graphql]" {
|
||||
p2pHttpWsGraphFlag += 1
|
||||
}
|
||||
|
||||
if line == telemetry || line == cache {
|
||||
databaseFlag += 1
|
||||
}
|
||||
|
||||
if line == telemetry || line == "[accounts]" {
|
||||
passwordFlag += 1
|
||||
}
|
||||
|
||||
if line == "[\"eth.requiredblocks\"]" || line == " [telemetry.influx.tags]" {
|
||||
ignoreLineFlag = true
|
||||
} else if line != "" {
|
||||
if strings.HasPrefix(strings.Fields(line)[0], "[") {
|
||||
ignoreLineFlag = false
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: nestif
|
||||
if !(strings.HasPrefix(line, "[") || strings.HasPrefix(line, " [") || strings.HasPrefix(line, " [") || line == "" || ignoreLineFlag) {
|
||||
flag := strings.Fields(line)[0]
|
||||
if flag == "snapshot" {
|
||||
flag = strconv.Itoa(cacheFlag) + "-" + flag
|
||||
} else if flag == "corsdomain" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "vhosts" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "enabled" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "host" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "api" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "port" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "prefix" {
|
||||
flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag
|
||||
} else if flag == "database" {
|
||||
flag = strconv.Itoa(databaseFlag) + "-" + flag
|
||||
} else if flag == "password" {
|
||||
flag = strconv.Itoa(passwordFlag) + "-" + flag
|
||||
}
|
||||
|
||||
if flag != "static-nodes" && flag != "trusted-nodes" {
|
||||
flag = nameTagMap[flag]
|
||||
|
||||
tempFlag := false
|
||||
|
||||
for _, val := range updatedArgs {
|
||||
if strings.Contains(val, flag) && (strings.Contains(val, "-") || strings.Contains(val, "--")) {
|
||||
tempFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
if !tempFlag || flag == "" {
|
||||
newLines[i] = "# " + line
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output := strings.Join(newLines, "\n")
|
||||
|
||||
err = os.WriteFile(path, []byte(output), 0600)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func checkBoolFlags(val string) bool {
|
||||
returnFlag := false
|
||||
|
||||
if strings.Contains(val, "=") {
|
||||
val = strings.Split(val, "=")[0]
|
||||
}
|
||||
|
||||
for _, flag := range currentBoolFlags {
|
||||
if val == "-"+flag || val == "--"+flag {
|
||||
returnFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
return returnFlag
|
||||
}
|
||||
|
||||
func beautifyArgs(args []string) ([]string, []string) {
|
||||
newArgs := []string{}
|
||||
|
||||
ignoreForNow := []string{}
|
||||
|
||||
temp := []string{}
|
||||
|
||||
for _, val := range args {
|
||||
// nolint: nestif
|
||||
if !(checkBoolFlags(val)) {
|
||||
if strings.HasPrefix(val, "-") {
|
||||
if strings.Contains(val, "=") {
|
||||
temparr := strings.Split(val, "=")
|
||||
newArgs = append(newArgs, temparr...)
|
||||
} else {
|
||||
newArgs = append(newArgs, val)
|
||||
}
|
||||
} else {
|
||||
newArgs = append(newArgs, val)
|
||||
}
|
||||
} else {
|
||||
ignoreForNow = append(ignoreForNow, val)
|
||||
}
|
||||
}
|
||||
|
||||
for j, val := range newArgs {
|
||||
if val == "-unlock" || val == "--unlock" {
|
||||
temp = append(temp, "--miner.etherbase")
|
||||
temp = append(temp, newArgs[j+1])
|
||||
}
|
||||
}
|
||||
|
||||
newArgs = append(newArgs, temp...)
|
||||
|
||||
return newArgs, ignoreForNow
|
||||
}
|
||||
|
||||
func main() {
|
||||
const notYet = "notYet"
|
||||
|
||||
temp := os.Args[1]
|
||||
args := os.Args[2:]
|
||||
|
||||
args, ignoreForNow := beautifyArgs(args)
|
||||
|
||||
c := server.Command{}
|
||||
flags := c.Flags()
|
||||
allFlags := flags.GetAllFlags()
|
||||
flagsToCheck := getFlagsToCheck(args)
|
||||
|
||||
if temp == notYet {
|
||||
getStaticTrustedNodes(args)
|
||||
}
|
||||
|
||||
outOfDateFlags := checkFlag(allFlags, flagsToCheck)
|
||||
updatedArgs := updateArgsClean(args, outOfDateFlags)
|
||||
updatedArgs = updateArgsAdd(updatedArgs)
|
||||
updatedArgs = handleGRPC(args, updatedArgs)
|
||||
|
||||
if temp == notYet {
|
||||
updatedArgs = append(updatedArgs, ignoreForNow...)
|
||||
dumpFlags(updatedArgs)
|
||||
}
|
||||
|
||||
if temp != notYet {
|
||||
updatedArgs = append(updatedArgs, ignoreForNow...)
|
||||
commentFlags(temp, updatedArgs)
|
||||
}
|
||||
}
|
||||
87
scripts/getconfig.sh
Executable file
87
scripts/getconfig.sh
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Instructions:
|
||||
# Execute `./getconfig.sh`, and follow the instructions displayed on the terminal
|
||||
# The `*-config.toml` file will be created in the same directory as start.sh
|
||||
# It is recommended to check the flags generated in config.toml
|
||||
|
||||
|
||||
read -p "* Path to start.sh: " startPath
|
||||
# check if start.sh is present
|
||||
if [[ ! -f $startPath ]]
|
||||
then
|
||||
echo "Error: start.sh do not exist."
|
||||
exit 1
|
||||
fi
|
||||
read -p "* Your validator address (e.g. 0xca67a8D767e45056DC92384b488E9Af654d78DE2), or press Enter to skip if running a sentry node: " ADD
|
||||
|
||||
echo "\nThank you, your inputs are:"
|
||||
echo "Path to start.sh: "$startPath
|
||||
echo "Address: "$ADD
|
||||
|
||||
confPath=${startPath%.sh}"-config.toml"
|
||||
echo "Path to the config file: "$confPath
|
||||
# check if config.toml is present
|
||||
if [[ -f $confPath ]]
|
||||
then
|
||||
echo "WARN: config.toml exists, data will be overwritten."
|
||||
fi
|
||||
|
||||
tmpDir="$(mktemp -d -t ./temp-dir-XXXXXXXXXXX || oops "Can't create temporary directory")"
|
||||
cleanup() {
|
||||
rm -rf "$tmpDir"
|
||||
}
|
||||
trap cleanup EXIT INT QUIT TERM
|
||||
|
||||
# SHA1 hash of `tempStart` -> `3305fe263dd4a999d58f96deb064e21bb70123d9`
|
||||
sed 's/bor --/go run getconfig.go notYet --/g' $startPath > $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh
|
||||
chmod +x $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh
|
||||
$tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD
|
||||
rm $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh
|
||||
|
||||
|
||||
sed -i '' "s%*%'*'%g" ./temp
|
||||
|
||||
# read the flags from `./temp`
|
||||
dumpconfigflags=$(head -1 ./temp)
|
||||
|
||||
# run the dumpconfig command with the flags from `./temp`
|
||||
command="bor dumpconfig "$dumpconfigflags" > "$confPath
|
||||
bash -c "$command"
|
||||
|
||||
rm ./temp
|
||||
|
||||
if [[ -f ./tempStaticNodes.json ]]
|
||||
then
|
||||
echo "JSON StaticNodes found"
|
||||
staticnodesjson=$(head -1 ./tempStaticNodes.json)
|
||||
sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath
|
||||
rm ./tempStaticNodes.json
|
||||
elif [[ -f ./tempStaticNodes.toml ]]
|
||||
then
|
||||
echo "TOML StaticNodes found"
|
||||
staticnodestoml=$(head -1 ./tempStaticNodes.toml)
|
||||
sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath
|
||||
rm ./tempStaticNodes.toml
|
||||
else
|
||||
echo "neither JSON nor TOML StaticNodes found"
|
||||
fi
|
||||
|
||||
if [[ -f ./tempTrustedNodes.toml ]]
|
||||
then
|
||||
echo "TOML TrustedNodes found"
|
||||
trustednodestoml=$(head -1 ./tempTrustedNodes.toml)
|
||||
sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath
|
||||
rm ./tempTrustedNodes.toml
|
||||
else
|
||||
echo "neither JSON nor TOML TrustedNodes found"
|
||||
fi
|
||||
|
||||
# comment flags in $configPath that were not passed through $startPath
|
||||
# SHA1 hash of `tempStart` -> `3305fe263dd4a999d58f96deb064e21bb70123d9`
|
||||
sed "s%bor --%go run getconfig.go ${confPath} --%" $startPath > $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh
|
||||
chmod +x $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh
|
||||
$tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD
|
||||
rm $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh
|
||||
|
||||
exit 0
|
||||
Loading…
Reference in a new issue