From 1f287110359b3a38f7db4fe7d45f847b16322015 Mon Sep 17 00:00:00 2001 From: Tasio Victoria Date: Tue, 15 Aug 2023 14:58:09 -0400 Subject: [PATCH] Connect versiondb streaming service to app.go --- app/app.go | 6 ++++++ versiondb/streaming_service.go | 8 ++++++-- versiondb/streaming_test.go | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index 443e79a55..65ec215b8 100644 --- a/app/app.go +++ b/app/app.go @@ -360,6 +360,12 @@ func NewStargazeApp( tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + // load state streaming if enabled + if _, _, err := LoadStreamingServices(bApp, appOpts, appCodec, keys); err != nil { + fmt.Printf("failed to load state streaming: %s", err) + os.Exit(1) + } + app := &App{ BaseApp: bApp, cdc: cdc, diff --git a/versiondb/streaming_service.go b/versiondb/streaming_service.go index 21d6d5167..9b53482a2 100644 --- a/versiondb/streaming_service.go +++ b/versiondb/streaming_service.go @@ -9,10 +9,13 @@ import ( "sync" "github.com/public-awesome/stargaze/v11/versiondb/tsrocksdb" + "github.com/spf13/cast" abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/store/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" ) @@ -30,10 +33,11 @@ type StreamingService struct { // NewFileStreamingService is the streaming.ServiceConstructor function for // creating a FileStreamingService. func NewVersionDbStreamingService( - homePath string, + opts servertypes.AppOptions, keys []storetypes.StoreKey, marshaller codec.BinaryCodec, -) (*StreamingService, error) { +) (baseapp.StreamingService, error) { + homePath := cast.ToString(opts.Get(flags.FlagHome)) dataDir := filepath.Join(homePath, "data", "versiondb") if err := os.MkdirAll(dataDir, os.ModePerm); err != nil { return nil, err diff --git a/versiondb/streaming_test.go b/versiondb/streaming_test.go index 45aba583b..139b26c9c 100644 --- a/versiondb/streaming_test.go +++ b/versiondb/streaming_test.go @@ -106,6 +106,18 @@ var ( mockValue3 = []byte{5, 4, 3} ) +type fakeOptions struct { + home string +} + +func (f fakeOptions) Get(key string) interface{} { + if key == "home" { + return f.home + + } + return nil +} + func TestVersionDbStreamingService(t *testing.T) { if os.Getenv("CI") != "" { t.Skip("Skipping TestFileStreamingService in CI environment") @@ -113,9 +125,12 @@ func TestVersionDbStreamingService(t *testing.T) { testKeys := []types.StoreKey{mockStoreKey1, mockStoreKey2} var err error + var ok bool - dbDir := t.TempDir() - testStreamingService, err = NewVersionDbStreamingService(dbDir, testKeys, testMarshaller) + testAppOptions := fakeOptions{} + streamingService, err := NewVersionDbStreamingService(testAppOptions, testKeys, testMarshaller) + testStreamingService, ok = streamingService.(*StreamingService) + require.True(t, ok) require.Nil(t, err) require.IsType(t, &StreamingService{}, testStreamingService)