diff --git a/cmd/tendermint/commands/reindex_event.go b/cmd/tendermint/commands/reindex_event.go index 58f11657b..bd9577963 100644 --- a/cmd/tendermint/commands/reindex_event.go +++ b/cmd/tendermint/commands/reindex_event.go @@ -3,6 +3,7 @@ package commands import ( "errors" "fmt" + "path/filepath" "strings" "github.com/spf13/cobra" @@ -16,6 +17,7 @@ import ( "github.com/tendermint/tendermint/internal/state/indexer/sink/kv" "github.com/tendermint/tendermint/internal/state/indexer/sink/psql" "github.com/tendermint/tendermint/internal/store" + "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/rpc/coretypes" "github.com/tendermint/tendermint/types" ) @@ -132,6 +134,10 @@ func loadEventSinks(cfg *tmcfg.Config) ([]indexer.EventSink, error) { func loadStateAndBlockStore(cfg *tmcfg.Config) (*store.BlockStore, state.Store, error) { dbType := dbm.BackendType(cfg.DBBackend) + if !os.FileExists(filepath.Join(cfg.DBDir(), "blockstore.db")) { + return nil, nil, fmt.Errorf("no blockstore found in %v", cfg.DBDir()) + } + // Get BlockStore blockStoreDB, err := dbm.NewDB("blockstore", dbType, cfg.DBDir()) if err != nil { @@ -139,6 +145,10 @@ func loadStateAndBlockStore(cfg *tmcfg.Config) (*store.BlockStore, state.Store, } blockStore := store.NewBlockStore(blockStoreDB) + if !os.FileExists(filepath.Join(cfg.DBDir(), "state.db")) { + return nil, nil, fmt.Errorf("no blockstore found in %v", cfg.DBDir()) + } + // Get StateStore stateDB, err := dbm.NewDB("state", dbType, cfg.DBDir()) if err != nil { diff --git a/cmd/tendermint/commands/reindex_event_test.go b/cmd/tendermint/commands/reindex_event_test.go index c76ce6d9a..2008251bc 100644 --- a/cmd/tendermint/commands/reindex_event_test.go +++ b/cmd/tendermint/commands/reindex_event_test.go @@ -15,6 +15,7 @@ import ( "github.com/tendermint/tendermint/internal/state/mocks" prototmstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/tendermint/tendermint/types" + dbm "github.com/tendermint/tm-db" _ "github.com/lib/pq" // for the psql sink ) @@ -109,12 +110,29 @@ func TestLoadEventSink(t *testing.T) { } func TestLoadBlockStore(t *testing.T) { - bs, ss, err := loadStateAndBlockStore(tmcfg.TestConfig()) + testCfg, err := tmcfg.ResetTestRoot(t.Name()) + require.NoError(t, err) + testCfg.DBBackend = "goleveldb" + _, _, err = loadStateAndBlockStore(testCfg) + // we should return an error because the state store and block store + // don't yet exist + require.Error(t, err) + + dbType := dbm.BackendType(testCfg.DBBackend) + bsdb, err := dbm.NewDB("blockstore", dbType, testCfg.DBDir()) + require.NoError(t, err) + bsdb.Close() + + ssdb, err := dbm.NewDB("state", dbType, testCfg.DBDir()) + require.NoError(t, err) + ssdb.Close() + + bs, ss, err := loadStateAndBlockStore(testCfg) require.NoError(t, err) require.NotNil(t, bs) require.NotNil(t, ss) - } + func TestReIndexEvent(t *testing.T) { mockBlockStore := &mocks.BlockStore{} mockStateStore := &mocks.Store{} diff --git a/cmd/tendermint/commands/rollback.go b/cmd/tendermint/commands/rollback.go index c19d35cce..8391ee506 100644 --- a/cmd/tendermint/commands/rollback.go +++ b/cmd/tendermint/commands/rollback.go @@ -26,7 +26,7 @@ application. return fmt.Errorf("failed to rollback state: %w", err) } - fmt.Printf("Rolled back state to height %d and hash %v", height, hash) + fmt.Printf("Rolled back state to height %d and hash %X", height, hash) return nil }, }