Skip to content

Commit

Permalink
fix(dot/sync): Pass logLvl to sync and digest (#4407)
Browse files Browse the repository at this point in the history
  • Loading branch information
mittal-parth authored Dec 18, 2024
1 parent bdcd738 commit fd06329
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/gossamer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/usage/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion dot/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion dot/digest/digest_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions dot/mock_node_builder_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})).
Expand Down
21 changes: 16 additions & 5 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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),
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion dot/services_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion dot/sync/message_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion dot/sync/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/babe/verify_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit fd06329

Please sign in to comment.