From 9c81010b64e7d9ac13a0ff6ca5e376a38bb781d4 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Wed, 24 Jan 2024 15:38:13 +0000 Subject: [PATCH] Add log-level to launcher + fix trace debug (#1757) * Add log-level to launcher + fix trace debug * Update testnet/launcher/cmd/cli.go * pr comments --- go/common/types.go | 3 +++ testnet/launcher/cmd/cli.go | 3 +++ testnet/launcher/cmd/cli_flags.go | 2 ++ testnet/launcher/cmd/main.go | 1 + testnet/launcher/config.go | 8 ++++++++ testnet/launcher/docker.go | 4 ++-- 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/go/common/types.go b/go/common/types.go index 8d126d9eef..e601535aa1 100644 --- a/go/common/types.go +++ b/go/common/types.go @@ -184,6 +184,9 @@ func (cf *ChainFork) IsFork() bool { } func (cf *ChainFork) String() string { + if cf == nil { + return "" + } return fmt.Sprintf("ChainFork{NewCanonical: %s, OldCanonical: %s, CommonAncestor: %s, CanonicalPath: %s, NonCanonicalPath: %s}", cf.NewCanonical.Hash(), cf.OldCanonical.Hash(), cf.CommonAncestor.Hash(), cf.CanonicalPath, cf.NonCanonicalPath) } diff --git a/testnet/launcher/cmd/cli.go b/testnet/launcher/cmd/cli.go index 351379f5b0..6f5469a6af 100644 --- a/testnet/launcher/cmd/cli.go +++ b/testnet/launcher/cmd/cli.go @@ -13,6 +13,7 @@ type TestnetConfigCLI struct { contractDeployerDockerImage string contractDeployerDebug bool isSGXEnabled bool + logLevel int } // ParseConfigCLI returns a NodeConfigCLI based the cli params and defaults. @@ -27,6 +28,7 @@ func ParseConfigCLI() *TestnetConfigCLI { contractDeployerDockerImage := flag.String(contractDeployerDockerImageFlag, "testnetobscuronet.azurecr.io/obscuronet/hardhatdeployer:latest", flagUsageMap[contractDeployerDockerImageFlag]) contractDeployerDebug := flag.Bool(contractDeployerDebugFlag, false, flagUsageMap[contractDeployerDebugFlag]) isSGXEnabled := flag.Bool(isSGXEnabledFlag, false, flagUsageMap[isSGXEnabledFlag]) + logLevel := flag.Int(logLevelFlag, 4, flagUsageMap[logLevelFlag]) flag.Parse() cfg.validatorEnclaveDockerImage = *validatorEnclaveDockerImage @@ -36,6 +38,7 @@ func ParseConfigCLI() *TestnetConfigCLI { cfg.contractDeployerDebug = *contractDeployerDebug cfg.contractDeployerDockerImage = *contractDeployerDockerImage cfg.isSGXEnabled = *isSGXEnabled + cfg.logLevel = *logLevel return cfg } diff --git a/testnet/launcher/cmd/cli_flags.go b/testnet/launcher/cmd/cli_flags.go index 5f5c5cc980..8c6dffe0c1 100644 --- a/testnet/launcher/cmd/cli_flags.go +++ b/testnet/launcher/cmd/cli_flags.go @@ -9,6 +9,7 @@ const ( contractDeployerDockerImageFlag = "contract-deployer-docker-image" contractDeployerDebugFlag = "contract-deployer-debug" isSGXEnabledFlag = "is-sgx-enabled" + logLevelFlag = "log-level" ) // Returns a map of the flag usages. @@ -22,5 +23,6 @@ func getFlagUsageMap() map[string]string { contractDeployerDockerImageFlag: "The docker image that runs the contract deployer", contractDeployerDebugFlag: "Enables the use of node inspector to debug the contract deployer", isSGXEnabledFlag: "Enables the SGX usage", + logLevelFlag: "Log level for all network", } } diff --git a/testnet/launcher/cmd/main.go b/testnet/launcher/cmd/main.go index 576679d504..5947d21bba 100644 --- a/testnet/launcher/cmd/main.go +++ b/testnet/launcher/cmd/main.go @@ -20,6 +20,7 @@ func main() { launcher.WithContractDeployerDebug(cliConfig.contractDeployerDebug), launcher.WithContractDeployerDockerImage(cliConfig.contractDeployerDockerImage), launcher.WithSGXEnabled(cliConfig.isSGXEnabled), + launcher.WithLogLevel(cliConfig.logLevel), ), ) err := testnet.Start() diff --git a/testnet/launcher/config.go b/testnet/launcher/config.go index aba2ee3f39..d8fb2e96bd 100644 --- a/testnet/launcher/config.go +++ b/testnet/launcher/config.go @@ -15,6 +15,8 @@ type Config struct { contractDeployerDebug bool isSGXEnabled bool + + logLevel int } func NewTestnetConfig(opts ...Option) *Config { @@ -68,3 +70,9 @@ func WithContractDeployerDebug(b bool) Option { c.contractDeployerDebug = b } } + +func WithLogLevel(i int) Option { + return func(c *Config) { + c.logLevel = i + } +} diff --git a/testnet/launcher/docker.go b/testnet/launcher/docker.go index 10443d5cb7..8939b12af4 100644 --- a/testnet/launcher/docker.go +++ b/testnet/launcher/docker.go @@ -62,7 +62,7 @@ func (t *Testnet) Start() error { node.WithL1Start(networkConfig.L1StartHash), node.WithInMemoryHostDB(true), node.WithDebugNamespaceEnabled(true), - node.WithLogLevel(4), + node.WithLogLevel(t.cfg.logLevel), node.WithEdgelessDBImage("ghcr.io/edgelesssys/edgelessdb-sgx-4gb:v0.3.2"), // default edgeless db value ) @@ -102,7 +102,7 @@ func (t *Testnet) Start() error { node.WithL1Start(networkConfig.L1StartHash), node.WithInMemoryHostDB(true), node.WithDebugNamespaceEnabled(true), - node.WithLogLevel(4), + node.WithLogLevel(t.cfg.logLevel), node.WithEdgelessDBImage("ghcr.io/edgelesssys/edgelessdb-sgx-4gb:v0.3.2"), // default edgeless db value )