diff --git a/CHANGELOG.md b/CHANGELOG.md index a3a4842197..e3aa703460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/app.go b/app/app.go index b4df0fc360..80401cee2e 100644 --- a/app/app.go +++ b/app/app.go @@ -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()) @@ -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)) diff --git a/store/setup.go b/store/setup.go index f17cedf6da..ee4bd9f306 100644 --- a/store/setup.go +++ b/store/setup.go @@ -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)), }