Skip to content

Commit

Permalink
Problem: memiavl configs are not defined in app.toml (#1028)
Browse files Browse the repository at this point in the history
* Problem: memiavl configs are not defined in app.toml

Solution:
- integrate custom configs into app.toml

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

* better memiavl setup code

* fix integration test

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang committed May 15, 2023
1 parent 47d7749 commit 0d5bf68
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [#950](https://github.com/crypto-org-chain/cronos/pull/950) Implement memiavl and integrate with state machine.
- [#985](https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions
- [#998](https://github.com/crypto-org-chain/cronos/pull/998) Bump grocksdb to v1.7.16 and rocksdb to v7.10.2
- [#1028](https://github.com/crypto-org-chain/cronos/pull/1028) Add memiavl configs into app.toml


*April 13, 2023*
Expand Down
16 changes: 1 addition & 15 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,11 +149,6 @@ const (
//
// NOTE: In the SDK, the default value is 255.
AddrLen = 20

FlagMemIAVL = "store.memiavl"
FlagAsyncWAL = "store.memiavl-async-wal"
// don't enable zero-copy together with inter-block cache.
FlagZeroCopy = "store.memiavl-zero-copy"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -349,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(FlagAsyncWAL)))
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
23 changes: 23 additions & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package config

import "github.com/evmos/ethermint/server/config"

type Config struct {
config.Config

MemIAVL MemIAVLConfig `mapstructure:"memiavl"`
}

type MemIAVLConfig struct {
// Enable defines if the memiavl should be enabled.
Enable bool `mapstructure:"enable"`
// ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
// the zero-copied slices must not be retained beyond current block's execution.
ZeroCopy bool `mapstructure:"zero-copy"`
// AsyncCommit defines if the memiavl should commit asynchronously, this greatly improve block catching-up performance.
AsyncCommit bool `mapstructure:"async-commit"`
}

func DefaultMemIAVLConfig() MemIAVLConfig {
return MemIAVLConfig{}
}
20 changes: 20 additions & 0 deletions app/config/toml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package config

// DefaultConfigTemplate defines the configuration template for the EVM RPC configuration
const DefaultConfigTemplate = `
###############################################################################
### Cronos Configuration ###
###############################################################################
[memiavl]
# Enable defines if the memiavl should be enabled.
enable = {{ .MemIAVL.Enable }}
# ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
# the zero-copied slices must not be retained beyond current block's execution.
zero-copy = {{ .MemIAVL.ZeroCopy }}
# AsyncCommit defines if the memiavl should commit asynchronously, this greatly improve block catching-up performance.
async-commit = {{ .MemIAVL.AsyncCommit }}
`
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
}
7 changes: 6 additions & 1 deletion cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
ethermint "github.com/evmos/ethermint/types"

"github.com/crypto-org-chain/cronos/v2/app"
cronoscfg "github.com/crypto-org-chain/cronos/v2/app/config"
"github.com/crypto-org-chain/cronos/v2/cmd/cronosd/opendb"
"github.com/crypto-org-chain/cronos/v2/x/cronos"
// this line is used by starport scaffolding # stargate/root/import
Expand Down Expand Up @@ -210,7 +211,11 @@ func txCommand() *cobra.Command {
// initAppConfig helps to override default appConfig template and configs.
// return "", nil if no custom configuration is required for the application.
func initAppConfig() (string, interface{}) {
return servercfg.AppConfig(ethermint.AttoPhoton)
tpl, cfg := servercfg.AppConfig(ethermint.AttoPhoton)
return tpl + cronoscfg.DefaultConfigTemplate, cronoscfg.Config{
Config: cfg.(servercfg.Config),
MemIAVL: cronoscfg.DefaultMemIAVLConfig(),
}
}

type appCreator struct {
Expand Down
1 change: 1 addition & 0 deletions integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config {
'app-config'+: {
'app-db-backend': 'rocksdb',
'minimum-gas-prices': '100000000000basetcro',
memiavl:: super.memiavl,
store:: super.store,
streamers:: super.streamers,
'iavl-lazy-loading':: super['iavl-lazy-loading'],
Expand Down
1 change: 1 addition & 0 deletions integration_tests/configs/cosmovisor_gravity.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config {
'app-config'+: {
'app-db-backend': 'rocksdb',
'minimum-gas-prices': '100000000000basetcro',
memiavl:: super.memiavl,
store:: super.store,
streamers:: super.streamers,
'iavl-lazy-loading':: super['iavl-lazy-loading'],
Expand Down
6 changes: 4 additions & 2 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': {
memiavl: {
enable: true,
'zero-copy': true,
},
store: {
memiavl: true,
'memiavl-zero-copy': true,
streamers: ['versiondb'],
},
},
Expand Down

0 comments on commit 0d5bf68

Please sign in to comment.