mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 08:23:46 +00:00
internal/cli, cmd/geth: replaced package naoina/toml with BurntSushi/toml and updated config name-tags (#486)
* removed package naoina/toml from dumpconfig and added BurntSushi/toml * updated cmd/gethconfig.go
This commit is contained in:
parent
d8d9360dfe
commit
16408ba324
7 changed files with 25 additions and 83 deletions
|
|
@ -17,17 +17,16 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"gopkg.in/urfave/cli.v1"
|
"gopkg.in/urfave/cli.v1"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/external"
|
"github.com/ethereum/go-ethereum/accounts/external"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/accounts/scwallet"
|
"github.com/ethereum/go-ethereum/accounts/scwallet"
|
||||||
|
|
@ -41,7 +40,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/naoina/toml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -61,28 +59,6 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 {
|
|
||||||
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
|
|
||||||
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 {
|
type ethstatsConfig struct {
|
||||||
URL string `toml:",omitempty"`
|
URL string `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
@ -95,18 +71,17 @@ type gethConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(file string, cfg *gethConfig) error {
|
func loadConfig(file string, cfg *gethConfig) error {
|
||||||
f, err := os.Open(file)
|
data, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
err = tomlSettings.NewDecoder(bufio.NewReader(f)).Decode(cfg)
|
tomlData := string(data)
|
||||||
// Add file name to errors that have a line number.
|
if _, err = toml.Decode(tomlData, &cfg); err != nil {
|
||||||
if _, ok := err.(*toml.LineError); ok {
|
return err
|
||||||
err = errors.New(file + ", " + err.Error())
|
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultNodeConfig() node.Config {
|
func defaultNodeConfig() node.Config {
|
||||||
|
|
@ -214,22 +189,10 @@ func dumpConfig(ctx *cli.Context) error {
|
||||||
comment += "# Note: this config doesn't contain the genesis block.\n\n"
|
comment += "# Note: this config doesn't contain the genesis block.\n\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := tomlSettings.Marshal(&cfg)
|
if err := toml.NewEncoder(os.Stdout).Encode(&cfg); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -51,7 +51,6 @@ require (
|
||||||
github.com/mattn/go-isatty v0.0.12
|
github.com/mattn/go-isatty v0.0.12
|
||||||
github.com/mitchellh/cli v1.1.2
|
github.com/mitchellh/cli v1.1.2
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
github.com/olekukonko/tablewriter v0.0.5
|
||||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
|
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
|
||||||
github.com/prometheus/tsdb v0.7.1
|
github.com/prometheus/tsdb v0.7.1
|
||||||
|
|
@ -120,7 +119,6 @@ require (
|
||||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||||
github.com/mitchellh/pointerstructure v1.2.0 // indirect
|
github.com/mitchellh/pointerstructure v1.2.0 // indirect
|
||||||
github.com/mitchellh/reflectwalk v1.0.0 // indirect
|
github.com/mitchellh/reflectwalk v1.0.0 // indirect
|
||||||
github.com/naoina/go-stringutil v0.1.0 // indirect
|
|
||||||
github.com/opentracing/opentracing-go v1.1.0 // indirect
|
github.com/opentracing/opentracing-go v1.1.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -382,10 +382,6 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
|
||||||
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
|
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
|
||||||
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg=
|
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg=
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
|
|
||||||
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
|
|
||||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 h1:shk/vn9oCoOTmwcouEdwIeOtOGA/ELRUw/GwvxwfT+0=
|
|
||||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
|
|
||||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,14 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/naoina/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/internal/cli/server"
|
"github.com/ethereum/go-ethereum/internal/cli/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// DumpconfigCommand is for exporting user provided flags into a config file
|
// DumpconfigCommand is for exporting user provided flags into a config file
|
||||||
type DumpconfigCommand struct {
|
type DumpconfigCommand struct {
|
||||||
*Meta2
|
*Meta2
|
||||||
|
|
@ -69,14 +59,10 @@ func (c *DumpconfigCommand) Run(args []string) int {
|
||||||
userConfig.Gpo.IgnorePriceRaw = userConfig.Gpo.IgnorePrice.String()
|
userConfig.Gpo.IgnorePriceRaw = userConfig.Gpo.IgnorePrice.String()
|
||||||
userConfig.Cache.RejournalRaw = userConfig.Cache.Rejournal.String()
|
userConfig.Cache.RejournalRaw = userConfig.Cache.Rejournal.String()
|
||||||
|
|
||||||
// Currently, the configurations (userConfig) is exported into `toml` file format.
|
if err := toml.NewEncoder(os.Stdout).Encode(userConfig); err != nil {
|
||||||
out, err := tomlSettings.Marshal(&userConfig)
|
|
||||||
if err != nil {
|
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
c.UI.Output(string(out))
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ type TxPoolConfig struct {
|
||||||
Journal string `hcl:"journal,optional" toml:"journal,optional"`
|
Journal string `hcl:"journal,optional" toml:"journal,optional"`
|
||||||
|
|
||||||
// Rejournal is the time interval to regenerate the local transaction journal
|
// Rejournal is the time interval to regenerate the local transaction journal
|
||||||
Rejournal time.Duration `hcl:"-,optional" toml:"-,optional"`
|
Rejournal time.Duration `hcl:"-,optional" toml:"-"`
|
||||||
RejournalRaw string `hcl:"rejournal,optional" toml:"rejournal,optional"`
|
RejournalRaw string `hcl:"rejournal,optional" toml:"rejournal,optional"`
|
||||||
|
|
||||||
// PriceLimit is the minimum gas price to enforce for acceptance into the pool
|
// PriceLimit is the minimum gas price to enforce for acceptance into the pool
|
||||||
|
|
@ -192,7 +192,7 @@ type TxPoolConfig struct {
|
||||||
GlobalQueue uint64 `hcl:"globalqueue,optional" toml:"globalqueue,optional"`
|
GlobalQueue uint64 `hcl:"globalqueue,optional" toml:"globalqueue,optional"`
|
||||||
|
|
||||||
// lifetime is the maximum amount of time non-executable transaction are queued
|
// lifetime is the maximum amount of time non-executable transaction are queued
|
||||||
LifeTime time.Duration `hcl:"-,optional" toml:"-,optional"`
|
LifeTime time.Duration `hcl:"-,optional" toml:"-"`
|
||||||
LifeTimeRaw string `hcl:"lifetime,optional" toml:"lifetime,optional"`
|
LifeTimeRaw string `hcl:"lifetime,optional" toml:"lifetime,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,7 +210,7 @@ type SealerConfig struct {
|
||||||
GasCeil uint64 `hcl:"gaslimit,optional" toml:"gaslimit,optional"`
|
GasCeil uint64 `hcl:"gaslimit,optional" toml:"gaslimit,optional"`
|
||||||
|
|
||||||
// GasPrice is the minimum gas price for mining a transaction
|
// GasPrice is the minimum gas price for mining a transaction
|
||||||
GasPrice *big.Int `hcl:"-,optional" toml:"-,optional"`
|
GasPrice *big.Int `hcl:"-,optional" toml:"-"`
|
||||||
GasPriceRaw string `hcl:"gasprice,optional" toml:"gasprice,optional"`
|
GasPriceRaw string `hcl:"gasprice,optional" toml:"gasprice,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,11 +273,11 @@ type GpoConfig struct {
|
||||||
Percentile uint64 `hcl:"percentile,optional" toml:"percentile,optional"`
|
Percentile uint64 `hcl:"percentile,optional" toml:"percentile,optional"`
|
||||||
|
|
||||||
// MaxPrice is an upper bound gas price
|
// MaxPrice is an upper bound gas price
|
||||||
MaxPrice *big.Int `hcl:"-,optional" toml:"-,optional"`
|
MaxPrice *big.Int `hcl:"-,optional" toml:"-"`
|
||||||
MaxPriceRaw string `hcl:"maxprice,optional" toml:"maxprice,optional"`
|
MaxPriceRaw string `hcl:"maxprice,optional" toml:"maxprice,optional"`
|
||||||
|
|
||||||
// IgnorePrice is a lower bound gas price
|
// IgnorePrice is a lower bound gas price
|
||||||
IgnorePrice *big.Int `hcl:"-,optional" toml:"-,optional"`
|
IgnorePrice *big.Int `hcl:"-,optional" toml:"-"`
|
||||||
IgnorePriceRaw string `hcl:"ignoreprice,optional" toml:"ignoreprice,optional"`
|
IgnorePriceRaw string `hcl:"ignoreprice,optional" toml:"ignoreprice,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -350,7 +350,7 @@ type CacheConfig struct {
|
||||||
Journal string `hcl:"journal,optional" toml:"journal,optional"`
|
Journal string `hcl:"journal,optional" toml:"journal,optional"`
|
||||||
|
|
||||||
// Rejournal is the time interval to regenerate the journal for clean cache
|
// Rejournal is the time interval to regenerate the journal for clean cache
|
||||||
Rejournal time.Duration `hcl:"-,optional" toml:"-,optional"`
|
Rejournal time.Duration `hcl:"-,optional" toml:"-"`
|
||||||
RejournalRaw string `hcl:"rejournal,optional" toml:"rejournal,optional"`
|
RejournalRaw string `hcl:"rejournal,optional" toml:"rejournal,optional"`
|
||||||
|
|
||||||
// NoPrefetch is used to disable prefetch of tries
|
// NoPrefetch is used to disable prefetch of tries
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfigLegacy(t *testing.T) {
|
func TestConfigLegacy(t *testing.T) {
|
||||||
|
|
@ -71,8 +72,8 @@ func TestConfigLegacy(t *testing.T) {
|
||||||
Gpo: &GpoConfig{
|
Gpo: &GpoConfig{
|
||||||
Blocks: 20,
|
Blocks: 20,
|
||||||
Percentile: 60,
|
Percentile: 60,
|
||||||
MaxPrice: big.NewInt(100),
|
MaxPrice: big.NewInt(5000 * params.GWei),
|
||||||
IgnorePrice: big.NewInt(2),
|
IgnorePrice: big.NewInt(4),
|
||||||
},
|
},
|
||||||
JsonRPC: &JsonRPCConfig{
|
JsonRPC: &JsonRPCConfig{
|
||||||
IPCDisable: false,
|
IPCDisable: false,
|
||||||
|
|
@ -129,7 +130,7 @@ func TestConfigLegacy(t *testing.T) {
|
||||||
PercGc: 25,
|
PercGc: 25,
|
||||||
PercSnapshot: 10,
|
PercSnapshot: 10,
|
||||||
Journal: "triecache",
|
Journal: "triecache",
|
||||||
Rejournal: 1 * time.Hour,
|
Rejournal: 1 * time.Second,
|
||||||
NoPrefetch: false,
|
NoPrefetch: false,
|
||||||
Preimages: false,
|
Preimages: false,
|
||||||
TxLookupLimit: 2350000,
|
TxLookupLimit: 2350000,
|
||||||
|
|
|
||||||
6
internal/cli/server/testdata/test.toml
vendored
6
internal/cli/server/testdata/test.toml
vendored
|
|
@ -8,7 +8,6 @@ maxpeers = 30
|
||||||
|
|
||||||
[txpool]
|
[txpool]
|
||||||
locals = []
|
locals = []
|
||||||
rejournal = "1h0m0s"
|
|
||||||
lifetime = "1s"
|
lifetime = "1s"
|
||||||
|
|
||||||
[miner]
|
[miner]
|
||||||
|
|
@ -17,9 +16,8 @@ gaslimit = 20000000
|
||||||
gasprice = "30000000000"
|
gasprice = "30000000000"
|
||||||
|
|
||||||
[gpo]
|
[gpo]
|
||||||
maxprice = "100"
|
ignoreprice = "4"
|
||||||
ignoreprice = "2"
|
|
||||||
|
|
||||||
[cache]
|
[cache]
|
||||||
cache = 1024
|
cache = 1024
|
||||||
rejournal = "1h0m0s"
|
rejournal = "1s"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue