From fd063291b731b73c189eda6c4dec2357b0704b35 Mon Sep 17 00:00:00 2001 From: Parth Mittal <76661350+mittal-parth@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:56:14 +0530 Subject: [PATCH] fix(dot/sync): Pass logLvl to sync and digest (#4407) --- cmd/gossamer/README.md | 2 +- cmd/gossamer/commands/root.go | 2 +- docs/docs/usage/command-line.md | 2 +- dot/digest/digest.go | 9 ++++++++- dot/digest/digest_integration_test.go | 5 ++++- dot/mock_node_builder_test.go | 8 ++++---- dot/node.go | 4 ++-- dot/node_integration_test.go | 2 +- dot/services.go | 21 ++++++++++++++++----- dot/services_integration_test.go | 2 +- dot/sync/message_integration_test.go | 4 +++- dot/sync/service.go | 4 +++- lib/babe/verify_integration_test.go | 4 +++- 13 files changed, 48 insertions(+), 21 deletions(-) diff --git a/cmd/gossamer/README.md b/cmd/gossamer/README.md index 31aae6cc92..60c48ff75b 100644 --- a/cmd/gossamer/README.md +++ b/cmd/gossamer/README.md @@ -79,7 +79,7 @@ Here are the list of basic flags for the `gossamer` command: --log: Set a logging filter. Syntax is a list of 'module=logLevel' (comma separated) e.g. --log sync=debug,core=trace - Modules are global, core, digest, sync, network, rpc, state, runtime, babe, grandpa, wasmer. + Modules are global, core, digest, sync, network, rpc, state, runtime, babe, grandpa. Log levels (least to most verbose) are error, warn, info, debug, and trace. By default, all modules log 'info'. The global log level can be set with --log global=debug diff --git a/cmd/gossamer/commands/root.go b/cmd/gossamer/commands/root.go index fa8050ca0b..0003833ef5 100644 --- a/cmd/gossamer/commands/root.go +++ b/cmd/gossamer/commands/root.go @@ -174,7 +174,7 @@ func addRootFlags(cmd *cobra.Command) error { `Set a logging filter. Syntax is a list of 'module=logLevel' (comma separated) e.g. --log sync=debug,core=trace - Modules are global, core, digest, sync, network, rpc, state, runtime, babe, grandpa, wasmer. + Modules are global, core, digest, sync, network, rpc, state, runtime, babe, grandpa. Log levels (least to most verbose) are error, warn, info, debug, and trace. By default, all modules log 'info'. The global log level can be set with --log global=debug`) diff --git a/docs/docs/usage/command-line.md b/docs/docs/usage/command-line.md index d69f034c65..659e9568f9 100644 --- a/docs/docs/usage/command-line.md +++ b/docs/docs/usage/command-line.md @@ -27,7 +27,7 @@ These are the flags that can be used with the `gossamer` command --log: Set a logging filter. Syntax is a list of 'module=logLevel' (comma separated) e.g. --log sync=debug,core=trace - Modules are global, core, digest, sync, network, rpc, state, runtime, babe, grandpa, wasmer. + Modules are global, core, digest, sync, network, rpc, state, runtime, babe, grandpa. Log levels (least to most verbose) are error, warn, info, debug, and trace. By default, all modules log 'info'. The global log level can be set with --log global=debug diff --git a/dot/digest/digest.go b/dot/digest/digest.go index 6ca31b1271..0c2c49c433 100644 --- a/dot/digest/digest.go +++ b/dot/digest/digest.go @@ -33,10 +33,17 @@ type Handler struct { } // NewHandler returns a new Handler -func NewHandler(blockState BlockState, epochState EpochState, grandpaState GrandpaState) (*Handler, error) { +func NewHandler( + logLvl log.Level, + blockState BlockState, + epochState EpochState, + grandpaState GrandpaState, +) (*Handler, error) { imported := blockState.GetImportedBlockNotifierChannel() finalised := blockState.GetFinalisedNotifierChannel() + logger.Patch(log.SetLevel(logLvl)) + ctx, cancel := context.WithCancel(context.Background()) return &Handler{ ctx: ctx, diff --git a/dot/digest/digest_integration_test.go b/dot/digest/digest_integration_test.go index c63ce25517..a2a9c99a27 100644 --- a/dot/digest/digest_integration_test.go +++ b/dot/digest/digest_integration_test.go @@ -13,6 +13,7 @@ import ( "github.com/ChainSafe/gossamer/dot/state" "github.com/ChainSafe/gossamer/dot/types" + "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/crypto/ed25519" "github.com/ChainSafe/gossamer/lib/crypto/sr25519" @@ -49,7 +50,9 @@ func newTestHandler(t *testing.T) (*Handler, *BlockImportHandler, *state.Service err = stateSrvc.Start() require.NoError(t, err) - dh, err := NewHandler(stateSrvc.Block, stateSrvc.Epoch, stateSrvc.Grandpa) + digestLogLvl := log.Info + + dh, err := NewHandler(digestLogLvl, stateSrvc.Block, stateSrvc.Epoch, stateSrvc.Grandpa) require.NoError(t, err) blockImportHandler := NewBlockImportHandler(stateSrvc.Epoch, stateSrvc.Grandpa) diff --git a/dot/mock_node_builder_test.go b/dot/mock_node_builder_test.go index f161ac6a6d..af06c82023 100644 --- a/dot/mock_node_builder_test.go +++ b/dot/mock_node_builder_test.go @@ -96,18 +96,18 @@ func (mr *MocknodeBuilderIfaceMockRecorder) createCoreService(config, ks, st, ne } // createDigestHandler mocks base method. -func (m *MocknodeBuilderIface) createDigestHandler(st *state.Service) (*digest.Handler, error) { +func (m *MocknodeBuilderIface) createDigestHandler(config *config.Config, st *state.Service) (*digest.Handler, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "createDigestHandler", st) + ret := m.ctrl.Call(m, "createDigestHandler", config, st) ret0, _ := ret[0].(*digest.Handler) ret1, _ := ret[1].(error) return ret0, ret1 } // createDigestHandler indicates an expected call of createDigestHandler. -func (mr *MocknodeBuilderIfaceMockRecorder) createDigestHandler(st any) *gomock.Call { +func (mr *MocknodeBuilderIfaceMockRecorder) createDigestHandler(config, st any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "createDigestHandler", reflect.TypeOf((*MocknodeBuilderIface)(nil).createDigestHandler), st) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "createDigestHandler", reflect.TypeOf((*MocknodeBuilderIface)(nil).createDigestHandler), config, st) } // createGRANDPAService mocks base method. diff --git a/dot/node.go b/dot/node.go index f420e86e52..d6ee8c4699 100644 --- a/dot/node.go +++ b/dot/node.go @@ -57,7 +57,7 @@ type nodeBuilderIface interface { loadRuntime(config *cfg.Config, ns *runtime.NodeStorage, stateSrvc *state.Service, ks *keystore.GlobalKeystore, net *network.Service) error createBlockVerifier(st *state.Service) *babe.VerificationManager - createDigestHandler(st *state.Service) (*digest.Handler, error) + createDigestHandler(config *cfg.Config, st *state.Service) (*digest.Handler, error) createCoreService(config *cfg.Config, ks *keystore.GlobalKeystore, st *state.Service, net *network.Service, ) (*core.Service, error) createGRANDPAService(config *cfg.Config, st *state.Service, ks KeyStore, @@ -355,7 +355,7 @@ func newNode(config *cfg.Config, ver := builder.createBlockVerifier(stateSrvc) - dh, err := builder.createDigestHandler(stateSrvc) + dh, err := builder.createDigestHandler(config, stateSrvc) if err != nil { return nil, err } diff --git a/dot/node_integration_test.go b/dot/node_integration_test.go index 7182c153ac..39b0ea403a 100644 --- a/dot/node_integration_test.go +++ b/dot/node_integration_test.go @@ -127,7 +127,7 @@ func TestNewNode(t *testing.T) { ks, gomock.AssignableToTypeOf(&network.Service{})).Return(nil) m.EXPECT().createBlockVerifier(gomock.AssignableToTypeOf(&state.Service{})). Return(&babe.VerificationManager{}) - m.EXPECT().createDigestHandler(gomock.AssignableToTypeOf(&state.Service{})). + m.EXPECT().createDigestHandler(initConfig, gomock.AssignableToTypeOf(&state.Service{})). Return(&digest.Handler{}, nil) m.EXPECT().createCoreService(initConfig, ks, gomock.AssignableToTypeOf(&state.Service{}), gomock.AssignableToTypeOf(&network.Service{})). diff --git a/dot/services.go b/dot/services.go index 231a13fe5d..653b400c22 100644 --- a/dot/services.go +++ b/dot/services.go @@ -180,16 +180,16 @@ func createRuntime(config *cfg.Config, ns runtime.NodeStorage, st *state.Service return nil, err } - wasmerLogLevel, err := log.ParseLevel(config.Log.Wasmer) + runtimeLogLvl, err := log.ParseLevel(config.Log.Runtime) if err != nil { - return nil, fmt.Errorf("failed to parse wasmer log level: %w", err) + return nil, fmt.Errorf("failed to parse runtime log level: %w", err) } switch config.Core.WasmInterpreter { case wazero_runtime.Name: rtCfg := wazero_runtime.Config{ Storage: ts, Keystore: ks, - LogLvl: wasmerLogLevel, + LogLvl: runtimeLogLvl, NodeStorage: ns, Network: net, Transaction: st.Transaction, @@ -518,6 +518,11 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync return nil, err } + syncLogLevel, err := log.ParseLevel(config.Log.Sync) + if err != nil { + return nil, fmt.Errorf("failed to parse sync log level: %w", err) + } + requestMaker := net.GetRequestResponseProtocol(network.SyncID, blockRequestTimeout, network.MaxBlockResponseSize) @@ -535,6 +540,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync fullSync := sync.NewFullSyncStrategy(syncCfg) return sync.NewSyncService( + syncLogLevel, sync.WithNetwork(net), sync.WithBlockState(st.Block), sync.WithSlotDuration(slotDuration), @@ -543,8 +549,13 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync ), nil } -func (nodeBuilder) createDigestHandler(st *state.Service) (*digest.Handler, error) { - return digest.NewHandler(st.Block, st.Epoch, st.Grandpa) +func (nodeBuilder) createDigestHandler(config *cfg.Config, st *state.Service) (*digest.Handler, error) { + digestLogLevel, err := log.ParseLevel(config.Log.Digest) + if err != nil { + return nil, fmt.Errorf("failed to parse digest log level: %w", err) + } + + return digest.NewHandler(digestLogLevel, st.Block, st.Epoch, st.Grandpa) } func createPprofService(config cfg.PprofConfig) (service *pprof.Service) { diff --git a/dot/services_integration_test.go b/dot/services_integration_test.go index a922cc0298..e9a27bdac1 100644 --- a/dot/services_integration_test.go +++ b/dot/services_integration_test.go @@ -838,6 +838,6 @@ func Test_createDigestHandler(t *testing.T) { err = startStateService(*config.State, stateSrvc) require.NoError(t, err) - _, err = builder.createDigestHandler(stateSrvc) + _, err = builder.createDigestHandler(config, stateSrvc) require.NoError(t, err) } diff --git a/dot/sync/message_integration_test.go b/dot/sync/message_integration_test.go index e2421d23fa..55e560a3be 100644 --- a/dot/sync/message_integration_test.go +++ b/dot/sync/message_integration_test.go @@ -156,7 +156,9 @@ func newFullSyncService(t *testing.T) *SyncService { WithStrategies(fullSync, nil), } - syncer := NewSyncService(serviceCfg...) + syncLogLvl := log.Info + + syncer := NewSyncService(syncLogLvl, serviceCfg...) return syncer } diff --git a/dot/sync/service.go b/dot/sync/service.go index 8873de0002..a290e1f322 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -113,7 +113,9 @@ type SyncService struct { stopCh chan struct{} } -func NewSyncService(cfgs ...ServiceConfig) *SyncService { +func NewSyncService(logLvl log.Level, cfgs ...ServiceConfig) *SyncService { + logger.Patch(log.SetLevel(logLvl)) + svc := &SyncService{ minPeers: minPeersDefault, waitPeersDuration: waitPeersDefaultTimeout, diff --git a/lib/babe/verify_integration_test.go b/lib/babe/verify_integration_test.go index 61b5168243..c309d6b9ba 100644 --- a/lib/babe/verify_integration_test.go +++ b/lib/babe/verify_integration_test.go @@ -16,6 +16,7 @@ import ( "github.com/ChainSafe/gossamer/dot/telemetry" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/internal/database" + "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/crypto/sr25519" "github.com/ChainSafe/gossamer/pkg/scale" "github.com/ChainSafe/gossamer/tests/utils/config" @@ -648,7 +649,8 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { onBlockImportDigestHandler := digest.NewBlockImportHandler(epochState, stateService.Grandpa) - digestHandler, err := digest.NewHandler(stateService.Block, epochState, stateService.Grandpa) + digestLogLvl := log.Info + digestHandler, err := digest.NewHandler(digestLogLvl, stateService.Block, epochState, stateService.Grandpa) require.NoError(t, err) digestHandler.Start()