Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: versiondb multistore can't query mem store state #1230

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [#1215](https://github.com/crypto-org-chain/cronos/pull/1215) Update ethermint to fix of concurrent write in fee history.
- [#1217](https://github.com/crypto-org-chain/cronos/pull/1217) Use the default chain-id behavour in sdk.
- [#]() Fix mem store in versiondb multistore.
yihuang marked this conversation as resolved.
Show resolved Hide resolved
yihuang marked this conversation as resolved.
Show resolved Hide resolved

*October 17, 2023*

Expand Down
34 changes: 17 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,23 +402,6 @@ func New(

keys, memKeys, tkeys := StoreKeys(skipGravity)

// load state streaming if enabled
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil {
fmt.Printf("failed to load state streaming: %s", err)
os.Exit(1)
}

// wire up the versiondb's `StreamingService` and `MultiStore`.
streamers := cast.ToStringSlice(appOpts.Get("store.streamers"))
var qms sdk.MultiStore
if slices.Contains(streamers, "versiondb") {
var err error
qms, err = setupVersionDB(homePath, bApp, keys, tkeys, memKeys)
if err != nil {
panic(err)
}
}

app := &App{
BaseApp: bApp,
cdc: cdc,
Expand Down Expand Up @@ -868,6 +851,23 @@ func New(
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

// load state streaming if enabled
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil {
fmt.Printf("failed to load state streaming: %s", err)
os.Exit(1)
}

// wire up the versiondb's `StreamingService` and `MultiStore`.
streamers := cast.ToStringSlice(appOpts.Get("store.streamers"))
var qms sdk.MultiStore
if slices.Contains(streamers, "versiondb") {
var err error
qms, err = app.setupVersionDB(homePath, keys, tkeys, memKeys)
if err != nil {
panic(err)
}
}
mmsqe marked this conversation as resolved.
Show resolved Hide resolved

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetPreBlocker(app.PreBlocker)
Expand Down
12 changes: 8 additions & 4 deletions app/versiondb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/crypto-org-chain/cronos/versiondb/tsrocksdb"
)

func setupVersionDB(
// setupVersionDB needs to reuse the existing mem store instances, call this **after** the `app.MountMemoryStores()`.
func (app *App) setupVersionDB(
homePath string,
app *baseapp.BaseApp,
keys map[string]*storetypes.KVStoreKey,
tkeys map[string]*storetypes.TransientStoreKey,
memKeys map[string]*storetypes.MemoryStoreKey,
Expand All @@ -41,7 +40,12 @@ func setupVersionDB(

verDB := versiondb.NewMultiStore(versionDB, exposeStoreKeys)
verDB.MountTransientStores(tkeys)
verDB.MountMemoryStores(memKeys)

memStores := make(map[storetypes.StoreKey]storetypes.KVStore)
for _, memKey := range memKeys {
memStores[memKey] = app.CommitMultiStore().GetKVStore(memKey)
}
verDB.MountMemoryStores(memStores)

app.SetQueryMultiStore(verDB)
return verDB, nil
Expand Down
4 changes: 1 addition & 3 deletions app/versiondb_placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ package app
import (
"errors"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func setupVersionDB(
func (app *App) setupVersionDB(
homePath string,
app *baseapp.BaseApp,
keys map[string]*storetypes.KVStoreKey,
tkeys map[string]*storetypes.TransientStoreKey,
memKeys map[string]*storetypes.MemoryStoreKey,
Expand Down
10 changes: 5 additions & 5 deletions versiondb/multistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sync"

"github.com/cosmos/cosmos-sdk/store/cachemulti"
"github.com/cosmos/cosmos-sdk/store/mem"
"github.com/cosmos/cosmos-sdk/store/transient"
"github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -89,10 +88,11 @@ func (s *MultiStore) MountTransientStores(keys map[string]*types.TransientStoreK
}
}

// MountMemoryStores simlates the same behavior as sdk to support grpc query service.
func (s *MultiStore) MountMemoryStores(keys map[string]*types.MemoryStoreKey) {
for _, key := range keys {
s.transientStores[key] = mem.NewStore()
// MountMemoryStores simlates the same behavior as sdk to support grpc query service,
// it shares the existing mem store instance.
func (s *MultiStore) MountMemoryStores(keys map[types.StoreKey]types.KVStore) {
for key, store := range keys {
s.transientStores[key] = store
}
}

Expand Down
Loading