forked from crypto-org-chain/chain-main
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: memiavl is not integrated (crypto-org-chain#989)
* Problem: memiavl is not integrated Solution: - integrate memiavl feature * test memiavl in integration test * Update CHANGELOG.md Signed-off-by: yihuang <huang@crypto.com> * Update app/config/toml.go Signed-off-by: yihuang <huang@crypto.com> * update memiavl * update memiavl * update memiavl --------- Signed-off-by: yihuang <huang@crypto.com>
- Loading branch information
Showing
12 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package config | ||
|
||
import "github.com/crypto-org-chain/cronos/memiavl" | ||
|
||
const DefaultCacheSize = 1000 | ||
|
||
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"` | ||
// 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"` | ||
// CacheSize defines the size of the cache for each memiavl store. | ||
CacheSize int `mapstructure:"cache-size"` | ||
} | ||
|
||
func DefaultMemIAVLConfig() MemIAVLConfig { | ||
return MemIAVLConfig{ | ||
CacheSize: DefaultCacheSize, | ||
SnapshotInterval: memiavl.DefaultSnapshotInterval, | ||
ZeroCopy: true, | ||
SnapshotKeepRecent: 1, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
// DefaultConfigTemplate defines the configuration template for the memiavl configuration | ||
const DefaultConfigTemplate = ` | ||
############################################################################### | ||
### MemIAVL 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 }} | ||
# 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 }} | ||
# CacheSize defines the size of the cache for each memiavl store, default to 1000. | ||
cache-size = {{ .MemIAVL.CacheSize }} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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" | ||
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" | ||
FlagSnapshotKeepRecent = "memiavl.snapshot-keep-recent" | ||
FlagSnapshotInterval = "memiavl.snapshot-interval" | ||
FlagCacheSize = "memiavl.cache-size" | ||
) | ||
|
||
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.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)), | ||
CacheSize: cast.ToInt(appOpts.Get(FlagCacheSize)), | ||
}) | ||
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) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local config = import 'default.jsonnet'; | ||
|
||
config { | ||
chaintest+: { | ||
validators: [super.validators[0] { | ||
'app-config':: super['app-config'], | ||
}] + super.validators[1:], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters