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 snapshot rewriting is not triggered #1034

Merged
merged 18 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
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 @@ -35,6 +35,7 @@
- [#1028](/~https://github.com/crypto-org-chain/cronos/pull/1028) Add memiavl configs into app.toml
- [#1027](/~https://github.com/crypto-org-chain/cronos/pull/1027) Integrate local state-sync commands.
- [#1029](/~https://github.com/crypto-org-chain/cronos/pull/1029) Change config `async-commit` to `async-commit-buffer`, make the channel size configurable.
- [#1034](/~https://github.com/crypto-org-chain/cronos/pull/1034) Support memiavl snapshot strategy configuration.

*April 13, 2023*

Expand Down
10 changes: 8 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import (

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

memiavlrootmulti "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 Down Expand Up @@ -995,6 +996,11 @@ func VerifyAddressFormat(bz []byte) error {
return nil
}

func setCMS(cms storetypes.CommitMultiStore) func(*baseapp.BaseApp) {
return func(bapp *baseapp.BaseApp) { bapp.SetCMS(cms) }
// Close will be called in graceful shutdown in start cmd
func (app *App) Close() error {
if cms, ok := app.CommitMultiStore().(*memiavlrootmulti.Store); ok {
return cms.WaitAsyncCommit()
}

return nil
}
4 changes: 4 additions & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type MemIAVLConfig struct {
// AsyncCommitBuffer defines the size of asynchronous commit queue, this greatly improve block catching-up
// performance, -1 means synchronous commit.
AsyncCommitBuffer int `mapstructure:"async-commit-buffer"`
// SnapshotKeepRecent defines what many old snapshots (excluding the latest one) to keep after new snapshots are taken.
SnapshotKeepRecent uint32 `mapstructure:"snapshot-keep-recent"`
// SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 1000.
SnapshotInterval uint32 `mapstructure:"snapshot-interval"`
}

func DefaultMemIAVLConfig() MemIAVLConfig {
Expand Down
6 changes: 6 additions & 0 deletions app/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ zero-copy = {{ .MemIAVL.ZeroCopy }}
# AsyncCommitBuffer defines the size of asynchronous commit queue, this greatly improve block catching-up
# performance, -1 means synchronous commit.
async-commit-buffer = {{ .MemIAVL.AsyncCommitBuffer }}

# SnapshotKeepRecent defines what many old snapshots (excluding the latest one) to keep after new snapshots are taken.
snapshot-keep-recent = {{ .MemIAVL.SnapshotKeepRecent }}

# SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 1000.
snapshot-interval = {{ .MemIAVL.SnapshotInterval }}
`
24 changes: 19 additions & 5 deletions app/memiavl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,39 @@ import (

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

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

const (
FlagMemIAVL = "memiavl.enable"
FlagAsyncCommitBuffer = "memiavl.async-commit-buffer"
FlagZeroCopy = "memiavl.zero-copy"
FlagMemIAVL = "memiavl.enable"
FlagAsyncCommitBuffer = "memiavl.async-commit-buffer"
FlagZeroCopy = "memiavl.zero-copy"
FlagSnapshotKeepRecent = "memiavl.snapshot-keep-recent"
FlagSnapshotInterval = "memiavl.snapshot-interval"
)

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.SetAsyncCommitBuffer(cast.ToInt(appOpts.Get(FlagAsyncCommitBuffer)))
cms.SetZeroCopy(cast.ToBool(appOpts.Get(FlagZeroCopy)))
cms.SetMemIAVLOptions(memiavl.Options{
AsyncCommitBuffer: cast.ToInt(appOpts.Get(FlagAsyncCommitBuffer)),
ZeroCopy: cast.ToBool(appOpts.Get(FlagZeroCopy)),
SnapshotKeepRecent: cast.ToUint32(appOpts.Get(FlagSnapshotKeepRecent)),
SnapshotInterval: cast.ToUint32(appOpts.Get(FlagSnapshotInterval)),
// make sure a few queryable states even with pruning="nothing", needed for ibc relayer to work.
MinQueryStates: 3,
})
baseAppOptions = append([]func(*baseapp.BaseApp){setCMS(cms)}, baseAppOptions...)
}

return baseAppOptions
}

func setCMS(cms storetypes.CommitMultiStore) func(*baseapp.BaseApp) {
return func(bapp *baseapp.BaseApp) { bapp.SetCMS(cms) }
}
2 changes: 2 additions & 0 deletions integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
staked: '1000000000000000000stake',
mnemonic: '${VALIDATOR1_MNEMONIC}',
'app-config': {
'inter-block-cache': false,
memiavl: {
enable: true,
'zero-copy': true,
'snapshot-interval': 5,
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
},
store: {
streamers: ['versiondb'],
Expand Down
Loading