diff --git a/internal/state/execution.go b/internal/state/execution.go index ef242b567..158d0d137 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -575,7 +575,7 @@ func fireEvents( func ExecCommitBlock( ctx context.Context, be *BlockExecutor, - appConnConsensus abciclient.Client, + appConn abciclient.Client, block *types.Block, logger log.Logger, store Store, @@ -583,7 +583,7 @@ func ExecCommitBlock( s State, ) ([]byte, error) { pbh := block.Header.ToProto() - finalizeBlockResponse, err := appConnConsensus.FinalizeBlock( + finalizeBlockResponse, err := appConn.FinalizeBlock( ctx, abci.RequestFinalizeBlock{ Hash: block.Hash(), @@ -623,7 +623,7 @@ func ExecCommitBlock( } // Commit block, get hash back - res, err := appConnConsensus.Commit(ctx) + res, err := appConn.Commit(ctx) if err != nil { logger.Error("client error during proxyAppConn.Commit", "err", res) return nil, err diff --git a/libs/log/default.go b/libs/log/default.go index ee729db23..706977659 100644 --- a/libs/log/default.go +++ b/libs/log/default.go @@ -60,17 +60,6 @@ func NewDefaultLogger(format, level string) (Logger, error) { }, nil } -// MustNewDefaultLogger delegates a call NewDefaultLogger where it panics on -// error. -func MustNewDefaultLogger(format, level string) Logger { - logger, err := NewDefaultLogger(format, level) - if err != nil { - panic(err) - } - - return logger -} - func (l defaultLogger) Info(msg string, keyVals ...interface{}) { l.Logger.Info().Fields(getLogFields(keyVals...)).Msg(msg) } diff --git a/test/e2e/app/app.go b/test/e2e/app/app.go index e0c080f87..098da250e 100644 --- a/test/e2e/app/app.go +++ b/test/e2e/app/app.go @@ -90,8 +90,13 @@ func NewApplication(cfg *Config) (*Application, error) { if err != nil { return nil, err } + logger, err := log.NewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo) + if err != nil { + return nil, err + } + return &Application{ - logger: log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo), + logger: logger, state: state, snapshots: snapshots, cfg: cfg, diff --git a/test/e2e/generator/main.go b/test/e2e/generator/main.go index 10b809279..bec78d89c 100644 --- a/test/e2e/generator/main.go +++ b/test/e2e/generator/main.go @@ -2,7 +2,9 @@ package main import ( + "context" "fmt" + stdlog "log" "math/rand" "os" "path/filepath" @@ -17,21 +19,35 @@ const ( randomSeed int64 = 4827085738 ) -var logger = log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo) - func main() { - NewCLI().Run() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + cli, err := NewCLI() + if err != nil { + stdlog.Fatal(err) + } + + cli.Run(ctx) } // CLI is the Cobra-based command-line interface. type CLI struct { - root *cobra.Command - opts Options + root *cobra.Command + opts Options + logger log.Logger } // NewCLI sets up the CLI. -func NewCLI() *CLI { - cli := &CLI{} +func NewCLI() (*CLI, error) { + logger, err := log.NewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo) + if err != nil { + return nil, err + } + + cli := &CLI{ + logger: logger, + } cli.root = &cobra.Command{ Use: "generator", Short: "End-to-end testnet generator", @@ -51,7 +67,7 @@ func NewCLI() *CLI { cli.root.PersistentFlags().IntVarP(&cli.opts.MaxNetworkSize, "max-size", "", 0, "Maxmum network size (nodes), 0 is unlimited") - return cli + return cli, nil } // generate generates manifests in a directory. @@ -90,9 +106,9 @@ func (cli *CLI) generate() error { } // Run runs the CLI. -func (cli *CLI) Run() { - if err := cli.root.Execute(); err != nil { - logger.Error(err.Error()) +func (cli *CLI) Run(ctx context.Context) { + if err := cli.root.ExecuteContext(ctx); err != nil { + cli.logger.Error(err.Error()) os.Exit(1) } } diff --git a/test/e2e/node/main.go b/test/e2e/node/main.go index 7f46eea89..54b9ef533 100644 --- a/test/e2e/node/main.go +++ b/test/e2e/node/main.go @@ -34,8 +34,6 @@ import ( e2e "github.com/tendermint/tendermint/test/e2e/pkg" ) -var logger = log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo) - // main is the binary entrypoint. func main() { ctx, cancel := context.WithCancel(context.Background()) @@ -51,7 +49,6 @@ func main() { } if err := run(ctx, configFile); err != nil { - logger.Error(err.Error()) os.Exit(1) } } @@ -63,9 +60,20 @@ func run(ctx context.Context, configFile string) error { return err } + logger, err := log.NewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo) + if err != nil { + // have print here because we can't log (yet), use the logger + // everywhere else. + fmt.Fprintln(os.Stderr, "ERROR:", err) + return err + } + // Start remote signer (must start before node if running builtin). if cfg.PrivValServer != "" { - if err = startSigner(ctx, cfg); err != nil { + if err = startSigner(ctx, logger, cfg); err != nil { + logger.Error("starting signer", + "server", cfg.PrivValServer, + "err", err) return err } if cfg.Protocol == "builtin" { @@ -76,11 +84,11 @@ func run(ctx context.Context, configFile string) error { // Start app server. switch cfg.Protocol { case "socket", "grpc": - err = startApp(ctx, cfg) + err = startApp(ctx, logger, cfg) case "builtin": switch cfg.Mode { case string(e2e.ModeLight): - err = startLightNode(ctx, cfg) + err = startLightNode(ctx, logger, cfg) case string(e2e.ModeSeed): err = startSeedNode(ctx) default: @@ -90,6 +98,10 @@ func run(ctx context.Context, configFile string) error { err = fmt.Errorf("invalid protocol %q", cfg.Protocol) } if err != nil { + logger.Error("starting node", + "protocol", cfg.Protocol, + "mode", cfg.Mode, + "err", err) return err } @@ -100,7 +112,7 @@ func run(ctx context.Context, configFile string) error { } // startApp starts the application server, listening for connections from Tendermint. -func startApp(ctx context.Context, cfg *Config) error { +func startApp(ctx context.Context, logger log.Logger, cfg *Config) error { app, err := app.NewApplication(cfg.App()) if err != nil { return err @@ -160,7 +172,7 @@ func startSeedNode(ctx context.Context) error { return n.Start(ctx) } -func startLightNode(ctx context.Context, cfg *Config) error { +func startLightNode(ctx context.Context, logger log.Logger, cfg *Config) error { tmcfg, nodeLogger, err := setupNode() if err != nil { return err @@ -218,7 +230,7 @@ func startLightNode(ctx context.Context, cfg *Config) error { } // startSigner starts a signer server connecting to the given endpoint. -func startSigner(ctx context.Context, cfg *Config) error { +func startSigner(ctx context.Context, logger log.Logger, cfg *Config) error { filePV, err := privval.LoadFilePV(cfg.PrivValKey, cfg.PrivValState) if err != nil { return err