From c8bee5c02594d8aa972747924d5a608c38d8496c Mon Sep 17 00:00:00 2001 From: Diego Essaya Date: Wed, 20 Sep 2023 18:53:27 -0300 Subject: [PATCH] fix(evm): debug logging of jsonrpc --- components/logger/component.go | 4 ++-- .../evm/evmlogger/evmlogger.go | 8 ++++--- packages/evm/evmtest/env.go | 21 ------------------- .../evm/jsonrpc/jsonrpctest/jsonrpc_test.go | 2 -- packages/solo/solo.go | 2 ++ tools/cluster/cluster.go | 2 ++ tools/cluster/tests/evm_jsonrpc_test.go | 3 --- 7 files changed, 11 insertions(+), 31 deletions(-) rename components/logger/evm.go => packages/evm/evmlogger/evmlogger.go (75%) delete mode 100644 packages/evm/evmtest/env.go diff --git a/components/logger/component.go b/components/logger/component.go index 704f31ada7..727878fb25 100644 --- a/components/logger/component.go +++ b/components/logger/component.go @@ -2,6 +2,7 @@ package logger import ( "github.com/iotaledger/hive.go/app" + "github.com/iotaledger/wasp/packages/evm/evmlogger" ) func init() { @@ -14,7 +15,6 @@ func init() { var Component *app.Component func configure() error { - initGoEthLogger(Component.App().NewLogger("go-ethereum")) - + evmlogger.Init(Component.App().NewLogger("go-ethereum")) return nil } diff --git a/components/logger/evm.go b/packages/evm/evmlogger/evmlogger.go similarity index 75% rename from components/logger/evm.go rename to packages/evm/evmlogger/evmlogger.go index 3ae0b7c3a2..aa9bfa146c 100644 --- a/components/logger/evm.go +++ b/packages/evm/evmlogger/evmlogger.go @@ -1,6 +1,8 @@ -package logger +package evmlogger import ( + "strings" + "github.com/ethereum/go-ethereum/log" "github.com/iotaledger/hive.go/logger" @@ -8,9 +10,9 @@ import ( var format = log.TerminalFormat(false) -func initGoEthLogger(waspLogger *logger.Logger) { +func Init(waspLogger *logger.Logger) { log.Root().SetHandler(log.FuncHandler(func(r *log.Record) error { - s := string(format.Format(r)) + s := strings.TrimRight(string(format.Format(r)), "\n") switch r.Lvl { case log.LvlCrit, log.LvlError: waspLogger.Error(s) diff --git a/packages/evm/evmtest/env.go b/packages/evm/evmtest/env.go deleted file mode 100644 index 6c4fbed9e9..0000000000 --- a/packages/evm/evmtest/env.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -package evmtest - -import ( - "testing" - - "github.com/ethereum/go-ethereum/log" -) - -var format = log.TerminalFormat(false) - -func InitGoEthLogger(t testing.TB) { - log.Root().SetHandler(log.FuncHandler(func(r *log.Record) error { - if r.Lvl <= log.LvlWarn { - t.Log(string(format.Format(r))) - } - return nil - })) -} diff --git a/packages/evm/jsonrpc/jsonrpctest/jsonrpc_test.go b/packages/evm/jsonrpc/jsonrpctest/jsonrpc_test.go index 4a09d38c92..e1374dd33e 100644 --- a/packages/evm/jsonrpc/jsonrpctest/jsonrpc_test.go +++ b/packages/evm/jsonrpc/jsonrpctest/jsonrpc_test.go @@ -38,8 +38,6 @@ type soloTestEnv struct { } func newSoloTestEnv(t testing.TB) *soloTestEnv { - evmtest.InitGoEthLogger(t) - var log *logger.Logger if _, ok := t.(*testing.B); ok { log = testlogger.NewSilentLogger(t.Name(), true) diff --git a/packages/solo/solo.go b/packages/solo/solo.go index fd25170279..753aff8dc5 100644 --- a/packages/solo/solo.go +++ b/packages/solo/solo.go @@ -22,6 +22,7 @@ import ( "github.com/iotaledger/wasp/packages/chain" "github.com/iotaledger/wasp/packages/cryptolib" "github.com/iotaledger/wasp/packages/database" + "github.com/iotaledger/wasp/packages/evm/evmlogger" "github.com/iotaledger/wasp/packages/hashing" "github.com/iotaledger/wasp/packages/isc" "github.com/iotaledger/wasp/packages/isc/coreutil" @@ -159,6 +160,7 @@ func New(t Context, initOptions ...*InitOptions) *Solo { opt.Log = testlogger.WithLevel(opt.Log, zapcore.InfoLevel, opt.PrintStackTrace) } } + evmlogger.Init(opt.Log) chainRecordRegistryProvider, err := registry.NewChainRecordRegistryImpl("") require.NoError(t, err) diff --git a/tools/cluster/cluster.go b/tools/cluster/cluster.go index 2c159e4207..8fe65fd552 100644 --- a/tools/cluster/cluster.go +++ b/tools/cluster/cluster.go @@ -32,6 +32,7 @@ import ( "github.com/iotaledger/wasp/components/app" "github.com/iotaledger/wasp/packages/apilib" "github.com/iotaledger/wasp/packages/cryptolib" + "github.com/iotaledger/wasp/packages/evm/evmlogger" "github.com/iotaledger/wasp/packages/isc" "github.com/iotaledger/wasp/packages/kv/codec" "github.com/iotaledger/wasp/packages/kv/dict" @@ -69,6 +70,7 @@ func New(name string, config *ClusterConfig, dataPath string, t *testing.T, log } log = testlogger.NewLogger(t) } + evmlogger.Init(log) config.setValidatorAddressIfNotSet() // privtangle prefix diff --git a/tools/cluster/tests/evm_jsonrpc_test.go b/tools/cluster/tests/evm_jsonrpc_test.go index 0d0fbb76f4..068d50b7cd 100644 --- a/tools/cluster/tests/evm_jsonrpc_test.go +++ b/tools/cluster/tests/evm_jsonrpc_test.go @@ -17,7 +17,6 @@ import ( "github.com/stretchr/testify/require" "github.com/iotaledger/wasp/clients/chainclient" - "github.com/iotaledger/wasp/packages/evm/evmtest" "github.com/iotaledger/wasp/packages/evm/jsonrpc/jsonrpctest" "github.com/iotaledger/wasp/packages/isc" "github.com/iotaledger/wasp/packages/kv" @@ -36,8 +35,6 @@ type clusterTestEnv struct { } func newClusterTestEnv(t *testing.T, env *ChainEnv, nodeIndex int) *clusterTestEnv { - evmtest.InitGoEthLogger(t) - evmJSONRPCPath := fmt.Sprintf("/v1/chains/%v/evm", env.Chain.ChainID.String()) jsonRPCEndpoint := env.Clu.Config.APIHost(nodeIndex) + evmJSONRPCPath rawClient, err := rpc.DialHTTP(jsonRPCEndpoint)