From f53981809ed494502d949a9e3fe0f3b4cd8c1ec5 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Thu, 14 Jul 2022 22:36:18 +0530 Subject: [PATCH 01/46] 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 --- docs/cli/server.md | 20 +++-- internal/cli/flagset/flagset.go | 13 ++-- internal/cli/flagset/flagset_test.go | 11 ++- internal/cli/server/config.go | 64 ++++++++-------- internal/cli/server/config_test.go | 9 +-- internal/cli/server/flags.go | 105 ++++++++++++++++++--------- internal/cli/server/server.go | 4 +- 7 files changed, 138 insertions(+), 88 deletions(-) diff --git a/docs/cli/server.md b/docs/cli/server.md index 0803208e3a..ac43555275 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -6,7 +6,7 @@ The ```bor server``` command runs the Bor client. - ```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 @@ -22,7 +22,7 @@ The ```bor server``` command runs the Bor client. - ```requiredblocks```: Comma separated block number-to-hash mappings to enforce (=) -- ```no-snapshot```: Disables the snapshot-database mode (default = false) +- ```snapshot```: Disables/Enables the snapshot-database mode (default = true) - ```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) -- ```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 @@ -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.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 @@ -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.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. diff --git a/internal/cli/flagset/flagset.go b/internal/cli/flagset/flagset.go index b57fff9996..0c19fa9758 100644 --- a/internal/cli/flagset/flagset.go +++ b/internal/cli/flagset/flagset.go @@ -202,10 +202,11 @@ func (f *Flagset) BigIntFlag(b *BigIntFlag) { } type SliceStringFlag struct { - Name string - Usage string - Value *[]string - Group string + Name string + Usage string + Value *[]string + Default []string + Group string } func (i *SliceStringFlag) String() string { @@ -217,8 +218,8 @@ func (i *SliceStringFlag) String() string { } 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 } diff --git a/internal/cli/flagset/flagset_test.go b/internal/cli/flagset/flagset_test.go index 2f046c3248..118361320d 100644 --- a/internal/cli/flagset/flagset_test.go +++ b/internal/cli/flagset/flagset_test.go @@ -23,14 +23,17 @@ func TestFlagsetBool(t *testing.T) { func TestFlagsetSliceString(t *testing.T) { f := NewFlagSet("") - value := []string{} + value := []string{"a", "b", "c"} f.SliceStringFlag(&SliceStringFlag{ - Name: "flag", - Value: &value, + Name: "flag", + 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.NoError(t, f.Parse([]string{"--flag", "a,b"})) + assert.Equal(t, value, []string{"a", "b"}) } func TestFlagsetDuration(t *testing.T) { diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 347287e22f..fdf253a37e 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -40,8 +40,8 @@ type Config struct { // Chain is the chain to sync with Chain string `hcl:"chain,optional"` - // Name, or identity of the node - Name string `hcl:"name,optional"` + // Identity of the node + Identity string `hcl:"identity,optional"` // RequiredBlocks is a list of required (block number, hash) pairs to accept RequiredBlocks map[string]string `hcl:"requiredblocks,optional"` @@ -61,8 +61,8 @@ type Config struct { // GcMode selects the garbage collection mode for the trie GcMode string `hcl:"gc-mode,optional"` - // NoSnapshot disables the snapshot database mode - NoSnapshot bool `hcl:"no-snapshot,optional"` + // Snapshot disables/enables the snapshot database mode + Snapshot bool `hcl:"snapshot,optional"` // Ethstats is the address of the ethstats server to send telemetry Ethstats string `hcl:"ethstats,optional"` @@ -217,12 +217,6 @@ type JsonRPCConfig struct { // IPCPath is the path of the ipc endpoint 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 uint64 `hcl:"gas-cap,optional"` @@ -232,10 +226,10 @@ type JsonRPCConfig struct { // Http has the json-rpc http related settings 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"` - // Http has the json-rpc graphql related settings + // Graphql has the json-rpc graphql related settings Graphql *APIConfig `hcl:"graphql,block"` } @@ -258,7 +252,13 @@ type APIConfig struct { Host string `hcl:"host,optional"` // 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 { @@ -387,7 +387,7 @@ type DeveloperConfig struct { func DefaultConfig() *Config { return &Config{ Chain: "mainnet", - Name: Hostname(), + Identity: Hostname(), RequiredBlocks: map[string]string{}, LogLevel: "INFO", DataDir: defaultDataDir(), @@ -412,9 +412,9 @@ func DefaultConfig() *Config { URL: "http://localhost:1317", Without: false, }, - SyncMode: "full", - GcMode: "full", - NoSnapshot: false, + SyncMode: "full", + GcMode: "full", + Snapshot: true, TxPool: &TxPoolConfig{ Locals: []string{}, NoLocals: false, @@ -444,8 +444,6 @@ func DefaultConfig() *Config { JsonRPC: &JsonRPCConfig{ IPCDisable: false, IPCPath: "", - Cors: []string{"*"}, - VHost: []string{"*"}, GasCap: ethconfig.Defaults.RPCGasCap, TxFeeCap: ethconfig.Defaults.RPCTxFeeCap, Http: &APIConfig{ @@ -453,17 +451,23 @@ func DefaultConfig() *Config { Port: 8545, Prefix: "", Host: "localhost", - Modules: []string{"eth", "net", "web3", "txpool", "bor"}, + API: []string{"eth", "net", "web3", "txpool", "bor"}, + Cors: []string{"*"}, + VHost: []string{"*"}, }, Ws: &APIConfig{ Enabled: false, Port: 8546, Prefix: "", Host: "localhost", - Modules: []string{"web3", "net"}, + API: []string{"web3", "net"}, + Cors: []string{"*"}, + VHost: []string{"*"}, }, Graphql: &APIConfig{ Enabled: false, + Cors: []string{"*"}, + VHost: []string{"*"}, }, }, Ethstats: "", @@ -864,7 +868,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (* } // snapshot disable check - if c.NoSnapshot { + if !c.Snapshot { if n.SyncMode == downloader.SnapSync { log.Info("Snap sync requested, enabling --snapshot") } else { @@ -908,15 +912,15 @@ func (c *Config) buildNode() (*node.Config, error) { ListenAddr: c.P2P.Bind + ":" + strconv.Itoa(int(c.P2P.Port)), DiscoveryV5: c.P2P.Discovery.V5Enabled, }, - HTTPModules: c.JsonRPC.Http.Modules, - HTTPCors: c.JsonRPC.Cors, - HTTPVirtualHosts: c.JsonRPC.VHost, + HTTPModules: c.JsonRPC.Http.API, + HTTPCors: c.JsonRPC.Http.Cors, + HTTPVirtualHosts: c.JsonRPC.Http.VHost, HTTPPathPrefix: c.JsonRPC.Http.Prefix, - WSModules: c.JsonRPC.Ws.Modules, - WSOrigins: c.JsonRPC.Cors, + WSModules: c.JsonRPC.Ws.API, + WSOrigins: c.JsonRPC.Ws.Cors, WSPathPrefix: c.JsonRPC.Ws.Prefix, - GraphQLCors: c.JsonRPC.Cors, - GraphQLVirtualHosts: c.JsonRPC.VHost, + GraphQLCors: c.JsonRPC.Graphql.Cors, + GraphQLVirtualHosts: c.JsonRPC.Graphql.VHost, } // dev mode @@ -999,7 +1003,7 @@ func (c *Config) buildNode() (*node.Config, error) { func (c *Config) Merge(cc ...*Config) error { 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) } } diff --git a/internal/cli/server/config_test.go b/internal/cli/server/config_test.go index 94c4496c03..c1c6c4ef4a 100644 --- a/internal/cli/server/config_test.go +++ b/internal/cli/server/config_test.go @@ -22,8 +22,8 @@ func TestConfigDefault(t *testing.T) { func TestConfigMerge(t *testing.T) { c0 := &Config{ - Chain: "0", - NoSnapshot: true, + Chain: "0", + Snapshot: true, RequiredBlocks: map[string]string{ "a": "b", }, @@ -54,8 +54,8 @@ func TestConfigMerge(t *testing.T) { } expected := &Config{ - Chain: "1", - NoSnapshot: false, + Chain: "1", + Snapshot: false, RequiredBlocks: map[string]string{ "a": "b", "b": "c", @@ -64,7 +64,6 @@ func TestConfigMerge(t *testing.T) { MaxPeers: 10, Discovery: &P2PDiscovery{ StaticNodes: []string{ - "a", "b", }, }, diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index 21e9a38cb9..e85428b9ee 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -16,10 +16,10 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.Chain, }) f.StringFlag(&flagset.StringFlag{ - Name: "name", + Name: "identity", Usage: "Name/Identity of the node", - Value: &c.cliConfig.Name, - Default: c.cliConfig.Name, + Value: &c.cliConfig.Identity, + Default: c.cliConfig.Identity, }) f.StringFlag(&flagset.StringFlag{ Name: "log-level", @@ -61,10 +61,10 @@ func (c *Command) Flags() *flagset.Flagset { Value: &c.cliConfig.RequiredBlocks, }) f.BoolFlag(&flagset.BoolFlag{ - Name: "no-snapshot", - Usage: `Disables the snapshot-database mode (default = false)`, - Value: &c.cliConfig.NoSnapshot, - Default: c.cliConfig.NoSnapshot, + Name: "snapshot", + Usage: `Disables/Enables the snapshot-database mode (default = true)`, + Value: &c.cliConfig.Snapshot, + Default: c.cliConfig.Snapshot, }) // heimdall @@ -83,10 +83,11 @@ func (c *Command) Flags() *flagset.Flagset { // txpool options f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "txpool.locals", - Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)", - Value: &c.cliConfig.TxPool.Locals, - Group: "Transaction Pool", + Name: "txpool.locals", + Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)", + Value: &c.cliConfig.TxPool.Locals, + Default: c.cliConfig.TxPool.Locals, + Group: "Transaction Pool", }) f.BoolFlag(&flagset.BoolFlag{ Name: "txpool.nolocals", @@ -329,16 +330,46 @@ func (c *Command) Flags() *flagset.Flagset { Group: "JsonRPC", }) f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "jsonrpc.corsdomain", - Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)", - Value: &c.cliConfig.JsonRPC.Cors, - Group: "JsonRPC", + Name: "http.corsdomain", + Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)", + Value: &c.cliConfig.JsonRPC.Http.Cors, + Default: c.cliConfig.JsonRPC.Http.Cors, + Group: "JsonRPC", }) f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "jsonrpc.vhosts", - Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.", - Value: &c.cliConfig.JsonRPC.VHost, - Group: "JsonRPC", + Name: "http.vhosts", + Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.", + Value: &c.cliConfig.JsonRPC.Http.VHost, + 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 @@ -371,10 +402,11 @@ func (c *Command) Flags() *flagset.Flagset { Group: "JsonRPC", }) f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "http.modules", - Usage: "API's offered over the HTTP-RPC interface", - Value: &c.cliConfig.JsonRPC.Http.Modules, - Group: "JsonRPC", + Name: "http.api", + Usage: "API's offered over the HTTP-RPC interface", + Value: &c.cliConfig.JsonRPC.Http.API, + Default: c.cliConfig.JsonRPC.Http.API, + Group: "JsonRPC", }) // ws options @@ -407,10 +439,11 @@ func (c *Command) Flags() *flagset.Flagset { Group: "JsonRPC", }) f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "ws.modules", - Usage: "API's offered over the WS-RPC interface", - Value: &c.cliConfig.JsonRPC.Ws.Modules, - Group: "JsonRPC", + Name: "ws.api", + Usage: "API's offered over the WS-RPC interface", + Value: &c.cliConfig.JsonRPC.Ws.API, + Default: c.cliConfig.JsonRPC.Ws.API, + Group: "JsonRPC", }) // graphql options @@ -438,10 +471,11 @@ func (c *Command) Flags() *flagset.Flagset { Group: "P2P", }) f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "bootnodes", - Usage: "Comma separated enode URLs for P2P discovery bootstrap", - Value: &c.cliConfig.P2P.Discovery.Bootnodes, - Group: "P2P", + Name: "bootnodes", + Usage: "Comma separated enode URLs for P2P discovery bootstrap", + Value: &c.cliConfig.P2P.Discovery.Bootnodes, + Default: c.cliConfig.P2P.Discovery.Bootnodes, + Group: "P2P", }) f.Uint64Flag(&flagset.Uint64Flag{ Name: "maxpeers", @@ -581,10 +615,11 @@ func (c *Command) Flags() *flagset.Flagset { // account f.SliceStringFlag(&flagset.SliceStringFlag{ - Name: "unlock", - Usage: "Comma separated list of accounts to unlock", - Value: &c.cliConfig.Accounts.Unlock, - Group: "Account Management", + Name: "unlock", + Usage: "Comma separated list of accounts to unlock", + Value: &c.cliConfig.Accounts.Unlock, + Default: c.cliConfig.Accounts.Unlock, + Group: "Account Management", }) f.StringFlag(&flagset.StringFlag{ Name: "password", diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 7d5ec2c8f3..cd706c1a9d 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -182,7 +182,7 @@ func NewServer(config *Config) (*Server, error) { // graphql is started from another place 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) } } @@ -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 } From e62beee1b2dda5c4ab9277ea351c9e4b73125c2f Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 27 Jul 2022 12:28:26 +0530 Subject: [PATCH 02/46] internal/cli: use config file for flags in new-cli, builder/files: update defaults (#457) * updated simple.json and simple.hcl * added annotations for developer and grpc block * added toml tags and simple.toml file * added support for toml config files * updated simple files toml, hcl, json * added config.toml in builder/files and updated bor.service * add dumpconfig command in cli for exporting configs * update docs * updated .goreleaser.yml (POS-651) * changed --config to -config * added test config for tests and fixed lint errors * made fields of type big.int and time.Duration private, removed merge from dumpconfig, setting up default values to the Raw fields in dumpconfig, and fixed one lint error * fixed lint errors (strange) * lint fix * private no-more, using '-' in name tags to ignore * updated name tags, made c.configFile as a stringFlag (only one config file supported) and updated the merge logic in command.go -> Run() * fix: set method for big.Int flags, added a TODO * handeled bigInt and timeDuration type, bug fix in config_legacy, lint fix * updated flags, consistent across flags.go and config.go * fixed config test and updated test hcl, json config files * updated config legacy test * added test to check values of cmd flags, restructured Run in command.go, linter fix * fix linters * lint again * changed 2 flags and assert -> require * changed the 2 flags back * updated correct congig.toml path and made mainnet default * updated config.toml with new flags * added sample config (toml) file * removed sample-config.toml and added it in docs/config.md Co-authored-by: Manav Darji --- .goreleaser.yml | 3 + builder/files/bor.service | 29 +- builder/files/config.toml | 44 ++++ docs/cli/README.md | 2 + docs/cli/dumpconfig.md | 3 + docs/config.md | 235 +++++++++-------- go.mod | 1 + go.sum | 6 + internal/cli/command.go | 5 + internal/cli/dumpconfig.go | 82 ++++++ internal/cli/flagset/flagset.go | 18 +- internal/cli/server/command.go | 57 +++- internal/cli/server/command_test.go | 50 ++++ internal/cli/server/config.go | 249 +++++++++--------- internal/cli/server/config_legacy.go | 40 +-- internal/cli/server/config_legacy_test.go | 45 +++- internal/cli/server/config_test.go | 6 +- internal/cli/server/flags.go | 2 +- internal/cli/server/proto/server.pb.go | 5 +- internal/cli/server/proto/server_grpc.pb.go | 1 + internal/cli/server/service_test.go | 3 +- internal/cli/server/testdata/simple.json | 15 -- .../server/testdata/{simple.hcl => test.hcl} | 8 +- internal/cli/server/testdata/test.json | 15 ++ internal/cli/server/testdata/test.toml | 25 ++ 25 files changed, 612 insertions(+), 337 deletions(-) create mode 100644 builder/files/config.toml create mode 100644 docs/cli/dumpconfig.md create mode 100644 internal/cli/dumpconfig.go create mode 100644 internal/cli/server/command_test.go delete mode 100644 internal/cli/server/testdata/simple.json rename internal/cli/server/testdata/{simple.hcl => test.hcl} (57%) create mode 100644 internal/cli/server/testdata/test.json create mode 100644 internal/cli/server/testdata/test.toml diff --git a/.goreleaser.yml b/.goreleaser.yml index d09cc43206..7fbc61ca4a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -90,6 +90,9 @@ nfpms: - src: builder/files/genesis-testnet-v4.json dst: /etc/bor/genesis-testnet-v4.json type: config + - src: builder/files/config.toml + dst: /var/lib/bor/config.toml + type: config overrides: rpm: diff --git a/builder/files/bor.service b/builder/files/bor.service index da0338368c..4b628cbf6e 100644 --- a/builder/files/bor.service +++ b/builder/files/bor.service @@ -6,34 +6,7 @@ [Service] Restart=on-failure RestartSec=5s - ExecStart=/usr/local/bin/bor server \ - --chain=mumbai \ - # --chain=mainnet \ - --datadir /var/lib/bor/data \ - --metrics \ - --metrics.prometheus-addr="127.0.0.1:7071" \ - --syncmode 'full' \ - --miner.gasprice '30000000000' \ - --miner.gaslimit '20000000' \ - --miner.gastarget '20000000' \ - --txpool.nolocals \ - --txpool.accountslots 16 \ - --txpool.globalslots 32768 \ - --txpool.accountqueue 16 \ - --txpool.globalqueue 32768 \ - --txpool.pricelimit '30000000000' \ - --txpool.lifetime '1h30m0s' \ - --bootnodes "enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303,enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303" - # Validator params - # Uncomment and configure the following lines in case you run a validator. Don't forget to add backslash (\) - # to previous command line. - # --keystore /var/lib/bor/keystore \ - # --unlock [VALIDATOR ADDRESS] \ - # --password /var/lib/bor/password.txt \ - # --allow-insecure-unlock \ - # --nodiscover --maxpeers 1 \ - # --miner.etherbase [VALIDATOR ADDRESS] \ - # --mine + ExecStart=/usr/local/bin/bor server -config="/var/lib/bor/config.toml" Type=simple User=ubuntu KillSignal=SIGINT diff --git a/builder/files/config.toml b/builder/files/config.toml new file mode 100644 index 0000000000..c55a143ed7 --- /dev/null +++ b/builder/files/config.toml @@ -0,0 +1,44 @@ +# chain = "mumbai" +chain = "mainnet" +datadir = "/var/lib/bor/data" +syncmode = "full" + +[telemetry] +metrics = true +prometheus-addr = "127.0.0.1:7071" + +[miner] +# *** Validator params +# *** Uncomment and configure the following lines in case you run a validator. +# mine = true +# etherbase = "VALIDATOR ADDRESS" +gasprice = "30000000000" +gasceil = 20000000 + + +[txpool] +accountqueue = 16 +accountslots = 16 +globalqueue = 32768 +globalslots = 32768 +lifetime = "1h30m0s" +nolocals = true +pricelimit = 30000000000 + +[p2p] +# *** Validator params +# *** Uncomment and configure the following lines in case you run a validator. +# nodiscover = true +# maxpeers = 1 + [p2p.discovery] + bootnodes = ["enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303", "enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303"] + +# *** Validator params +# *** Uncomment and configure the following lines in case you run a validator. + +# keystore = "/var/lib/bor/keystore" + +# [accounts] +# allow-insecure-unlock = true +# password = "/var/lib/bor/password.txt" +# unlock = ["VALIDATOR ADDRESS"] \ No newline at end of file diff --git a/docs/cli/README.md b/docs/cli/README.md index d92a7b5a05..3bc3daddc5 100644 --- a/docs/cli/README.md +++ b/docs/cli/README.md @@ -26,6 +26,8 @@ - [```debug pprof```](./debug_pprof.md) +- [```dumpconfig```](./dumpconfig.md) + - [```fingerprint```](./fingerprint.md) - [```peers```](./peers.md) diff --git a/docs/cli/dumpconfig.md b/docs/cli/dumpconfig.md new file mode 100644 index 0000000000..0383c47310 --- /dev/null +++ b/docs/cli/dumpconfig.md @@ -0,0 +1,3 @@ +# Dumpconfig + +The ```bor dumpconfig ``` command will export the user provided flags into a configuration file \ No newline at end of file diff --git a/docs/config.md b/docs/config.md index 4f4dec157b..196a0bf388 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,133 +1,144 @@ # Config -Toml files format used in geth are being deprecated. - -Bor uses uses JSON and [HCL](https://github.com/hashicorp/hcl) formats to create configuration files. This is the format in HCL alongside the default values: - +- The `bor dumpconfig` command prints the default configurations, in the TOML format, on the terminal. + - One can `pipe (>)` this to a file (say `config.toml`) and use it to start bor. + - Command to provide a config file: `bor server -config config.toml` +- Bor uses TOML, HCL, and JSON format config files. +- This is the format of the config file in TOML: + - **NOTE: The values of these following flags are just for reference** + - `config.toml` file: ``` chain = "mainnet" -log-level = "info" -data-dir = "" -sync-mode = "fast" -gc-mode = "full" +identity = "myIdentity" +log-level = "INFO" +datadir = "/var/lib/bor/data" +keystore = "path/to/keystore" +syncmode = "full" +gcmode = "full" snapshot = true ethstats = "" -whitelist = {} -p2p { - max-peers = 30 - max-pend-peers = 50 - bind = "0.0.0.0" - port = 30303 - no-discover = false - nat = "any" - discovery { - v5-enabled = false - bootnodes = [] - bootnodesv4 = [] - bootnodesv5 = [] - staticNodes = [] - trustedNodes = [] - dns = [] - } -} +[p2p] +maxpeers = 30 +maxpendpeers = 50 +bind = "0.0.0.0" +port = 30303 +nodiscover = false +nat = "any" -heimdall { - url = "http://localhost:1317" - without = false -} +[p2p.discovery] +v5disc = false +bootnodes = ["enode://d860a01f9722d78051619d1e2351aba3f43f943f6f00718d1b9baa4101932a1f5011f16bb2b1bb35db20d6fe28fa0bf09636d26a87d31de9ec6203eeedb1f666@18.138.108.67:30303", "enode://22a8232c3abc76a16ae9d6c3b164f98775fe226f0917b0ca871128a74a8e9630b458460865bab457221f1d448dd9791d24c4e5d88786180ac185df813a68d4de@3.209.45.79:30303"] +bootnodesv4 = [] +bootnodesv5 = ["enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2Gxb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNlY3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA", "enr:-KG4QDyytgmE4f7AnvW-ZaUOIi9i79qX4JwjRAiXBZCU65wOfBu-3Nb5I7b_Rmg3KCOcZM_C3y5pg7EBU5XGrcLTduQEhGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQ2_DUbiXNlY3AyNTZrMaEDKnz_-ps3UUOfHWVYaskI5kWYO_vtYMGYCQRAR3gHDouDdGNwgiMog3VkcIIjKA"] +static-nodes = ["enode://8499da03c47d637b20eee24eec3c356c9a2e6148d6fe25ca195c7949ab8ec2c03e3556126b0d7ed644675e78c4318b08691b7b57de10e5f0d40d05b09238fa0a@52.187.207.27:30303"] +trusted-nodes = ["enode://2b252ab6a1d0f971d9722cb839a42cb81db019ba44c08754628ab4a823487071b5695317c8ccd085219c3a03af063495b2f1da8d18218da2d6a82981b45e6ffc@65.108.70.101:30303"] +dns = [] -txpool { - locals = [] - no-locals = false - journal = "" - rejournal = "1h" - price-limit = 1 - price-bump = 10 - account-slots = 16 - global-slots = 4096 - account-queue = 64 - global-queue = 1024 - lifetime = "3h" -} +[heimdall] +url = "http://localhost:1317" +"bor.without" = false -sealer { - enabled = false - etherbase = "" - gas-ceil = 8000000 - extra-data = "" -} +[txpool] +locals = ["$ADDRESS1", "$ADDRESS2"] +nolocals = false +journal = "" +rejournal = "1h0m0s" +pricelimit = 30000000000 +pricebump = 10 +accountslots = 16 +globalslots = 32768 +accountqueue = 16 +globalqueue = 32768 +lifetime = "3h0m0s" -gpo { - blocks = 20 - percentile = 60 -} +[miner] +mine = false +etherbase = "" +extradata = "" +gaslimit = 20000000 +gasprice = "30000000000" -jsonrpc { - ipc-disable = false - ipc-path = "" - modules = ["web3", "net"] - cors = ["*"] - vhost = ["*"] - - http { - enabled = false - port = 8545 - prefix = "" - host = "localhost" - } +[jsonrpc] +ipcdisable = false +ipcpath = "/var/lib/bor/bor.ipc" +gascap = 50000000 +txfeecap = 5e+00 - ws { - enabled = false - port = 8546 - prefix = "" - host = "localhost" - } +[jsonrpc.http] +enabled = false +port = 8545 +prefix = "" +host = "localhost" +api = ["eth", "net", "web3", "txpool", "bor"] +vhosts = ["*"] +corsdomain = ["*"] - graphqh { - enabled = false - } -} +[jsonrpc.ws] +enabled = false +port = 8546 +prefix = "" +host = "localhost" +api = ["web3", "net"] +vhosts = ["*"] +corsdomain = ["*"] -telemetry { - enabled = false - expensive = false +[jsonrpc.graphql] +enabled = false +port = 0 +prefix = "" +host = "" +api = [] +vhosts = ["*"] +corsdomain = ["*"] - influxdb { - v1-enabled = false - endpoint = "" - database = "" - username = "" - password = "" - v2-enabled = false - token = "" - bucket = "" - organization = "" - } -} +[gpo] +blocks = 20 +percentile = 60 +maxprice = "5000000000000" +ignoreprice = "2" -cache { - cache = 1024 - perc-database = 50 - perc-trie = 15 - perc-gc = 25 - perc-snapshot = 10 - journal = "triecache" - rejournal = "60m" - no-prefetch = false - preimages = false - tx-lookup-limit = 2350000 -} +[telemetry] +metrics = false +expensive = false +prometheus-addr = "" +opencollector-endpoint = "" -accounts { - unlock = [] - password-file = "" - allow-insecure-unlock = false - use-lightweight-kdf = false -} +[telemetry.influx] +influxdb = false +endpoint = "" +database = "" +username = "" +password = "" +influxdbv2 = false +token = "" +bucket = "" +organization = "" -grpc { - addr = ":3131" -} +[cache] +cache = 1024 +gc = 25 +snapshot = 10 +database = 50 +trie = 15 +journal = "triecache" +rejournal = "1h0m0s" +noprefetch = false +preimages = false +txlookuplimit = 2350000 + +[accounts] +unlock = ["$ADDRESS1", "$ADDRESS2"] +password = "path/to/password.txt" +allow-insecure-unlock = false +lightkdf = false +disable-bor-wallet = false + +[grpc] +addr = ":3131" + +[developer] +dev = false +period = 0 ``` diff --git a/go.mod b/go.mod index 1b452a67a1..3f90695d47 100644 --- a/go.mod +++ b/go.mod @@ -83,6 +83,7 @@ require ( require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect + github.com/BurntSushi/toml v1.1.0 // indirect github.com/Masterminds/goutils v1.1.0 // indirect github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/sprig v2.22.0+incompatible // indirect diff --git a/go.sum b/go.sum index 374ab3066e..fc58b621e6 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,8 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSu github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 h1:Px2UA+2RvSSvv+RvJNuUB6n7rs5Wsel4dXLe90Um2n4= github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= @@ -456,6 +458,10 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= diff --git a/internal/cli/command.go b/internal/cli/command.go index 1ff95b410f..06127a9823 100644 --- a/internal/cli/command.go +++ b/internal/cli/command.go @@ -82,6 +82,11 @@ func Commands() map[string]MarkDownCommandFactory { UI: ui, }, nil }, + "dumpconfig": func() (MarkDownCommand, error) { + return &DumpconfigCommand{ + Meta2: meta2, + }, nil + }, "debug": func() (MarkDownCommand, error) { return &DebugCommand{ UI: ui, diff --git a/internal/cli/dumpconfig.go b/internal/cli/dumpconfig.go new file mode 100644 index 0000000000..3e4688fc24 --- /dev/null +++ b/internal/cli/dumpconfig.go @@ -0,0 +1,82 @@ +package cli + +import ( + "reflect" + "strings" + + "github.com/naoina/toml" + + "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 +type DumpconfigCommand struct { + *Meta2 +} + +// MarkDown implements cli.MarkDown interface +func (p *DumpconfigCommand) MarkDown() string { + items := []string{ + "# Dumpconfig", + "The ```bor dumpconfig ``` command will export the user provided flags into a configuration file", + } + + return strings.Join(items, "\n\n") +} + +// Help implements the cli.Command interface +func (c *DumpconfigCommand) Help() string { + return `Usage: bor dumpconfig + + This command will will export the user provided flags into a configuration file` +} + +// Synopsis implements the cli.Command interface +func (c *DumpconfigCommand) Synopsis() string { + return "Export configuration file" +} + +// TODO: add flags for file location and format (toml, json, hcl) of the configuration file. + +// Run implements the cli.Command interface +func (c *DumpconfigCommand) Run(args []string) int { + // Initialize an empty command instance to get flags + command := server.Command{} + flags := command.Flags() + + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + userConfig := command.GetConfig() + + // convert the big.Int and time.Duration fields to their corresponding Raw fields + userConfig.TxPool.RejournalRaw = userConfig.TxPool.Rejournal.String() + userConfig.TxPool.LifeTimeRaw = userConfig.TxPool.LifeTime.String() + userConfig.Sealer.GasPriceRaw = userConfig.Sealer.GasPrice.String() + userConfig.Gpo.MaxPriceRaw = userConfig.Gpo.MaxPrice.String() + userConfig.Gpo.IgnorePriceRaw = userConfig.Gpo.IgnorePrice.String() + userConfig.Cache.RejournalRaw = userConfig.Cache.Rejournal.String() + + // Currently, the configurations (userConfig) is exported into `toml` file format. + out, err := tomlSettings.Marshal(&userConfig) + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + c.UI.Output(string(out)) + + return 0 +} diff --git a/internal/cli/flagset/flagset.go b/internal/cli/flagset/flagset.go index 0c19fa9758..d9e204f0e4 100644 --- a/internal/cli/flagset/flagset.go +++ b/internal/cli/flagset/flagset.go @@ -180,14 +180,15 @@ func (b *BigIntFlag) Set(value string) error { var ok bool if strings.HasPrefix(value, "0x") { num, ok = num.SetString(value[2:], 16) + *b.Value = *num } else { num, ok = num.SetString(value, 10) + *b.Value = *num } if !ok { return fmt.Errorf("failed to set big int") } - b.Value = num return nil } @@ -209,6 +210,19 @@ type SliceStringFlag struct { Group string } +// SplitAndTrim splits input separated by a comma +// and trims excessive white space from the substrings. +func SplitAndTrim(input string) (ret []string) { + l := strings.Split(input, ",") + for _, r := range l { + if r = strings.TrimSpace(r); r != "" { + ret = append(ret, r) + } + } + + return ret +} + func (i *SliceStringFlag) String() string { if i.Value == nil { return "" @@ -219,7 +233,7 @@ func (i *SliceStringFlag) String() string { func (i *SliceStringFlag) Set(value string) error { // overwritting insted of appending - *i.Value = strings.Split(value, ",") + *i.Value = SplitAndTrim(value) return nil } diff --git a/internal/cli/server/command.go b/internal/cli/server/command.go index a0b8a6d87c..2995f10f69 100644 --- a/internal/cli/server/command.go +++ b/internal/cli/server/command.go @@ -7,8 +7,9 @@ import ( "strings" "syscall" - "github.com/ethereum/go-ethereum/log" "github.com/mitchellh/cli" + + "github.com/ethereum/go-ethereum/log" ) // Command is the command to start the sever @@ -21,7 +22,7 @@ type Command struct { // final configuration config *Config - configFile []string + configFile string srv *Server } @@ -50,34 +51,57 @@ func (c *Command) Synopsis() string { return "Run the Bor server" } -// Run implements the cli.Command interface -func (c *Command) Run(args []string) int { +func (c *Command) extractFlags(args []string) error { + config := *DefaultConfig() + flags := c.Flags() if err := flags.Parse(args); err != nil { c.UI.Error(err.Error()) - return 1 + c.config = &config + + return err } - // read config file - config := DefaultConfig() - for _, configFile := range c.configFile { - cfg, err := readConfigFile(configFile) + // TODO: Check if this can be removed or not + // read cli flags + if err := config.Merge(c.cliConfig); err != nil { + c.UI.Error(err.Error()) + c.config = &config + + return err + } + // read if config file is provided, this will overwrite the cli flags, if provided + if c.configFile != "" { + log.Warn("Config File provided, this will overwrite the cli flags.", "configFile:", c.configFile) + cfg, err := readConfigFile(c.configFile) if err != nil { c.UI.Error(err.Error()) - return 1 + c.config = &config + + return err } if err := config.Merge(cfg); err != nil { c.UI.Error(err.Error()) - return 1 + c.config = &config + + return err } } - if err := config.Merge(c.cliConfig); err != nil { + + c.config = &config + + return nil +} + +// Run implements the cli.Command interface +func (c *Command) Run(args []string) int { + err := c.extractFlags(args) + if err != nil { c.UI.Error(err.Error()) return 1 } - c.config = config - srv, err := NewServer(config) + srv, err := NewServer(c.config) if err != nil { c.UI.Error(err.Error()) return 1 @@ -112,3 +136,8 @@ func (c *Command) handleSignals() int { } return 1 } + +// GetConfig returns the user specified config +func (c *Command) GetConfig() *Config { + return c.cliConfig +} diff --git a/internal/cli/server/command_test.go b/internal/cli/server/command_test.go new file mode 100644 index 0000000000..9006559d0f --- /dev/null +++ b/internal/cli/server/command_test.go @@ -0,0 +1,50 @@ +package server + +import ( + "math/big" + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestFlags(t *testing.T) { + t.Parallel() + + var c Command + + args := []string{ + "--txpool.rejournal", "30m0s", + "--txpool.lifetime", "30m0s", + "--miner.gasprice", "20000000000", + "--gpo.maxprice", "70000000000", + "--gpo.ignoreprice", "1", + "--cache.trie.rejournal", "40m0s", + "--dev", + "--dev.period", "2", + "--datadir", "./data", + "--maxpeers", "30", + "--requiredblocks", "a=b", + "--http.api", "eth,web3,bor", + } + err := c.extractFlags(args) + + require.NoError(t, err) + + txRe, _ := time.ParseDuration("30m0s") + txLt, _ := time.ParseDuration("30m0s") + caRe, _ := time.ParseDuration("40m0s") + + require.Equal(t, c.config.DataDir, "./data") + require.Equal(t, c.config.Developer.Enabled, true) + require.Equal(t, c.config.Developer.Period, uint64(2)) + require.Equal(t, c.config.TxPool.Rejournal, txRe) + require.Equal(t, c.config.TxPool.LifeTime, txLt) + require.Equal(t, c.config.Sealer.GasPrice, big.NewInt(20000000000)) + require.Equal(t, c.config.Gpo.MaxPrice, big.NewInt(70000000000)) + require.Equal(t, c.config.Gpo.IgnorePrice, big.NewInt(1)) + require.Equal(t, c.config.Cache.Rejournal, caRe) + require.Equal(t, c.config.P2P.MaxPeers, uint64(30)) + require.Equal(t, c.config.RequiredBlocks, map[string]string{"a": "b"}) + require.Equal(t, c.config.JsonRPC.Http.API, []string{"eth", "web3", "bor"}) +} diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index fdf253a37e..819ab1aca5 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -14,6 +14,11 @@ import ( godebug "runtime/debug" + "github.com/hashicorp/hcl/v2/hclsimple" + "github.com/imdario/mergo" + "github.com/mitchellh/go-homedir" + gopsutil "github.com/shirou/gopsutil/mem" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" @@ -28,360 +33,356 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/params" - "github.com/hashicorp/hcl/v2/hclsimple" - "github.com/imdario/mergo" - "github.com/mitchellh/go-homedir" - gopsutil "github.com/shirou/gopsutil/mem" ) type Config struct { chain *chains.Chain // Chain is the chain to sync with - Chain string `hcl:"chain,optional"` + Chain string `hcl:"chain,optional" toml:"chain,optional"` // Identity of the node - Identity string `hcl:"identity,optional"` + 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"` + RequiredBlocks map[string]string `hcl:"requiredblocks,optional" toml:"requiredblocks,optional"` // LogLevel is the level of the logs to put out - LogLevel string `hcl:"log-level,optional"` + LogLevel string `hcl:"log-level,optional" toml:"log-level,optional"` // DataDir is the directory to store the state in - DataDir string `hcl:"data-dir,optional"` + DataDir string `hcl:"datadir,optional" toml:"datadir,optional"` // KeyStoreDir is the directory to store keystores - KeyStoreDir string `hcl:"keystore-dir,optional"` + KeyStoreDir string `hcl:"keystore,optional" toml:"keystore,optional"` // SyncMode selects the sync protocol - SyncMode string `hcl:"sync-mode,optional"` + SyncMode string `hcl:"syncmode,optional" toml:"syncmode,optional"` // GcMode selects the garbage collection mode for the trie - GcMode string `hcl:"gc-mode,optional"` + GcMode string `hcl:"gcmode,optional" toml:"gcmode,optional"` // Snapshot disables/enables the snapshot database mode - Snapshot bool `hcl:"snapshot,optional"` + Snapshot bool `hcl:"snapshot,optional" toml:"snapshot,optional"` // Ethstats is the address of the ethstats server to send telemetry - Ethstats string `hcl:"ethstats,optional"` + Ethstats string `hcl:"ethstats,optional" toml:"ethstats,optional"` // P2P has the p2p network related settings - P2P *P2PConfig `hcl:"p2p,block"` + P2P *P2PConfig `hcl:"p2p,block" toml:"p2p,block"` // Heimdall has the heimdall connection related settings - Heimdall *HeimdallConfig `hcl:"heimdall,block"` + Heimdall *HeimdallConfig `hcl:"heimdall,block" toml:"heimdall,block"` // TxPool has the transaction pool related settings - TxPool *TxPoolConfig `hcl:"txpool,block"` + TxPool *TxPoolConfig `hcl:"txpool,block" toml:"txpool,block"` // Sealer has the validator related settings - Sealer *SealerConfig `hcl:"sealer,block"` + Sealer *SealerConfig `hcl:"miner,block" toml:"miner,block"` // JsonRPC has the json-rpc related settings - JsonRPC *JsonRPCConfig `hcl:"jsonrpc,block"` + JsonRPC *JsonRPCConfig `hcl:"jsonrpc,block" toml:"jsonrpc,block"` // Gpo has the gas price oracle related settings - Gpo *GpoConfig `hcl:"gpo,block"` + Gpo *GpoConfig `hcl:"gpo,block" toml:"gpo,block"` // Telemetry has the telemetry related settings - Telemetry *TelemetryConfig `hcl:"telemetry,block"` + Telemetry *TelemetryConfig `hcl:"telemetry,block" toml:"telemetry,block"` // Cache has the cache related settings - Cache *CacheConfig `hcl:"cache,block"` + Cache *CacheConfig `hcl:"cache,block" toml:"cache,block"` // Account has the validator account related settings - Accounts *AccountsConfig `hcl:"accounts,block"` + Accounts *AccountsConfig `hcl:"accounts,block" toml:"accounts,block"` // GRPC has the grpc server related settings - GRPC *GRPCConfig + GRPC *GRPCConfig `hcl:"grpc,block" toml:"grpc,block"` // Developer has the developer mode related settings - Developer *DeveloperConfig + Developer *DeveloperConfig `hcl:"developer,block" toml:"developer,block"` } type P2PConfig struct { // MaxPeers sets the maximum number of connected peers - MaxPeers uint64 `hcl:"max-peers,optional"` + MaxPeers uint64 `hcl:"maxpeers,optional" toml:"maxpeers,optional"` // MaxPendPeers sets the maximum number of pending connected peers - MaxPendPeers uint64 `hcl:"max-pend-peers,optional"` + MaxPendPeers uint64 `hcl:"maxpendpeers,optional" toml:"maxpendpeers,optional"` // Bind is the bind address - Bind string `hcl:"bind,optional"` + Bind string `hcl:"bind,optional" toml:"bind,optional"` // Port is the port number - Port uint64 `hcl:"port,optional"` + Port uint64 `hcl:"port,optional" toml:"port,optional"` // NoDiscover is used to disable discovery - NoDiscover bool `hcl:"no-discover,optional"` + NoDiscover bool `hcl:"nodiscover,optional" toml:"nodiscover,optional"` // NAT it used to set NAT options - NAT string `hcl:"nat,optional"` + NAT string `hcl:"nat,optional" toml:"nat,optional"` // Discovery has the p2p discovery related settings - Discovery *P2PDiscovery `hcl:"discovery,block"` + Discovery *P2PDiscovery `hcl:"discovery,block" toml:"discovery,block"` } type P2PDiscovery struct { // V5Enabled is used to enable disc v5 discovery mode - V5Enabled bool `hcl:"v5-enabled,optional"` + V5Enabled bool `hcl:"v5disc,optional" toml:"v5disc,optional"` // Bootnodes is the list of initial bootnodes - Bootnodes []string `hcl:"bootnodes,optional"` + Bootnodes []string `hcl:"bootnodes,optional" toml:"bootnodes,optional"` // BootnodesV4 is the list of initial v4 bootnodes - BootnodesV4 []string `hcl:"bootnodesv4,optional"` + BootnodesV4 []string `hcl:"bootnodesv4,optional" toml:"bootnodesv4,optional"` // BootnodesV5 is the list of initial v5 bootnodes - BootnodesV5 []string `hcl:"bootnodesv5,optional"` + BootnodesV5 []string `hcl:"bootnodesv5,optional" toml:"bootnodesv5,optional"` // StaticNodes is the list of static nodes - StaticNodes []string `hcl:"static-nodes,optional"` + StaticNodes []string `hcl:"static-nodes,optional" toml:"static-nodes,optional"` // TrustedNodes is the list of trusted nodes - TrustedNodes []string `hcl:"trusted-nodes,optional"` + TrustedNodes []string `hcl:"trusted-nodes,optional" toml:"trusted-nodes,optional"` // DNS is the list of enrtree:// URLs which will be queried for nodes to connect to - DNS []string `hcl:"dns,optional"` + DNS []string `hcl:"dns,optional" toml:"dns,optional"` } type HeimdallConfig struct { // URL is the url of the heimdall server - URL string `hcl:"url,optional"` + URL string `hcl:"url,optional" toml:"url,optional"` // Without is used to disable remote heimdall during testing - Without bool `hcl:"without,optional"` + Without bool `hcl:"bor.without,optional" toml:"bor.without,optional"` } type TxPoolConfig struct { // Locals are the addresses that should be treated by default as local - Locals []string `hcl:"locals,optional"` + Locals []string `hcl:"locals,optional" toml:"locals,optional"` // NoLocals enables whether local transaction handling should be disabled - NoLocals bool `hcl:"no-locals,optional"` + NoLocals bool `hcl:"nolocals,optional" toml:"nolocals,optional"` // Journal is the path to store local transactions to survive node restarts - Journal string `hcl:"journal,optional"` + Journal string `hcl:"journal,optional" toml:"journal,optional"` // Rejournal is the time interval to regenerate the local transaction journal - Rejournal time.Duration - RejournalRaw string `hcl:"rejournal,optional"` + Rejournal time.Duration `hcl:"-,optional" toml:"-,optional"` + RejournalRaw string `hcl:"rejournal,optional" toml:"rejournal,optional"` // PriceLimit is the minimum gas price to enforce for acceptance into the pool - PriceLimit uint64 `hcl:"price-limit,optional"` + PriceLimit uint64 `hcl:"pricelimit,optional" toml:"pricelimit,optional"` // PriceBump is the minimum price bump percentage to replace an already existing transaction (nonce) - PriceBump uint64 `hcl:"price-bump,optional"` + PriceBump uint64 `hcl:"pricebump,optional" toml:"pricebump,optional"` // AccountSlots is the number of executable transaction slots guaranteed per account - AccountSlots uint64 `hcl:"account-slots,optional"` + AccountSlots uint64 `hcl:"accountslots,optional" toml:"accountslots,optional"` // GlobalSlots is the maximum number of executable transaction slots for all accounts - GlobalSlots uint64 `hcl:"global-slots,optional"` + GlobalSlots uint64 `hcl:"globalslots,optional" toml:"globalslots,optional"` // AccountQueue is the maximum number of non-executable transaction slots permitted per account - AccountQueue uint64 `hcl:"account-queue,optional"` + AccountQueue uint64 `hcl:"accountqueue,optional" toml:"accountqueue,optional"` // GlobalQueueis the maximum number of non-executable transaction slots for all accounts - GlobalQueue uint64 `hcl:"global-queue,optional"` + GlobalQueue uint64 `hcl:"globalqueue,optional" toml:"globalqueue,optional"` - // Lifetime is the maximum amount of time non-executable transaction are queued - LifeTime time.Duration - LifeTimeRaw string `hcl:"lifetime,optional"` + // lifetime is the maximum amount of time non-executable transaction are queued + LifeTime time.Duration `hcl:"-,optional" toml:"-,optional"` + LifeTimeRaw string `hcl:"lifetime,optional" toml:"lifetime,optional"` } type SealerConfig struct { // Enabled is used to enable validator mode - Enabled bool `hcl:"enabled,optional"` + Enabled bool `hcl:"mine,optional" toml:"mine,optional"` // Etherbase is the address of the validator - Etherbase string `hcl:"etherbase,optional"` + Etherbase string `hcl:"etherbase,optional" toml:"etherbase,optional"` // ExtraData is the block extra data set by the miner - ExtraData string `hcl:"extra-data,optional"` + ExtraData string `hcl:"extradata,optional" toml:"extradata,optional"` // GasCeil is the target gas ceiling for mined blocks. - GasCeil uint64 `hcl:"gas-ceil,optional"` + GasCeil uint64 `hcl:"gaslimit,optional" toml:"gaslimit,optional"` // GasPrice is the minimum gas price for mining a transaction - GasPrice *big.Int - GasPriceRaw string `hcl:"gas-price,optional"` + GasPrice *big.Int `hcl:"-,optional" toml:"-,optional"` + GasPriceRaw string `hcl:"gasprice,optional" toml:"gasprice,optional"` } type JsonRPCConfig struct { // IPCDisable enables whether ipc is enabled or not - IPCDisable bool `hcl:"ipc-disable,optional"` + IPCDisable bool `hcl:"ipcdisable,optional" toml:"ipcdisable,optional"` // IPCPath is the path of the ipc endpoint - IPCPath string `hcl:"ipc-path,optional"` + IPCPath string `hcl:"ipcpath,optional" toml:"ipcpath,optional"` // GasCap is the global gas cap for eth-call variants. - GasCap uint64 `hcl:"gas-cap,optional"` + GasCap uint64 `hcl:"gascap,optional" toml:"gascap,optional"` // TxFeeCap is the global transaction fee cap for send-transaction variants - TxFeeCap float64 `hcl:"tx-fee-cap,optional"` + TxFeeCap float64 `hcl:"txfeecap,optional" toml:"txfeecap,optional"` // Http has the json-rpc http related settings - Http *APIConfig `hcl:"http,block"` + Http *APIConfig `hcl:"http,block" toml:"http,block"` // Ws has the json-rpc websocket related settings - Ws *APIConfig `hcl:"ws,block"` + Ws *APIConfig `hcl:"ws,block" toml:"ws,block"` // Graphql has the json-rpc graphql related settings - Graphql *APIConfig `hcl:"graphql,block"` + Graphql *APIConfig `hcl:"graphql,block" toml:"graphql,block"` } type GRPCConfig struct { // Addr is the bind address for the grpc rpc server - Addr string + Addr string `hcl:"addr,optional" toml:"addr,optional"` } type APIConfig struct { // Enabled selects whether the api is enabled - Enabled bool `hcl:"enabled,optional"` + Enabled bool `hcl:"enabled,optional" toml:"enabled,optional"` // Port is the port number for this api - Port uint64 `hcl:"port,optional"` + Port uint64 `hcl:"port,optional" toml:"port,optional"` // Prefix is the http prefix to expose this api - Prefix string `hcl:"prefix,optional"` + Prefix string `hcl:"prefix,optional" toml:"prefix,optional"` // Host is the address to bind the api - Host string `hcl:"host,optional"` + Host string `hcl:"host,optional" toml:"host,optional"` - // Modules is the list of enabled api modules - API []string `hcl:"modules,optional"` + // API is the list of enabled api modules + API []string `hcl:"api,optional" toml:"api,optional"` // VHost is the list of valid virtual hosts - VHost []string `hcl:"vhost,optional"` + VHost []string `hcl:"vhosts,optional" toml:"vhosts,optional"` // Cors is the list of Cors endpoints - Cors []string `hcl:"cors,optional"` + Cors []string `hcl:"corsdomain,optional" toml:"corsdomain,optional"` } type GpoConfig struct { // Blocks is the number of blocks to track to compute the price oracle - Blocks uint64 `hcl:"blocks,optional"` + Blocks uint64 `hcl:"blocks,optional" toml:"blocks,optional"` // Percentile sets the weights to new blocks - Percentile uint64 `hcl:"percentile,optional"` + Percentile uint64 `hcl:"percentile,optional" toml:"percentile,optional"` // MaxPrice is an upper bound gas price - MaxPrice *big.Int - MaxPriceRaw string `hcl:"max-price,optional"` + MaxPrice *big.Int `hcl:"-,optional" toml:"-,optional"` + MaxPriceRaw string `hcl:"maxprice,optional" toml:"maxprice,optional"` // IgnorePrice is a lower bound gas price - IgnorePrice *big.Int - IgnorePriceRaw string `hcl:"ignore-price,optional"` + IgnorePrice *big.Int `hcl:"-,optional" toml:"-,optional"` + IgnorePriceRaw string `hcl:"ignoreprice,optional" toml:"ignoreprice,optional"` } type TelemetryConfig struct { // Enabled enables metrics - Enabled bool `hcl:"enabled,optional"` + Enabled bool `hcl:"metrics,optional" toml:"metrics,optional"` // Expensive enables expensive metrics - Expensive bool `hcl:"expensive,optional"` + Expensive bool `hcl:"expensive,optional" toml:"expensive,optional"` // InfluxDB has the influxdb related settings - InfluxDB *InfluxDBConfig `hcl:"influx,block"` + InfluxDB *InfluxDBConfig `hcl:"influx,block" toml:"influx,block"` // Prometheus Address - PrometheusAddr string `hcl:"prometheus-addr,optional"` + PrometheusAddr string `hcl:"prometheus-addr,optional" toml:"prometheus-addr,optional"` // Open collector endpoint - OpenCollectorEndpoint string `hcl:"opencollector-endpoint,optional"` + OpenCollectorEndpoint string `hcl:"opencollector-endpoint,optional" toml:"opencollector-endpoint,optional"` } type InfluxDBConfig struct { // V1Enabled enables influx v1 mode - V1Enabled bool `hcl:"v1-enabled,optional"` + V1Enabled bool `hcl:"influxdb,optional" toml:"influxdb,optional"` // Endpoint is the url endpoint of the influxdb service - Endpoint string `hcl:"endpoint,optional"` + Endpoint string `hcl:"endpoint,optional" toml:"endpoint,optional"` // Database is the name of the database in Influxdb to store the metrics. - Database string `hcl:"database,optional"` + Database string `hcl:"database,optional" toml:"database,optional"` // Enabled is the username to authorize access to Influxdb - Username string `hcl:"username,optional"` + Username string `hcl:"username,optional" toml:"username,optional"` // Password is the password to authorize access to Influxdb - Password string `hcl:"password,optional"` + Password string `hcl:"password,optional" toml:"password,optional"` // Tags are tags attaches to all generated metrics - Tags map[string]string `hcl:"tags,optional"` + Tags map[string]string `hcl:"tags,optional" toml:"tags,optional"` // Enabled enables influx v2 mode - V2Enabled bool `hcl:"v2-enabled,optional"` + V2Enabled bool `hcl:"influxdbv2,optional" toml:"influxdbv2,optional"` // Token is the token to authorize access to Influxdb V2. - Token string `hcl:"token,optional"` + Token string `hcl:"token,optional" toml:"token,optional"` // Bucket is the bucket to store metrics in Influxdb V2. - Bucket string `hcl:"bucket,optional"` + Bucket string `hcl:"bucket,optional" toml:"bucket,optional"` // Organization is the name of the organization for Influxdb V2. - Organization string `hcl:"organization,optional"` + Organization string `hcl:"organization,optional" toml:"organization,optional"` } type CacheConfig struct { // Cache is the amount of cache of the node - Cache uint64 `hcl:"cache,optional"` + Cache uint64 `hcl:"cache,optional" toml:"cache,optional"` // PercGc is percentage of cache used for garbage collection - PercGc uint64 `hcl:"perc-gc,optional"` + PercGc uint64 `hcl:"gc,optional" toml:"gc,optional"` // PercSnapshot is percentage of cache used for snapshots - PercSnapshot uint64 `hcl:"perc-snapshot,optional"` + PercSnapshot uint64 `hcl:"snapshot,optional" toml:"snapshot,optional"` // PercDatabase is percentage of cache used for the database - PercDatabase uint64 `hcl:"perc-database,optional"` + PercDatabase uint64 `hcl:"database,optional" toml:"database,optional"` // PercTrie is percentage of cache used for the trie - PercTrie uint64 `hcl:"perc-trie,optional"` + PercTrie uint64 `hcl:"trie,optional" toml:"trie,optional"` // Journal is the disk journal directory for trie cache to survive node restarts - Journal string `hcl:"journal,optional"` + Journal string `hcl:"journal,optional" toml:"journal,optional"` // Rejournal is the time interval to regenerate the journal for clean cache - Rejournal time.Duration - RejournalRaw string `hcl:"rejournal,optional"` + Rejournal time.Duration `hcl:"-,optional" toml:"-,optional"` + RejournalRaw string `hcl:"rejournal,optional" toml:"rejournal,optional"` // NoPrefetch is used to disable prefetch of tries - NoPrefetch bool `hcl:"no-prefetch,optional"` + NoPrefetch bool `hcl:"noprefetch,optional" toml:"noprefetch,optional"` // Preimages is used to enable the track of hash preimages - Preimages bool `hcl:"preimages,optional"` + Preimages bool `hcl:"preimages,optional" toml:"preimages,optional"` // TxLookupLimit sets the maximum number of blocks from head whose tx indices are reserved. - TxLookupLimit uint64 `hcl:"tx-lookup-limit,optional"` + TxLookupLimit uint64 `hcl:"txlookuplimit,optional" toml:"txlookuplimit,optional"` } type AccountsConfig struct { // Unlock is the list of addresses to unlock in the node - Unlock []string `hcl:"unlock,optional"` + Unlock []string `hcl:"unlock,optional" toml:"unlock,optional"` // PasswordFile is the file where the account passwords are stored - PasswordFile string `hcl:"password-file,optional"` + PasswordFile string `hcl:"password,optional" toml:"password,optional"` // AllowInsecureUnlock allows user to unlock accounts in unsafe http environment. - AllowInsecureUnlock bool `hcl:"allow-insecure-unlock,optional"` + AllowInsecureUnlock bool `hcl:"allow-insecure-unlock,optional" toml:"allow-insecure-unlock,optional"` // UseLightweightKDF enables a faster but less secure encryption of accounts - UseLightweightKDF bool `hcl:"use-lightweight-kdf,optional"` + UseLightweightKDF bool `hcl:"lightkdf,optional" toml:"lightkdf,optional"` // DisableBorWallet disables the personal wallet endpoints - DisableBorWallet bool `hcl:"disable-bor-wallet,optional"` + DisableBorWallet bool `hcl:"disable-bor-wallet,optional" toml:"disable-bor-wallet,optional"` } type DeveloperConfig struct { // Enabled enables the developer mode - Enabled bool `hcl:"dev,optional"` + Enabled bool `hcl:"dev,optional" toml:"dev,optional"` // Period is the block period to use in developer mode - Period uint64 `hcl:"period,optional"` + Period uint64 `hcl:"period,optional" toml:"period,optional"` } func DefaultConfig() *Config { @@ -419,14 +420,14 @@ func DefaultConfig() *Config { Locals: []string{}, NoLocals: false, Journal: "", - Rejournal: time.Duration(1 * time.Hour), + Rejournal: 1 * time.Hour, PriceLimit: 30000000000, PriceBump: 10, AccountSlots: 16, GlobalSlots: 32768, AccountQueue: 16, GlobalQueue: 32768, - LifeTime: time.Duration(3 * time.Hour), + LifeTime: 3 * time.Hour, }, Sealer: &SealerConfig{ Enabled: false, @@ -526,7 +527,7 @@ func (c *Config) fillBigInt() error { }{ {"gpo.maxprice", &c.Gpo.MaxPrice, &c.Gpo.MaxPriceRaw}, {"gpo.ignoreprice", &c.Gpo.IgnorePrice, &c.Gpo.IgnorePriceRaw}, - {"sealer.gasprice", &c.Sealer.GasPrice, &c.Sealer.GasPriceRaw}, + {"miner.gasprice", &c.Sealer.GasPrice, &c.Sealer.GasPriceRaw}, } for _, x := range tds { @@ -582,13 +583,7 @@ func (c *Config) fillTimeDurations() error { func readConfigFile(path string) (*Config, error) { ext := filepath.Ext(path) if ext == ".toml" { - // read file and apply the legacy config - data, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - - return readLegacyConfig(data) + return readLegacyConfig(path) } config := &Config{ @@ -1076,7 +1071,7 @@ func Hostname() string { func MakePasswordListFromFile(path string) ([]string, error) { text, err := ioutil.ReadFile(path) if err != nil { - return nil, fmt.Errorf("Failed to read password file: %v", err) + return nil, fmt.Errorf("failed to read password file: %v", err) } lines := strings.Split(string(text), "\n") diff --git a/internal/cli/server/config_legacy.go b/internal/cli/server/config_legacy.go index 0d96b2e023..50508a58b6 100644 --- a/internal/cli/server/config_legacy.go +++ b/internal/cli/server/config_legacy.go @@ -1,33 +1,33 @@ package server import ( - "bytes" + "fmt" + "io/ioutil" - "github.com/naoina/toml" + "github.com/BurntSushi/toml" ) -type legacyConfig struct { - Node struct { - P2P struct { - StaticNodes []string - TrustedNodes []string - } +func readLegacyConfig(path string) (*Config, error) { + data, err := ioutil.ReadFile(path) + tomlData := string(data) + + if err != nil { + return nil, fmt.Errorf("failed to read toml config file: %v", err) } -} -func (l *legacyConfig) Config() *Config { - c := DefaultConfig() - c.P2P.Discovery.StaticNodes = l.Node.P2P.StaticNodes - c.P2P.Discovery.TrustedNodes = l.Node.P2P.TrustedNodes - return c -} + var conf Config -func readLegacyConfig(data []byte) (*Config, error) { - var legacy legacyConfig + if _, err := toml.Decode(tomlData, &conf); err != nil { + return nil, fmt.Errorf("failed to decode toml config file: %v", err) + } - r := toml.NewDecoder(bytes.NewReader(data)) - if err := r.Decode(&legacy); err != nil { + if err := conf.fillBigInt(); err != nil { return nil, err } - return legacy.Config(), nil + + if err := conf.fillTimeDurations(); err != nil { + return nil, err + } + + return &conf, nil } diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index 399481fc9b..6fb662d62b 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -1,21 +1,50 @@ package server import ( + "math/big" "testing" + "time" "github.com/stretchr/testify/assert" ) func TestConfigLegacy(t *testing.T) { - toml := `[Node.P2P] -StaticNodes = ["node1"] -TrustedNodes = ["node2"]` - config, err := readLegacyConfig([]byte(toml)) - if err != nil { - t.Fatal(err) + readFile := func(path string) { + config, err := readLegacyConfig(path) + assert.NoError(t, err) + + assert.Equal(t, config, &Config{ + DataDir: "./data", + RequiredBlocks: map[string]string{ + "a": "b", + }, + P2P: &P2PConfig{ + MaxPeers: 30, + }, + TxPool: &TxPoolConfig{ + Locals: []string{}, + Rejournal: 1 * time.Hour, + LifeTime: 1 * time.Second, + }, + Gpo: &GpoConfig{ + MaxPrice: big.NewInt(100), + IgnorePrice: big.NewInt(2), + }, + Sealer: &SealerConfig{ + Enabled: false, + GasCeil: 20000000, + GasPrice: big.NewInt(30000000000), + }, + Cache: &CacheConfig{ + Cache: 1024, + Rejournal: 1 * time.Hour, + }, + }) } - assert.Equal(t, config.P2P.Discovery.StaticNodes, []string{"node1"}) - assert.Equal(t, config.P2P.Discovery.TrustedNodes, []string{"node2"}) + // read file in hcl format + t.Run("toml", func(t *testing.T) { + readFile("./testdata/test.toml") + }) } diff --git a/internal/cli/server/config_test.go b/internal/cli/server/config_test.go index c1c6c4ef4a..bf7787ac2e 100644 --- a/internal/cli/server/config_test.go +++ b/internal/cli/server/config_test.go @@ -115,7 +115,7 @@ func TestConfigLoadFile(t *testing.T) { MaxPeers: 30, }, TxPool: &TxPoolConfig{ - LifeTime: time.Duration(1 * time.Second), + LifeTime: 1 * time.Second, }, Gpo: &GpoConfig{ MaxPrice: big.NewInt(100), @@ -127,12 +127,12 @@ func TestConfigLoadFile(t *testing.T) { // read file in hcl format t.Run("hcl", func(t *testing.T) { - readFile("./testdata/simple.hcl") + readFile("./testdata/test.hcl") }) // read file in json format t.Run("json", func(t *testing.T) { - readFile("./testdata/simple.json") + readFile("./testdata/test.json") }) } diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index e85428b9ee..bbc7f44036 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -38,7 +38,7 @@ func (c *Command) Flags() *flagset.Flagset { Usage: "Path of the directory to store keystores", Value: &c.cliConfig.KeyStoreDir, }) - f.SliceStringFlag(&flagset.SliceStringFlag{ + f.StringFlag(&flagset.StringFlag{ Name: "config", Usage: "File for the config file", Value: &c.configFile, diff --git a/internal/cli/server/proto/server.pb.go b/internal/cli/server/proto/server.pb.go index 5512d83b72..3e928ac170 100644 --- a/internal/cli/server/proto/server.pb.go +++ b/internal/cli/server/proto/server.pb.go @@ -7,11 +7,12 @@ package proto import ( + reflect "reflect" + sync "sync" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" emptypb "google.golang.org/protobuf/types/known/emptypb" - reflect "reflect" - sync "sync" ) const ( diff --git a/internal/cli/server/proto/server_grpc.pb.go b/internal/cli/server/proto/server_grpc.pb.go index 63f1fa6187..bd4ecb660d 100644 --- a/internal/cli/server/proto/server_grpc.pb.go +++ b/internal/cli/server/proto/server_grpc.pb.go @@ -8,6 +8,7 @@ package proto import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/internal/cli/server/service_test.go b/internal/cli/server/service_test.go index 7850525686..86cf68e75e 100644 --- a/internal/cli/server/service_test.go +++ b/internal/cli/server/service_test.go @@ -4,8 +4,9 @@ import ( "math/big" "testing" - "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/stretchr/testify/assert" + + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) func TestGatherBlocks(t *testing.T) { diff --git a/internal/cli/server/testdata/simple.json b/internal/cli/server/testdata/simple.json deleted file mode 100644 index 6270ee6d13..0000000000 --- a/internal/cli/server/testdata/simple.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "data-dir": "./data", - "requiredblocks": { - "a": "b" - }, - "p2p": { - "max-peers": 30 - }, - "txpool": { - "lifetime": "1s" - }, - "gpo": { - "max-price": "100" - } -} \ No newline at end of file diff --git a/internal/cli/server/testdata/simple.hcl b/internal/cli/server/testdata/test.hcl similarity index 57% rename from internal/cli/server/testdata/simple.hcl rename to internal/cli/server/testdata/test.hcl index 5afc091859..208fdc51c1 100644 --- a/internal/cli/server/testdata/simple.hcl +++ b/internal/cli/server/testdata/test.hcl @@ -1,11 +1,11 @@ -data-dir = "./data" +datadir = "./data" requiredblocks = { a = "b" } p2p { - max-peers = 30 + maxpeers = 30 } txpool { @@ -13,5 +13,5 @@ txpool { } gpo { - max-price = "100" -} + maxprice = "100" +} \ No newline at end of file diff --git a/internal/cli/server/testdata/test.json b/internal/cli/server/testdata/test.json new file mode 100644 index 0000000000..467835e755 --- /dev/null +++ b/internal/cli/server/testdata/test.json @@ -0,0 +1,15 @@ +{ + "datadir": "./data", + "requiredblocks": { + "a": "b" + }, + "p2p": { + "maxpeers": 30 + }, + "txpool": { + "lifetime": "1s" + }, + "gpo": { + "maxprice": "100" + } +} \ No newline at end of file diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml new file mode 100644 index 0000000000..81fc4c4630 --- /dev/null +++ b/internal/cli/server/testdata/test.toml @@ -0,0 +1,25 @@ +datadir = "./data" + +[requiredblocks] +a = "b" + +[p2p] +maxpeers = 30 + +[txpool] +locals = [] +rejournal = "1h0m0s" +lifetime = "1s" + +[miner] +mine = false +gaslimit = 20000000 +gasprice = "30000000000" + +[gpo] +maxprice = "100" +ignoreprice = "2" + +[cache] +cache = 1024 +rejournal = "1h0m0s" From 8378cc9ecb9159b7a35027eca22aa273b67b0fb3 Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 28 Jul 2022 12:33:23 -0700 Subject: [PATCH 03/46] Add 'bor' user during package installation --- .goreleaser.yml | 9 +++++++++ builder/files/bor-post-install.sh | 9 +++++++++ builder/files/bor.service | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 builder/files/bor-post-install.sh diff --git a/.goreleaser.yml b/.goreleaser.yml index 7fbc61ca4a..acafc4abc0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -75,12 +75,18 @@ nfpms: description: Polygon Blockchain license: GPLv3 LGPLv3 + bindir: /usr/local/bin + formats: - apk - deb - rpm contents: + - dst: /var/lib/bor + type: dir + file_info: + mode: 0777 - src: builder/files/bor.service dst: /lib/systemd/system/bor.service type: config @@ -94,6 +100,9 @@ nfpms: dst: /var/lib/bor/config.toml type: config + scripts: + postinstall: builder/files/bor-post-install.sh + overrides: rpm: replacements: diff --git a/builder/files/bor-post-install.sh b/builder/files/bor-post-install.sh new file mode 100644 index 0000000000..1419479983 --- /dev/null +++ b/builder/files/bor-post-install.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +PKG="bor" + +if ! getent passwd $PKG >/dev/null ; then + adduser --disabled-password --disabled-login --shell /usr/sbin/nologin --quiet --system --no-create-home --home /nonexistent $PKG + echo "Created system user $PKG" +fi diff --git a/builder/files/bor.service b/builder/files/bor.service index 4b628cbf6e..2deff3dbc9 100644 --- a/builder/files/bor.service +++ b/builder/files/bor.service @@ -8,7 +8,7 @@ RestartSec=5s ExecStart=/usr/local/bin/bor server -config="/var/lib/bor/config.toml" Type=simple - User=ubuntu + User=bor KillSignal=SIGINT TimeoutStopSec=120 From 694dc02a0196d947266355b6560a5c5004aac9e8 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 29 Jul 2022 17:30:25 +0530 Subject: [PATCH 04/46] fixed the bug caused by fillBigInt and FillTime.Duration functions (#474) --- internal/cli/server/config_legacy.go | 2 +- internal/cli/server/config_legacy_test.go | 130 ++++++++++++++++++++-- 2 files changed, 120 insertions(+), 12 deletions(-) diff --git a/internal/cli/server/config_legacy.go b/internal/cli/server/config_legacy.go index 50508a58b6..9411b8290d 100644 --- a/internal/cli/server/config_legacy.go +++ b/internal/cli/server/config_legacy.go @@ -15,7 +15,7 @@ func readLegacyConfig(path string) (*Config, error) { return nil, fmt.Errorf("failed to read toml config file: %v", err) } - var conf Config + conf := *DefaultConfig() if _, err := toml.Decode(tomlData, &conf); err != nil { return nil, fmt.Errorf("failed to decode toml config file: %v", err) diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index 6fb662d62b..1b52096216 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -6,6 +6,8 @@ import ( "time" "github.com/stretchr/testify/assert" + + "github.com/ethereum/go-ethereum/eth/ethconfig" ) func TestConfigLegacy(t *testing.T) { @@ -15,30 +17,136 @@ func TestConfigLegacy(t *testing.T) { assert.NoError(t, err) assert.Equal(t, config, &Config{ - DataDir: "./data", + Chain: "mainnet", + Identity: Hostname(), RequiredBlocks: map[string]string{ "a": "b", }, + LogLevel: "INFO", + DataDir: "./data", P2P: &P2PConfig{ - MaxPeers: 30, + MaxPeers: 30, + MaxPendPeers: 50, + Bind: "0.0.0.0", + Port: 30303, + NoDiscover: false, + NAT: "any", + Discovery: &P2PDiscovery{ + V5Enabled: false, + Bootnodes: []string{}, + BootnodesV4: []string{}, + BootnodesV5: []string{}, + StaticNodes: []string{}, + TrustedNodes: []string{}, + DNS: []string{}, + }, }, + Heimdall: &HeimdallConfig{ + URL: "http://localhost:1317", + Without: false, + }, + SyncMode: "full", + GcMode: "full", + Snapshot: true, TxPool: &TxPoolConfig{ - Locals: []string{}, - Rejournal: 1 * time.Hour, - LifeTime: 1 * time.Second, + Locals: []string{}, + NoLocals: false, + Journal: "", + Rejournal: 1 * time.Hour, + PriceLimit: 30000000000, + PriceBump: 10, + AccountSlots: 16, + GlobalSlots: 32768, + AccountQueue: 16, + GlobalQueue: 32768, + LifeTime: 1 * time.Second, + }, + Sealer: &SealerConfig{ + Enabled: false, + Etherbase: "", + GasCeil: 20000000, + GasPrice: big.NewInt(30000000000), + ExtraData: "", }, Gpo: &GpoConfig{ + Blocks: 20, + Percentile: 60, MaxPrice: big.NewInt(100), IgnorePrice: big.NewInt(2), }, - Sealer: &SealerConfig{ - Enabled: false, - GasCeil: 20000000, - GasPrice: big.NewInt(30000000000), + JsonRPC: &JsonRPCConfig{ + IPCDisable: false, + IPCPath: "", + GasCap: ethconfig.Defaults.RPCGasCap, + TxFeeCap: ethconfig.Defaults.RPCTxFeeCap, + Http: &APIConfig{ + Enabled: false, + Port: 8545, + Prefix: "", + Host: "localhost", + API: []string{"eth", "net", "web3", "txpool", "bor"}, + Cors: []string{"*"}, + VHost: []string{"*"}, + }, + Ws: &APIConfig{ + Enabled: false, + Port: 8546, + Prefix: "", + Host: "localhost", + API: []string{"web3", "net"}, + Cors: []string{"*"}, + VHost: []string{"*"}, + }, + Graphql: &APIConfig{ + Enabled: false, + Cors: []string{"*"}, + VHost: []string{"*"}, + }, + }, + Ethstats: "", + Telemetry: &TelemetryConfig{ + Enabled: false, + Expensive: false, + PrometheusAddr: "", + OpenCollectorEndpoint: "", + InfluxDB: &InfluxDBConfig{ + V1Enabled: false, + Endpoint: "", + Database: "", + Username: "", + Password: "", + Tags: map[string]string{}, + V2Enabled: false, + Token: "", + Bucket: "", + Organization: "", + }, }, Cache: &CacheConfig{ - Cache: 1024, - Rejournal: 1 * time.Hour, + Cache: 1024, + PercDatabase: 50, + PercTrie: 15, + PercGc: 25, + PercSnapshot: 10, + Journal: "triecache", + Rejournal: 1 * time.Hour, + NoPrefetch: false, + Preimages: false, + TxLookupLimit: 2350000, + }, + Accounts: &AccountsConfig{ + Unlock: []string{}, + PasswordFile: "", + AllowInsecureUnlock: false, + UseLightweightKDF: false, + DisableBorWallet: false, + }, + GRPC: &GRPCConfig{ + Addr: ":3131", + }, + Developer: &DeveloperConfig{ + Enabled: false, + Period: 0, }, }) } From 18fafc01c673c4996748072d804981f13953fb88 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 4 Aug 2022 12:42:50 +0530 Subject: [PATCH 05/46] disable bor wallet by default --- internal/cli/server/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 819ab1aca5..34ad0e60f7 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -507,7 +507,7 @@ func DefaultConfig() *Config { PasswordFile: "", AllowInsecureUnlock: false, UseLightweightKDF: false, - DisableBorWallet: false, + DisableBorWallet: true, }, GRPC: &GRPCConfig{ Addr: ":3131", From ba184918413bac197a53914693fdd0728cfd182a Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 4 Aug 2022 16:33:30 +0530 Subject: [PATCH 06/46] fix: tests --- internal/cli/server/config_legacy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index 1b52096216..a8127915a1 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -139,7 +139,7 @@ func TestConfigLegacy(t *testing.T) { PasswordFile: "", AllowInsecureUnlock: false, UseLightweightKDF: false, - DisableBorWallet: false, + DisableBorWallet: true, }, GRPC: &GRPCConfig{ Addr: ":3131", From 49cd8c8e7c10e3d0d0050c0e0fd3499c059eee81 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 17 Aug 2022 13:28:55 +0530 Subject: [PATCH 07/46] update version --- params/version.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/params/version.go b/params/version.go index 4b608b1a5f..ec3923a884 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 0 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 16 // Patch version component of the current release - VersionMeta = "stable" // Version metadata to append to the version string + VersionMajor = 0 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 17 // Patch version component of the current release + VersionMeta = "beta" // Version metadata to append to the version string ) // Version holds the textual version string. From 43b67c361f02d97f3377d01b7b42bd013cac6ca7 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 17 Aug 2022 13:55:27 +0530 Subject: [PATCH 08/46] handle snap sync mode switches (#495) --- cmd/utils/flags.go | 7 +++++++ eth/handler.go | 11 +++++++++-- eth/sync.go | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index e2bbdb17f8..79c73903fb 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1620,6 +1620,13 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.GlobalIsSet(SyncModeFlag.Name) { cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) + + // To be extra preventive, we won't allow the node to start + // in snap sync mode until we have it working + // TODO(snap): Comment when we have snap sync working + if cfg.SyncMode == downloader.SnapSync { + cfg.SyncMode = downloader.FullSync + } } if ctx.GlobalIsSet(NetworkIdFlag.Name) { cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name) diff --git a/eth/handler.go b/eth/handler.go index 40edfa2d17..8d56537df9 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -155,8 +155,15 @@ func newHandler(config *handlerConfig) (*handler, error) { // In these cases however it's safe to reenable snap sync. fullBlock, fastBlock := h.chain.CurrentBlock(), h.chain.CurrentFastBlock() if fullBlock.NumberU64() == 0 && fastBlock.NumberU64() > 0 { - h.snapSync = uint32(1) - log.Warn("Switch sync mode from full sync to snap sync") + // Note: Ideally this should never happen with bor, but to be extra + // preventive we won't allow it to roll over to snap sync until + // we have it working + + // TODO(snap): Uncomment when we have snap sync working + // h.snapSync = uint32(1) + // log.Warn("Switch sync mode from full sync to snap sync") + + log.Warn("Preventing switching sync mode from full sync to snap sync") } } else { if h.chain.CurrentBlock().NumberU64() > 0 { diff --git a/eth/sync.go b/eth/sync.go index d67d2311d0..aa79b6181c 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -204,25 +204,36 @@ func peerToSyncOp(mode downloader.SyncMode, p *eth.Peer) *chainSyncOp { } func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) { - // If we're in snap sync mode, return that directly - if atomic.LoadUint32(&cs.handler.snapSync) == 1 { - block := cs.handler.chain.CurrentFastBlock() - td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) - return downloader.SnapSync, td - } - // We are probably in full sync, but we might have rewound to before the - // snap sync pivot, check if we should reenable - if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { - if head := cs.handler.chain.CurrentBlock(); head.NumberU64() < *pivot { - block := cs.handler.chain.CurrentFastBlock() - td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) - return downloader.SnapSync, td - } - } - // Nope, we're really full syncing + // Note: Ideally this should never happen with bor, but to be extra + // preventive we won't allow it to roll over to snap sync until + // we have it working + + // Handle full sync mode only head := cs.handler.chain.CurrentBlock() td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64()) return downloader.FullSync, td + + // TODO(snap): Uncomment when we have snap sync working + + // If we're in snap sync mode, return that directly + // if atomic.LoadUint32(&cs.handler.snapSync) == 1 { + // block := cs.handler.chain.CurrentFastBlock() + // td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) + // return downloader.SnapSync, td + // } + // // We are probably in full sync, but we might have rewound to before the + // // snap sync pivot, check if we should reenable + // if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { + // if head := cs.handler.chain.CurrentBlock(); head.NumberU64() < *pivot { + // block := cs.handler.chain.CurrentFastBlock() + // td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) + // return downloader.SnapSync, td + // } + // } + // // Nope, we're really full syncing + // head := cs.handler.chain.CurrentBlock() + // td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64()) + // return downloader.FullSync, td } // startSync launches doSync in a new goroutine. From 77f444a24b78f1c77cb4d7b95c5011705478441f Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 17 Aug 2022 21:11:40 +0530 Subject: [PATCH 09/46] fix: whitelist/requiredblocks regression (#497) --- eth/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index 8d56537df9..bd31e0f117 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -432,7 +432,7 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error { }() } // If we have any explicit peer required block hashes, request them - for number := range h.peerRequiredBlocks { + for number, hash := range h.peerRequiredBlocks { resCh := make(chan *eth.Response) if _, err := peer.RequestHeadersByNumber(number, 1, 0, false, resCh); err != nil { return err From 10c1ff2a7434246aba9e6ec3197bd3996dd2c5a8 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Tue, 9 Aug 2022 09:16:42 +0530 Subject: [PATCH 10/46] internal/cli: add support for removedb (#478) * internal/cli: add support for removedb * update docs * internal/cli: use constant path, handle err --- docs/cli/README.md | 2 + docs/cli/removedb.md | 7 ++ internal/cli/command.go | 5 ++ internal/cli/removedb.go | 154 ++++++++++++++++++++++++++++++++++ internal/cli/server/config.go | 4 +- 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 docs/cli/removedb.md create mode 100644 internal/cli/removedb.go diff --git a/docs/cli/README.md b/docs/cli/README.md index 3bc3daddc5..bf37d6ef56 100644 --- a/docs/cli/README.md +++ b/docs/cli/README.md @@ -40,6 +40,8 @@ - [```peers status```](./peers_status.md) +- [```removedb```](./removedb.md) + - [```server```](./server.md) - [```status```](./status.md) diff --git a/docs/cli/removedb.md b/docs/cli/removedb.md new file mode 100644 index 0000000000..3c6e84f1d6 --- /dev/null +++ b/docs/cli/removedb.md @@ -0,0 +1,7 @@ +# RemoveDB + +The ```bor removedb``` command will remove the blockchain and state databases at the given datadir location + +## Options + +- ```datadir```: Path of the data directory to store information diff --git a/internal/cli/command.go b/internal/cli/command.go index 06127a9823..93dca4cb3e 100644 --- a/internal/cli/command.go +++ b/internal/cli/command.go @@ -184,6 +184,11 @@ func Commands() map[string]MarkDownCommandFactory { UI: ui, }, nil }, + "removedb": func() (MarkDownCommand, error) { + return &RemoveDBCommand{ + Meta2: meta2, + }, nil + }, } } diff --git a/internal/cli/removedb.go b/internal/cli/removedb.go new file mode 100644 index 0000000000..4a604086ed --- /dev/null +++ b/internal/cli/removedb.go @@ -0,0 +1,154 @@ +package cli + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/node" + + "github.com/mitchellh/cli" +) + +// RemoveDBCommand is for removing blockchain and state databases +type RemoveDBCommand struct { + *Meta2 + + datadir string +} + +const ( + chaindataPath string = "chaindata" + ancientPath string = "ancient" + lightchaindataPath string = "lightchaindata" +) + +// MarkDown implements cli.MarkDown interface +func (c *RemoveDBCommand) MarkDown() string { + items := []string{ + "# RemoveDB", + "The ```bor removedb``` command will remove the blockchain and state databases at the given datadir location", + c.Flags().MarkDown(), + } + + return strings.Join(items, "\n\n") +} + +// Help implements the cli.Command interface +func (c *RemoveDBCommand) Help() string { + return `Usage: bor removedb + + This command will remove the blockchain and state databases at the given datadir location` +} + +// Synopsis implements the cli.Command interface +func (c *RemoveDBCommand) Synopsis() string { + return "Remove blockchain and state databases" +} + +func (c *RemoveDBCommand) Flags() *flagset.Flagset { + flags := c.NewFlagSet("removedb") + + flags.StringFlag(&flagset.StringFlag{ + Name: "datadir", + Value: &c.datadir, + Usage: "Path of the data directory to store information", + }) + + return flags +} + +// Run implements the cli.Command interface +func (c *RemoveDBCommand) Run(args []string) int { + flags := c.Flags() + + // parse datadir + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + datadir := c.datadir + if datadir == "" { + datadir = server.DefaultDataDir() + } + + // create ethereum node config with just the datadir + nodeCfg := &node.Config{DataDir: datadir} + + // Remove the full node state database + path := nodeCfg.ResolvePath(chaindataPath) + if common.FileExist(path) { + confirmAndRemoveDB(c.UI, path, "full node state database") + } else { + log.Info("Full node state database missing", "path", path) + } + + // Remove the full node ancient database + // Note: The old cli used DatabaseFreezer path from config if provided explicitly + // We don't have access to eth config and hence we assume it to be + // under the "chaindata" folder. + path = filepath.Join(nodeCfg.ResolvePath(chaindataPath), ancientPath) + if common.FileExist(path) { + confirmAndRemoveDB(c.UI, path, "full node ancient database") + } else { + log.Info("Full node ancient database missing", "path", path) + } + + // Remove the light node database + path = nodeCfg.ResolvePath(lightchaindataPath) + if common.FileExist(path) { + confirmAndRemoveDB(c.UI, path, "light node database") + } else { + log.Info("Light node database missing", "path", path) + } + + return 0 +} + +// confirmAndRemoveDB prompts the user for a last confirmation and removes the +// folder if accepted. +func confirmAndRemoveDB(ui cli.Ui, database string, kind string) { + for { + confirm, err := ui.Ask(fmt.Sprintf("Remove %s (%s)? [y/n]", kind, database)) + + switch { + case err != nil: + ui.Output(err.Error()) + return + case confirm != "": + switch strings.ToLower(confirm) { + case "y": + start := time.Now() + err = filepath.Walk(database, func(path string, info os.FileInfo, err error) error { + // If we're at the top level folder, recurse into + if path == database { + return nil + } + // Delete all the files, but not subfolders + if !info.IsDir() { + return os.Remove(path) + } + return filepath.SkipDir + }) + + if err != nil && err != filepath.SkipDir { + ui.Output(err.Error()) + } else { + log.Info("Database successfully deleted", "path", database, "elapsed", common.PrettyDuration(time.Since(start))) + } + + return + case "n": + log.Info("Database deletion skipped", "path", database) + return + } + } + } +} diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 34ad0e60f7..faa8452742 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -391,7 +391,7 @@ func DefaultConfig() *Config { Identity: Hostname(), RequiredBlocks: map[string]string{}, LogLevel: "INFO", - DataDir: defaultDataDir(), + DataDir: DefaultDataDir(), P2P: &P2PConfig{ MaxPeers: 30, MaxPendPeers: 50, @@ -1035,7 +1035,7 @@ func parseBootnodes(urls []string) ([]*enode.Node, error) { return dst, nil } -func defaultDataDir() string { +func DefaultDataDir() string { // Try to place the data folder in the user's home dir home, _ := homedir.Dir() if home == "" { From 0b28230c22b907cad39872de97602b8f2ea39f85 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 17 Aug 2022 12:01:53 +0530 Subject: [PATCH 11/46] updated config.toml in builder/files, added all fields and commented those which are not used (#491) --- builder/files/config.toml | 161 ++++++++++++++++++++++++++++++-------- 1 file changed, 127 insertions(+), 34 deletions(-) diff --git a/builder/files/config.toml b/builder/files/config.toml index c55a143ed7..d8503e4351 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -1,44 +1,137 @@ -# chain = "mumbai" +# NOTE: Uncomment and configure the following 8 fields in case you run a validator: +# `mine`, `etherbase`, `nodiscover`, `maxpeers`, `keystore`, `allow-insecure-unlock`, `password`, `unlock` + chain = "mainnet" +# chain = "mumbai" +# identity = "Pratiks-MacBook-Pro.local" +# log-level = "INFO" datadir = "/var/lib/bor/data" +# keystore = "/var/lib/bor/keystore" syncmode = "full" +# gcmode = "full" +# snapshot = true +# ethstats = "" -[telemetry] -metrics = true -prometheus-addr = "127.0.0.1:7071" - -[miner] -# *** Validator params -# *** Uncomment and configure the following lines in case you run a validator. -# mine = true -# etherbase = "VALIDATOR ADDRESS" -gasprice = "30000000000" -gasceil = 20000000 - - -[txpool] -accountqueue = 16 -accountslots = 16 -globalqueue = 32768 -globalslots = 32768 -lifetime = "1h30m0s" -nolocals = true -pricelimit = 30000000000 +# [requiredblocks] [p2p] -# *** Validator params -# *** Uncomment and configure the following lines in case you run a validator. -# nodiscover = true -# maxpeers = 1 + # maxpeers = 1 + # nodiscover = true + # maxpendpeers = 50 + # bind = "0.0.0.0" + # port = 30303 + # nat = "any" [p2p.discovery] - bootnodes = ["enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303", "enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303"] + # v5disc = false + bootnodes = ["enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303", "enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303"] + # Uncomment below `bootnodes` field for Mumbai bootnode + # bootnodes = ["enode://095c4465fe509bd7107bbf421aea0d3ad4d4bfc3ff8f9fdc86f4f950892ae3bbc3e5c715343c4cf60c1c06e088e621d6f1b43ab9130ae56c2cacfd356a284ee4@18.213.200.99:30303"] + # bootnodesv4 = [] + # bootnodesv5 = [] + # static-nodes = [] + # trusted-nodes = [] + # dns = [] -# *** Validator params -# *** Uncomment and configure the following lines in case you run a validator. +# [heimdall] + # url = "http://localhost:1317" + # "bor.without" = false + # grpc-address = "" -# keystore = "/var/lib/bor/keystore" +[txpool] + nolocals = true + pricelimit = 30000000000 + accountslots = 16 + globalslots = 32768 + accountqueue = 16 + globalqueue = 32768 + lifetime = "1h30m0s" + # locals = [] + # journal = "" + # rejournal = "1h0m0s" + # pricebump = 10 -# [accounts] -# allow-insecure-unlock = true -# password = "/var/lib/bor/password.txt" -# unlock = ["VALIDATOR ADDRESS"] \ No newline at end of file +[miner] + gaslimit = 20000000 + gasprice = "30000000000" + # mine = true + # etherbase = "VALIDATOR ADDRESS" + # extradata = "" + + +# [jsonrpc] + # ipcdisable = false + # ipcpath = "" + # gascap = 50000000 + # txfeecap = 5.0 + # [jsonrpc.http] + # enabled = false + # port = 8545 + # prefix = "" + # host = "localhost" + # api = ["eth", "net", "web3", "txpool", "bor"] + # vhosts = ["*"] + # corsdomain = ["*"] + # [jsonrpc.ws] + # enabled = false + # port = 8546 + # prefix = "" + # host = "localhost" + # api = ["web3", "net"] + # vhosts = ["*"] + # corsdomain = ["*"] + # [jsonrpc.graphql] + # enabled = false + # port = 0 + # prefix = "" + # host = "" + # vhosts = ["*"] + # corsdomain = ["*"] + +# [gpo] + # blocks = 20 + # percentile = 60 + # maxprice = "5000000000000" + # ignoreprice = "2" + +[telemetry] + metrics = true + # expensive = false + prometheus-addr = "127.0.0.1:7071" + # opencollector-endpoint = "" + # [telemetry.influx] + # influxdb = false + # endpoint = "" + # database = "" + # username = "" + # password = "" + # influxdbv2 = false + # token = "" + # bucket = "" + # organization = "" + # [telemetry.influx.tags] + +# [cache] + # cache = 1024 + # gc = 25 + # snapshot = 10 + # database = 50 + # trie = 15 + # journal = "triecache" + # rejournal = "1h0m0s" + # noprefetch = false + # preimages = false + # txlookuplimit = 2350000 + +[accounts] + # allow-insecure-unlock = true + # password = "/var/lib/bor/password.txt" + # unlock = ["VALIDATOR ADDRESS"] + # lightkdf = false + # disable-bor-wallet = false + +# [grpc] + # addr = ":3131" + +# [developer] + # dev = false + # period = 0 \ No newline at end of file From 2aacbde0976c6d12fbd349c394c6337537f7d026 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 17 Aug 2022 15:18:16 +0530 Subject: [PATCH 12/46] eth, cli: prevent snap sync mode migration - v0.3.x (#494) * handle snap sync mode switches * fix linters --- cmd/utils/flags.go | 7 ++++++ eth/handler.go | 11 +++++++-- eth/sync.go | 43 ++++++++++++++++++++++------------- internal/cli/server/config.go | 5 +++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index e2bbdb17f8..79c73903fb 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1620,6 +1620,13 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.GlobalIsSet(SyncModeFlag.Name) { cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) + + // To be extra preventive, we won't allow the node to start + // in snap sync mode until we have it working + // TODO(snap): Comment when we have snap sync working + if cfg.SyncMode == downloader.SnapSync { + cfg.SyncMode = downloader.FullSync + } } if ctx.GlobalIsSet(NetworkIdFlag.Name) { cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name) diff --git a/eth/handler.go b/eth/handler.go index ab95f5f769..3d8380412c 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -161,8 +161,15 @@ func newHandler(config *handlerConfig) (*handler, error) { // In these cases however it's safe to reenable snap sync. fullBlock, fastBlock := h.chain.CurrentBlock(), h.chain.CurrentFastBlock() if fullBlock.NumberU64() == 0 && fastBlock.NumberU64() > 0 { - h.snapSync = uint32(1) - log.Warn("Switch sync mode from full sync to snap sync") + // Note: Ideally this should never happen with bor, but to be extra + // preventive we won't allow it to roll over to snap sync until + // we have it working + + // TODO(snap): Uncomment when we have snap sync working + // h.snapSync = uint32(1) + // log.Warn("Switch sync mode from full sync to snap sync") + + log.Warn("Preventing switching sync mode from full sync to snap sync") } } else { if h.chain.CurrentBlock().NumberU64() > 0 { diff --git a/eth/sync.go b/eth/sync.go index d67d2311d0..22c0c9054a 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -204,25 +204,36 @@ func peerToSyncOp(mode downloader.SyncMode, p *eth.Peer) *chainSyncOp { } func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) { - // If we're in snap sync mode, return that directly - if atomic.LoadUint32(&cs.handler.snapSync) == 1 { - block := cs.handler.chain.CurrentFastBlock() - td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) - return downloader.SnapSync, td - } - // We are probably in full sync, but we might have rewound to before the - // snap sync pivot, check if we should reenable - if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { - if head := cs.handler.chain.CurrentBlock(); head.NumberU64() < *pivot { - block := cs.handler.chain.CurrentFastBlock() - td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) - return downloader.SnapSync, td - } - } - // Nope, we're really full syncing + // Note: Ideally this should never happen with bor, but to be extra + // preventive we won't allow it to roll over to snap sync until + // we have it working + + // Handle full sync mode only head := cs.handler.chain.CurrentBlock() td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64()) return downloader.FullSync, td + + // TODO(snap): Uncomment when we have snap sync working + + // If we're in snap sync mode, return that directly + // if atomic.LoadUint32(&cs.handler.snapSync) == 1 { + // block := cs.handler.chain.CurrentFastBlock() + // td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) + // return downloader.SnapSync, td + // } + // // We are probably in full sync, but we might have rewound to before the + // // snap sync pivot, check if we should reenable + // if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { + // if head := cs.handler.chain.CurrentBlock(); head.NumberU64() < *pivot { + // block := cs.handler.chain.CurrentFastBlock() + // td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) + // return downloader.SnapSync, td + // } + // } + // Nope, we're really full syncing + // head := cs.handler.chain.CurrentBlock() + // td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64()) + // return downloader.FullSync, td } // startSync launches doSync in a new goroutine. diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index faa8452742..e10b7e9c36 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -843,7 +843,10 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (* case "full": n.SyncMode = downloader.FullSync case "snap": - n.SyncMode = downloader.SnapSync + // n.SyncMode = downloader.SnapSync // TODO(snap): Uncomment when we have snap sync working + n.SyncMode = downloader.FullSync + + log.Warn("Bor doesn't support Snap Sync yet, switching to Full Sync mode") default: return nil, fmt.Errorf("sync mode '%s' not found", c.SyncMode) } From 8c97faaa8c9a046266aa7a0636df3ee55956dbc0 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 5 Aug 2022 14:56:41 +0530 Subject: [PATCH 13/46] 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 --- cmd/geth/config.go | 57 ++++------------------- go.mod | 2 - go.sum | 4 -- internal/cli/dumpconfig.go | 20 ++------ internal/cli/server/config.go | 12 ++--- internal/cli/server/config_legacy_test.go | 7 +-- internal/cli/server/testdata/test.toml | 6 +-- 7 files changed, 25 insertions(+), 83 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index d8ba5366fe..08b76f83da 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -17,17 +17,16 @@ package main import ( - "bufio" - "errors" "fmt" + "io/ioutil" "math/big" "os" - "reflect" "time" - "unicode" "gopkg.in/urfave/cli.v1" + "github.com/BurntSushi/toml" + "github.com/ethereum/go-ethereum/accounts/external" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/scwallet" @@ -41,7 +40,6 @@ import ( "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/params" - "github.com/naoina/toml" ) 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 { URL string `toml:",omitempty"` } @@ -95,18 +71,17 @@ type gethConfig struct { } func loadConfig(file string, cfg *gethConfig) error { - f, err := os.Open(file) + data, err := ioutil.ReadFile(file) if err != nil { return err } - defer f.Close() - err = tomlSettings.NewDecoder(bufio.NewReader(f)).Decode(cfg) - // Add file name to errors that have a line number. - if _, ok := err.(*toml.LineError); ok { - err = errors.New(file + ", " + err.Error()) + tomlData := string(data) + if _, err = toml.Decode(tomlData, &cfg); err != nil { + return err } - return err + + return nil } 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" } - out, err := tomlSettings.Marshal(&cfg) - if err != nil { + if err := toml.NewEncoder(os.Stdout).Encode(&cfg); err != nil { 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 } diff --git a/go.mod b/go.mod index 3f90695d47..39bbeb240d 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,6 @@ require ( github.com/mitchellh/cli v1.1.2 github.com/mitchellh/go-grpc-net-conn v0.0.0-20200427190222-eb030e4876f0 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/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 github.com/prometheus/tsdb v0.7.1 @@ -119,7 +118,6 @@ require ( github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/mitchellh/pointerstructure v1.2.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/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/go.sum b/go.sum index fc58b621e6..88c9152eef 100644 --- a/go.sum +++ b/go.sum @@ -374,10 +374,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/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/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/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= diff --git a/internal/cli/dumpconfig.go b/internal/cli/dumpconfig.go index 3e4688fc24..dad0be923d 100644 --- a/internal/cli/dumpconfig.go +++ b/internal/cli/dumpconfig.go @@ -1,24 +1,14 @@ package cli import ( - "reflect" + "os" "strings" - "github.com/naoina/toml" + "github.com/BurntSushi/toml" "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 type DumpconfigCommand struct { *Meta2 @@ -69,14 +59,10 @@ func (c *DumpconfigCommand) Run(args []string) int { userConfig.Gpo.IgnorePriceRaw = userConfig.Gpo.IgnorePrice.String() userConfig.Cache.RejournalRaw = userConfig.Cache.Rejournal.String() - // Currently, the configurations (userConfig) is exported into `toml` file format. - out, err := tomlSettings.Marshal(&userConfig) - if err != nil { + if err := toml.NewEncoder(os.Stdout).Encode(userConfig); err != nil { c.UI.Error(err.Error()) return 1 } - c.UI.Output(string(out)) - return 0 } diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index e10b7e9c36..255cf633eb 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -167,7 +167,7 @@ type TxPoolConfig struct { Journal string `hcl:"journal,optional" toml:"journal,optional"` // 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"` // PriceLimit is the minimum gas price to enforce for acceptance into the pool @@ -189,7 +189,7 @@ type TxPoolConfig struct { GlobalQueue uint64 `hcl:"globalqueue,optional" toml:"globalqueue,optional"` // 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"` } @@ -207,7 +207,7 @@ type SealerConfig struct { GasCeil uint64 `hcl:"gaslimit,optional" toml:"gaslimit,optional"` // 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"` } @@ -270,11 +270,11 @@ type GpoConfig struct { Percentile uint64 `hcl:"percentile,optional" toml:"percentile,optional"` // 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"` // 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"` } @@ -347,7 +347,7 @@ type CacheConfig struct { Journal string `hcl:"journal,optional" toml:"journal,optional"` // 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"` // NoPrefetch is used to disable prefetch of tries diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index a8127915a1..b28d7ae536 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/ethereum/go-ethereum/params" ) func TestConfigLegacy(t *testing.T) { @@ -71,8 +72,8 @@ func TestConfigLegacy(t *testing.T) { Gpo: &GpoConfig{ Blocks: 20, Percentile: 60, - MaxPrice: big.NewInt(100), - IgnorePrice: big.NewInt(2), + MaxPrice: big.NewInt(5000 * params.GWei), + IgnorePrice: big.NewInt(4), }, JsonRPC: &JsonRPCConfig{ IPCDisable: false, @@ -129,7 +130,7 @@ func TestConfigLegacy(t *testing.T) { PercGc: 25, PercSnapshot: 10, Journal: "triecache", - Rejournal: 1 * time.Hour, + Rejournal: 1 * time.Second, NoPrefetch: false, Preimages: false, TxLookupLimit: 2350000, diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml index 81fc4c4630..ecc313b5b5 100644 --- a/internal/cli/server/testdata/test.toml +++ b/internal/cli/server/testdata/test.toml @@ -8,7 +8,6 @@ maxpeers = 30 [txpool] locals = [] -rejournal = "1h0m0s" lifetime = "1s" [miner] @@ -17,9 +16,8 @@ gaslimit = 20000000 gasprice = "30000000000" [gpo] -maxprice = "100" -ignoreprice = "2" +ignoreprice = "4" [cache] cache = 1024 -rejournal = "1h0m0s" +rejournal = "1s" From 54719fb180ad54e6fffa15afb8b3a3d7411c84e1 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 27 Jul 2022 22:27:26 +0530 Subject: [PATCH 14/46] Makefile: copy bor binary to go bin (#469) --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 46ecdec886..a8e14cf06a 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,8 @@ GOTEST = GODEBUG=cgocheck=0 go test $(GO_FLAGS) -p 1 bor: mkdir -p $(GOPATH)/bin/ go build -o $(GOBIN)/bor ./cmd/cli/main.go + cp $(GOBIN)/bor $(GOPATH)/bin/ + @echo "Done building." protoc: protoc --go_out=. --go-grpc_out=. ./internal/cli/server/proto/*.proto From 75f4411102bf5e10f5ef70184776646f16267b67 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Fri, 26 Aug 2022 17:59:05 +0530 Subject: [PATCH 15/46] fix: rename requiredblocks flag usage (#505) --- cmd/geth/main.go | 2 +- cmd/geth/usage.go | 2 +- cmd/utils/flags.go | 28 ++++++++++++++-------------- eth/backend.go | 20 ++++++++++---------- eth/ethconfig/config.go | 4 ++-- eth/ethconfig/gen_config.go | 10 +++++----- eth/handler.go | 26 +++++++++++++------------- internal/cli/server/config.go | 4 ++-- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 600e929706..af565d71ae 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -109,7 +109,7 @@ var ( utils.UltraLightFractionFlag, utils.UltraLightOnlyAnnounceFlag, utils.LightNoSyncServeFlag, - utils.EthPeerRequiredBlocksFlag, + utils.EthRequiredBlocksFlag, utils.LegacyWhitelistFlag, utils.BloomFilterSizeFlag, utils.CacheFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index af5175cd63..28f8f84533 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -56,7 +56,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.EthStatsURLFlag, utils.IdentityFlag, utils.LightKDFFlag, - utils.EthPeerRequiredBlocksFlag, + utils.EthRequiredBlocksFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 79c73903fb..85f28cc942 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -249,13 +249,13 @@ var ( Name: "lightkdf", Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", } - EthPeerRequiredBlocksFlag = cli.StringFlag{ + EthRequiredBlocksFlag = cli.StringFlag{ Name: "eth.requiredblocks", Usage: "Comma separated block number-to-hash mappings to require for peering (=)", } LegacyWhitelistFlag = cli.StringFlag{ Name: "whitelist", - Usage: "Comma separated block number-to-hash mappings to enforce (=) (deprecated in favor of --peer.requiredblocks)", + Usage: "Comma separated block number-to-hash mappings to enforce (=) (deprecated in favor of --eth.requiredblocks)", } BloomFilterSizeFlag = cli.Uint64Flag{ Name: "bloomfilter.size", @@ -1498,33 +1498,33 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) { } } -func setPeerRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { - peerRequiredBlocks := ctx.GlobalString(EthPeerRequiredBlocksFlag.Name) +func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { + requiredBlocks := ctx.GlobalString(EthRequiredBlocksFlag.Name) - if peerRequiredBlocks == "" { + if requiredBlocks == "" { if ctx.GlobalIsSet(LegacyWhitelistFlag.Name) { - log.Warn("The flag --rpc is deprecated and will be removed, please use --peer.requiredblocks") - peerRequiredBlocks = ctx.GlobalString(LegacyWhitelistFlag.Name) + log.Warn("The flag --whitelist is deprecated and will be removed, please use --eth.requiredblocks") + requiredBlocks = ctx.GlobalString(LegacyWhitelistFlag.Name) } else { return } } - cfg.PeerRequiredBlocks = make(map[uint64]common.Hash) - for _, entry := range strings.Split(peerRequiredBlocks, ",") { + cfg.RequiredBlocks = make(map[uint64]common.Hash) + for _, entry := range strings.Split(requiredBlocks, ",") { parts := strings.Split(entry, "=") if len(parts) != 2 { - Fatalf("Invalid peer required block entry: %s", entry) + Fatalf("Invalid required block entry: %s", entry) } number, err := strconv.ParseUint(parts[0], 0, 64) if err != nil { - Fatalf("Invalid peer required block number %s: %v", parts[0], err) + Fatalf("Invalid required block number %s: %v", parts[0], err) } var hash common.Hash if err = hash.UnmarshalText([]byte(parts[1])); err != nil { - Fatalf("Invalid peer required block hash %s: %v", parts[1], err) + Fatalf("Invalid required block hash %s: %v", parts[1], err) } - cfg.PeerRequiredBlocks[number] = hash + cfg.RequiredBlocks[number] = hash } } @@ -1591,7 +1591,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { setTxPool(ctx, &cfg.TxPool) setEthash(ctx, cfg) setMiner(ctx, &cfg.Miner) - setPeerRequiredBlocks(ctx, cfg) + setRequiredBlocks(ctx, cfg) setLes(ctx, cfg) if ctx.GlobalIsSet(BorLogsFlag.Name) { diff --git a/eth/backend.go b/eth/backend.go index 05d6c5c927..2f31b7360f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -243,16 +243,16 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { checkpoint = params.TrustedCheckpoints[genesisHash] } if eth.handler, err = newHandler(&handlerConfig{ - Database: chainDb, - Chain: eth.blockchain, - TxPool: eth.txPool, - Merger: merger, - Network: config.NetworkId, - Sync: config.SyncMode, - BloomCache: uint64(cacheLimit), - EventMux: eth.eventMux, - Checkpoint: checkpoint, - PeerRequiredBlocks: config.PeerRequiredBlocks, + Database: chainDb, + Chain: eth.blockchain, + TxPool: eth.txPool, + Merger: merger, + Network: config.NetworkId, + Sync: config.SyncMode, + BloomCache: uint64(cacheLimit), + EventMux: eth.eventMux, + Checkpoint: checkpoint, + RequiredBlocks: config.RequiredBlocks, }); err != nil { return nil, err } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 6ab43891f7..d25ae20dcb 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -140,10 +140,10 @@ type Config struct { TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. - // PeerRequiredBlocks is a set of block number -> hash mappings which must be in the + // RequiredBlocks is a set of block number -> hash mappings which must be in the // canonical chain of all remote peers. Setting the option makes geth verify the // presence of these blocks for every new peer connection. - PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` + RequiredBlocks map[uint64]common.Hash `toml:"-"` // Light client options LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 874e30dffd..0930348c21 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -26,7 +26,7 @@ func (c Config) MarshalTOML() (interface{}, error) { NoPruning bool NoPrefetch bool TxLookupLimit uint64 `toml:",omitempty"` - PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` + RequiredBlocks map[uint64]common.Hash `toml:"-"` LightServ int `toml:",omitempty"` LightIngress int `toml:",omitempty"` LightEgress int `toml:",omitempty"` @@ -71,7 +71,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.NoPruning = c.NoPruning enc.NoPrefetch = c.NoPrefetch enc.TxLookupLimit = c.TxLookupLimit - enc.PeerRequiredBlocks = c.PeerRequiredBlocks + enc.RequiredBlocks = c.RequiredBlocks enc.LightServ = c.LightServ enc.LightIngress = c.LightIngress enc.LightEgress = c.LightEgress @@ -120,7 +120,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { NoPruning *bool NoPrefetch *bool TxLookupLimit *uint64 `toml:",omitempty"` - PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` + RequiredBlocks map[uint64]common.Hash `toml:"-"` LightServ *int `toml:",omitempty"` LightIngress *int `toml:",omitempty"` LightEgress *int `toml:",omitempty"` @@ -184,8 +184,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.TxLookupLimit != nil { c.TxLookupLimit = *dec.TxLookupLimit } - if dec.PeerRequiredBlocks != nil { - c.PeerRequiredBlocks = dec.PeerRequiredBlocks + if dec.RequiredBlocks != nil { + c.RequiredBlocks = dec.RequiredBlocks } if dec.LightServ != nil { c.LightServ = *dec.LightServ diff --git a/eth/handler.go b/eth/handler.go index bd31e0f117..55d3c5f8f5 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -87,7 +87,7 @@ type handlerConfig struct { EventMux *event.TypeMux // Legacy event mux, deprecate for `feed` Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges - PeerRequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges + RequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges } type handler struct { @@ -116,7 +116,7 @@ type handler struct { txsSub event.Subscription minedBlockSub *event.TypeMuxSubscription - peerRequiredBlocks map[uint64]common.Hash + requiredBlocks map[uint64]common.Hash // channels for fetcher, syncer, txsyncLoop quitSync chan struct{} @@ -133,16 +133,16 @@ func newHandler(config *handlerConfig) (*handler, error) { config.EventMux = new(event.TypeMux) // Nicety initialization for tests } h := &handler{ - networkID: config.Network, - forkFilter: forkid.NewFilter(config.Chain), - eventMux: config.EventMux, - database: config.Database, - txpool: config.TxPool, - chain: config.Chain, - peers: newPeerSet(), - merger: config.Merger, - peerRequiredBlocks: config.PeerRequiredBlocks, - quitSync: make(chan struct{}), + networkID: config.Network, + forkFilter: forkid.NewFilter(config.Chain), + eventMux: config.EventMux, + database: config.Database, + txpool: config.TxPool, + chain: config.Chain, + peers: newPeerSet(), + merger: config.Merger, + requiredBlocks: config.RequiredBlocks, + quitSync: make(chan struct{}), } if config.Sync == downloader.FullSync { // The database seems empty as the current block is the genesis. Yet the snap @@ -432,7 +432,7 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error { }() } // If we have any explicit peer required block hashes, request them - for number, hash := range h.peerRequiredBlocks { + for number, hash := range h.requiredBlocks { resCh := make(chan *eth.Response) if _, err := peer.RequestHeadersByNumber(number, 1, 0, false, resCh); err != nil { return err diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 06ec8c16af..72f50dcdd7 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -723,7 +723,7 @@ func (c *Config) buildEth(stack *node.Node) (*ethconfig.Config, error) { // whitelist { - n.PeerRequiredBlocks = map[uint64]common.Hash{} + n.RequiredBlocks = map[uint64]common.Hash{} for k, v := range c.Whitelist { number, err := strconv.ParseUint(k, 0, 64) if err != nil { @@ -733,7 +733,7 @@ func (c *Config) buildEth(stack *node.Node) (*ethconfig.Config, error) { if err = hash.UnmarshalText([]byte(v)); err != nil { return nil, fmt.Errorf("invalid whitelist hash %s: %v", v, err) } - n.PeerRequiredBlocks[number] = hash + n.RequiredBlocks[number] = hash } } From d73d6df32bd98a4bc71b81fe92f4ec546fc3b3ff Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Tue, 30 Aug 2022 16:16:26 +0530 Subject: [PATCH 16/46] params: update meta version --- params/version.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/params/version.go b/params/version.go index ec3923a884..3984f99233 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 0 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 17 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 0 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 17 // Patch version component of the current release + VersionMeta = "stable" // Version metadata to append to the version string ) // Version holds the textual version string. @@ -41,9 +41,9 @@ var VersionWithMeta = func() string { return v }() -// ArchiveVersion holds the textual version string used for Geth archives. -// e.g. "1.8.11-dea1ce05" for stable releases, or -// "1.8.13-unstable-21c059b6" for unstable releases +// ArchiveVersion holds the textual version string used for Geth archives. e.g. +// "1.8.11-dea1ce05" for stable releases, or "1.8.13-unstable-21c059b6" for unstable +// releases. func ArchiveVersion(gitCommit string) string { vsn := Version if VersionMeta != "stable" { From 7bb7bacd5042d41bb2c3a5c13e4fcc4f543afce2 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 1 Sep 2022 11:07:49 +0530 Subject: [PATCH 17/46] Merge pull request #503 from maticnetwork/shivam/sealer-gasPrice (#506) internal/cli/server: update default cli values Co-authored-by: SHIVAM SHARMA --- internal/cli/server/config.go | 20 ++++++++-------- internal/cli/server/config_legacy_test.go | 28 ++++++++++++----------- internal/cli/server/testdata/test.toml | 4 ++-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 255cf633eb..8ee023db76 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -419,7 +419,7 @@ func DefaultConfig() *Config { TxPool: &TxPoolConfig{ Locals: []string{}, NoLocals: false, - Journal: "", + Journal: "transactions.rlp", Rejournal: 1 * time.Hour, PriceLimit: 30000000000, PriceBump: 10, @@ -432,8 +432,8 @@ func DefaultConfig() *Config { Sealer: &SealerConfig{ Enabled: false, Etherbase: "", - GasCeil: 20000000, - GasPrice: big.NewInt(30 * params.GWei), + GasCeil: 30_000_000, + GasPrice: big.NewInt(1 * params.GWei), ExtraData: "", }, Gpo: &GpoConfig{ @@ -453,22 +453,22 @@ func DefaultConfig() *Config { Prefix: "", Host: "localhost", API: []string{"eth", "net", "web3", "txpool", "bor"}, - Cors: []string{"*"}, - VHost: []string{"*"}, + Cors: []string{"localhost"}, + VHost: []string{"localhost"}, }, Ws: &APIConfig{ Enabled: false, Port: 8546, Prefix: "", Host: "localhost", - API: []string{"web3", "net"}, - Cors: []string{"*"}, - VHost: []string{"*"}, + API: []string{"net", "web3"}, + Cors: []string{"localhost"}, + VHost: []string{"localhost"}, }, Graphql: &APIConfig{ Enabled: false, - Cors: []string{"*"}, - VHost: []string{"*"}, + Cors: []string{"localhost"}, + VHost: []string{"localhost"}, }, }, Ethstats: "", diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index b28d7ae536..b11e9646f4 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -14,10 +14,10 @@ import ( func TestConfigLegacy(t *testing.T) { readFile := func(path string) { - config, err := readLegacyConfig(path) + expectedConfig, err := readLegacyConfig(path) assert.NoError(t, err) - assert.Equal(t, config, &Config{ + testConfig := &Config{ Chain: "mainnet", Identity: Hostname(), RequiredBlocks: map[string]string{ @@ -52,7 +52,7 @@ func TestConfigLegacy(t *testing.T) { TxPool: &TxPoolConfig{ Locals: []string{}, NoLocals: false, - Journal: "", + Journal: "transactions.rlp", Rejournal: 1 * time.Hour, PriceLimit: 30000000000, PriceBump: 10, @@ -65,8 +65,8 @@ func TestConfigLegacy(t *testing.T) { Sealer: &SealerConfig{ Enabled: false, Etherbase: "", - GasCeil: 20000000, - GasPrice: big.NewInt(30000000000), + GasCeil: 30000000, + GasPrice: big.NewInt(1 * params.GWei), ExtraData: "", }, Gpo: &GpoConfig{ @@ -86,22 +86,22 @@ func TestConfigLegacy(t *testing.T) { Prefix: "", Host: "localhost", API: []string{"eth", "net", "web3", "txpool", "bor"}, - Cors: []string{"*"}, - VHost: []string{"*"}, + Cors: []string{"localhost"}, + VHost: []string{"localhost"}, }, Ws: &APIConfig{ Enabled: false, Port: 8546, Prefix: "", Host: "localhost", - API: []string{"web3", "net"}, - Cors: []string{"*"}, - VHost: []string{"*"}, + API: []string{"net", "web3"}, + Cors: []string{"localhost"}, + VHost: []string{"localhost"}, }, Graphql: &APIConfig{ Enabled: false, - Cors: []string{"*"}, - VHost: []string{"*"}, + Cors: []string{"localhost"}, + VHost: []string{"localhost"}, }, }, Ethstats: "", @@ -149,7 +149,9 @@ func TestConfigLegacy(t *testing.T) { Enabled: false, Period: 0, }, - }) + } + + assert.Equal(t, expectedConfig, testConfig) } // read file in hcl format diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml index ecc313b5b5..2277e03664 100644 --- a/internal/cli/server/testdata/test.toml +++ b/internal/cli/server/testdata/test.toml @@ -12,8 +12,8 @@ lifetime = "1s" [miner] mine = false -gaslimit = 20000000 -gasprice = "30000000000" +gaslimit = 30000000 +gasprice = "1000000000" [gpo] ignoreprice = "4" From d2eb2df62e9571d958cf86c8e6aa4621afb7e1eb Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 7 Sep 2022 13:35:22 +0400 Subject: [PATCH 18/46] changed 'requiredblocks' flag back to 'eth.requiredblocks' --- builder/files/config.toml | 2 +- docs/config.md | 2 ++ internal/cli/server/config.go | 2 +- internal/cli/server/flags.go | 2 +- internal/cli/server/testdata/test.toml | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/builder/files/config.toml b/builder/files/config.toml index d8503e4351..84c3327bbf 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -12,7 +12,7 @@ syncmode = "full" # snapshot = true # ethstats = "" -# [requiredblocks] +# ["eth.requiredblocks"] [p2p] # maxpeers = 1 diff --git a/docs/config.md b/docs/config.md index 196a0bf388..aebd9e12b9 100644 --- a/docs/config.md +++ b/docs/config.md @@ -19,6 +19,8 @@ gcmode = "full" snapshot = true ethstats = "" +["eth.requiredblocks"] + [p2p] maxpeers = 30 maxpendpeers = 50 diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 8ee023db76..f91e336ace 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -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"` diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index bbc7f44036..e19e578c57 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -56,7 +56,7 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.GcMode, }) f.MapStringFlag(&flagset.MapStringFlag{ - Name: "requiredblocks", + Name: "eth.requiredblocks", Usage: "Comma separated block number-to-hash mappings to enforce (=)", Value: &c.cliConfig.RequiredBlocks, }) diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml index 2277e03664..6d07abdad7 100644 --- a/internal/cli/server/testdata/test.toml +++ b/internal/cli/server/testdata/test.toml @@ -1,6 +1,6 @@ datadir = "./data" -[requiredblocks] +["eth.requiredblocks"] a = "b" [p2p] From 7c6f0a67e6e01430ea9304a7adef80ede21e903f Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 7 Sep 2022 16:21:55 +0400 Subject: [PATCH 19/46] updated tests, and removed requiredblocks from json and hcl --- internal/cli/server/command_test.go | 2 +- internal/cli/server/config_test.go | 3 --- internal/cli/server/testdata/test.hcl | 4 ---- internal/cli/server/testdata/test.json | 3 --- 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/internal/cli/server/command_test.go b/internal/cli/server/command_test.go index 9006559d0f..ab28de5ee6 100644 --- a/internal/cli/server/command_test.go +++ b/internal/cli/server/command_test.go @@ -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) diff --git a/internal/cli/server/config_test.go b/internal/cli/server/config_test.go index bf7787ac2e..5f3118996b 100644 --- a/internal/cli/server/config_test.go +++ b/internal/cli/server/config_test.go @@ -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, }, diff --git a/internal/cli/server/testdata/test.hcl b/internal/cli/server/testdata/test.hcl index 208fdc51c1..44138970fc 100644 --- a/internal/cli/server/testdata/test.hcl +++ b/internal/cli/server/testdata/test.hcl @@ -1,9 +1,5 @@ datadir = "./data" -requiredblocks = { - a = "b" -} - p2p { maxpeers = 30 } diff --git a/internal/cli/server/testdata/test.json b/internal/cli/server/testdata/test.json index 467835e755..a08e5aceb1 100644 --- a/internal/cli/server/testdata/test.json +++ b/internal/cli/server/testdata/test.json @@ -1,8 +1,5 @@ { "datadir": "./data", - "requiredblocks": { - "a": "b" - }, "p2p": { "maxpeers": 30 }, From 2cf5945321290da53edebf71dd7e4a45b230d388 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 5 Sep 2022 23:25:46 -0700 Subject: [PATCH 20/46] Remove orphaned containers when shutdown devnet This will potentially resolve "ERROR: network docker_default has active endpoints" problem --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 336b2fea56..639a68703f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,7 +168,7 @@ jobs: if: always() run: | cd matic-cli/devnet - docker compose down + docker compose down --remove-orphans cd - mkdir -p ${{ github.run_id }}/matic-cli sudo mv bor ${{ github.run_id }} From c91d4ca1fa4fd0b6555ce8f3734e91a1d5761815 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 22 Sep 2022 10:36:21 +0530 Subject: [PATCH 21/46] rpc, ethclient: cater 'finalized' and 'safe' blocks in ethclient (#517) * rpc: add finalized and safe block types * ethclient: honour safe and finalized block requests * fix: remove BlockByNumberWithoutTx function --- ethclient/ethclient.go | 8 ++++++++ ethclient/gethclient/gethclient.go | 8 ++++++++ rpc/types.go | 8 +++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 6e8915358b..c0b91b8569 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -537,6 +537,14 @@ func toBlockNumArg(number *big.Int) string { if number.Cmp(pending) == 0 { return "pending" } + finalized := big.NewInt(int64(rpc.FinalizedBlockNumber)) + if number.Cmp(finalized) == 0 { + return "finalized" + } + safe := big.NewInt(int64(rpc.SafeBlockNumber)) + if number.Cmp(safe) == 0 { + return "safe" + } return hexutil.EncodeBig(number) } diff --git a/ethclient/gethclient/gethclient.go b/ethclient/gethclient/gethclient.go index 538e23727d..ae147a40a3 100644 --- a/ethclient/gethclient/gethclient.go +++ b/ethclient/gethclient/gethclient.go @@ -187,6 +187,14 @@ func toBlockNumArg(number *big.Int) string { if number.Cmp(pending) == 0 { return "pending" } + finalized := big.NewInt(int64(rpc.FinalizedBlockNumber)) + if number.Cmp(finalized) == 0 { + return "finalized" + } + safe := big.NewInt(int64(rpc.SafeBlockNumber)) + if number.Cmp(safe) == 0 { + return "safe" + } return hexutil.EncodeBig(number) } diff --git a/rpc/types.go b/rpc/types.go index 46b08caf68..e4d40ab98f 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -61,9 +61,11 @@ type jsonWriter interface { type BlockNumber int64 const ( - PendingBlockNumber = BlockNumber(-2) - LatestBlockNumber = BlockNumber(-1) - EarliestBlockNumber = BlockNumber(0) + SafeBlockNumber = BlockNumber(-4) + FinalizedBlockNumber = BlockNumber(-3) + PendingBlockNumber = BlockNumber(-2) + LatestBlockNumber = BlockNumber(-1) + EarliestBlockNumber = BlockNumber(0) ) // UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports: From ebbe100ff16d378a5b4860561ebc03f5d6423e98 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 27 Sep 2022 22:54:17 -0700 Subject: [PATCH 22/46] Change heimdall branch to develop in CI --- .github/matic-cli-config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/matic-cli-config.yml b/.github/matic-cli-config.yml index f643f4b192..c7dab39b0e 100644 --- a/.github/matic-cli-config.yml +++ b/.github/matic-cli-config.yml @@ -8,4 +8,4 @@ numOfNonValidators: 0 ethURL: http://ganache:9545 devnetType: docker borDockerBuildContext: "../../bor" -heimdallDockerBuildContext: "https://github.com/maticnetwork/heimdall.git#v0.3.0-dev" \ No newline at end of file +heimdallDockerBuildContext: "https://github.com/maticnetwork/heimdall.git#develop" \ No newline at end of file From 43e5d3aa090c8f88b3ced29ff8bb1bbb16fa0dca Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Thu, 29 Sep 2022 14:25:27 +0530 Subject: [PATCH 23/46] PR#518 and PR#529 -> qa (#532) * 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 * internal/cli/server: fix flag behaviour (#529) * remove setting maxpeers to 0 for nodiscover flag * set default prometheus and open-collector endpoint * skip building grpc address from pprof address and port * fix: linters * fix and improve tests * use loopback address for prometheus and open-collector endpoint * add logs for prometheus and open-collector setup * updated the script to handle prometheus-addr * updated builder/files/config.toml Co-authored-by: Pratik Patil Co-authored-by: Manav Darji --- builder/files/config.toml | 4 +- go.mod | 1 + go.sum | 2 + internal/cli/flagset/flagset.go | 9 + internal/cli/server/config.go | 7 +- internal/cli/server/config_legacy_test.go | 151 +---- internal/cli/server/flags.go | 2 +- internal/cli/server/server.go | 4 + internal/cli/server/testdata/test.toml | 6 +- scripts/getconfig.go | 687 ++++++++++++++++++++++ scripts/getconfig.sh | 87 +++ 11 files changed, 816 insertions(+), 144 deletions(-) create mode 100644 scripts/getconfig.go create mode 100755 scripts/getconfig.sh diff --git a/builder/files/config.toml b/builder/files/config.toml index 84c3327bbf..ce9fd782d0 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -96,8 +96,8 @@ syncmode = "full" [telemetry] metrics = true # expensive = false - prometheus-addr = "127.0.0.1:7071" - # opencollector-endpoint = "" + # prometheus-addr = "127.0.0.1:7071" + # opencollector-endpoint = "127.0.0.1:4317" # [telemetry.influx] # influxdb = false # endpoint = "" diff --git a/go.mod b/go.mod index 39bbeb240d..e31612cfe3 100644 --- a/go.mod +++ b/go.mod @@ -119,6 +119,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 diff --git a/go.sum b/go.sum index 88c9152eef..593c8e11d0 100644 --- a/go.sum +++ b/go.sum @@ -391,6 +391,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= diff --git a/internal/cli/flagset/flagset.go b/internal/cli/flagset/flagset.go index d9e204f0e4..933fe59060 100644 --- a/internal/cli/flagset/flagset.go +++ b/internal/cli/flagset/flagset.go @@ -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 { diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index f91e336ace..a4f642a6e3 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -475,8 +475,8 @@ func DefaultConfig() *Config { Telemetry: &TelemetryConfig{ Enabled: false, Expensive: false, - PrometheusAddr: "", - OpenCollectorEndpoint: "", + PrometheusAddr: "127.0.0.1:7071", + OpenCollectorEndpoint: "127.0.0.1:4317", InfluxDB: &InfluxDBConfig{ V1Enabled: false, Endpoint: "", @@ -991,8 +991,7 @@ func (c *Config) buildNode() (*node.Config, error) { } if c.P2P.NoDiscover { - // Disable networking, for now, we will not even allow incomming connections - cfg.P2P.MaxPeers = 0 + // Disable peer discovery cfg.P2P.NoDiscovery = true } diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index b11e9646f4..29cefdd7bf 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -6,9 +6,6 @@ import ( "time" "github.com/stretchr/testify/assert" - - "github.com/ethereum/go-ethereum/eth/ethconfig" - "github.com/ethereum/go-ethereum/params" ) func TestConfigLegacy(t *testing.T) { @@ -17,139 +14,23 @@ func TestConfigLegacy(t *testing.T) { expectedConfig, err := readLegacyConfig(path) assert.NoError(t, err) - testConfig := &Config{ - Chain: "mainnet", - Identity: Hostname(), - RequiredBlocks: map[string]string{ - "a": "b", - }, - LogLevel: "INFO", - DataDir: "./data", - P2P: &P2PConfig{ - MaxPeers: 30, - MaxPendPeers: 50, - Bind: "0.0.0.0", - Port: 30303, - NoDiscover: false, - NAT: "any", - Discovery: &P2PDiscovery{ - V5Enabled: false, - Bootnodes: []string{}, - BootnodesV4: []string{}, - BootnodesV5: []string{}, - StaticNodes: []string{}, - TrustedNodes: []string{}, - DNS: []string{}, - }, - }, - Heimdall: &HeimdallConfig{ - URL: "http://localhost:1317", - Without: false, - }, - SyncMode: "full", - GcMode: "full", - Snapshot: true, - TxPool: &TxPoolConfig{ - Locals: []string{}, - NoLocals: false, - Journal: "transactions.rlp", - Rejournal: 1 * time.Hour, - PriceLimit: 30000000000, - PriceBump: 10, - AccountSlots: 16, - GlobalSlots: 32768, - AccountQueue: 16, - GlobalQueue: 32768, - LifeTime: 1 * time.Second, - }, - Sealer: &SealerConfig{ - Enabled: false, - Etherbase: "", - GasCeil: 30000000, - GasPrice: big.NewInt(1 * params.GWei), - ExtraData: "", - }, - Gpo: &GpoConfig{ - Blocks: 20, - Percentile: 60, - MaxPrice: big.NewInt(5000 * params.GWei), - IgnorePrice: big.NewInt(4), - }, - JsonRPC: &JsonRPCConfig{ - IPCDisable: false, - IPCPath: "", - GasCap: ethconfig.Defaults.RPCGasCap, - TxFeeCap: ethconfig.Defaults.RPCTxFeeCap, - Http: &APIConfig{ - Enabled: false, - Port: 8545, - Prefix: "", - Host: "localhost", - API: []string{"eth", "net", "web3", "txpool", "bor"}, - Cors: []string{"localhost"}, - VHost: []string{"localhost"}, - }, - Ws: &APIConfig{ - Enabled: false, - Port: 8546, - Prefix: "", - Host: "localhost", - API: []string{"net", "web3"}, - Cors: []string{"localhost"}, - VHost: []string{"localhost"}, - }, - Graphql: &APIConfig{ - Enabled: false, - Cors: []string{"localhost"}, - VHost: []string{"localhost"}, - }, - }, - Ethstats: "", - Telemetry: &TelemetryConfig{ - Enabled: false, - Expensive: false, - PrometheusAddr: "", - OpenCollectorEndpoint: "", - InfluxDB: &InfluxDBConfig{ - V1Enabled: false, - Endpoint: "", - Database: "", - Username: "", - Password: "", - Tags: map[string]string{}, - V2Enabled: false, - Token: "", - Bucket: "", - Organization: "", - }, - }, - Cache: &CacheConfig{ - Cache: 1024, - PercDatabase: 50, - PercTrie: 15, - PercGc: 25, - PercSnapshot: 10, - Journal: "triecache", - Rejournal: 1 * time.Second, - NoPrefetch: false, - Preimages: false, - TxLookupLimit: 2350000, - }, - Accounts: &AccountsConfig{ - Unlock: []string{}, - PasswordFile: "", - AllowInsecureUnlock: false, - UseLightweightKDF: false, - DisableBorWallet: true, - }, - GRPC: &GRPCConfig{ - Addr: ":3131", - }, - Developer: &DeveloperConfig{ - Enabled: false, - Period: 0, - }, + testConfig := DefaultConfig() + + testConfig.DataDir = "./data" + testConfig.Snapshot = false + testConfig.RequiredBlocks = map[string]string{ + "31000000": "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e", + "32000000": "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68", } + testConfig.P2P.MaxPeers = 30 + testConfig.TxPool.Locals = []string{} + testConfig.TxPool.LifeTime = time.Second + testConfig.Sealer.Enabled = true + testConfig.Sealer.GasCeil = 30000000 + testConfig.Sealer.GasPrice = big.NewInt(1000000000) + testConfig.Gpo.IgnorePrice = big.NewInt(4) + testConfig.Cache.Cache = 1024 + testConfig.Cache.Rejournal = time.Second assert.Equal(t, expectedConfig, testConfig) } diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index e19e578c57..835ff0ab95 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -57,7 +57,7 @@ func (c *Command) Flags() *flagset.Flagset { }) f.MapStringFlag(&flagset.MapStringFlag{ Name: "eth.requiredblocks", - Usage: "Comma separated block number-to-hash mappings to enforce (=)", + Usage: "Comma separated block number-to-hash mappings to require for peering (=)", Value: &c.cliConfig.RequiredBlocks, }) f.BoolFlag(&flagset.BoolFlag{ diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index cd706c1a9d..adacb44ce7 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -281,6 +281,8 @@ func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error } }() + log.Info("Enabling metrics export to prometheus", "path", fmt.Sprintf("http://%s/debug/metrics/prometheus", config.PrometheusAddr)) + } if config.OpenCollectorEndpoint != "" { @@ -322,6 +324,8 @@ func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error // set the tracer s.tracer = tracerProvider + + log.Info("Open collector tracing started", "address", config.OpenCollectorEndpoint) } return nil diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml index 6d07abdad7..4ccc644ee9 100644 --- a/internal/cli/server/testdata/test.toml +++ b/internal/cli/server/testdata/test.toml @@ -1,7 +1,9 @@ datadir = "./data" +snapshot = false ["eth.requiredblocks"] -a = "b" +"31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e" +"32000000" = "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68" [p2p] maxpeers = 30 @@ -11,7 +13,7 @@ locals = [] lifetime = "1s" [miner] -mine = false +mine = true gaslimit = 30000000 gasprice = "1000000000" diff --git a/scripts/getconfig.go b/scripts/getconfig.go new file mode 100644 index 0000000000..689ed68fbf --- /dev/null +++ b/scripts/getconfig.go @@ -0,0 +1,687 @@ +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 handlePrometheus(args []string, updatedArgs []string) []string { + var newUpdatedArgs []string + + mAddr := "" + mPort := "" + + pAddr := "" + pPort := "" + + newUpdatedArgs = append(newUpdatedArgs, updatedArgs...) + + for i, val := range args { + if strings.Contains(val, "metrics.addr") && strings.HasPrefix(val, "-") { + mAddr = args[i+1] + } + + if strings.Contains(val, "metrics.port") && strings.HasPrefix(val, "-") { + mPort = args[i+1] + } + + if strings.Contains(val, "pprof.addr") && strings.HasPrefix(val, "-") { + pAddr = args[i+1] + } + + if strings.Contains(val, "pprof.port") && strings.HasPrefix(val, "-") { + pPort = args[i+1] + } + } + + if mAddr != "" && mPort != "" { + newUpdatedArgs = append(newUpdatedArgs, "--metrics.prometheus-addr") + newUpdatedArgs = append(newUpdatedArgs, mAddr+":"+mPort) + } else if pAddr != "" && pPort != "" { + newUpdatedArgs = append(newUpdatedArgs, "--metrics.prometheus-addr") + newUpdatedArgs = append(newUpdatedArgs, pAddr+":"+pPort) + } + + 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 = handlePrometheus(args, updatedArgs) + + if temp == notYet { + updatedArgs = append(updatedArgs, ignoreForNow...) + dumpFlags(updatedArgs) + } + + if temp != notYet { + updatedArgs = append(updatedArgs, ignoreForNow...) + commentFlags(temp, updatedArgs) + } +} diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh new file mode 100755 index 0000000000..26d5d0138c --- /dev/null +++ b/scripts/getconfig.sh @@ -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 From c7246711725de10452d436b3f86d26f28821acfb Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 25 Aug 2022 23:13:22 +0530 Subject: [PATCH 24/46] rm: snapshot found log in bor consensus (#504) --- consensus/bor/bor.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 826a45dae2..f140146976 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -535,8 +535,6 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co number, hash = number-1, header.ParentHash } - log.Info("Snapshot has been found in", "headers depth", len(headers)) - // check if snapshot is nil if snap == nil { return nil, fmt.Errorf("Unknown error while retrieving snapshot at block number %v", number) From 1a515607262cd327ae7345671ba316e98f7ebe74 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Tue, 4 Oct 2022 21:54:47 +0530 Subject: [PATCH 25/46] make script OS independent (#538) --- scripts/getconfig.sh | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh index 26d5d0138c..943d540a88 100755 --- a/scripts/getconfig.sh +++ b/scripts/getconfig.sh @@ -1,10 +1,19 @@ #!/usr/bin/env sh +set -e # 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 +# Some checks to make commands OS independent +OS="$(uname -s)" +MKTEMPOPTION= +SEDOPTION= ## Not used as of now (TODO) +shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then + SEDOPTION="''" + MKTEMPOPTION="-t" +fi read -p "* Path to start.sh: " startPath # check if start.sh is present @@ -15,7 +24,7 @@ then 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:" +printf "\nThank you, your inputs are:\n" echo "Path to start.sh: "$startPath echo "Address: "$ADD @@ -26,8 +35,9 @@ if [[ -f $confPath ]] then echo "WARN: config.toml exists, data will be overwritten." fi +printf "\n" -tmpDir="$(mktemp -d -t ./temp-dir-XXXXXXXXXXX || oops "Can't create temporary directory")" +tmpDir="$(mktemp -d $MKTEMPOPTION ./temp-dir-XXXXXXXXXXX || oops "Can't create temporary directory")" cleanup() { rm -rf "$tmpDir" } @@ -39,8 +49,11 @@ chmod +x $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD rm $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh - -sed -i '' "s%*%'*'%g" ./temp +shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then + sed -i '' "s%*%'*'%g" ./temp +else + sed -i "s%*%'*'%g" ./temp +fi # read the flags from `./temp` dumpconfigflags=$(head -1 ./temp) @@ -51,17 +64,27 @@ bash -c "$command" rm ./temp +printf "\n" + if [[ -f ./tempStaticNodes.json ]] then echo "JSON StaticNodes found" staticnodesjson=$(head -1 ./tempStaticNodes.json) - sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath + shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then + sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath + else + sed -i "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath + fi 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 + shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then + sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath + else + sed -i "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath + fi rm ./tempStaticNodes.toml else echo "neither JSON nor TOML StaticNodes found" @@ -71,12 +94,18 @@ if [[ -f ./tempTrustedNodes.toml ]] then echo "TOML TrustedNodes found" trustednodestoml=$(head -1 ./tempTrustedNodes.toml) - sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath + shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then + sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath + else + sed -i "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath + fi rm ./tempTrustedNodes.toml else echo "neither JSON nor TOML TrustedNodes found" fi +printf "\n" + # 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 From 083c3fead17e2317b45925d3547cc9497d2313e5 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 5 Oct 2022 23:38:19 +0530 Subject: [PATCH 26/46] internal/cli: add support for bor.logs flag in new-cli (#541) * add support for bor.logs flag in new-cli * handle bor.withoutheimdall flag commenting in conversion script --- builder/files/config.toml | 3 ++- docs/cli/removedb.md | 4 +++- docs/cli/server.md | 10 +++++++--- internal/cli/server/config.go | 8 +++++++- internal/cli/server/flags.go | 10 ++++++++-- scripts/getconfig.go | 4 +++- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/builder/files/config.toml b/builder/files/config.toml index ce9fd782d0..0d01f85d71 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -10,6 +10,7 @@ datadir = "/var/lib/bor/data" syncmode = "full" # gcmode = "full" # snapshot = true +# "bor.logs" = false # ethstats = "" # ["eth.requiredblocks"] @@ -134,4 +135,4 @@ syncmode = "full" # [developer] # dev = false - # period = 0 \ No newline at end of file + # period = 0 diff --git a/docs/cli/removedb.md b/docs/cli/removedb.md index 3c6e84f1d6..473d47ecef 100644 --- a/docs/cli/removedb.md +++ b/docs/cli/removedb.md @@ -4,4 +4,6 @@ The ```bor removedb``` command will remove the blockchain and state databases at ## Options -- ```datadir```: Path of the data directory to store information +- ```address```: Address of the grpc endpoint + +- ```datadir```: Path of the data directory to store information \ No newline at end of file diff --git a/docs/cli/server.md b/docs/cli/server.md index ac43555275..5fe440b5fd 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -16,18 +16,22 @@ The ```bor server``` command runs the Bor client. - ```config```: File for the config file -- ```syncmode```: Blockchain sync mode ("fast", "full", or "snap") +- ```syncmode```: Blockchain sync mode (only "full" sync supported) - ```gcmode```: Blockchain garbage collection mode ("full", "archive") -- ```requiredblocks```: Comma separated block number-to-hash mappings to enforce (=) +- ```eth.requiredblocks```: Comma separated block number-to-hash mappings to require for peering (=) -- ```snapshot```: Disables/Enables the snapshot-database mode (default = true) +- ```snapshot```: Enables the snapshot-database mode (default = true) + +- ```bor.logs```: Enables bor log retrieval (default = false) - ```bor.heimdall```: URL of Heimdall service - ```bor.withoutheimdall```: Run without Heimdall service (for testing purpose) +- ```bor.heimdallgRPC```: Address of Heimdall gRPC service + - ```ethstats```: Reporting URL of a ethstats service (nodename:secret@host:port) - ```gpo.blocks```: Number of recent blocks to check for gas prices diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index a4f642a6e3..c9e770c5ba 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -62,9 +62,12 @@ type Config struct { // GcMode selects the garbage collection mode for the trie GcMode string `hcl:"gcmode,optional" toml:"gcmode,optional"` - // Snapshot disables/enables the snapshot database mode + // Snapshot enables the snapshot database mode Snapshot bool `hcl:"snapshot,optional" toml:"snapshot,optional"` + // BorLogs enables bor log retrieval + BorLogs bool `hcl:"bor.logs,optional" toml:"bor.logs,optional"` + // Ethstats is the address of the ethstats server to send telemetry Ethstats string `hcl:"ethstats,optional" toml:"ethstats,optional"` @@ -416,6 +419,7 @@ func DefaultConfig() *Config { SyncMode: "full", GcMode: "full", Snapshot: true, + BorLogs: false, TxPool: &TxPoolConfig{ Locals: []string{}, NoLocals: false, @@ -645,6 +649,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (* n.NetworkId = c.chain.NetworkId n.Genesis = c.chain.Genesis } + n.HeimdallURL = c.Heimdall.URL n.WithoutHeimdall = c.Heimdall.Without @@ -876,6 +881,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (* } } + n.BorLogs = c.BorLogs n.DatabaseHandles = dbHandles return &n, nil diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index 835ff0ab95..ec74f89991 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -45,7 +45,7 @@ func (c *Command) Flags() *flagset.Flagset { }) f.StringFlag(&flagset.StringFlag{ Name: "syncmode", - Usage: `Blockchain sync mode ("fast", "full", or "snap")`, + Usage: `Blockchain sync mode (only "full" sync supported)`, Value: &c.cliConfig.SyncMode, Default: c.cliConfig.SyncMode, }) @@ -62,10 +62,16 @@ func (c *Command) Flags() *flagset.Flagset { }) f.BoolFlag(&flagset.BoolFlag{ Name: "snapshot", - Usage: `Disables/Enables the snapshot-database mode (default = true)`, + Usage: `Enables the snapshot-database mode (default = true)`, Value: &c.cliConfig.Snapshot, Default: c.cliConfig.Snapshot, }) + f.BoolFlag(&flagset.BoolFlag{ + Name: "bor.logs", + Usage: `Enables bor log retrieval (default = false)`, + Value: &c.cliConfig.BorLogs, + Default: c.cliConfig.BorLogs, + }) // heimdall f.StringFlag(&flagset.StringFlag{ diff --git a/scripts/getconfig.go b/scripts/getconfig.go index 689ed68fbf..136b69ecab 100644 --- a/scripts/getconfig.go +++ b/scripts/getconfig.go @@ -109,8 +109,9 @@ var nameTagMap = map[string]string{ "gcmode": "gcmode", "eth.requiredblocks": "eth.requiredblocks", "0-snapshot": "snapshot", + "\"bor.logs\"": "bor.logs", "url": "bor.heimdall", - "bor.without": "bor.withoutheimdall", + "\"bor.without\"": "bor.withoutheimdall", "grpc-address": "bor.heimdallgRPC", "locals": "txpool.locals", "nolocals": "txpool.nolocals", @@ -231,6 +232,7 @@ var replacedFlagsMapFlag = map[string]string{ var currentBoolFlags = []string{ "snapshot", + "bor.logs", "bor.withoutheimdall", "txpool.nolocals", "mine", From cb12a6e4d6b93f86777128463738953649bee929 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 19 Oct 2022 14:55:31 -0700 Subject: [PATCH 27/46] Force load default tracers --- internal/cli/server/server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index adacb44ce7..6758d74312 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -36,6 +36,10 @@ import ( "github.com/ethereum/go-ethereum/metrics/influxdb" "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" + + // Force-load the tracer engines to trigger registration + _ "github.com/ethereum/go-ethereum/eth/tracers/js" + _ "github.com/ethereum/go-ethereum/eth/tracers/native" ) type Server struct { From a977a76f97251d0a902921dd3a93610d969bb645 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Fri, 21 Oct 2022 02:15:42 +0530 Subject: [PATCH 28/46] metrics: handle values from config file (#565) * metrics: handle metrics flag from config in metrics.init() * internal/cli/server: log for metrics enabling and misconfiguration --- internal/cli/server/server.go | 10 +++++++ metrics/metrics.go | 53 ++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 6758d74312..1346fe613a 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -233,6 +233,12 @@ func (s *Server) Stop() { } func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error { + // Check the global metrics if they're matching with the provided config + if metrics.Enabled != config.Enabled || metrics.EnabledExpensive != config.Expensive { + log.Warn("Metric misconfiguration, some of them might not be visible") + } + + // Update the values anyways (for services which don't need immediate attention) metrics.Enabled = config.Enabled metrics.EnabledExpensive = config.Expensive @@ -243,6 +249,10 @@ func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error log.Info("Enabling metrics collection") + if metrics.EnabledExpensive { + log.Info("Enabling expensive metrics collection") + } + // influxdb if v1Enabled, v2Enabled := config.InfluxDB.V1Enabled, config.InfluxDB.V2Enabled; v1Enabled || v2Enabled { if v1Enabled && v2Enabled { diff --git a/metrics/metrics.go b/metrics/metrics.go index 747d6471a7..1d0133e850 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "github.com/ethereum/go-ethereum/log" + "github.com/BurntSushi/toml" ) // Enabled is checked by the constructor functions for all of the @@ -32,26 +32,71 @@ var enablerFlags = []string{"metrics"} // expensiveEnablerFlags is the CLI flag names to use to enable metrics collections. var expensiveEnablerFlags = []string{"metrics.expensive"} +// configFlag is the CLI flag name to use to start node by providing a toml based config +var configFlag = "config" + // Init enables or disables the metrics system. Since we need this to run before // any other code gets to create meters and timers, we'll actually do an ugly hack // and peek into the command line args for the metrics flag. func init() { - for _, arg := range os.Args { + var configFile string + + for i := 0; i < len(os.Args); i++ { + arg := os.Args[i] + flag := strings.TrimLeft(arg, "-") + // check for existence of `config` flag + if flag == configFlag && i < len(os.Args)-1 { + configFile = strings.TrimLeft(os.Args[i+1], "-") // find the value of flag + } + for _, enabler := range enablerFlags { if !Enabled && flag == enabler { - log.Info("Enabling metrics collection") Enabled = true } } + for _, enabler := range expensiveEnablerFlags { if !EnabledExpensive && flag == enabler { - log.Info("Enabling expensive metrics collection") EnabledExpensive = true } } } + + // Update the global metrics value, if they're provided in the config file + updateMetricsFromConfig(configFile) +} + +func updateMetricsFromConfig(path string) { + // Don't act upon any errors here. They're already taken into + // consideration when the toml config file will be parsed in the cli. + data, err := os.ReadFile(path) + tomlData := string(data) + + if err != nil { + return + } + + // Create a minimal config to decode + type TelemetryConfig struct { + Enabled bool `hcl:"metrics,optional" toml:"metrics,optional"` + Expensive bool `hcl:"expensive,optional" toml:"expensive,optional"` + } + + type CliConfig struct { + Telemetry *TelemetryConfig `hcl:"telemetry,block" toml:"telemetry,block"` + } + + conf := &CliConfig{} + + if _, err := toml.Decode(tomlData, &conf); err != nil || conf == nil { + return + } + + // We have the values now, update them + Enabled = conf.Telemetry.Enabled + EnabledExpensive = conf.Telemetry.Expensive } // CollectProcessMetrics periodically collects various metrics about the running From 5c5c9924405721b03f240ae994520fe94fec5b6e Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 21 Oct 2022 08:54:38 +0530 Subject: [PATCH 29/46] Changed default value of maxpeers from 200 to 50, update docs (#555) * changed default of maxpeers from 200 to 50 * docs: update additional notes for new-cli * docs: update additional notes for new-cli * small bug fix in the script to fix shopt issue Co-authored-by: Manav Darji --- cmd/geth/config.go | 4 ++-- docs/README.md | 18 ++++++++---------- docs/config.md | 2 +- internal/cli/server/config.go | 2 +- scripts/getconfig.sh | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 08b76f83da..101f4b2de6 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -329,7 +329,7 @@ func setDefaultMumbaiGethConfig(ctx *cli.Context, config *gethConfig) { config.Eth.TxPool.AccountQueue = 64 config.Eth.TxPool.GlobalQueue = 131072 config.Eth.TxPool.Lifetime = 90 * time.Minute - config.Node.P2P.MaxPeers = 200 + config.Node.P2P.MaxPeers = 50 config.Metrics.Enabled = true // --pprof is enabled in 'internal/debug/flags.go' } @@ -352,7 +352,7 @@ func setDefaultBorMainnetGethConfig(ctx *cli.Context, config *gethConfig) { config.Eth.TxPool.AccountQueue = 64 config.Eth.TxPool.GlobalQueue = 131072 config.Eth.TxPool.Lifetime = 90 * time.Minute - config.Node.P2P.MaxPeers = 200 + config.Node.P2P.MaxPeers = 50 config.Metrics.Enabled = true // --pprof is enabled in 'internal/debug/flags.go' } diff --git a/docs/README.md b/docs/README.md index 95ba38b0da..5ebdbd7e26 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,18 +5,16 @@ - [Configuration file](./config.md) -## Deprecation notes +## Additional notes - The new entrypoint to run the Bor client is ```server```. -``` -$ bor server -``` + ``` + $ bor server + ``` -- Toml files to configure nodes are being deprecated. Currently, we only allow for static and trusted nodes to be configured using toml files. +- Toml files used earlier just to configure static/trusted nodes are being deprecated. Instead, a toml file now can be used instead of flags and can contain all configuration for the node to run. The link to a sample config file is given above. To simply run bor with a configuration file, the following command can be used. -``` -$ bor server --config ./legacy.toml -``` - -- ```Admin```, ```Personal``` and account related endpoints in ```Eth``` are being removed from the JsonRPC interface. Some of this functionality will be moved to the new GRPC server for operational tasks. + ``` + $ bor server --config + ``` diff --git a/docs/config.md b/docs/config.md index aebd9e12b9..57f4c25fef 100644 --- a/docs/config.md +++ b/docs/config.md @@ -22,7 +22,7 @@ ethstats = "" ["eth.requiredblocks"] [p2p] -maxpeers = 30 +maxpeers = 50 maxpendpeers = 50 bind = "0.0.0.0" port = 30303 diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index c9e770c5ba..86b611ac78 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -396,7 +396,7 @@ func DefaultConfig() *Config { LogLevel: "INFO", DataDir: DefaultDataDir(), P2P: &P2PConfig{ - MaxPeers: 30, + MaxPeers: 50, MaxPendPeers: 50, Bind: "0.0.0.0", Port: 30303, diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh index 943d540a88..a2971c4f12 100755 --- a/scripts/getconfig.sh +++ b/scripts/getconfig.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/bash set -e # Instructions: From b8c3b0043c1c7ad4f57b956e4ebcba30e9ee4bf8 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 12 Oct 2022 20:06:00 +0530 Subject: [PATCH 30/46] add : Add state sync transaction to debug_traceBlock --- consensus/bor/statefull/processor.go | 52 +++++++-- core/vm/interface.go | 2 + eth/tracers/api.go | 159 +++++++++++++++++++++------ eth/tracers/api_test.go | 11 +- 4 files changed, 178 insertions(+), 46 deletions(-) diff --git a/consensus/bor/statefull/processor.go b/consensus/bor/statefull/processor.go index e30fb4fd21..192ea5fa38 100644 --- a/consensus/bor/statefull/processor.go +++ b/consensus/bor/statefull/processor.go @@ -30,22 +30,22 @@ func (c ChainContext) GetHeader(hash common.Hash, number uint64) *types.Header { } // callmsg implements core.Message to allow passing it as a transaction simulator. -type callmsg struct { +type Callmsg struct { ethereum.CallMsg } -func (m callmsg) From() common.Address { return m.CallMsg.From } -func (m callmsg) Nonce() uint64 { return 0 } -func (m callmsg) CheckNonce() bool { return false } -func (m callmsg) To() *common.Address { return m.CallMsg.To } -func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } -func (m callmsg) Gas() uint64 { return m.CallMsg.Gas } -func (m callmsg) Value() *big.Int { return m.CallMsg.Value } -func (m callmsg) Data() []byte { return m.CallMsg.Data } +func (m Callmsg) From() common.Address { return m.CallMsg.From } +func (m Callmsg) Nonce() uint64 { return 0 } +func (m Callmsg) CheckNonce() bool { return false } +func (m Callmsg) To() *common.Address { return m.CallMsg.To } +func (m Callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } +func (m Callmsg) Gas() uint64 { return m.CallMsg.Gas } +func (m Callmsg) Value() *big.Int { return m.CallMsg.Value } +func (m Callmsg) Data() []byte { return m.CallMsg.Data } // get system message -func GetSystemMessage(toAddress common.Address, data []byte) callmsg { - return callmsg{ +func GetSystemMessage(toAddress common.Address, data []byte) Callmsg { + return Callmsg{ ethereum.CallMsg{ From: systemAddress, Gas: math.MaxUint64 / 2, @@ -59,7 +59,7 @@ func GetSystemMessage(toAddress common.Address, data []byte) callmsg { // apply message func ApplyMessage( - msg callmsg, + msg Callmsg, state *state.StateDB, header *types.Header, chainConfig *params.ChainConfig, @@ -90,4 +90,32 @@ func ApplyMessage( gasUsed := initialGas - gasLeft return gasUsed, nil + +} + +func ApplyBorMessage(vmenv vm.EVM, msg Callmsg) (*core.ExecutionResult, error) { + + initialGas := msg.Gas() + + // Apply the transaction to the current state (included in the env) + ret, gasLeft, err := vmenv.Call( + vm.AccountRef(msg.From()), + *msg.To(), + msg.Data(), + msg.Gas(), + msg.Value(), + ) + // Update the state with pending changes + if err != nil { + vmenv.StateDB.Finalise(true) + } + + gasUsed := initialGas - gasLeft + + return &core.ExecutionResult{ + UsedGas: gasUsed, + Err: err, + ReturnData: ret, + }, nil + } diff --git a/core/vm/interface.go b/core/vm/interface.go index ad9b05d666..1064adf590 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -74,6 +74,8 @@ type StateDB interface { AddPreimage(common.Hash, []byte) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error + + Finalise(bool) } // CallContext provides a basic interface for the EVM calling conventions. The EVM diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 08c17601e4..12b1411ae7 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -28,9 +28,11 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/consensus/bor/statefull" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" @@ -80,6 +82,9 @@ type Backend interface { // so this method should be called with the parent. StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, checkLive, preferDisk bool) (*state.StateDB, error) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, error) + + // Bor related APIs + GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) } // API is the collection of tracing APIs exposed over the private debugging endpoint. @@ -164,6 +169,25 @@ func (api *API) blockByNumberAndHash(ctx context.Context, number rpc.BlockNumber return api.blockByHash(ctx, hash) } +// returns block transactions along with state-sync transaction if present +func (api *API) getAllBlockTransactions(ctx context.Context, block *types.Block) (types.Transactions, bool) { + txs := block.Transactions() + + stateSyncPresent := false + + borReceipt := rawdb.ReadBorReceipt(api.backend.ChainDb(), block.Hash(), block.NumberU64()) + if borReceipt != nil { + txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash())) + if txHash != (common.Hash{}) { + borTx, _, _, _, _ := api.backend.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash()) + txs = append(txs, borTx) + stateSyncPresent = true + } + } + + return txs, stateSyncPresent +} + // TraceConfig holds extra parameters to trace functions. type TraceConfig struct { *logger.Config @@ -274,19 +298,30 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config signer := types.MakeSigner(api.backend.ChainConfig(), task.block.Number()) blockCtx := core.NewEVMBlockContext(task.block.Header(), api.chainContext(localctx), nil) // Trace all the transactions contained within - for i, tx := range task.block.Transactions() { + txs, stateSyncPresent := api.getAllBlockTransactions(ctx, task.block) + for i, tx := range txs { msg, _ := tx.AsMessage(signer, task.block.BaseFee()) txctx := &Context{ BlockHash: task.block.Hash(), TxIndex: i, TxHash: tx.Hash(), } - res, err := api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config) + + var res interface{} + var err error + + if stateSyncPresent && i == len(txs)-1 { + res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config, true) + } else { + res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config, false) + } + if err != nil { task.results[i] = &txTraceResult{Error: err.Error()} log.Warn("Tracing failed", "hash", tx.Hash(), "block", task.block.NumberU64(), "err", err) break } + // Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect task.statedb.Finalise(api.backend.ChainConfig().IsEIP158(task.block.Number())) task.results[i] = &txTraceResult{Result: res} @@ -492,6 +527,23 @@ func (api *API) StandardTraceBlockToFile(ctx context.Context, hash common.Hash, return api.standardTraceBlockToFile(ctx, block, config) } +func prepareCallMessage(msg core.Message) statefull.Callmsg { + + return statefull.Callmsg{ + ethereum.CallMsg{ + From: msg.From(), + To: msg.To(), + Gas: msg.Gas(), + GasPrice: msg.GasPrice(), + GasFeeCap: msg.GasFeeCap(), + GasTipCap: msg.GasTipCap(), + Value: msg.Value(), + Data: msg.Data(), + AccessList: msg.AccessList(), + }} + +} + // IntermediateRoots executes a block (bad- or canon- or side-), and returns a list // of intermediate roots: the stateroot after each transaction. func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config *TraceConfig) ([]common.Hash, error) { @@ -525,23 +577,42 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config vmctx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) deleteEmptyObjects = chainConfig.IsEIP158(block.Number()) ) - for i, tx := range block.Transactions() { + txs, stateSyncPresent := api.getAllBlockTransactions(ctx, block) + for i, tx := range txs { var ( msg, _ = tx.AsMessage(signer, block.BaseFee()) txContext = core.NewEVMTxContext(msg) vmenv = vm.NewEVM(vmctx, txContext, statedb, chainConfig, vm.Config{}) ) statedb.Prepare(tx.Hash(), i) - if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { - log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) - // We intentionally don't return the error here: if we do, then the RPC server will not - // return the roots. Most likely, the caller already knows that a certain transaction fails to - // be included, but still want the intermediate roots that led to that point. - // It may happen the tx_N causes an erroneous state, which in turn causes tx_N+M to not be - // executable. - // N.B: This should never happen while tracing canon blocks, only when tracing bad blocks. - return roots, nil + if stateSyncPresent && i == len(txs)-1 { + callmsg := prepareCallMessage(msg) + + if _, err := statefull.ApplyMessage(ctx, callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx)); err != nil { + log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) + // We intentionally don't return the error here: if we do, then the RPC server will not + // return the roots. Most likely, the caller already knows that a certain transaction fails to + // be included, but still want the intermediate roots that led to that point. + // It may happen the tx_N causes an erroneous state, which in turn causes tx_N+M to not be + // executable. + // N.B: This should never happen while tracing canon blocks, only when tracing bad blocks. + return roots, nil + } + + } else { + if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { + log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) + // We intentionally don't return the error here: if we do, then the RPC server will not + // return the roots. Most likely, the caller already knows that a certain transaction fails to + // be included, but still want the intermediate roots that led to that point. + // It may happen the tx_N causes an erroneous state, which in turn causes tx_N+M to not be + // executable. + // N.B: This should never happen while tracing canon blocks, only when tracing bad blocks. + return roots, nil + } + } + // calling IntermediateRoot will internally call Finalize on the state // so any modifications are written to the trie roots = append(roots, statedb.IntermediateRoot(deleteEmptyObjects)) @@ -581,9 +652,9 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac } // Execute all the transaction contained within the block concurrently var ( - signer = types.MakeSigner(api.backend.ChainConfig(), block.Number()) - txs = block.Transactions() - results = make([]*txTraceResult, len(txs)) + signer = types.MakeSigner(api.backend.ChainConfig(), block.Number()) + txs, stateSyncPresent = api.getAllBlockTransactions(ctx, block) + results = make([]*txTraceResult, len(txs)) pend = new(sync.WaitGroup) jobs = make(chan *txTraceTask, len(txs)) @@ -606,7 +677,13 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac TxIndex: task.index, TxHash: txs[task.index].Hash(), } - res, err := api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config) + var res interface{} + var err error + if stateSyncPresent && task.index == len(txs)-1 { + res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config, true) + } else { + res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config, false) + } if err != nil { results[task.index] = &txTraceResult{Error: err.Error()} continue @@ -650,7 +727,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) { // If we're tracing a single transaction, make sure it's present if config != nil && config.TxHash != (common.Hash{}) { - if !containsTx(block, config.TxHash) { + if !api.containsTx(ctx, block, config.TxHash) { return nil, fmt.Errorf("transaction %#x not found in block", config.TxHash) } } @@ -705,7 +782,8 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block canon = false } } - for i, tx := range block.Transactions() { + txs, stateSyncPresent := api.getAllBlockTransactions(ctx, block) + for i, tx := range txs { // Prepare the trasaction for un-traced execution var ( msg, _ = tx.AsMessage(signer, block.BaseFee()) @@ -739,10 +817,19 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block // Execute the transaction and flush any traces to disk vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf) statedb.Prepare(tx.Hash(), i) - _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())) - if writer != nil { - writer.Flush() + if stateSyncPresent && i == len(txs)-1 { + callmsg := prepareCallMessage(msg) + _, err = statefull.ApplyBorMessage(*vmenv, callmsg) + if writer != nil { + writer.Flush() + } + } else { + _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())) + if writer != nil { + writer.Flush() + } } + if dump != nil { dump.Close() log.Info("Wrote standard trace", "file", dump.Name()) @@ -764,8 +851,9 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block // containsTx reports whether the transaction with a certain hash // is contained within the specified block. -func containsTx(block *types.Block, hash common.Hash) bool { - for _, tx := range block.Transactions() { +func (api *API) containsTx(ctx context.Context, block *types.Block, hash common.Hash) bool { + txs, _ := api.getAllBlockTransactions(ctx, block) + for _, tx := range txs { if tx.Hash() == hash { return true } @@ -775,7 +863,7 @@ func containsTx(block *types.Block, hash common.Hash) bool { // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. -func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { +func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig, borTx bool) (interface{}, error) { tx, blockHash, blockNumber, index, err := api.backend.GetTransaction(ctx, hash) if tx == nil { // For BorTransaction, there will be no trace available @@ -811,14 +899,14 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * TxIndex: int(index), TxHash: hash, } - return api.traceTx(ctx, msg, txctx, vmctx, statedb, config) + return api.traceTx(ctx, msg, txctx, vmctx, statedb, config, borTx) } // TraceCall lets you trace a given eth_call. It collects the structured logs // created during the execution of EVM if the given transaction was added on // top of the provided block and returns them as a JSON object. // You can provide -2 as a block number to trace on top of the pending block. -func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) { +func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig, borTx bool) (interface{}, error) { // Try to retrieve the specified block var ( err error @@ -865,13 +953,13 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc Reexec: config.Reexec, } } - return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig) + return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig, borTx) } // traceTx configures a new tracer according to the provided configuration, and // executes the given message in the provided environment. The return value will // be tracer dependent. -func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { +func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig, borTx bool) (interface{}, error) { // Assemble the structured logger or the JavaScript tracer var ( tracer vm.EVMLogger @@ -911,9 +999,18 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex // Call Prepare to clear out the statedb access list statedb.Prepare(txctx.TxHash, txctx.TxIndex) - result, err := core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas())) - if err != nil { - return nil, fmt.Errorf("tracing failed: %w", err) + var result *core.ExecutionResult + if borTx { + callmsg := prepareCallMessage(message) + if result, err = statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { + return nil, fmt.Errorf("tracing failed: %w", err) + } + + } else { + result, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas())) + if err != nil { + return nil, fmt.Errorf("tracing failed: %w", err) + } } // Depending on the tracer type, format and return the output. diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index a3c0a72494..32c36f16ee 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -176,6 +176,11 @@ func (b *testBackend) StateAtTransaction(ctx context.Context, block *types.Block return nil, vm.BlockContext{}, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, block.Hash()) } +func (b *testBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { + tx, blockHash, blockNumber, index := rawdb.ReadBorTransactionWithBlockHash(b.ChainDb(), txHash, blockHash) + return tx, blockHash, blockNumber, index, nil +} + func TestTraceCall(t *testing.T) { t.Parallel() @@ -285,7 +290,7 @@ func TestTraceCall(t *testing.T) { }, } for _, testspec := range testSuite { - result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config) + result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config, false) if testspec.expectErr != nil { if err == nil { t.Errorf("Expect error %v, get nothing", testspec.expectErr) @@ -325,7 +330,7 @@ func TestTraceTransaction(t *testing.T) { b.AddTx(tx) target = tx.Hash() })) - result, err := api.TraceTransaction(context.Background(), target, nil) + result, err := api.TraceTransaction(context.Background(), target, nil, false) if err != nil { t.Errorf("Failed to trace transaction %v", err) } @@ -508,7 +513,7 @@ func TestTracingWithOverrides(t *testing.T) { }, } for i, tc := range testSuite { - result, err := api.TraceCall(context.Background(), tc.call, rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, tc.config) + result, err := api.TraceCall(context.Background(), tc.call, rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, tc.config, false) if tc.expectErr != nil { if err == nil { t.Errorf("test %d: want error %v, have nothing", i, tc.expectErr) From ee18b3cd18bb5ec6d435b761f68c34936dfe0c39 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Thu, 13 Oct 2022 15:36:21 +0530 Subject: [PATCH 31/46] chg : major fix --- eth/tracers/api.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 12b1411ae7..c6398d1a8a 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -702,11 +702,22 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac // Generate the next state snapshot fast without tracing msg, _ := tx.AsMessage(signer, block.BaseFee()) statedb.Prepare(tx.Hash(), i) + vmenv := vm.NewEVM(blockCtx, core.NewEVMTxContext(msg), statedb, api.backend.ChainConfig(), vm.Config{}) - if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { - failed = err - break + + if stateSyncPresent && i == len(txs)-1 { + callmsg := prepareCallMessage(msg) + if _, err := statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { + failed = err + break + } + } else { + if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { + failed = err + break + } } + // Finalize the state so any modifications are written to the trie // Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number())) From bfd4f3e74e8f8f2ab3fc1429ec68c9b2f6ffb85a Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Thu, 13 Oct 2022 15:55:45 +0530 Subject: [PATCH 32/46] chg : support state-sync in newcli server debugBorBlock --- eth/tracers/api_bor.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/eth/tracers/api_bor.go b/eth/tracers/api_bor.go index 6ab1a4290a..8993b9ae38 100644 --- a/eth/tracers/api_bor.go +++ b/eth/tracers/api_bor.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/bor/statefull" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -68,14 +69,14 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T // Execute all the transaction contained within the block concurrently var ( - signer = types.MakeSigner(api.backend.ChainConfig(), block.Number()) - txs = block.Transactions() - deleteEmptyObjects = api.backend.ChainConfig().IsEIP158(block.Number()) + signer = types.MakeSigner(api.backend.ChainConfig(), block.Number()) + txs, stateSyncPresent = api.getAllBlockTransactions(ctx, block) + deleteEmptyObjects = api.backend.ChainConfig().IsEIP158(block.Number()) ) blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) - traceTxn := func(indx int, tx *types.Transaction) *TxTraceResult { + traceTxn := func(indx int, tx *types.Transaction, borTx bool) *TxTraceResult { message, _ := tx.AsMessage(signer, block.BaseFee()) txContext := core.NewEVMTxContext(message) @@ -88,7 +89,15 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T // Not sure if we need to do this statedb.Prepare(tx.Hash(), indx) - execRes, err := core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas())) + var execRes *core.ExecutionResult + + if borTx { + callmsg := prepareCallMessage(message) + execRes, err = statefull.ApplyBorMessage(*vmenv, callmsg) + } else { + execRes, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas())) + } + if err != nil { return &TxTraceResult{ Error: err.Error(), @@ -115,7 +124,11 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T } for indx, tx := range txs { - res.Transactions = append(res.Transactions, traceTxn(indx, tx)) + if stateSyncPresent && indx == len(txs)-1 { + res.Transactions = append(res.Transactions, traceTxn(indx, tx, true)) + } else { + res.Transactions = append(res.Transactions, traceTxn(indx, tx, false)) + } } return res, nil From bce66b7ef5352b687d92e373f5da5fc125be1770 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 14 Oct 2022 12:53:46 +0530 Subject: [PATCH 33/46] chg : lint files --- consensus/bor/statefull/processor.go | 3 --- eth/tracers/api.go | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/consensus/bor/statefull/processor.go b/consensus/bor/statefull/processor.go index 192ea5fa38..98ed41ed92 100644 --- a/consensus/bor/statefull/processor.go +++ b/consensus/bor/statefull/processor.go @@ -90,11 +90,9 @@ func ApplyMessage( gasUsed := initialGas - gasLeft return gasUsed, nil - } func ApplyBorMessage(vmenv vm.EVM, msg Callmsg) (*core.ExecutionResult, error) { - initialGas := msg.Gas() // Apply the transaction to the current state (included in the env) @@ -117,5 +115,4 @@ func ApplyBorMessage(vmenv vm.EVM, msg Callmsg) (*core.ExecutionResult, error) { Err: err, ReturnData: ret, }, nil - } diff --git a/eth/tracers/api.go b/eth/tracers/api.go index c6398d1a8a..baf9417b82 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -308,6 +308,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config } var res interface{} + var err error if stateSyncPresent && i == len(txs)-1 { @@ -528,9 +529,8 @@ func (api *API) StandardTraceBlockToFile(ctx context.Context, hash common.Hash, } func prepareCallMessage(msg core.Message) statefull.Callmsg { - return statefull.Callmsg{ - ethereum.CallMsg{ + CallMsg: ethereum.CallMsg{ From: msg.From(), To: msg.To(), Gas: msg.Gas(), @@ -541,7 +541,6 @@ func prepareCallMessage(msg core.Message) statefull.Callmsg { Data: msg.Data(), AccessList: msg.AccessList(), }} - } // IntermediateRoots executes a block (bad- or canon- or side-), and returns a list @@ -577,6 +576,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config vmctx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) deleteEmptyObjects = chainConfig.IsEIP158(block.Number()) ) + txs, stateSyncPresent := api.getAllBlockTransactions(ctx, block) for i, tx := range txs { var ( @@ -585,6 +585,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config vmenv = vm.NewEVM(vmctx, txContext, statedb, chainConfig, vm.Config{}) ) statedb.Prepare(tx.Hash(), i) + if stateSyncPresent && i == len(txs)-1 { callmsg := prepareCallMessage(msg) @@ -598,7 +599,6 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config // N.B: This should never happen while tracing canon blocks, only when tracing bad blocks. return roots, nil } - } else { if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) @@ -677,7 +677,9 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac TxIndex: task.index, TxHash: txs[task.index].Hash(), } + var res interface{} + var err error if stateSyncPresent && task.index == len(txs)-1 { res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config, true) @@ -793,6 +795,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block canon = false } } + txs, stateSyncPresent := api.getAllBlockTransactions(ctx, block) for i, tx := range txs { // Prepare the trasaction for un-traced execution @@ -828,9 +831,11 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block // Execute the transaction and flush any traces to disk vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf) statedb.Prepare(tx.Hash(), i) + if stateSyncPresent && i == len(txs)-1 { callmsg := prepareCallMessage(msg) _, err = statefull.ApplyBorMessage(*vmenv, callmsg) + if writer != nil { writer.Flush() } @@ -910,6 +915,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * TxIndex: int(index), TxHash: hash, } + return api.traceTx(ctx, msg, txctx, vmctx, statedb, config, borTx) } @@ -964,6 +970,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc Reexec: config.Reexec, } } + return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig, borTx) } @@ -1011,12 +1018,12 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex statedb.Prepare(txctx.TxHash, txctx.TxIndex) var result *core.ExecutionResult + if borTx { callmsg := prepareCallMessage(message) if result, err = statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { return nil, fmt.Errorf("tracing failed: %w", err) } - } else { result, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas())) if err != nil { From 967b20ebf782c14c030d4e3e96fb8df89d8d7718 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Oct 2022 04:41:49 +0530 Subject: [PATCH 34/46] chg : major fix --- eth/tracers/api.go | 123 +++++++++++++++++++++++++++++----------- eth/tracers/api_test.go | 6 +- 2 files changed, 94 insertions(+), 35 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index baf9417b82..135f1156cd 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -191,9 +191,11 @@ func (api *API) getAllBlockTransactions(ctx context.Context, block *types.Block) // TraceConfig holds extra parameters to trace functions. type TraceConfig struct { *logger.Config - Tracer *string - Timeout *string - Reexec *uint64 + Tracer *string + Timeout *string + Reexec *uint64 + BorTraceEnabled *bool + BorTx *bool } // TraceCallConfig is the config for traceCall API. It holds one more @@ -209,8 +211,9 @@ type TraceCallConfig struct { // StdTraceConfig holds extra parameters to standard-json trace functions. type StdTraceConfig struct { logger.Config - Reexec *uint64 - TxHash common.Hash + Reexec *uint64 + TxHash common.Hash + BorTrace *bool } // txTraceResult is the result of a single transaction trace. @@ -264,6 +267,11 @@ func (api *API) TraceChain(ctx context.Context, start, end rpc.BlockNumber, conf // executes all the transactions contained within. The return value will be one item // per transaction, dependent on the requested tracer. func (api *API) traceChain(ctx context.Context, start, end *types.Block, config *TraceConfig) (*rpc.Subscription, error) { + if config == nil { + config = &TraceConfig{ + BorTraceEnabled: newBoolPtr(false), + } + } // Tracing a chain is a **long** operation, only do with subscriptions notifier, supported := rpc.NotifierFromContext(ctx) if !supported { @@ -312,9 +320,14 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config var err error if stateSyncPresent && i == len(txs)-1 { - res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config, true) + if *config.BorTraceEnabled { + config.BorTx = newBoolPtr(true) + res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config) + } else { + break + } } else { - res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config, false) + res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config) } if err != nil { @@ -466,6 +479,11 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config return sub, nil } +func newBoolPtr(bb bool) *bool { + b := bb + return &b +} + // TraceBlockByNumber returns the structured logs created during the execution of // EVM and returns them as a JSON object. func (api *API) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *TraceConfig) ([]*txTraceResult, error) { @@ -546,6 +564,12 @@ func prepareCallMessage(msg core.Message) statefull.Callmsg { // IntermediateRoots executes a block (bad- or canon- or side-), and returns a list // of intermediate roots: the stateroot after each transaction. func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config *TraceConfig) ([]common.Hash, error) { + if config == nil { + config = &TraceConfig{ + BorTraceEnabled: newBoolPtr(false), + } + } + block, _ := api.blockByHash(ctx, hash) if block == nil { // Check in the bad blocks @@ -587,18 +611,23 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config statedb.Prepare(tx.Hash(), i) if stateSyncPresent && i == len(txs)-1 { - callmsg := prepareCallMessage(msg) + if *config.BorTraceEnabled { + callmsg := prepareCallMessage(msg) - if _, err := statefull.ApplyMessage(ctx, callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx)); err != nil { - log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) - // We intentionally don't return the error here: if we do, then the RPC server will not - // return the roots. Most likely, the caller already knows that a certain transaction fails to - // be included, but still want the intermediate roots that led to that point. - // It may happen the tx_N causes an erroneous state, which in turn causes tx_N+M to not be - // executable. - // N.B: This should never happen while tracing canon blocks, only when tracing bad blocks. - return roots, nil + if _, err := statefull.ApplyMessage(ctx, callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx)); err != nil { + log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) + // We intentionally don't return the error here: if we do, then the RPC server will not + // return the roots. Most likely, the caller already knows that a certain transaction fails to + // be included, but still want the intermediate roots that led to that point. + // It may happen the tx_N causes an erroneous state, which in turn causes tx_N+M to not be + // executable. + // N.B: This should never happen while tracing canon blocks, only when tracing bad blocks. + return roots, nil + } + } else { + break } + } else { if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) @@ -635,6 +664,13 @@ func (api *API) StandardTraceBadBlockToFile(ctx context.Context, hash common.Has // executes all the transactions contained within. The return value will be one item // per transaction, dependent on the requestd tracer. func (api *API) traceBlock(ctx context.Context, block *types.Block, config *TraceConfig) ([]*txTraceResult, error) { + + if config == nil { + config = &TraceConfig{ + BorTraceEnabled: newBoolPtr(false), + } + } + if block.NumberU64() == 0 { return nil, errors.New("genesis is not traceable") } @@ -682,9 +718,14 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac var err error if stateSyncPresent && task.index == len(txs)-1 { - res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config, true) + if *config.BorTraceEnabled { + config.BorTx = newBoolPtr(true) + res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config) + } else { + break + } } else { - res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config, false) + res, err = api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config) } if err != nil { results[task.index] = &txTraceResult{Error: err.Error()} @@ -708,9 +749,13 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac vmenv := vm.NewEVM(blockCtx, core.NewEVMTxContext(msg), statedb, api.backend.ChainConfig(), vm.Config{}) if stateSyncPresent && i == len(txs)-1 { - callmsg := prepareCallMessage(msg) - if _, err := statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { - failed = err + if *config.BorTraceEnabled { + callmsg := prepareCallMessage(msg) + if _, err := statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { + failed = err + break + } + } else { break } } else { @@ -738,6 +783,11 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac // and traces either a full block or an individual transaction. The return value will // be one filename per transaction traced. func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) { + if config == nil { + config = &StdTraceConfig{ + BorTrace: newBoolPtr(false), + } + } // If we're tracing a single transaction, make sure it's present if config != nil && config.TxHash != (common.Hash{}) { if !api.containsTx(ctx, block, config.TxHash) { @@ -833,11 +883,15 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block statedb.Prepare(tx.Hash(), i) if stateSyncPresent && i == len(txs)-1 { - callmsg := prepareCallMessage(msg) - _, err = statefull.ApplyBorMessage(*vmenv, callmsg) + if *config.BorTrace { + callmsg := prepareCallMessage(msg) + _, err = statefull.ApplyBorMessage(*vmenv, callmsg) - if writer != nil { - writer.Flush() + if writer != nil { + writer.Flush() + } + } else { + break } } else { _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())) @@ -879,7 +933,12 @@ func (api *API) containsTx(ctx context.Context, block *types.Block, hash common. // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. -func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig, borTx bool) (interface{}, error) { +func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { + if config == nil { + config = &TraceConfig{ + BorTraceEnabled: newBoolPtr(false), + } + } tx, blockHash, blockNumber, index, err := api.backend.GetTransaction(ctx, hash) if tx == nil { // For BorTransaction, there will be no trace available @@ -916,14 +975,14 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * TxHash: hash, } - return api.traceTx(ctx, msg, txctx, vmctx, statedb, config, borTx) + return api.traceTx(ctx, msg, txctx, vmctx, statedb, config) } // TraceCall lets you trace a given eth_call. It collects the structured logs // created during the execution of EVM if the given transaction was added on // top of the provided block and returns them as a JSON object. // You can provide -2 as a block number to trace on top of the pending block. -func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig, borTx bool) (interface{}, error) { +func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) { // Try to retrieve the specified block var ( err error @@ -971,13 +1030,13 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc } } - return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig, borTx) + return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig) } // traceTx configures a new tracer according to the provided configuration, and // executes the given message in the provided environment. The return value will // be tracer dependent. -func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig, borTx bool) (interface{}, error) { +func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { // Assemble the structured logger or the JavaScript tracer var ( tracer vm.EVMLogger @@ -1019,7 +1078,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex var result *core.ExecutionResult - if borTx { + if *config.BorTx { callmsg := prepareCallMessage(message) if result, err = statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { return nil, fmt.Errorf("tracing failed: %w", err) diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 32c36f16ee..aa9f913396 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -290,7 +290,7 @@ func TestTraceCall(t *testing.T) { }, } for _, testspec := range testSuite { - result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config, false) + result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config) if testspec.expectErr != nil { if err == nil { t.Errorf("Expect error %v, get nothing", testspec.expectErr) @@ -330,7 +330,7 @@ func TestTraceTransaction(t *testing.T) { b.AddTx(tx) target = tx.Hash() })) - result, err := api.TraceTransaction(context.Background(), target, nil, false) + result, err := api.TraceTransaction(context.Background(), target, nil) if err != nil { t.Errorf("Failed to trace transaction %v", err) } @@ -513,7 +513,7 @@ func TestTracingWithOverrides(t *testing.T) { }, } for i, tc := range testSuite { - result, err := api.TraceCall(context.Background(), tc.call, rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, tc.config, false) + result, err := api.TraceCall(context.Background(), tc.call, rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, tc.config) if tc.expectErr != nil { if err == nil { t.Errorf("test %d: want error %v, have nothing", i, tc.expectErr) From 06a8f2870337dc84ea238ab616fd61c1080fa08b Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Oct 2022 04:56:21 +0530 Subject: [PATCH 35/46] chg : minor fix --- eth/tracers/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 135f1156cd..c5ba6b9779 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -270,6 +270,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config if config == nil { config = &TraceConfig{ BorTraceEnabled: newBoolPtr(false), + BorTx: newBoolPtr(false), } } // Tracing a chain is a **long** operation, only do with subscriptions @@ -567,6 +568,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config if config == nil { config = &TraceConfig{ BorTraceEnabled: newBoolPtr(false), + BorTx: newBoolPtr(false), } } @@ -668,6 +670,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac if config == nil { config = &TraceConfig{ BorTraceEnabled: newBoolPtr(false), + BorTx: newBoolPtr(false), } } @@ -937,6 +940,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * if config == nil { config = &TraceConfig{ BorTraceEnabled: newBoolPtr(false), + BorTx: newBoolPtr(false), } } tx, blockHash, blockNumber, index, err := api.backend.GetTransaction(ctx, hash) @@ -1078,6 +1082,10 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex var result *core.ExecutionResult + if config.BorTx == nil { + config.BorTx = newBoolPtr(false) + } + if *config.BorTx { callmsg := prepareCallMessage(message) if result, err = statefull.ApplyBorMessage(*vmenv, callmsg); err != nil { From 5e574bf129aef96dc7f0f88ef7ed9021ee2a177d Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Oct 2022 05:38:45 +0530 Subject: [PATCH 36/46] chg : fix derference error on config without borTraceEnabled --- eth/tracers/api.go | 47 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index c5ba6b9779..4534f4675f 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -65,6 +65,8 @@ const ( defaultTracechainMemLimit = common.StorageSize(500 * 1024 * 1024) ) +var defaultBorTraceEnabled = newBoolPtr(false) + // Backend interface provides the common API services (that are provided by // both full and light clients) with access to necessary functions. type Backend interface { @@ -269,10 +271,13 @@ func (api *API) TraceChain(ctx context.Context, start, end rpc.BlockNumber, conf func (api *API) traceChain(ctx context.Context, start, end *types.Block, config *TraceConfig) (*rpc.Subscription, error) { if config == nil { config = &TraceConfig{ - BorTraceEnabled: newBoolPtr(false), + BorTraceEnabled: defaultBorTraceEnabled, BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { + config.BorTraceEnabled = defaultBorTraceEnabled + } // Tracing a chain is a **long** operation, only do with subscriptions notifier, supported := rpc.NotifierFromContext(ctx) if !supported { @@ -308,6 +313,10 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config blockCtx := core.NewEVMBlockContext(task.block.Header(), api.chainContext(localctx), nil) // Trace all the transactions contained within txs, stateSyncPresent := api.getAllBlockTransactions(ctx, task.block) + if !*config.BorTraceEnabled && stateSyncPresent { + txs = txs[:len(txs)-1] + stateSyncPresent = false + } for i, tx := range txs { msg, _ := tx.AsMessage(signer, task.block.BaseFee()) txctx := &Context{ @@ -324,8 +333,6 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config if *config.BorTraceEnabled { config.BorTx = newBoolPtr(true) res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config) - } else { - break } } else { res, err = api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config) @@ -567,10 +574,13 @@ func prepareCallMessage(msg core.Message) statefull.Callmsg { func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config *TraceConfig) ([]common.Hash, error) { if config == nil { config = &TraceConfig{ - BorTraceEnabled: newBoolPtr(false), + BorTraceEnabled: defaultBorTraceEnabled, BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { + config.BorTraceEnabled = defaultBorTraceEnabled + } block, _ := api.blockByHash(ctx, hash) if block == nil { @@ -669,10 +679,13 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac if config == nil { config = &TraceConfig{ - BorTraceEnabled: newBoolPtr(false), + BorTraceEnabled: defaultBorTraceEnabled, BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { + config.BorTraceEnabled = defaultBorTraceEnabled + } if block.NumberU64() == 0 { return nil, errors.New("genesis is not traceable") @@ -779,7 +792,12 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac if failed != nil { return nil, failed } - return results, nil + + if !*config.BorTraceEnabled && stateSyncPresent { + return results[:len(results)-1], nil + } else { + return results, nil + } } // standardTraceBlockToFile configures a new tracer which uses standard JSON output, @@ -939,10 +957,14 @@ func (api *API) containsTx(ctx context.Context, block *types.Block, hash common. func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { if config == nil { config = &TraceConfig{ - BorTraceEnabled: newBoolPtr(false), + BorTraceEnabled: defaultBorTraceEnabled, BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { + config.BorTraceEnabled = defaultBorTraceEnabled + } + tx, blockHash, blockNumber, index, err := api.backend.GetTransaction(ctx, hash) if tx == nil { // For BorTransaction, there will be no trace available @@ -1041,6 +1063,17 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc // executes the given message in the provided environment. The return value will // be tracer dependent. func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { + + if config == nil { + config = &TraceConfig{ + BorTraceEnabled: defaultBorTraceEnabled, + BorTx: newBoolPtr(false), + } + } + if config.BorTraceEnabled == nil { + config.BorTraceEnabled = defaultBorTraceEnabled + } + // Assemble the structured logger or the JavaScript tracer var ( tracer vm.EVMLogger From 3a0cedc4b17ee3402cc5269452871ccb931ed5ab Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Oct 2022 06:26:43 +0530 Subject: [PATCH 37/46] chg : standardTraceBlockToFile fix --- eth/tracers/api.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 4534f4675f..ad52373038 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -213,9 +213,9 @@ type TraceCallConfig struct { // StdTraceConfig holds extra parameters to standard-json trace functions. type StdTraceConfig struct { logger.Config - Reexec *uint64 - TxHash common.Hash - BorTrace *bool + Reexec *uint64 + TxHash common.Hash + BorTraceEnabled *bool } // txTraceResult is the result of a single transaction trace. @@ -806,9 +806,12 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) { if config == nil { config = &StdTraceConfig{ - BorTrace: newBoolPtr(false), + BorTraceEnabled: defaultBorTraceEnabled, } } + if config.BorTraceEnabled == nil { + config.BorTraceEnabled = defaultBorTraceEnabled + } // If we're tracing a single transaction, make sure it's present if config != nil && config.TxHash != (common.Hash{}) { if !api.containsTx(ctx, block, config.TxHash) { @@ -868,6 +871,11 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block } txs, stateSyncPresent := api.getAllBlockTransactions(ctx, block) + if !*config.BorTraceEnabled && stateSyncPresent { + txs = txs[:len(txs)-1] + stateSyncPresent = false + } + for i, tx := range txs { // Prepare the trasaction for un-traced execution var ( @@ -904,15 +912,13 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block statedb.Prepare(tx.Hash(), i) if stateSyncPresent && i == len(txs)-1 { - if *config.BorTrace { + if *config.BorTraceEnabled { callmsg := prepareCallMessage(msg) _, err = statefull.ApplyBorMessage(*vmenv, callmsg) if writer != nil { writer.Flush() } - } else { - break } } else { _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())) From 2ec9e7b540bf94f0cb23bed54baa666f5beafd0d Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Oct 2022 06:49:01 +0530 Subject: [PATCH 38/46] add : lint --- eth/tracers/api.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index ad52373038..3fce91ac9c 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -275,6 +275,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { config.BorTraceEnabled = defaultBorTraceEnabled } @@ -317,6 +318,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config txs = txs[:len(txs)-1] stateSyncPresent = false } + for i, tx := range txs { msg, _ := tx.AsMessage(signer, task.block.BaseFee()) txctx := &Context{ @@ -578,6 +580,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { config.BorTraceEnabled = defaultBorTraceEnabled } @@ -621,7 +624,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config vmenv = vm.NewEVM(vmctx, txContext, statedb, chainConfig, vm.Config{}) ) statedb.Prepare(tx.Hash(), i) - + //nolint: nestif if stateSyncPresent && i == len(txs)-1 { if *config.BorTraceEnabled { callmsg := prepareCallMessage(msg) @@ -639,7 +642,6 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config } else { break } - } else { if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) @@ -683,6 +685,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { config.BorTraceEnabled = defaultBorTraceEnabled } @@ -733,6 +736,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac var res interface{} var err error + if stateSyncPresent && task.index == len(txs)-1 { if *config.BorTraceEnabled { config.BorTx = newBoolPtr(true) @@ -763,7 +767,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac statedb.Prepare(tx.Hash(), i) vmenv := vm.NewEVM(blockCtx, core.NewEVMTxContext(msg), statedb, api.backend.ChainConfig(), vm.Config{}) - + //nolint: nestif if stateSyncPresent && i == len(txs)-1 { if *config.BorTraceEnabled { callmsg := prepareCallMessage(msg) @@ -809,6 +813,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block BorTraceEnabled: defaultBorTraceEnabled, } } + if config.BorTraceEnabled == nil { config.BorTraceEnabled = defaultBorTraceEnabled } @@ -910,7 +915,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block // Execute the transaction and flush any traces to disk vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf) statedb.Prepare(tx.Hash(), i) - + //nolint: nestif if stateSyncPresent && i == len(txs)-1 { if *config.BorTraceEnabled { callmsg := prepareCallMessage(msg) @@ -967,6 +972,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { config.BorTraceEnabled = defaultBorTraceEnabled } @@ -1076,6 +1082,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex BorTx: newBoolPtr(false), } } + if config.BorTraceEnabled == nil { config.BorTraceEnabled = defaultBorTraceEnabled } From 0bc9f60756a63a4199a4bdadb3c1185e258257b6 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 1 Nov 2022 17:00:41 -0700 Subject: [PATCH 39/46] Remove context from ApplyMessage --- eth/tracers/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 3fce91ac9c..36296e0d42 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -629,7 +629,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config if *config.BorTraceEnabled { callmsg := prepareCallMessage(msg) - if _, err := statefull.ApplyMessage(ctx, callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx)); err != nil { + if _, err := statefull.ApplyMessage(callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx)); err != nil { log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", tx.Hash(), "err", err) // We intentionally don't return the error here: if we do, then the RPC server will not // return the roots. Most likely, the caller already knows that a certain transaction fails to From 8cc0b25353df448f4e09c043981e1752fa8236d5 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 4 Nov 2022 01:24:57 +0530 Subject: [PATCH 40/46] Removed vhosts for ws and replaced cors with origins (#574) * removed vhosts for ws and added replaced cors with origins * updated script --- builder/files/config.toml | 3 +-- docs/cli/server.md | 6 +++--- internal/cli/server/config.go | 8 +++++--- internal/cli/server/flags.go | 15 ++++----------- scripts/getconfig.go | 10 ++++------ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/builder/files/config.toml b/builder/files/config.toml index 0d01f85d71..8f70f62a13 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -78,8 +78,7 @@ syncmode = "full" # prefix = "" # host = "localhost" # api = ["web3", "net"] - # vhosts = ["*"] - # corsdomain = ["*"] + # origins = ["*"] # [jsonrpc.graphql] # enabled = false # port = 0 diff --git a/docs/cli/server.md b/docs/cli/server.md index 5fe440b5fd..d52b135fa3 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -80,6 +80,8 @@ The ```bor server``` command runs the Bor client. - ```cache.preimages```: Enable recording the SHA3/keccak preimages of trie keys +- ```cache.triesinmemory```: Number of block states (tries) to keep in memory (default = 128) + - ```txlookuplimit```: Number of recent blocks to maintain transactions index for (default = about 56 days, 0 = entire chain) ### JsonRPC Options @@ -96,9 +98,7 @@ The ```bor server``` command runs the Bor client. - ```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. +- ```ws.origins```: Origins from which to accept websockets requests - ```graphql.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 86b611ac78..7070afca24 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -263,6 +263,9 @@ type APIConfig struct { // Cors is the list of Cors endpoints Cors []string `hcl:"corsdomain,optional" toml:"corsdomain,optional"` + + // Origins is the list of endpoints to accept requests from (only consumed for websockets) + Origins []string `hcl:"origins,optional" toml:"origins,optional"` } type GpoConfig struct { @@ -466,8 +469,7 @@ func DefaultConfig() *Config { Prefix: "", Host: "localhost", API: []string{"net", "web3"}, - Cors: []string{"localhost"}, - VHost: []string{"localhost"}, + Origins: []string{"localhost"}, }, Graphql: &APIConfig{ Enabled: false, @@ -921,7 +923,7 @@ func (c *Config) buildNode() (*node.Config, error) { HTTPVirtualHosts: c.JsonRPC.Http.VHost, HTTPPathPrefix: c.JsonRPC.Http.Prefix, WSModules: c.JsonRPC.Ws.API, - WSOrigins: c.JsonRPC.Ws.Cors, + WSOrigins: c.JsonRPC.Ws.Origins, WSPathPrefix: c.JsonRPC.Ws.Prefix, GraphQLCors: c.JsonRPC.Graphql.Cors, GraphQLVirtualHosts: c.JsonRPC.Graphql.VHost, diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index ec74f89991..79aec3157a 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -350,17 +350,10 @@ func (c *Command) Flags() *flagset.Flagset { 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, + Name: "ws.origins", + Usage: "Origins from which to accept websockets requests", + Value: &c.cliConfig.JsonRPC.Ws.Origins, + Default: c.cliConfig.JsonRPC.Ws.Origins, Group: "JsonRPC", }) f.SliceStringFlag(&flagset.SliceStringFlag{ diff --git a/scripts/getconfig.go b/scripts/getconfig.go index 136b69ecab..caf3f45a8e 100644 --- a/scripts/getconfig.go +++ b/scripts/getconfig.go @@ -95,7 +95,7 @@ var flagMap = map[string][]string{ "override.arrowglacier": {"notABoolFlag", "No"}, "override.terminaltotaldifficulty": {"notABoolFlag", "No"}, "verbosity": {"notABoolFlag", "YesFV"}, - "ws.origins": {"notABoolFlag", "YesF"}, + "ws.origins": {"notABoolFlag", "No"}, } // map from cli flags to corresponding toml tags @@ -150,8 +150,7 @@ var nameTagMap = map[string]string{ "ipcpath": "ipcpath", "1-corsdomain": "http.corsdomain", "1-vhosts": "http.vhosts", - "2-corsdomain": "ws.corsdomain", - "2-vhosts": "ws.vhosts", + "origins": "ws.origins", "3-corsdomain": "graphql.corsdomain", "3-vhosts": "graphql.vhosts", "1-enabled": "http", @@ -226,9 +225,8 @@ var replacedFlagsMapFlagAndValue = map[string]map[string]map[string]string{ }, } -var replacedFlagsMapFlag = map[string]string{ - "ws.origins": "ws.corsdomain", -} +// Do not remove +var replacedFlagsMapFlag = map[string]string{} var currentBoolFlags = []string{ "snapshot", From 06c8ca661198eef3254989550a2ce8b102a17af8 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Sun, 20 Nov 2022 21:47:00 +0530 Subject: [PATCH 41/46] fix unused imports --- cmd/geth/config.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index d152dcbc87..80bf95b1ac 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "math/big" "os" "time" @@ -26,8 +25,6 @@ import ( "github.com/BurntSushi/toml" "gopkg.in/urfave/cli.v1" - "github.com/BurntSushi/toml" - "github.com/ethereum/go-ethereum/accounts/external" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/scwallet" From ac0593d6e17d440c9bbd8e8d349b81b97cd31a38 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 22 Nov 2022 01:20:09 +0530 Subject: [PATCH 42/46] mumbai fork - 13th dewc --- builder/files/genesis-testnet-v4.json | 13 +++++++++---- internal/cli/server/chains/mumbai.go | 9 +++++++-- .../chains/test_files/chain_legacy_test.json | 15 ++++++++++----- .../cli/server/chains/test_files/chain_test.json | 15 ++++++++++----- params/config.go | 9 +++++++-- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/builder/files/genesis-testnet-v4.json b/builder/files/genesis-testnet-v4.json index 8a0af45088..fe066411a3 100644 --- a/builder/files/genesis-testnet-v4.json +++ b/builder/files/genesis-testnet-v4.json @@ -15,19 +15,24 @@ "londonBlock": 22640000, "bor": { "jaipurBlock": 22770000, + "delhiBlock": 29638656, "period": { "0": 2, - "25275000": 5 + "25275000": 5, + "29638656": 2 }, "producerDelay": { - "0": 6 + "0": 6, + "29638656": 4 }, "sprint": { - "0": 64 + "0": 64, + "29638656": 16 }, "backupMultiplier": { "0": 2, - "25275000": 5 + "25275000": 5, + "29638656": 2 }, "validatorContract": "0x0000000000000000000000000000000000001000", "stateReceiverContract": "0x0000000000000000000000000000000000001001", diff --git a/internal/cli/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go index 3858ad68d6..64a5b80060 100644 --- a/internal/cli/server/chains/mumbai.go +++ b/internal/cli/server/chains/mumbai.go @@ -30,19 +30,24 @@ var mumbaiTestnet = &Chain{ LondonBlock: big.NewInt(22640000), Bor: ¶ms.BorConfig{ JaipurBlock: big.NewInt(22770000), + DelhiBlock: big.NewInt(29638656), Period: map[string]uint64{ "0": 2, "25275000": 5, + "29638656": 2, }, ProducerDelay: map[string]uint64{ - "0": 6, + "0": 6, + "29638656": 4, }, Sprint: map[string]uint64{ - "0": 64, + "0": 64, + "29638656": 16, }, BackupMultiplier: map[string]uint64{ "0": 2, "25275000": 5, + "29638656": 2, }, ValidatorContract: "0x0000000000000000000000000000000000001000", StateReceiverContract: "0x0000000000000000000000000000000000001001", diff --git a/internal/cli/server/chains/test_files/chain_legacy_test.json b/internal/cli/server/chains/test_files/chain_legacy_test.json index 7adf825b0e..b97c8b1f8e 100644 --- a/internal/cli/server/chains/test_files/chain_legacy_test.json +++ b/internal/cli/server/chains/test_files/chain_legacy_test.json @@ -17,17 +17,21 @@ "bor": { "period": { "0": 2, - "25275000": 5 + "25275000": 5, + "29638656": 2 }, "producerDelay": { - "0": 6 + "0": 6, + "29638656": 4 }, "sprint": { - "0": 64 + "0": 64, + "29638656": 16 }, "backupMultiplier": { "0": 2, - "25275000": 5 + "25275000": 5, + "29638656": 2 }, "validatorContract": "0x0000000000000000000000000000000000001000", "stateReceiverContract": "0x0000000000000000000000000000000000001001", @@ -43,7 +47,8 @@ "burntContract": { "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38" }, - "jaipurBlock": 22770000 + "jaipurBlock": 22770000, + "delhiBlock": 29638656 } }, "nonce": "0x0", diff --git a/internal/cli/server/chains/test_files/chain_test.json b/internal/cli/server/chains/test_files/chain_test.json index 9dc949e6f2..7907adfcfa 100644 --- a/internal/cli/server/chains/test_files/chain_test.json +++ b/internal/cli/server/chains/test_files/chain_test.json @@ -19,17 +19,21 @@ "bor":{ "period":{ "0":2, - "25275000": 5 + "25275000": 5, + "29638656": 2 }, "producerDelay":{ - "0": 6 + "0": 6, + "29638656": 4 }, "sprint":{ - "0": 64 + "0": 64, + "29638656": 16 }, "backupMultiplier":{ "0": 2, - "25275000": 5 + "25275000": 5, + "29638656": 2 }, "validatorContract":"0x0000000000000000000000000000000000001000", "stateReceiverContract":"0x0000000000000000000000000000000000001001", @@ -45,7 +49,8 @@ "burntContract":{ "22640000":"0x70bcA57F4579f58670aB2d18Ef16e02C17553C38" }, - "jaipurBlock":22770000 + "jaipurBlock":22770000, + "delhiBlock": 29638656 } }, "nonce":"0x0", diff --git a/params/config.go b/params/config.go index a480218e22..d97d6957fa 100644 --- a/params/config.go +++ b/params/config.go @@ -350,19 +350,24 @@ var ( LondonBlock: big.NewInt(22640000), Bor: &BorConfig{ JaipurBlock: big.NewInt(22770000), + DelhiBlock: big.NewInt(29638656), Period: map[string]uint64{ "0": 2, "25275000": 5, + "29638656": 2, }, ProducerDelay: map[string]uint64{ - "0": 6, + "0": 6, + "29638656": 4, }, Sprint: map[string]uint64{ - "0": 64, + "0": 64, + "29638656": 16, }, BackupMultiplier: map[string]uint64{ "0": 2, "25275000": 5, + "29638656": 2, }, ValidatorContract: "0x0000000000000000000000000000000000001000", StateReceiverContract: "0x0000000000000000000000000000000000001001", From 8ca3251aab76a498a9a5135209558ae950bc99d4 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 22 Nov 2022 01:27:22 +0530 Subject: [PATCH 43/46] version change --- params/version.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/params/version.go b/params/version.go index abb840e986..64b58283bb 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 0 // Major version component of the current release - VersionMinor = 3 // Minor version component of the current release - VersionPatch = 1 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 0 // Major version component of the current release + VersionMinor = 3 // Minor version component of the current release + VersionPatch = 1 // Patch version component of the current release + VersionMeta = "mumbai" // Version metadata to append to the version string ) // Version holds the textual version string. From be58978cdcb78a5c23ab9b4ac68916eb6533835b Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 22 Nov 2022 12:20:57 +0530 Subject: [PATCH 44/46] revert some changes --- cmd/utils/flags.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a263e5ef56..5de9c982d4 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -250,13 +250,13 @@ var ( Name: "lightkdf", Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", } - EthRequiredBlocksFlag = cli.StringFlag{ + EthPeerRequiredBlocksFlag = cli.StringFlag{ Name: "eth.requiredblocks", Usage: "Comma separated block number-to-hash mappings to require for peering (=)", } LegacyWhitelistFlag = cli.StringFlag{ Name: "whitelist", - Usage: "Comma separated block number-to-hash mappings to enforce (=) (deprecated in favor of --eth.requiredblocks)", + Usage: "Comma separated block number-to-hash mappings to enforce (=) (deprecated in favor of --peer.requiredblocks)", } BloomFilterSizeFlag = cli.Uint64Flag{ Name: "bloomfilter.size", @@ -1499,20 +1499,20 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) { } } -func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { - requiredBlocks := ctx.GlobalString(EthRequiredBlocksFlag.Name) +func setPeerRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { + peerRequiredBlocks := ctx.GlobalString(EthPeerRequiredBlocksFlag.Name) - if requiredBlocks == "" { + if peerRequiredBlocks == "" { if ctx.GlobalIsSet(LegacyWhitelistFlag.Name) { log.Warn("The flag --whitelist is deprecated and will be removed, please use --eth.requiredblocks") - requiredBlocks = ctx.GlobalString(LegacyWhitelistFlag.Name) + peerRequiredBlocks = ctx.GlobalString(LegacyWhitelistFlag.Name) } else { return } } cfg.PeerRequiredBlocks = make(map[uint64]common.Hash) - for _, entry := range strings.Split(requiredBlocks, ",") { + for _, entry := range strings.Split(peerRequiredBlocks, ",") { parts := strings.Split(entry, "=") if len(parts) != 2 { Fatalf("Invalid required block entry: %s", entry) @@ -1592,7 +1592,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { setTxPool(ctx, &cfg.TxPool) setEthash(ctx, cfg) setMiner(ctx, &cfg.Miner) - setRequiredBlocks(ctx, cfg) + setPeerRequiredBlocks(ctx, cfg) setLes(ctx, cfg) if ctx.GlobalIsSet(BorLogsFlag.Name) { From d89759c3185ce59adf0d3086826ee513e45ca0be Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 22 Nov 2022 12:22:22 +0530 Subject: [PATCH 45/46] fix issues --- cmd/geth/main.go | 2 +- cmd/geth/usage.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index af565d71ae..600e929706 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -109,7 +109,7 @@ var ( utils.UltraLightFractionFlag, utils.UltraLightOnlyAnnounceFlag, utils.LightNoSyncServeFlag, - utils.EthRequiredBlocksFlag, + utils.EthPeerRequiredBlocksFlag, utils.LegacyWhitelistFlag, utils.BloomFilterSizeFlag, utils.CacheFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 28f8f84533..af5175cd63 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -56,7 +56,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.EthStatsURLFlag, utils.IdentityFlag, utils.LightKDFFlag, - utils.EthRequiredBlocksFlag, + utils.EthPeerRequiredBlocksFlag, }, }, { From 7ae5bce4d522c060ce89a74c723f8b7f6dad7c90 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 22 Nov 2022 12:28:57 +0530 Subject: [PATCH 46/46] minor refactor --- cmd/utils/flags.go | 6 +++--- eth/ethconfig/config.go | 2 +- eth/ethconfig/gen_config.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5de9c982d4..81ce27ef4c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1515,15 +1515,15 @@ func setPeerRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { for _, entry := range strings.Split(peerRequiredBlocks, ",") { parts := strings.Split(entry, "=") if len(parts) != 2 { - Fatalf("Invalid required block entry: %s", entry) + Fatalf("Invalid peer required block entry: %s", entry) } number, err := strconv.ParseUint(parts[0], 0, 64) if err != nil { - Fatalf("Invalid required block number %s: %v", parts[0], err) + Fatalf("Invalid peer required block number %s: %v", parts[0], err) } var hash common.Hash if err = hash.UnmarshalText([]byte(parts[1])); err != nil { - Fatalf("Invalid required block hash %s: %v", parts[1], err) + Fatalf("Invalid peer required block hash %s: %v", parts[1], err) } cfg.PeerRequiredBlocks[number] = hash } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 8089794948..c9272758ab 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -144,7 +144,7 @@ type Config struct { TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. - // RequiredBlocks is a set of block number -> hash mappings which must be in the + // PeerRequiredBlocks is a set of block number -> hash mappings which must be in the // canonical chain of all remote peers. Setting the option makes geth verify the // presence of these blocks for every new peer connection. PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index fdb6fe11e1..874e30dffd 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -26,7 +26,7 @@ func (c Config) MarshalTOML() (interface{}, error) { NoPruning bool NoPrefetch bool TxLookupLimit uint64 `toml:",omitempty"` - PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` + PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` LightServ int `toml:",omitempty"` LightIngress int `toml:",omitempty"` LightEgress int `toml:",omitempty"` @@ -120,7 +120,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { NoPruning *bool NoPrefetch *bool TxLookupLimit *uint64 `toml:",omitempty"` - PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` + PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` LightServ *int `toml:",omitempty"` LightIngress *int `toml:",omitempty"` LightEgress *int `toml:",omitempty"`