Skip to content

Commit

Permalink
Problem: memiavl cache not compatible with block-stm
Browse files Browse the repository at this point in the history
Solution:
- disable the memiavl cache if block-stm is enabled
  • Loading branch information
yihuang committed Aug 13, 2024
1 parent b4cb3ed commit 9b94779
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* (block-stm) [#1515](https://github.com/crypto-org-chain/cronos/pull/1515) Improve performance by cache signature verification result between incarnations of same tx.
* (store) [#1526](https://github.com/crypto-org-chain/cronos/pull/1526) Cache index/filters in rocksdb application.db to reduce ram usage.
* (store)[#1529](https://github.com/crypto-org-chain/cronos/pull/1529) Enable pinL0FilterAndIndexBlocksInCache.
* (store)[#]() Disable memiavl cache if block-stm is enabled.

### Bug Fixes

Expand Down
10 changes: 9 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const (
AddrLen = 20

FlagBlockedAddresses = "blocked-addresses"
FlagCacheSize = "memiavl.cache-size"
)

var Forks = []Fork{}
Expand Down Expand Up @@ -382,8 +383,15 @@ func New(
app.SetProcessProposal(handler.ProcessProposalHandler())
})

blockSTMEnabled := cast.ToString(appOpts.Get(srvflags.EVMBlockExecutor)) == "block-stm"

homePath := cast.ToString(appOpts.Get(flags.FlagHome))
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, baseAppOptions)
var cacheSize int
if !blockSTMEnabled {
// only enable memiavl cache if block-stm is not enabled, because it's not concurrency-safe.
cacheSize = cast.ToInt(appOpts.Get(FlagCacheSize))
}
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, cacheSize, baseAppOptions)

// enable optimistic execution
baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution())
Expand Down
13 changes: 10 additions & 3 deletions store/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@ const (
FlagZeroCopy = "memiavl.zero-copy"
FlagSnapshotKeepRecent = "memiavl.snapshot-keep-recent"
FlagSnapshotInterval = "memiavl.snapshot-interval"
FlagCacheSize = "memiavl.cache-size"
FlagSnapshotWriterLimit = "memiavl.snapshot-writer-limit"
)

// SetupMemIAVL insert the memiavl setter in front of baseapp options, so that
// the default rootmulti store is replaced by memiavl store,
func SetupMemIAVL(logger log.Logger, homePath string, appOpts servertypes.AppOptions, sdk46Compact bool, supportExportNonSnapshotVersion bool, baseAppOptions []func(*baseapp.BaseApp)) []func(*baseapp.BaseApp) {
func SetupMemIAVL(
logger log.Logger,
homePath string,
appOpts servertypes.AppOptions,
sdk46Compact bool,
supportExportNonSnapshotVersion bool,
cacheSize int,
baseAppOptions []func(*baseapp.BaseApp),
) []func(*baseapp.BaseApp) {
if cast.ToBool(appOpts.Get(FlagMemIAVL)) {
opts := 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)),
CacheSize: cacheSize,
SnapshotWriterLimit: cast.ToInt(appOpts.Get(FlagSnapshotWriterLimit)),
}

Expand Down

0 comments on commit 9b94779

Please sign in to comment.