Skip to content

Commit

Permalink
Added script to generate config.toml fromstart.sh (ethereum#518)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pratikspatil024 authored Sep 23, 2022
1 parent 2a677a5 commit 77db80c
Show file tree
Hide file tree
Showing 14 changed files with 779 additions and 16 deletions.
2 changes: 1 addition & 1 deletion builder/files/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ syncmode = "full"
# snapshot = true
# ethstats = ""

# [requiredblocks]
# ["eth.requiredblocks"]

[p2p]
# maxpeers = 1
Expand Down
2 changes: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ gcmode = "full"
snapshot = true
ethstats = ""
["eth.requiredblocks"]
[p2p]
maxpeers = 30
maxpendpeers = 50
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 9 additions & 0 deletions internal/cli/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 0 additions & 3 deletions internal/cli/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 0 additions & 4 deletions internal/cli/server/testdata/test.hcl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
datadir = "./data"

requiredblocks = {
a = "b"
}

p2p {
maxpeers = 30
}
Expand Down
3 changes: 0 additions & 3 deletions internal/cli/server/testdata/test.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"datadir": "./data",
"requiredblocks": {
"a": "b"
},
"p2p": {
"maxpeers": 30
},
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/server/testdata/test.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
datadir = "./data"

[requiredblocks]
["eth.requiredblocks"]
a = "b"

[p2p]
Expand Down
Loading

0 comments on commit 77db80c

Please sign in to comment.