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: memiavl configs are not defined in app.toml #1028

Merged
merged 4 commits into from
May 15, 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
Prev Previous commit
Next Next commit
better memiavl setup code
  • Loading branch information
yihuang committed May 15, 2023
commit bc88c8ef08a40f86c17d934c831aeb64d6b841b8
15 changes: 1 addition & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ import (

// this line is used by starport scaffolding # stargate/app/moduleImport

"github.com/crypto-org-chain/cronos/store/rootmulti"
"github.com/crypto-org-chain/cronos/v2/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client"
cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
Expand All @@ -150,10 +149,6 @@ const (
//
// NOTE: In the SDK, the default value is 255.
AddrLen = 20

FlagMemIAVL = "memiavl.enable"
FlagAsyncCommit = "memiavl.async-commit"
FlagZeroCopy = "memiavl.zero-copy"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -348,15 +343,7 @@ func New(
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

if cast.ToBool(appOpts.Get(FlagMemIAVL)) {
// cms must be overridden before the other options, because they may use the cms,
// FIXME we are assuming the cms won't be overridden by the other options, but we can't be sure.
cms := rootmulti.NewStore(filepath.Join(homePath, "data", "memiavl.db"), logger)
cms.SetAsyncWAL(cast.ToBool(appOpts.Get(FlagAsyncCommit)))
cms.SetZeroCopy(cast.ToBool(appOpts.Get(FlagZeroCopy)))
baseAppOptions = append([]func(*baseapp.BaseApp){setCMS(cms)}, baseAppOptions...)
}

baseAppOptions = SetupMemIAVL(logger, homePath, appOpts, baseAppOptions)
bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)

bApp.SetCommitMultiStoreTracer(traceStore)
Expand Down
32 changes: 32 additions & 0 deletions app/memiavl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package app

import (
"path/filepath"

"github.com/spf13/cast"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/baseapp"
servertypes "github.com/cosmos/cosmos-sdk/server/types"

"github.com/crypto-org-chain/cronos/store/rootmulti"
)

const (
FlagMemIAVL = "memiavl.enable"
FlagAsyncCommit = "memiavl.async-commit"
FlagZeroCopy = "memiavl.zero-copy"
)

func SetupMemIAVL(logger log.Logger, homePath string, appOpts servertypes.AppOptions, baseAppOptions []func(*baseapp.BaseApp)) []func(*baseapp.BaseApp) {
if cast.ToBool(appOpts.Get(FlagMemIAVL)) {
// cms must be overridden before the other options, because they may use the cms,
// make sure the cms aren't be overridden by the other options later on.
cms := rootmulti.NewStore(filepath.Join(homePath, "data", "memiavl.db"), logger)
cms.SetAsyncWAL(cast.ToBool(appOpts.Get(FlagAsyncCommit)))
cms.SetZeroCopy(cast.ToBool(appOpts.Get(FlagZeroCopy)))
baseAppOptions = append([]func(*baseapp.BaseApp){setCMS(cms)}, baseAppOptions...)
}

return baseAppOptions
}