From 07d10184a11fd2a155ad251df3544badf495ea8a Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Wed, 22 Sep 2021 12:32:49 -0400 Subject: [PATCH] inspect: remove duplicated construction path (#6966) --- cmd/tendermint/commands/inspect.go | 28 ++----------------- {inspect => internal/inspect}/doc.go | 0 {inspect => internal/inspect}/inspect.go | 5 ++-- {inspect => internal/inspect}/inspect_test.go | 10 +++++-- {inspect => internal/inspect}/rpc/rpc.go | 0 5 files changed, 11 insertions(+), 32 deletions(-) rename {inspect => internal/inspect}/doc.go (100%) rename {inspect => internal/inspect}/inspect.go (96%) rename {inspect => internal/inspect}/inspect_test.go (98%) rename {inspect => internal/inspect}/rpc/rpc.go (100%) diff --git a/cmd/tendermint/commands/inspect.go b/cmd/tendermint/commands/inspect.go index de31d33d4..3cd6ef572 100644 --- a/cmd/tendermint/commands/inspect.go +++ b/cmd/tendermint/commands/inspect.go @@ -8,12 +8,7 @@ import ( "github.com/spf13/cobra" - cfg "github.com/tendermint/tendermint/config" - "github.com/tendermint/tendermint/inspect" - "github.com/tendermint/tendermint/state" - "github.com/tendermint/tendermint/state/indexer/sink" - "github.com/tendermint/tendermint/store" - "github.com/tendermint/tendermint/types" + "github.com/tendermint/tendermint/internal/inspect" ) // InspectCmd is the command for starting an inspect server. @@ -55,29 +50,10 @@ func runInspect(cmd *cobra.Command, args []string) error { cancel() }() - blockStoreDB, err := cfg.DefaultDBProvider(&cfg.DBContext{ID: "blockstore", Config: config}) + ins, err := inspect.NewFromConfig(logger, config) if err != nil { return err } - blockStore := store.NewBlockStore(blockStoreDB) - stateDB, err := cfg.DefaultDBProvider(&cfg.DBContext{ID: "state", Config: config}) - if err != nil { - if err := blockStoreDB.Close(); err != nil { - logger.Error("error closing block store db", "error", err) - } - return err - } - genDoc, err := types.GenesisDocFromFile(config.GenesisFile()) - if err != nil { - return err - } - sinks, err := sink.EventSinksFromConfig(config, cfg.DefaultDBProvider, genDoc.ChainID) - if err != nil { - return err - } - stateStore := state.NewStore(stateDB) - - ins := inspect.New(config.RPC, blockStore, stateStore, sinks, logger) logger.Info("starting inspect server") if err := ins.Run(ctx); err != nil { diff --git a/inspect/doc.go b/internal/inspect/doc.go similarity index 100% rename from inspect/doc.go rename to internal/inspect/doc.go diff --git a/inspect/inspect.go b/internal/inspect/inspect.go similarity index 96% rename from inspect/inspect.go rename to internal/inspect/inspect.go index 38bc9ed5d..f27baa6ef 100644 --- a/inspect/inspect.go +++ b/internal/inspect/inspect.go @@ -7,7 +7,7 @@ import ( "net" "github.com/tendermint/tendermint/config" - "github.com/tendermint/tendermint/inspect/rpc" + "github.com/tendermint/tendermint/internal/inspect/rpc" "github.com/tendermint/tendermint/libs/log" tmstrings "github.com/tendermint/tendermint/libs/strings" rpccore "github.com/tendermint/tendermint/rpc/core" @@ -58,7 +58,7 @@ func New(cfg *config.RPCConfig, bs state.BlockStore, ss state.Store, es []indexe } // NewFromConfig constructs an Inspector using the values defined in the passed in config. -func NewFromConfig(cfg *config.Config) (*Inspector, error) { +func NewFromConfig(logger log.Logger, cfg *config.Config) (*Inspector, error) { bsDB, err := config.DefaultDBProvider(&config.DBContext{ID: "blockstore", Config: cfg}) if err != nil { return nil, err @@ -76,7 +76,6 @@ func NewFromConfig(cfg *config.Config) (*Inspector, error) { if err != nil { return nil, err } - logger := log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo, false) ss := state.NewStore(sDB) return New(cfg.RPC, bs, ss, sinks, logger), nil } diff --git a/inspect/inspect_test.go b/internal/inspect/inspect_test.go similarity index 98% rename from inspect/inspect_test.go rename to internal/inspect/inspect_test.go index c2a1df571..6d814208f 100644 --- a/inspect/inspect_test.go +++ b/internal/inspect/inspect_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" - "github.com/tendermint/tendermint/inspect" + "github.com/tendermint/tendermint/internal/inspect" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/pubsub/query" "github.com/tendermint/tendermint/proto/tendermint/state" @@ -28,10 +28,12 @@ import ( func TestInspectConstructor(t *testing.T) { cfg := config.ResetTestRoot("test") + testLogger := log.TestingLogger() t.Cleanup(leaktest.Check(t)) defer func() { _ = os.RemoveAll(cfg.RootDir) }() t.Run("from config", func(t *testing.T) { - d, err := inspect.NewFromConfig(cfg) + logger := testLogger.With(t.Name()) + d, err := inspect.NewFromConfig(logger, cfg) require.NoError(t, err) require.NotNil(t, d) }) @@ -40,10 +42,12 @@ func TestInspectConstructor(t *testing.T) { func TestInspectRun(t *testing.T) { cfg := config.ResetTestRoot("test") + testLogger := log.TestingLogger() t.Cleanup(leaktest.Check(t)) defer func() { _ = os.RemoveAll(cfg.RootDir) }() t.Run("from config", func(t *testing.T) { - d, err := inspect.NewFromConfig(cfg) + logger := testLogger.With(t.Name()) + d, err := inspect.NewFromConfig(logger, cfg) require.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) stoppedWG := &sync.WaitGroup{} diff --git a/inspect/rpc/rpc.go b/internal/inspect/rpc/rpc.go similarity index 100% rename from inspect/rpc/rpc.go rename to internal/inspect/rpc/rpc.go