Change diverged flags back to Geth's convention (POS-602) (#451)

* changed name -> identity

* changed no-snapshot -> snapchot=true/false

* changed jsonrpc.corsdomain -> http.corsdomain

* changed jsonrpc.vhosts -> http.vhosts

* changed http/ws.modules to http/ws.api

* updated readme

* updated config_test

* make docs

* handelling string array flag, overwrite insted of append

* added 'Default' to SliceStringFlag

* added separate flags for corsdomain and vhosts for http, ws, graphql

* modified tests
This commit is contained in:
Pratik Patil 2022-07-14 22:36:18 +05:30 committed by GitHub
parent 7b25997830
commit 3df1d6f017
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 88 deletions

View file

@ -6,7 +6,7 @@ The ```bor server``` command runs the Bor client.
- ```chain```: Name of the chain to sync - ```chain```: Name of the chain to sync
- ```name```: Name/Identity of the node - ```identity```: Name/Identity of the node
- ```log-level```: Set log level for the server - ```log-level```: Set log level for the server
@ -22,7 +22,7 @@ The ```bor server``` command runs the Bor client.
- ```requiredblocks```: Comma separated block number-to-hash mappings to enforce (<number>=<hash>) - ```requiredblocks```: Comma separated block number-to-hash mappings to enforce (<number>=<hash>)
- ```no-snapshot```: Disables the snapshot-database mode (default = false) - ```snapshot```: Disables/Enables the snapshot-database mode (default = true)
- ```bor.heimdall```: URL of Heimdall service - ```bor.heimdall```: URL of Heimdall service
@ -88,9 +88,17 @@ The ```bor server``` command runs the Bor client.
- ```ipcpath```: Filename for IPC socket/pipe within the datadir (explicit paths escape it) - ```ipcpath```: Filename for IPC socket/pipe within the datadir (explicit paths escape it)
- ```jsonrpc.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) - ```http.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced)
- ```jsonrpc.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. - ```http.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.
- ```ws.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced)
- ```ws.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.
- ```graphql.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced)
- ```graphql.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.
- ```http```: Enable the HTTP-RPC server - ```http```: Enable the HTTP-RPC server
@ -100,7 +108,7 @@ The ```bor server``` command runs the Bor client.
- ```http.rpcprefix```: HTTP path path prefix on which JSON-RPC is served. Use '/' to serve on all paths. - ```http.rpcprefix```: HTTP path path prefix on which JSON-RPC is served. Use '/' to serve on all paths.
- ```http.modules```: API's offered over the HTTP-RPC interface - ```http.api```: API's offered over the HTTP-RPC interface
- ```ws```: Enable the WS-RPC server - ```ws```: Enable the WS-RPC server
@ -110,7 +118,7 @@ The ```bor server``` command runs the Bor client.
- ```ws.rpcprefix```: HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths. - ```ws.rpcprefix```: HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths.
- ```ws.modules```: API's offered over the WS-RPC interface - ```ws.api```: API's offered over the WS-RPC interface
- ```graphql```: Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well. - ```graphql```: Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well.

View file

@ -202,10 +202,11 @@ func (f *Flagset) BigIntFlag(b *BigIntFlag) {
} }
type SliceStringFlag struct { type SliceStringFlag struct {
Name string Name string
Usage string Usage string
Value *[]string Value *[]string
Group string Default []string
Group string
} }
func (i *SliceStringFlag) String() string { func (i *SliceStringFlag) String() string {
@ -217,8 +218,8 @@ func (i *SliceStringFlag) String() string {
} }
func (i *SliceStringFlag) Set(value string) error { func (i *SliceStringFlag) Set(value string) error {
*i.Value = append(*i.Value, strings.Split(value, ",")...) // overwritting insted of appending
*i.Value = strings.Split(value, ",")
return nil return nil
} }

View file

@ -23,14 +23,17 @@ func TestFlagsetBool(t *testing.T) {
func TestFlagsetSliceString(t *testing.T) { func TestFlagsetSliceString(t *testing.T) {
f := NewFlagSet("") f := NewFlagSet("")
value := []string{} value := []string{"a", "b", "c"}
f.SliceStringFlag(&SliceStringFlag{ f.SliceStringFlag(&SliceStringFlag{
Name: "flag", Name: "flag",
Value: &value, Value: &value,
Default: value,
}) })
assert.NoError(t, f.Parse([]string{"--flag", "a,b", "--flag", "c"})) assert.NoError(t, f.Parse([]string{}))
assert.Equal(t, value, []string{"a", "b", "c"}) assert.Equal(t, value, []string{"a", "b", "c"})
assert.NoError(t, f.Parse([]string{"--flag", "a,b"}))
assert.Equal(t, value, []string{"a", "b"})
} }
func TestFlagsetDuration(t *testing.T) { func TestFlagsetDuration(t *testing.T) {

View file

@ -40,8 +40,8 @@ type Config struct {
// Chain is the chain to sync with // Chain is the chain to sync with
Chain string `hcl:"chain,optional"` Chain string `hcl:"chain,optional"`
// Name, or identity of the node // Identity of the node
Name string `hcl:"name,optional"` Identity string `hcl:"identity,optional"`
// RequiredBlocks is a list of required (block number, hash) pairs to accept // RequiredBlocks is a list of required (block number, hash) pairs to accept
RequiredBlocks map[string]string `hcl:"requiredblocks,optional"` RequiredBlocks map[string]string `hcl:"requiredblocks,optional"`
@ -61,8 +61,8 @@ type Config struct {
// GcMode selects the garbage collection mode for the trie // GcMode selects the garbage collection mode for the trie
GcMode string `hcl:"gc-mode,optional"` GcMode string `hcl:"gc-mode,optional"`
// NoSnapshot disables the snapshot database mode // Snapshot disables/enables the snapshot database mode
NoSnapshot bool `hcl:"no-snapshot,optional"` Snapshot bool `hcl:"snapshot,optional"`
// Ethstats is the address of the ethstats server to send telemetry // Ethstats is the address of the ethstats server to send telemetry
Ethstats string `hcl:"ethstats,optional"` Ethstats string `hcl:"ethstats,optional"`
@ -217,12 +217,6 @@ type JsonRPCConfig struct {
// IPCPath is the path of the ipc endpoint // IPCPath is the path of the ipc endpoint
IPCPath string `hcl:"ipc-path,optional"` IPCPath string `hcl:"ipc-path,optional"`
// VHost is the list of valid virtual hosts
VHost []string `hcl:"vhost,optional"`
// Cors is the list of Cors endpoints
Cors []string `hcl:"cors,optional"`
// GasCap is the global gas cap for eth-call variants. // GasCap is the global gas cap for eth-call variants.
GasCap uint64 `hcl:"gas-cap,optional"` GasCap uint64 `hcl:"gas-cap,optional"`
@ -232,10 +226,10 @@ type JsonRPCConfig struct {
// Http has the json-rpc http related settings // Http has the json-rpc http related settings
Http *APIConfig `hcl:"http,block"` Http *APIConfig `hcl:"http,block"`
// Http has the json-rpc websocket related settings // Ws has the json-rpc websocket related settings
Ws *APIConfig `hcl:"ws,block"` Ws *APIConfig `hcl:"ws,block"`
// Http has the json-rpc graphql related settings // Graphql has the json-rpc graphql related settings
Graphql *APIConfig `hcl:"graphql,block"` Graphql *APIConfig `hcl:"graphql,block"`
} }
@ -258,7 +252,13 @@ type APIConfig struct {
Host string `hcl:"host,optional"` Host string `hcl:"host,optional"`
// Modules is the list of enabled api modules // Modules is the list of enabled api modules
Modules []string `hcl:"modules,optional"` API []string `hcl:"modules,optional"`
// VHost is the list of valid virtual hosts
VHost []string `hcl:"vhost,optional"`
// Cors is the list of Cors endpoints
Cors []string `hcl:"cors,optional"`
} }
type GpoConfig struct { type GpoConfig struct {
@ -387,7 +387,7 @@ type DeveloperConfig struct {
func DefaultConfig() *Config { func DefaultConfig() *Config {
return &Config{ return &Config{
Chain: "mainnet", Chain: "mainnet",
Name: Hostname(), Identity: Hostname(),
RequiredBlocks: map[string]string{}, RequiredBlocks: map[string]string{},
LogLevel: "INFO", LogLevel: "INFO",
DataDir: defaultDataDir(), DataDir: defaultDataDir(),
@ -412,9 +412,9 @@ func DefaultConfig() *Config {
URL: "http://localhost:1317", URL: "http://localhost:1317",
Without: false, Without: false,
}, },
SyncMode: "full", SyncMode: "full",
GcMode: "full", GcMode: "full",
NoSnapshot: false, Snapshot: true,
TxPool: &TxPoolConfig{ TxPool: &TxPoolConfig{
Locals: []string{}, Locals: []string{},
NoLocals: false, NoLocals: false,
@ -444,8 +444,6 @@ func DefaultConfig() *Config {
JsonRPC: &JsonRPCConfig{ JsonRPC: &JsonRPCConfig{
IPCDisable: false, IPCDisable: false,
IPCPath: "", IPCPath: "",
Cors: []string{"*"},
VHost: []string{"*"},
GasCap: ethconfig.Defaults.RPCGasCap, GasCap: ethconfig.Defaults.RPCGasCap,
TxFeeCap: ethconfig.Defaults.RPCTxFeeCap, TxFeeCap: ethconfig.Defaults.RPCTxFeeCap,
Http: &APIConfig{ Http: &APIConfig{
@ -453,17 +451,23 @@ func DefaultConfig() *Config {
Port: 8545, Port: 8545,
Prefix: "", Prefix: "",
Host: "localhost", Host: "localhost",
Modules: []string{"eth", "net", "web3", "txpool", "bor"}, API: []string{"eth", "net", "web3", "txpool", "bor"},
Cors: []string{"*"},
VHost: []string{"*"},
}, },
Ws: &APIConfig{ Ws: &APIConfig{
Enabled: false, Enabled: false,
Port: 8546, Port: 8546,
Prefix: "", Prefix: "",
Host: "localhost", Host: "localhost",
Modules: []string{"web3", "net"}, API: []string{"web3", "net"},
Cors: []string{"*"},
VHost: []string{"*"},
}, },
Graphql: &APIConfig{ Graphql: &APIConfig{
Enabled: false, Enabled: false,
Cors: []string{"*"},
VHost: []string{"*"},
}, },
}, },
Ethstats: "", Ethstats: "",
@ -864,7 +868,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
} }
// snapshot disable check // snapshot disable check
if c.NoSnapshot { if !c.Snapshot {
if n.SyncMode == downloader.SnapSync { if n.SyncMode == downloader.SnapSync {
log.Info("Snap sync requested, enabling --snapshot") log.Info("Snap sync requested, enabling --snapshot")
} else { } else {
@ -908,15 +912,15 @@ func (c *Config) buildNode() (*node.Config, error) {
ListenAddr: c.P2P.Bind + ":" + strconv.Itoa(int(c.P2P.Port)), ListenAddr: c.P2P.Bind + ":" + strconv.Itoa(int(c.P2P.Port)),
DiscoveryV5: c.P2P.Discovery.V5Enabled, DiscoveryV5: c.P2P.Discovery.V5Enabled,
}, },
HTTPModules: c.JsonRPC.Http.Modules, HTTPModules: c.JsonRPC.Http.API,
HTTPCors: c.JsonRPC.Cors, HTTPCors: c.JsonRPC.Http.Cors,
HTTPVirtualHosts: c.JsonRPC.VHost, HTTPVirtualHosts: c.JsonRPC.Http.VHost,
HTTPPathPrefix: c.JsonRPC.Http.Prefix, HTTPPathPrefix: c.JsonRPC.Http.Prefix,
WSModules: c.JsonRPC.Ws.Modules, WSModules: c.JsonRPC.Ws.API,
WSOrigins: c.JsonRPC.Cors, WSOrigins: c.JsonRPC.Ws.Cors,
WSPathPrefix: c.JsonRPC.Ws.Prefix, WSPathPrefix: c.JsonRPC.Ws.Prefix,
GraphQLCors: c.JsonRPC.Cors, GraphQLCors: c.JsonRPC.Graphql.Cors,
GraphQLVirtualHosts: c.JsonRPC.VHost, GraphQLVirtualHosts: c.JsonRPC.Graphql.VHost,
} }
// dev mode // dev mode
@ -999,7 +1003,7 @@ func (c *Config) buildNode() (*node.Config, error) {
func (c *Config) Merge(cc ...*Config) error { func (c *Config) Merge(cc ...*Config) error {
for _, elem := range cc { for _, elem := range cc {
if err := mergo.Merge(c, elem, mergo.WithOverwriteWithEmptyValue, mergo.WithAppendSlice); err != nil { if err := mergo.Merge(c, elem, mergo.WithOverwriteWithEmptyValue); err != nil {
return fmt.Errorf("failed to merge configurations: %v", err) return fmt.Errorf("failed to merge configurations: %v", err)
} }
} }

View file

@ -22,8 +22,8 @@ func TestConfigDefault(t *testing.T) {
func TestConfigMerge(t *testing.T) { func TestConfigMerge(t *testing.T) {
c0 := &Config{ c0 := &Config{
Chain: "0", Chain: "0",
NoSnapshot: true, Snapshot: true,
RequiredBlocks: map[string]string{ RequiredBlocks: map[string]string{
"a": "b", "a": "b",
}, },
@ -54,8 +54,8 @@ func TestConfigMerge(t *testing.T) {
} }
expected := &Config{ expected := &Config{
Chain: "1", Chain: "1",
NoSnapshot: false, Snapshot: false,
RequiredBlocks: map[string]string{ RequiredBlocks: map[string]string{
"a": "b", "a": "b",
"b": "c", "b": "c",
@ -64,7 +64,6 @@ func TestConfigMerge(t *testing.T) {
MaxPeers: 10, MaxPeers: 10,
Discovery: &P2PDiscovery{ Discovery: &P2PDiscovery{
StaticNodes: []string{ StaticNodes: []string{
"a",
"b", "b",
}, },
}, },

View file

@ -16,10 +16,10 @@ func (c *Command) Flags() *flagset.Flagset {
Default: c.cliConfig.Chain, Default: c.cliConfig.Chain,
}) })
f.StringFlag(&flagset.StringFlag{ f.StringFlag(&flagset.StringFlag{
Name: "name", Name: "identity",
Usage: "Name/Identity of the node", Usage: "Name/Identity of the node",
Value: &c.cliConfig.Name, Value: &c.cliConfig.Identity,
Default: c.cliConfig.Name, Default: c.cliConfig.Identity,
}) })
f.StringFlag(&flagset.StringFlag{ f.StringFlag(&flagset.StringFlag{
Name: "log-level", Name: "log-level",
@ -61,10 +61,10 @@ func (c *Command) Flags() *flagset.Flagset {
Value: &c.cliConfig.RequiredBlocks, Value: &c.cliConfig.RequiredBlocks,
}) })
f.BoolFlag(&flagset.BoolFlag{ f.BoolFlag(&flagset.BoolFlag{
Name: "no-snapshot", Name: "snapshot",
Usage: `Disables the snapshot-database mode (default = false)`, Usage: `Disables/Enables the snapshot-database mode (default = true)`,
Value: &c.cliConfig.NoSnapshot, Value: &c.cliConfig.Snapshot,
Default: c.cliConfig.NoSnapshot, Default: c.cliConfig.Snapshot,
}) })
// heimdall // heimdall
@ -83,10 +83,11 @@ func (c *Command) Flags() *flagset.Flagset {
// txpool options // txpool options
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "txpool.locals", Name: "txpool.locals",
Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)", Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)",
Value: &c.cliConfig.TxPool.Locals, Value: &c.cliConfig.TxPool.Locals,
Group: "Transaction Pool", Default: c.cliConfig.TxPool.Locals,
Group: "Transaction Pool",
}) })
f.BoolFlag(&flagset.BoolFlag{ f.BoolFlag(&flagset.BoolFlag{
Name: "txpool.nolocals", Name: "txpool.nolocals",
@ -329,16 +330,46 @@ func (c *Command) Flags() *flagset.Flagset {
Group: "JsonRPC", Group: "JsonRPC",
}) })
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "jsonrpc.corsdomain", Name: "http.corsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)", Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
Value: &c.cliConfig.JsonRPC.Cors, Value: &c.cliConfig.JsonRPC.Http.Cors,
Group: "JsonRPC", Default: c.cliConfig.JsonRPC.Http.Cors,
Group: "JsonRPC",
}) })
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "jsonrpc.vhosts", Name: "http.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.", Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: &c.cliConfig.JsonRPC.VHost, Value: &c.cliConfig.JsonRPC.Http.VHost,
Group: "JsonRPC", Default: c.cliConfig.JsonRPC.Http.VHost,
Group: "JsonRPC",
})
f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "ws.corsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
Value: &c.cliConfig.JsonRPC.Ws.Cors,
Default: c.cliConfig.JsonRPC.Ws.Cors,
Group: "JsonRPC",
})
f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "ws.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: &c.cliConfig.JsonRPC.Ws.VHost,
Default: c.cliConfig.JsonRPC.Ws.VHost,
Group: "JsonRPC",
})
f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "graphql.corsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
Value: &c.cliConfig.JsonRPC.Graphql.Cors,
Default: c.cliConfig.JsonRPC.Graphql.Cors,
Group: "JsonRPC",
})
f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "graphql.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: &c.cliConfig.JsonRPC.Graphql.VHost,
Default: c.cliConfig.JsonRPC.Graphql.VHost,
Group: "JsonRPC",
}) })
// http options // http options
@ -371,10 +402,11 @@ func (c *Command) Flags() *flagset.Flagset {
Group: "JsonRPC", Group: "JsonRPC",
}) })
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "http.modules", Name: "http.api",
Usage: "API's offered over the HTTP-RPC interface", Usage: "API's offered over the HTTP-RPC interface",
Value: &c.cliConfig.JsonRPC.Http.Modules, Value: &c.cliConfig.JsonRPC.Http.API,
Group: "JsonRPC", Default: c.cliConfig.JsonRPC.Http.API,
Group: "JsonRPC",
}) })
// ws options // ws options
@ -407,10 +439,11 @@ func (c *Command) Flags() *flagset.Flagset {
Group: "JsonRPC", Group: "JsonRPC",
}) })
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "ws.modules", Name: "ws.api",
Usage: "API's offered over the WS-RPC interface", Usage: "API's offered over the WS-RPC interface",
Value: &c.cliConfig.JsonRPC.Ws.Modules, Value: &c.cliConfig.JsonRPC.Ws.API,
Group: "JsonRPC", Default: c.cliConfig.JsonRPC.Ws.API,
Group: "JsonRPC",
}) })
// graphql options // graphql options
@ -438,10 +471,11 @@ func (c *Command) Flags() *flagset.Flagset {
Group: "P2P", Group: "P2P",
}) })
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "bootnodes", Name: "bootnodes",
Usage: "Comma separated enode URLs for P2P discovery bootstrap", Usage: "Comma separated enode URLs for P2P discovery bootstrap",
Value: &c.cliConfig.P2P.Discovery.Bootnodes, Value: &c.cliConfig.P2P.Discovery.Bootnodes,
Group: "P2P", Default: c.cliConfig.P2P.Discovery.Bootnodes,
Group: "P2P",
}) })
f.Uint64Flag(&flagset.Uint64Flag{ f.Uint64Flag(&flagset.Uint64Flag{
Name: "maxpeers", Name: "maxpeers",
@ -581,10 +615,11 @@ func (c *Command) Flags() *flagset.Flagset {
// account // account
f.SliceStringFlag(&flagset.SliceStringFlag{ f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "unlock", Name: "unlock",
Usage: "Comma separated list of accounts to unlock", Usage: "Comma separated list of accounts to unlock",
Value: &c.cliConfig.Accounts.Unlock, Value: &c.cliConfig.Accounts.Unlock,
Group: "Account Management", Default: c.cliConfig.Accounts.Unlock,
Group: "Account Management",
}) })
f.StringFlag(&flagset.StringFlag{ f.StringFlag(&flagset.StringFlag{
Name: "password", Name: "password",

View file

@ -182,7 +182,7 @@ func NewServer(config *Config) (*Server, error) {
// graphql is started from another place // graphql is started from another place
if config.JsonRPC.Graphql.Enabled { if config.JsonRPC.Graphql.Enabled {
if err := graphql.New(stack, srv.backend.APIBackend, config.JsonRPC.Cors, config.JsonRPC.VHost); err != nil { if err := graphql.New(stack, srv.backend.APIBackend, config.JsonRPC.Graphql.Cors, config.JsonRPC.Graphql.VHost); err != nil {
return nil, fmt.Errorf("failed to register the GraphQL service: %v", err) return nil, fmt.Errorf("failed to register the GraphQL service: %v", err)
} }
} }
@ -201,7 +201,7 @@ func NewServer(config *Config) (*Server, error) {
} }
} }
if err := srv.setupMetrics(config.Telemetry, config.Name); err != nil { if err := srv.setupMetrics(config.Telemetry, config.Identity); err != nil {
return nil, err return nil, err
} }