Skip to content

Commit

Permalink
Connect versiondb streaming service to app.go
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Aug 15, 2023
1 parent b33b394 commit 1f28711
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions versiondb/streaming_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down
19 changes: 17 additions & 2 deletions versiondb/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,31 @@ 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")
}

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)
Expand Down

0 comments on commit 1f28711

Please sign in to comment.