From 53e3e18eb66b2890f95e8b4b873aba079a830f6a Mon Sep 17 00:00:00 2001 From: otherview Date: Tue, 23 Jan 2024 17:03:02 +0000 Subject: [PATCH 1/3] Add log-level to launcher + fix trace debug --- go/enclave/components/block_processor.go | 2 +- 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, 17 insertions(+), 3 deletions(-) diff --git a/go/enclave/components/block_processor.go b/go/enclave/components/block_processor.go index a80b893004..cf6f03f369 100644 --- a/go/enclave/components/block_processor.go +++ b/go/enclave/components/block_processor.go @@ -115,7 +115,7 @@ func (bp *l1BlockProcessor) tryAndInsertBlock(br *common.BlockAndReceipts) (*Blo return nil, err } bp.logger.Trace("Block inserted successfully", - log.BlockHeightKey, block.NumberU64(), log.BlockHashKey, block.Hash(), "ingestionType", ingestionType) + log.BlockHeightKey, block.NumberU64(), log.BlockHashKey, block.Hash()) err = bp.storage.StoreBlock(block, ingestionType.ChainFork) if err != nil { diff --git a/testnet/launcher/cmd/cli.go b/testnet/launcher/cmd/cli.go index 351379f5b0..216517a22e 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[isSGXEnabledFlag]) 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 ) From 482a02d5a33a7e7580346976c847ad16cb495d4a Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Wed, 24 Jan 2024 14:37:04 +0000 Subject: [PATCH 2/3] Update testnet/launcher/cmd/cli.go --- testnet/launcher/cmd/cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testnet/launcher/cmd/cli.go b/testnet/launcher/cmd/cli.go index 216517a22e..6f5469a6af 100644 --- a/testnet/launcher/cmd/cli.go +++ b/testnet/launcher/cmd/cli.go @@ -28,7 +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[isSGXEnabledFlag]) + logLevel := flag.Int(logLevelFlag, 4, flagUsageMap[logLevelFlag]) flag.Parse() cfg.validatorEnclaveDockerImage = *validatorEnclaveDockerImage From 1dfae32cc04ea52cef77807d7d2ad08d38386c94 Mon Sep 17 00:00:00 2001 From: otherview Date: Wed, 24 Jan 2024 15:21:14 +0000 Subject: [PATCH 3/3] pr comments --- go/common/types.go | 3 +++ go/enclave/components/block_processor.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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/go/enclave/components/block_processor.go b/go/enclave/components/block_processor.go index cf6f03f369..a80b893004 100644 --- a/go/enclave/components/block_processor.go +++ b/go/enclave/components/block_processor.go @@ -115,7 +115,7 @@ func (bp *l1BlockProcessor) tryAndInsertBlock(br *common.BlockAndReceipts) (*Blo return nil, err } bp.logger.Trace("Block inserted successfully", - log.BlockHeightKey, block.NumberU64(), log.BlockHashKey, block.Hash()) + log.BlockHeightKey, block.NumberU64(), log.BlockHashKey, block.Hash(), "ingestionType", ingestionType) err = bp.storage.StoreBlock(block, ingestionType.ChainFork) if err != nil {