Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/cli/server: fix flag behaviour #529

Merged
merged 9 commits into from
Sep 27, 2022
7 changes: 3 additions & 4 deletions internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,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: "",
Expand Down Expand Up @@ -996,8 +996,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
pratikspatil024 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
151 changes: 16 additions & 135 deletions internal/cli/server/config_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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: 1,
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)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,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 != "" {
Expand Down Expand Up @@ -346,6 +348,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
Expand Down
6 changes: 4 additions & 2 deletions internal/cli/server/testdata/test.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
datadir = "./data"
snapshot = false

["eth.requiredblocks"]
a = "b"
"31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e"
"32000000" = "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68"

[p2p]
maxpeers = 30
Expand All @@ -11,7 +13,7 @@ locals = []
lifetime = "1s"

[miner]
mine = false
mine = true
gaslimit = 30000000
gasprice = "1000000000"

Expand Down
35 changes: 25 additions & 10 deletions scripts/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,27 +445,42 @@ func updateArgsAdd(args []string) []string {
return args
}

func handleGRPC(args []string, updatedArgs []string) []string {
func handlePrometheus(args []string, updatedArgs []string) []string {
var newUpdatedArgs []string

var addr string
mAddr := ""
mPort := ""

var port string
pAddr := ""
pPort := ""

newUpdatedArgs = append(newUpdatedArgs, updatedArgs...)

for i, val := range args {
if strings.Contains(val, "pprof.addr") && strings.Contains(val, "-") {
addr = args[i+1]
if strings.Contains(val, "metrics.addr") && strings.HasPrefix(val, "-") {
mAddr = args[i+1]
}

if strings.Contains(val, "pprof.port") && strings.Contains(val, "-") {
port = 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]
}
}

newUpdatedArgs = append(newUpdatedArgs, "--grpc.addr")
newUpdatedArgs = append(newUpdatedArgs, addr+":"+port)
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
}
Expand Down Expand Up @@ -658,7 +673,7 @@ func main() {
outOfDateFlags := checkFlag(allFlags, flagsToCheck)
updatedArgs := updateArgsClean(args, outOfDateFlags)
updatedArgs = updateArgsAdd(updatedArgs)
updatedArgs = handleGRPC(args, updatedArgs)
updatedArgs = handlePrometheus(args, updatedArgs)

if temp == notYet {
updatedArgs = append(updatedArgs, ignoreForNow...)
Expand Down