Skip to content

Commit

Permalink
Problem: memiavl cache not compatible with block-stm (#1547)
Browse files Browse the repository at this point in the history
* Problem: memiavl cache not compatible with block-stm

Solution:
- disable the memiavl cache if block-stm is enabled

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

* cleanup

* fix test

* cleanup

* cleanup

---------

Signed-off-by: yihuang <[email protected]>
Co-authored-by: mmsqe <[email protected]>
  • Loading branch information
yihuang and mmsqe authored Aug 13, 2024
1 parent b4cb3ed commit bc5dfc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 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)[#1547](https://github.com/crypto-org-chain/cronos/pull/1547) Disable memiavl cache if block-stm is enabled.

### Bug Fixes

Expand Down
12 changes: 9 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,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(memiavlstore.FlagCacheSize))
}
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, cacheSize, baseAppOptions)

// enable optimistic execution
baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution())
Expand Down Expand Up @@ -414,8 +421,7 @@ func New(

app.SetDisableBlockGasMeter(true)

executor := cast.ToString(appOpts.Get(srvflags.EVMBlockExecutor))
if executor == "block-stm" {
if blockSTMEnabled {
sdk.SetAddrCacheEnabled(false)
workers := cast.ToInt(appOpts.Get(srvflags.EVMBlockSTMWorkers))
app.SetTxExecutor(evmapp.STMTxExecutor(app.GetStoreKeys(), workers))
Expand Down
12 changes: 10 additions & 2 deletions store/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ const (

// 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 bc5dfc5

Please sign in to comment.