diff --git a/cmd/blobstream/base/config.go b/cmd/blobstream/base/config.go index a27a93ce..4649413d 100644 --- a/cmd/blobstream/base/config.go +++ b/cmd/blobstream/base/config.go @@ -2,9 +2,15 @@ package base import ( "fmt" + "io" "os" "strings" + "github.com/cosmos/cosmos-sdk/server" + "github.com/rs/zerolog" + tmconfig "github.com/tendermint/tendermint/config" + tmlog "github.com/tendermint/tendermint/libs/log" + ethcmn "github.com/ethereum/go-ethereum/common" "github.com/celestiaorg/orchestrator-relayer/evm" @@ -75,8 +81,45 @@ const ( FlagCoreRPC = "core.rpc" FlagStartingNonce = "starting-nonce" + + FlagLogLevel = "log.level" + FlagLogFormat = "log.format" ) +func AddLogLevelFlag(cmd *cobra.Command) { + cmd.Flags().String( + FlagLogLevel, + "info", + "The logging level (trace|debug|info|warn|error|fatal|panic)", + ) +} + +func GetLogFormatFlag(cmd *cobra.Command) (string, bool, error) { + changed := cmd.Flags().Changed(FlagLogFormat) + val, err := cmd.Flags().GetString(FlagLogFormat) + if err != nil { + return "", changed, err + } + return val, changed, nil +} + +func AddLogFormatFlag(cmd *cobra.Command) { + cmd.Flags().String( + FlagLogFormat, + "plain", + "The logging format (json|plain)", + ) +} + +func GetLogLevelFlag(cmd *cobra.Command) (string, bool, error) { + changed := cmd.Flags().Changed(FlagLogLevel) + val, err := cmd.Flags().GetString(FlagLogLevel) + if err != nil { + return "", changed, err + } + return val, changed, nil +} + func AddStartingNonceFlag(cmd *cobra.Command) { cmd.Flags().String( FlagStartingNonce, @@ -278,3 +321,19 @@ func ValidateEVMAddress(addr string) error { func EnsureConfigPath(configPath string) error { return os.MkdirAll(configPath, os.ModePerm) } + +// GetLogger creates a new logger and returns +func GetLogger(level string, format string) (tmlog.Logger, error) { + logLvl, err := zerolog.ParseLevel(level) + if err != nil { + return nil, fmt.Errorf("failed to parse log level (%s): %w", level, err) + } + var logWriter io.Writer + if strings.ToLower(format) == tmconfig.LogFormatPlain { + logWriter = zerolog.ConsoleWriter{Out: os.Stderr} + } else { + logWriter = os.Stderr + } + + return server.ZeroLogWrapper{Logger: zerolog.New(logWriter).Level(logLvl).With().Timestamp().Logger()}, nil +} diff --git a/cmd/blobstream/bootstrapper/cmd.go b/cmd/blobstream/bootstrapper/cmd.go index e9e91962..5bd4529d 100644 --- a/cmd/blobstream/bootstrapper/cmd.go +++ b/cmd/blobstream/bootstrapper/cmd.go @@ -2,10 +2,11 @@ package bootstrapper import ( "context" - "os" "strings" "time" + "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base" + p2pcmd "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/keys/p2p" "github.com/celestiaorg/orchestrator-relayer/helpers" "github.com/celestiaorg/orchestrator-relayer/p2p" @@ -14,7 +15,6 @@ import ( dssync "github.com/ipfs/go-datastore/sync" "github.com/libp2p/go-libp2p/core/peer" "github.com/spf13/cobra" - tmlog "github.com/tendermint/tendermint/libs/log" ) func Command() *cobra.Command { @@ -48,8 +48,11 @@ func Start() *cobra.Command { } // creating the logger - logger := tmlog.NewTMLogger(os.Stdout) - logger.Debug("starting bootstrapper node") + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } + logger.Info("starting bootstrapper node") ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() @@ -144,7 +147,10 @@ func Init() *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{ NeedDataStore: false, diff --git a/cmd/blobstream/bootstrapper/config.go b/cmd/blobstream/bootstrapper/config.go index 19310dbd..0f2e2bbb 100644 --- a/cmd/blobstream/bootstrapper/config.go +++ b/cmd/blobstream/bootstrapper/config.go @@ -18,6 +18,8 @@ func addStartFlags(cmd *cobra.Command) *cobra.Command { base.AddP2PNicknameFlag(cmd) base.AddP2PListenAddressFlag(cmd) base.AddBootstrappersFlag(cmd) + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } @@ -25,6 +27,8 @@ type StartConfig struct { home string p2pListenAddr, p2pNickname string bootstrappers string + logLevel string + logFormat string } func parseStartFlags(cmd *cobra.Command) (StartConfig, error) { @@ -52,11 +56,23 @@ func parseStartFlags(cmd *cobra.Command) (StartConfig, error) { return StartConfig{}, err } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return StartConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return StartConfig{}, err + } + return StartConfig{ p2pNickname: p2pNickname, p2pListenAddr: p2pListenAddress, home: homeDir, bootstrappers: bootstrappers, + logFormat: logFormat, + logLevel: logLevel, }, nil } @@ -66,11 +82,15 @@ func addInitFlags(cmd *cobra.Command) *cobra.Command { panic(err) } cmd.Flags().String(base.FlagHome, homeDir, "The Blobstream bootstrappers home directory") + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } type InitConfig struct { - home string + home string + logLevel string + logFormat string } func parseInitFlags(cmd *cobra.Command) (InitConfig, error) { @@ -85,8 +105,18 @@ func parseInitFlags(cmd *cobra.Command) (InitConfig, error) { return InitConfig{}, err } } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return InitConfig{}, err + } + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return InitConfig{}, err + } return InitConfig{ - home: homeDir, + home: homeDir, + logFormat: logFormat, + logLevel: logLevel, }, nil } diff --git a/cmd/blobstream/deploy/cmd.go b/cmd/blobstream/deploy/cmd.go index cf1c6b14..fa37840b 100644 --- a/cmd/blobstream/deploy/cmd.go +++ b/cmd/blobstream/deploy/cmd.go @@ -2,9 +2,10 @@ package deploy import ( "context" - "os" "strconv" + "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base" + evm2 "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/keys/evm" "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/keys" @@ -32,7 +33,10 @@ func Command() *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } // checking if the provided home is already initiated isInit := store.IsInit(logger, config.Home, store.InitOptions{NeedEVMKeyStore: true}) @@ -109,7 +113,7 @@ func Command() *cobra.Command { }(s.EVMKeyStore, acc.Address) evmClient := evm.NewClient( - tmlog.NewTMLogger(os.Stdout), + logger, nil, s.EVMKeyStore, &acc, diff --git a/cmd/blobstream/deploy/config.go b/cmd/blobstream/deploy/config.go index 2187dd0c..44657bd7 100644 --- a/cmd/blobstream/deploy/config.go +++ b/cmd/blobstream/deploy/config.go @@ -29,6 +29,8 @@ func addDeployFlags(cmd *cobra.Command) *cobra.Command { } base.AddHomeFlag(cmd, ServiceNameDeployer, homeDir) base.AddGRPCInsecureFlag(cmd) + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } @@ -41,6 +43,8 @@ type deployConfig struct { startingNonce string evmGasLimit uint64 grpcInsecure bool + logLevel string + logFormat string } func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) { @@ -100,6 +104,16 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) { return deployConfig{}, err } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return deployConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return deployConfig{}, err + } + return deployConfig{ Config: base.Config{ Home: homeDir, @@ -113,5 +127,7 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) { startingNonce: startingNonce, evmGasLimit: evmGasLimit, grpcInsecure: grpcInsecure, + logFormat: logFormat, + logLevel: logLevel, }, nil } diff --git a/cmd/blobstream/keys/evm/config.go b/cmd/blobstream/keys/evm/config.go index a96834fc..7cca1a16 100644 --- a/cmd/blobstream/keys/evm/config.go +++ b/cmd/blobstream/keys/evm/config.go @@ -17,11 +17,15 @@ func keysConfigFlags(cmd *cobra.Command, service string) *cobra.Command { } cmd.Flags().String(base.FlagHome, homeDir, "The Blobstream evm keys home directory") cmd.Flags().String(base.FlagEVMPassphrase, "", "the evm account passphrase (if not specified as a flag, it will be asked interactively)") + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } type KeysConfig struct { *base.Config + logLevel string + logFormat string } func parseKeysConfigFlags(cmd *cobra.Command, serviceName string) (KeysConfig, error) { @@ -41,11 +45,23 @@ func parseKeysConfigFlags(cmd *cobra.Command, serviceName string) (KeysConfig, e return KeysConfig{}, err } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return KeysConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return KeysConfig{}, err + } + return KeysConfig{ Config: &base.Config{ Home: homeDir, EVMPassphrase: passphrase, }, + logFormat: logFormat, + logLevel: logLevel, }, nil } @@ -57,12 +73,16 @@ func keysNewPassphraseConfigFlags(cmd *cobra.Command, service string) *cobra.Com cmd.Flags().String(base.FlagHome, homeDir, "The Blobstream evm keys home directory") cmd.Flags().String(base.FlagEVMPassphrase, "", "the evm account passphrase (if not specified as a flag, it will be asked interactively)") cmd.Flags().String(FlagNewEVMPassphrase, "", "the evm account new passphrase (if not specified as a flag, it will be asked interactively)") + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } type KeysNewPassphraseConfig struct { *base.Config newPassphrase string + logLevel string + logFormat string } func parseKeysNewPassphraseConfigFlags(cmd *cobra.Command, serviceName string) (KeysNewPassphraseConfig, error) { @@ -87,8 +107,20 @@ func parseKeysNewPassphraseConfigFlags(cmd *cobra.Command, serviceName string) ( return KeysNewPassphraseConfig{}, err } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return KeysNewPassphraseConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return KeysNewPassphraseConfig{}, err + } + return KeysNewPassphraseConfig{ Config: &base.Config{Home: homeDir, EVMPassphrase: passphrase}, newPassphrase: newPassphrase, + logFormat: logFormat, + logLevel: logLevel, }, nil } diff --git a/cmd/blobstream/keys/evm/evm.go b/cmd/blobstream/keys/evm/evm.go index 300d118b..34b881ea 100644 --- a/cmd/blobstream/keys/evm/evm.go +++ b/cmd/blobstream/keys/evm/evm.go @@ -9,6 +9,8 @@ import ( "io" "os" + "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base" + "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/go-bip39" @@ -57,7 +59,10 @@ func Add(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedEVMKeyStore: true} isInit := store.IsInit(logger, config.Home, initOptions) @@ -150,7 +155,10 @@ func List(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } isInit := store.IsInit(logger, config.Home, store.InitOptions{NeedEVMKeyStore: true}) @@ -195,7 +203,10 @@ func Delete(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } isInit := store.IsInit(logger, config.Home, store.InitOptions{NeedEVMKeyStore: true}) @@ -286,7 +297,10 @@ func ImportFile(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedEVMKeyStore: true} isInit := store.IsInit(logger, config.Home, initOptions) @@ -372,7 +386,10 @@ func ImportECDSA(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedEVMKeyStore: true} isInit := store.IsInit(logger, config.Home, initOptions) @@ -437,7 +454,10 @@ func ImportMnemonic(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedEVMKeyStore: true} isInit := store.IsInit(logger, config.Home, initOptions) @@ -518,7 +538,10 @@ func Update(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedEVMKeyStore: true} isInit := store.IsInit(logger, config.Home, initOptions) diff --git a/cmd/blobstream/keys/p2p/config.go b/cmd/blobstream/keys/p2p/config.go index f2d76a47..a19eccb3 100644 --- a/cmd/blobstream/keys/p2p/config.go +++ b/cmd/blobstream/keys/p2p/config.go @@ -12,11 +12,15 @@ func keysConfigFlags(cmd *cobra.Command, service string) *cobra.Command { panic(err) } cmd.Flags().String(base.FlagHome, homeDir, "The Blobstream p2p keys home directory") + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } type KeysConfig struct { - home string + home string + logLevel string + logFormat string } func parseKeysConfigFlags(cmd *cobra.Command, serviceName string) (KeysConfig, error) { @@ -31,7 +35,18 @@ func parseKeysConfigFlags(cmd *cobra.Command, serviceName string) (KeysConfig, e return KeysConfig{}, err } } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return KeysConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return KeysConfig{}, err + } return KeysConfig{ - home: homeDir, + home: homeDir, + logFormat: logFormat, + logLevel: logLevel, }, nil } diff --git a/cmd/blobstream/keys/p2p/p2p.go b/cmd/blobstream/keys/p2p/p2p.go index 1b5c9586..6184b7f4 100644 --- a/cmd/blobstream/keys/p2p/p2p.go +++ b/cmd/blobstream/keys/p2p/p2p.go @@ -3,8 +3,8 @@ package p2p import ( "encoding/hex" "fmt" - "os" + "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base" "github.com/ipfs/boxo/keystore" "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/keys/common" @@ -44,7 +44,10 @@ func Add(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedP2PKeyStore: true} isInit := store.IsInit(logger, config.home, initOptions) @@ -120,7 +123,10 @@ func List(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedP2PKeyStore: true} isInit := store.IsInit(logger, config.home, initOptions) @@ -172,7 +178,10 @@ func Import(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedP2PKeyStore: true} isInit := store.IsInit(logger, config.home, initOptions) @@ -231,7 +240,10 @@ func Delete(serviceName string) *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{NeedP2PKeyStore: true} isInit := store.IsInit(logger, config.home, initOptions) diff --git a/cmd/blobstream/orchestrator/cmd.go b/cmd/blobstream/orchestrator/cmd.go index aee75815..83768757 100644 --- a/cmd/blobstream/orchestrator/cmd.go +++ b/cmd/blobstream/orchestrator/cmd.go @@ -2,7 +2,6 @@ package orchestrator import ( "context" - "os" "path/filepath" "time" @@ -19,7 +18,6 @@ import ( "github.com/celestiaorg/orchestrator-relayer/helpers" "github.com/celestiaorg/orchestrator-relayer/orchestrator" "github.com/spf13/cobra" - tmlog "github.com/tendermint/tendermint/libs/log" ) func Command() *cobra.Command { @@ -47,14 +45,10 @@ func Start() *cobra.Command { Use: "start ", Short: "Starts the Blobstream orchestrator to sign attestations", RunE: func(cmd *cobra.Command, args []string) error { - logger := tmlog.NewTMLogger(os.Stdout) - homeDir, err := base.GetHomeDirectory(cmd, ServiceNameOrchestrator) if err != nil { return err } - logger.Debug("initializing orchestrator", "home", homeDir) - fileConfig, err := LoadFileConfiguration(homeDir) if err != nil { return err @@ -67,6 +61,13 @@ func Start() *cobra.Command { return err } + logger, err := base.GetLogger(config.LogLevel, config.LogFormat) + if err != nil { + return err + } + + logger.Info("initializing orchestrator", "home", homeDir) + ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() @@ -141,7 +142,7 @@ func Start() *cobra.Command { return err } - logger.Debug("starting orchestrator") + logger.Info("starting orchestrator") // Listen for and trap any OS signal to graceful shutdown and exit go helpers.TrapSignal(logger, cancel) @@ -166,7 +167,10 @@ func Init() *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{ NeedDataStore: true, diff --git a/cmd/blobstream/orchestrator/config.go b/cmd/blobstream/orchestrator/config.go index e4f48bdb..a81675e7 100644 --- a/cmd/blobstream/orchestrator/config.go +++ b/cmd/blobstream/orchestrator/config.go @@ -61,6 +61,8 @@ func addOrchestratorFlags(cmd *cobra.Command) *cobra.Command { base.AddP2PListenAddressFlag(cmd) base.AddBootstrappersFlag(cmd) base.AddGRPCInsecureFlag(cmd) + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } @@ -73,6 +75,8 @@ type StartConfig struct { P2PListenAddr string `mapstructure:"listen-addr" json:"listen-addr"` P2pNickname string GRPCInsecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"` + LogLevel string + LogFormat string } func DefaultStartConfig() *StartConfig { @@ -162,6 +166,18 @@ func parseOrchestratorFlags(cmd *cobra.Command, startConf *StartConfig) (StartCo startConf.GRPCInsecure = grpcInsecure } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return StartConfig{}, err + } + startConf.LogLevel = logLevel + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return StartConfig{}, err + } + startConf.LogFormat = logFormat + return *startConf, nil } @@ -171,11 +187,15 @@ func addInitFlags(cmd *cobra.Command) *cobra.Command { panic(err) } base.AddHomeFlag(cmd, ServiceNameOrchestrator, homeDir) + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } type InitConfig struct { - home string + home string + logLevel string + logFormat string } func parseInitFlags(cmd *cobra.Command) (InitConfig, error) { @@ -191,8 +211,20 @@ func parseInitFlags(cmd *cobra.Command) (InitConfig, error) { } } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return InitConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return InitConfig{}, err + } + return InitConfig{ - home: homeDir, + home: homeDir, + logFormat: logFormat, + logLevel: logLevel, }, nil } diff --git a/cmd/blobstream/relayer/cmd.go b/cmd/blobstream/relayer/cmd.go index 3b0c3991..91b8842f 100644 --- a/cmd/blobstream/relayer/cmd.go +++ b/cmd/blobstream/relayer/cmd.go @@ -2,7 +2,6 @@ package relayer import ( "context" - "os" "path/filepath" "time" @@ -25,7 +24,6 @@ import ( "github.com/celestiaorg/orchestrator-relayer/relayer" "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" - tmlog "github.com/tendermint/tendermint/libs/log" ) func Command() *cobra.Command { @@ -58,7 +56,10 @@ func Init() *cobra.Command { return err } - logger := tmlog.NewTMLogger(os.Stdout) + logger, err := base.GetLogger(config.logLevel, config.logFormat) + if err != nil { + return err + } initOptions := store.InitOptions{ NeedDataStore: true, @@ -96,13 +97,10 @@ func Start() *cobra.Command { Use: "start ", Short: "Runs the Blobstream relayer to submit attestations to the target EVM chain", RunE: func(cmd *cobra.Command, args []string) error { - logger := tmlog.NewTMLogger(os.Stdout) - homeDir, err := base.GetHomeDirectory(cmd, ServiceNameRelayer) if err != nil { return err } - logger.Debug("initializing relayer", "home", homeDir) fileConfig, err := LoadFileConfiguration(homeDir) if err != nil { @@ -116,6 +114,12 @@ func Start() *cobra.Command { return err } + logger, err := base.GetLogger(config.LogLevel, config.LogFormat) + if err != nil { + return err + } + + logger.Info("initializing relayer", "home", homeDir) ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() @@ -202,7 +206,7 @@ func Start() *cobra.Command { // Listen for and trap any OS signal to graceful shutdown and exit go helpers.TrapSignal(logger, cancel) - logger.Debug("starting relayer") + logger.Info("starting relayer") err = relay.Start(ctx) if err != nil { return err diff --git a/cmd/blobstream/relayer/config.go b/cmd/blobstream/relayer/config.go index adbca550..40f6bdb7 100644 --- a/cmd/blobstream/relayer/config.go +++ b/cmd/blobstream/relayer/config.go @@ -83,6 +83,8 @@ func addRelayerStartFlags(cmd *cobra.Command) *cobra.Command { base.AddP2PListenAddressFlag(cmd) base.AddBootstrappersFlag(cmd) base.AddGRPCInsecureFlag(cmd) + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } @@ -100,6 +102,8 @@ type StartConfig struct { P2PListenAddr string `mapstructure:"listen-addr" json:"listen-addr"` p2pNickname string GrpcInsecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"` + LogLevel string + LogFormat string } func DefaultStartConfig() *StartConfig { @@ -225,6 +229,18 @@ func parseRelayerStartFlags(cmd *cobra.Command, fileConfig *StartConfig) (StartC fileConfig.GrpcInsecure = grpcInsecure } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return StartConfig{}, err + } + fileConfig.LogLevel = logLevel + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return StartConfig{}, err + } + fileConfig.LogFormat = logFormat + return *fileConfig, nil } @@ -234,11 +250,15 @@ func addInitFlags(cmd *cobra.Command) *cobra.Command { panic(err) } base.AddHomeFlag(cmd, ServiceNameRelayer, homeDir) + base.AddLogLevelFlag(cmd) + base.AddLogFormatFlag(cmd) return cmd } type InitConfig struct { - home string + home string + logLevel string + logFormat string } func parseInitFlags(cmd *cobra.Command) (InitConfig, error) { @@ -254,8 +274,20 @@ func parseInitFlags(cmd *cobra.Command) (InitConfig, error) { } } + logLevel, _, err := base.GetLogLevelFlag(cmd) + if err != nil { + return InitConfig{}, err + } + + logFormat, _, err := base.GetLogFormatFlag(cmd) + if err != nil { + return InitConfig{}, err + } + return InitConfig{ - home: homeDir, + home: homeDir, + logFormat: logFormat, + logLevel: logLevel, }, nil } diff --git a/e2e/scripts/deploy_blobstream_contract.sh b/e2e/scripts/deploy_blobstream_contract.sh index d53b068c..3dd75af8 100644 --- a/e2e/scripts/deploy_blobstream_contract.sh +++ b/e2e/scripts/deploy_blobstream_contract.sh @@ -71,8 +71,8 @@ echo "deploying Blobstream contract..." --grpc.insecure \ --starting-nonce "${STARTING_NONCE}" \ --evm.rpc "${EVM_ENDPOINT}" \ - --evm.passphrase=123 > /opt/output + --evm.passphrase=123 2> /opt/output echo $(cat /opt/output) -cat /opt/output | grep "deployed" | awk '{ print $5 }' | cut -f 2 -d = > /opt/blobstream_address.txt +cat /opt/output | grep "deployed" | awk '{ print $6 }' | grep -o '0x.*' > /opt/blobstream_address.txt diff --git a/go.mod b/go.mod index 7770b046..df5d28a0 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.25.1 github.com/mitchellh/go-homedir v1.1.0 github.com/multiformats/go-multiaddr v0.12.0 + github.com/rs/zerolog v1.31.0 github.com/spf13/viper v1.17.0 github.com/tendermint/tendermint v0.34.28 ) @@ -244,7 +245,6 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/rs/cors v1.8.2 // indirect - github.com/rs/zerolog v1.31.0 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect diff --git a/orchestrator/orchestrator.go b/orchestrator/orchestrator.go index 22631257..a4da8a4b 100644 --- a/orchestrator/orchestrator.go +++ b/orchestrator/orchestrator.go @@ -106,7 +106,6 @@ func (orch Orchestrator) Start(ctx context.Context) { orch.Logger.Error("error enqueuing missing attestations", "err", err) cancel() } - orch.Logger.Error("stopping enqueuing missing attestations") }() wg.Wait() @@ -175,7 +174,7 @@ func (orch Orchestrator) StartNewEventsListener( if err != nil { return err } - orch.Logger.Info("enqueueing new attestation nonce", "nonce", nonce) + orch.Logger.Debug("enqueueing new attestation nonce", "nonce", nonce) select { case <-ctx.Done(): return ctx.Err() @@ -303,7 +302,7 @@ func (orch Orchestrator) Process(ctx context.Context, nonce uint64) error { return errors.Wrap(err, fmt.Sprintf("valset %d", nonce)) } if resp != nil { - orch.Logger.Debug("already signed valset", "nonce", nonce, "signature", resp.Signature) + orch.Logger.Info("already signed valset", "nonce", nonce, "signature", resp.Signature) return nil } err = orch.ProcessValsetEvent(ctx, *castedAtt) @@ -332,7 +331,7 @@ func (orch Orchestrator) Process(ctx context.Context, nonce uint64) error { return errors.Wrap(err, fmt.Sprintf("data commitment %d", nonce)) } if resp != nil { - orch.Logger.Debug("already signed data commitment", "nonce", nonce, "begin_block", castedAtt.BeginBlock, "end_block", castedAtt.EndBlock, "data_root_tuple_root", dataRootHash.Hex(), "signature", resp.Signature) + orch.Logger.Info("already signed data commitment", "nonce", nonce, "begin_block", castedAtt.BeginBlock, "end_block", castedAtt.EndBlock, "data_root_tuple_root", dataRootHash.Hex(), "signature", resp.Signature) return nil } err = orch.ProcessDataCommitmentEvent(ctx, *castedAtt, dataRootHash) diff --git a/p2p/querier.go b/p2p/querier.go index 5529b0c6..4e78fcfe 100644 --- a/p2p/querier.go +++ b/p2p/querier.go @@ -73,7 +73,7 @@ func (q Querier) QueryTwoThirdsDataCommitmentConfirms( } if currThreshold >= majThreshHold { - q.logger.Debug("found enough data commitment confirms to be relayed", + q.logger.Info("found enough data commitment confirms to be relayed", "majThreshHold", majThreshHold, "currThreshold", @@ -178,7 +178,7 @@ func (q Querier) QueryTwoThirdsValsetConfirms( } if currThreshold >= majThreshHold { - q.logger.Debug("found enough valset confirms to be relayed", + q.logger.Info("found enough valset confirms to be relayed", "majThreshHold", majThreshHold, "currThreshold", diff --git a/relayer/relayer.go b/relayer/relayer.go index 0fd031e1..f6a58752 100644 --- a/relayer/relayer.go +++ b/relayer/relayer.go @@ -215,7 +215,7 @@ func (r *Relayer) QueryValsetFromP2PNetworkAndValidateIt(ctx context.Context) (* if err != nil { return nil, err } - r.logger.Info("found the latest valset in P2P network. Authenticating it against the contract to verify it's valid", "nonce", vs.Nonce, "hash", vsHash.Hex()) + r.logger.Debug("found the latest valset in P2P network. Authenticating it against the contract to verify it's valid", "nonce", vs.Nonce, "hash", vsHash.Hex()) contractHash, err := r.EVMClient.StateLastValidatorSetCheckpoint(&bind.CallOpts{Context: ctx}) if err != nil { @@ -228,7 +228,7 @@ func (r *Relayer) QueryValsetFromP2PNetworkAndValidateIt(ctx context.Context) (* } if !bytes.Equal(bzVSHash, contractHash[:]) { - r.logger.Error("valset hash from contract mismatches that of P2P one, halting. try running the relayer with an archive node to continue relaying", "contract_vs_hash", ethcmn.Bytes2Hex(contractHash[:]), "p2p_vs_hash", vsHash.Hex()) + r.logger.Error("valset hash from contract mismatches that of P2P one, halting. try running the relayer with an archive node (if that's not the case) to continue relaying", "contract_vs_hash", ethcmn.Bytes2Hex(contractHash[:]), "p2p_vs_hash", vsHash.Hex()) return nil, ErrValidatorSetMismatch }