Skip to content

Commit 0d5bf68

Browse files
author
yihuang
authored
Problem: memiavl configs are not defined in app.toml (#1028)
* 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>
1 parent 47d7749 commit 0d5bf68

9 files changed

Lines changed: 89 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [#950](https://github.com/crypto-org-chain/cronos/pull/950) Implement memiavl and integrate with state machine.
3232
- [#985](https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions
3333
- [#998](https://github.com/crypto-org-chain/cronos/pull/998) Bump grocksdb to v1.7.16 and rocksdb to v7.10.2
34+
- [#1028](https://github.com/crypto-org-chain/cronos/pull/1028) Add memiavl configs into app.toml
3435

3536

3637
*April 13, 2023*

app/app.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ import (
125125

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

128-
"github.com/crypto-org-chain/cronos/store/rootmulti"
129128
"github.com/crypto-org-chain/cronos/v2/x/cronos"
130129
cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client"
131130
cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
@@ -150,11 +149,6 @@ const (
150149
//
151150
// NOTE: In the SDK, the default value is 255.
152151
AddrLen = 20
153-
154-
FlagMemIAVL = "store.memiavl"
155-
FlagAsyncWAL = "store.memiavl-async-wal"
156-
// don't enable zero-copy together with inter-block cache.
157-
FlagZeroCopy = "store.memiavl-zero-copy"
158152
)
159153

160154
// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
@@ -349,15 +343,7 @@ func New(
349343
cdc := encodingConfig.Amino
350344
interfaceRegistry := encodingConfig.InterfaceRegistry
351345

352-
if cast.ToBool(appOpts.Get(FlagMemIAVL)) {
353-
// cms must be overridden before the other options, because they may use the cms,
354-
// FIXME we are assuming the cms won't be overridden by the other options, but we can't be sure.
355-
cms := rootmulti.NewStore(filepath.Join(homePath, "data", "memiavl.db"), logger)
356-
cms.SetAsyncWAL(cast.ToBool(appOpts.Get(FlagAsyncWAL)))
357-
cms.SetZeroCopy(cast.ToBool(appOpts.Get(FlagZeroCopy)))
358-
baseAppOptions = append([]func(*baseapp.BaseApp){setCMS(cms)}, baseAppOptions...)
359-
}
360-
346+
baseAppOptions = SetupMemIAVL(logger, homePath, appOpts, baseAppOptions)
361347
bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
362348

363349
bApp.SetCommitMultiStoreTracer(traceStore)

app/config/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package config
2+
3+
import "github.com/evmos/ethermint/server/config"
4+
5+
type Config struct {
6+
config.Config
7+
8+
MemIAVL MemIAVLConfig `mapstructure:"memiavl"`
9+
}
10+
11+
type MemIAVLConfig struct {
12+
// Enable defines if the memiavl should be enabled.
13+
Enable bool `mapstructure:"enable"`
14+
// ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
15+
// the zero-copied slices must not be retained beyond current block's execution.
16+
ZeroCopy bool `mapstructure:"zero-copy"`
17+
// AsyncCommit defines if the memiavl should commit asynchronously, this greatly improve block catching-up performance.
18+
AsyncCommit bool `mapstructure:"async-commit"`
19+
}
20+
21+
func DefaultMemIAVLConfig() MemIAVLConfig {
22+
return MemIAVLConfig{}
23+
}

app/config/toml.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package config
2+
3+
// DefaultConfigTemplate defines the configuration template for the EVM RPC configuration
4+
const DefaultConfigTemplate = `
5+
###############################################################################
6+
### Cronos Configuration ###
7+
###############################################################################
8+
9+
[memiavl]
10+
11+
# Enable defines if the memiavl should be enabled.
12+
enable = {{ .MemIAVL.Enable }}
13+
14+
# ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
15+
# the zero-copied slices must not be retained beyond current block's execution.
16+
zero-copy = {{ .MemIAVL.ZeroCopy }}
17+
18+
# AsyncCommit defines if the memiavl should commit asynchronously, this greatly improve block catching-up performance.
19+
async-commit = {{ .MemIAVL.AsyncCommit }}
20+
`

app/memiavl.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package app
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/spf13/cast"
7+
"github.com/tendermint/tendermint/libs/log"
8+
9+
"github.com/cosmos/cosmos-sdk/baseapp"
10+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
11+
12+
"github.com/crypto-org-chain/cronos/store/rootmulti"
13+
)
14+
15+
const (
16+
FlagMemIAVL = "memiavl.enable"
17+
FlagAsyncCommit = "memiavl.async-commit"
18+
FlagZeroCopy = "memiavl.zero-copy"
19+
)
20+
21+
func SetupMemIAVL(logger log.Logger, homePath string, appOpts servertypes.AppOptions, baseAppOptions []func(*baseapp.BaseApp)) []func(*baseapp.BaseApp) {
22+
if cast.ToBool(appOpts.Get(FlagMemIAVL)) {
23+
// cms must be overridden before the other options, because they may use the cms,
24+
// make sure the cms aren't be overridden by the other options later on.
25+
cms := rootmulti.NewStore(filepath.Join(homePath, "data", "memiavl.db"), logger)
26+
cms.SetAsyncWAL(cast.ToBool(appOpts.Get(FlagAsyncCommit)))
27+
cms.SetZeroCopy(cast.ToBool(appOpts.Get(FlagZeroCopy)))
28+
baseAppOptions = append([]func(*baseapp.BaseApp){setCMS(cms)}, baseAppOptions...)
29+
}
30+
31+
return baseAppOptions
32+
}

cmd/cronosd/cmd/root.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
ethermint "github.com/evmos/ethermint/types"
4040

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

216221
type appCreator struct {

integration_tests/configs/cosmovisor.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config {
55
'app-config'+: {
66
'app-db-backend': 'rocksdb',
77
'minimum-gas-prices': '100000000000basetcro',
8+
memiavl:: super.memiavl,
89
store:: super.store,
910
streamers:: super.streamers,
1011
'iavl-lazy-loading':: super['iavl-lazy-loading'],

integration_tests/configs/cosmovisor_gravity.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config {
55
'app-config'+: {
66
'app-db-backend': 'rocksdb',
77
'minimum-gas-prices': '100000000000basetcro',
8+
memiavl:: super.memiavl,
89
store:: super.store,
910
streamers:: super.streamers,
1011
'iavl-lazy-loading':: super['iavl-lazy-loading'],

integration_tests/configs/default.jsonnet

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
staked: '1000000000000000000stake',
2828
mnemonic: '${VALIDATOR1_MNEMONIC}',
2929
'app-config': {
30+
memiavl: {
31+
enable: true,
32+
'zero-copy': true,
33+
},
3034
store: {
31-
memiavl: true,
32-
'memiavl-zero-copy': true,
3335
streamers: ['versiondb'],
3436
},
3537
},

0 commit comments

Comments
 (0)