Skip to content

Commit

Permalink
mpt gap commit (#14)
Browse files Browse the repository at this point in the history
* unify TriesInMemory and TrieCommitGap

* modify mpt ac gap param

* update trie chosen logic

* if TrieCommitGap < TriesInMemory, we should commit trie

* delete cap

* async store

* just test mpt ac

* just test mpt ac

* del the treeInMemory

* rename inmport

* update go mod

* remove async commit

* modify mpt ac gap param

* remove unsupport method

* rm iavl-enable-async-commit & add tree-enable-async-commit

* mpt EnableAsyncCommit param

* mpt EnableAsyncCommit

* fix typo

* fix merge

---------

Co-authored-by: lyh169 <[email protected]>
Co-authored-by: lyh169 <[email protected]>
Co-authored-by: KamiD <[email protected]>
  • Loading branch information
4 people authored Mar 15, 2023
1 parent 22e25aa commit 85c9256
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 83 deletions.
17 changes: 8 additions & 9 deletions app/node_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"sort"
"strings"

"github.com/spf13/viper"

"github.com/okx/okbchain/app/config"
appconfig "github.com/okx/okbchain/app/config"
"github.com/okx/okbchain/app/rpc/backend"
Expand All @@ -16,13 +14,14 @@ import (
"github.com/okx/okbchain/libs/cosmos-sdk/server"
store "github.com/okx/okbchain/libs/cosmos-sdk/store/iavl"
"github.com/okx/okbchain/libs/cosmos-sdk/types/innertx"
"github.com/okx/okbchain/libs/iavl"
"github.com/okx/okbchain/libs/system"
abcitypes "github.com/okx/okbchain/libs/tendermint/abci/types"
"github.com/okx/okbchain/libs/tendermint/libs/log"
"github.com/okx/okbchain/libs/tendermint/mempool"
tmtypes "github.com/okx/okbchain/libs/tendermint/types"
evmtypes "github.com/okx/okbchain/x/evm/types"
"github.com/okx/okbchain/x/evm/watcher"
"github.com/spf13/viper"
)

func setNodeConfig(ctx *server.Context) error {
Expand Down Expand Up @@ -59,22 +58,22 @@ func setRpcConfig(ctx *server.Context) {
viper.SetDefault(watcher.FlagFastQuery, false)
viper.SetDefault(backend.FlagApiBackendBlockLruCache, 30000)
viper.SetDefault(backend.FlagApiBackendTxLruCache, 100000)
viper.SetDefault(iavl.FlagIavlEnableAsyncCommit, false)
viper.SetDefault(system.FlagTreeEnableAsyncCommit, false)
viper.SetDefault(flags.FlagMaxOpenConnections, 20000)
viper.SetDefault(mempool.FlagEnablePendingPool, true)
viper.SetDefault(server.FlagCORS, "*")
ctx.Logger.Info(fmt.Sprintf(
"Set --%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v by rpc node mode",
abcitypes.FlagDisableABCIQueryMutex, true, evmtypes.FlagEnableBloomFilter, true, watcher.FlagFastQueryLru, 10000,
watcher.FlagFastQuery, false, iavl.FlagIavlEnableAsyncCommit, false,
watcher.FlagFastQuery, false, system.FlagTreeEnableAsyncCommit, false,
flags.FlagMaxOpenConnections, 20000, mempool.FlagEnablePendingPool, true,
server.FlagCORS, "*"))
}

func setValidatorConfig(ctx *server.Context) {
viper.SetDefault(abcitypes.FlagDisableABCIQueryMutex, true)
viper.SetDefault(appconfig.FlagDynamicGpMode, tmtypes.MinimalGpMode)
viper.SetDefault(iavl.FlagIavlEnableAsyncCommit, false)
viper.SetDefault(system.FlagTreeEnableAsyncCommit, false)
viper.SetDefault(store.FlagIavlCacheSize, 10000000)
viper.SetDefault(server.FlagPruning, "everything")
viper.SetDefault(evmtypes.FlagEnableBloomFilter, false)
Expand All @@ -84,7 +83,7 @@ func setValidatorConfig(ctx *server.Context) {
viper.SetDefault(config.FlagEnablePGU, true)

ctx.Logger.Info(fmt.Sprintf("Set --%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v by validator node mode",
abcitypes.FlagDisableABCIQueryMutex, true, appconfig.FlagDynamicGpMode, tmtypes.MinimalGpMode, iavl.FlagIavlEnableAsyncCommit, false,
abcitypes.FlagDisableABCIQueryMutex, true, appconfig.FlagDynamicGpMode, tmtypes.MinimalGpMode, system.FlagTreeEnableAsyncCommit, false,
store.FlagIavlCacheSize, 10000000, server.FlagPruning, "everything",
evmtypes.FlagEnableBloomFilter, false, watcher.FlagFastQuery, false, appconfig.FlagMaxGasUsedPerBlock, 120000000,
mempool.FlagEnablePendingPool, false))
Expand All @@ -94,13 +93,13 @@ func setArchiveConfig(ctx *server.Context) {
viper.SetDefault(server.FlagPruning, "nothing")
viper.SetDefault(abcitypes.FlagDisableABCIQueryMutex, true)
viper.SetDefault(evmtypes.FlagEnableBloomFilter, true)
viper.SetDefault(iavl.FlagIavlEnableAsyncCommit, false)
viper.SetDefault(system.FlagTreeEnableAsyncCommit, false)
viper.SetDefault(flags.FlagMaxOpenConnections, 20000)
viper.SetDefault(server.FlagCORS, "*")
ctx.Logger.Info(fmt.Sprintf(
"Set --%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v\n--%s=%v by archive node mode",
server.FlagPruning, "nothing", abcitypes.FlagDisableABCIQueryMutex, true, evmtypes.FlagEnableBloomFilter, true,
iavl.FlagIavlEnableAsyncCommit, true, flags.FlagMaxOpenConnections, 20000,
system.FlagTreeEnableAsyncCommit, true, flags.FlagMaxOpenConnections, 20000,
server.FlagCORS, "*"))
}

Expand Down
9 changes: 7 additions & 2 deletions app/repair_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

"github.com/okx/okbchain/app/config"
"github.com/okx/okbchain/app/utils/appstatus"

"github.com/okx/okbchain/libs/cosmos-sdk/server"
"github.com/okx/okbchain/libs/cosmos-sdk/store/flatkv"
mpttypes "github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"
"github.com/okx/okbchain/libs/cosmos-sdk/store/rootmulti"
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
"github.com/okx/okbchain/libs/iavl"
"github.com/okx/okbchain/libs/system"
cfg "github.com/okx/okbchain/libs/tendermint/config"
"github.com/okx/okbchain/libs/tendermint/global"
tmlog "github.com/okx/okbchain/libs/tendermint/libs/log"
Expand Down Expand Up @@ -64,6 +64,7 @@ func repairStateOnStart(ctx *server.Context) {
orgIgnoreVersionCheck := iavl.GetIgnoreVersionCheck()
orgEnableFlatKV := viper.GetBool(flatkv.FlagEnable)
iavl.EnableAsyncCommit = false
mpttypes.EnableAsyncCommit = false
viper.Set(flatkv.FlagEnable, false)
iavl.SetEnableFastStorage(appstatus.IsFastStorageStrategy())
iavl.SetForceReadIavl(true)
Expand All @@ -75,7 +76,11 @@ func repairStateOnStart(ctx *server.Context) {
iavl.SetForceReadIavl(false)
sm.SetIgnoreSmbCheck(orgIgnoreSmbCheck)
iavl.SetIgnoreVersionCheck(orgIgnoreVersionCheck)
iavl.EnableAsyncCommit = viper.GetBool(iavl.FlagIavlEnableAsyncCommit)

treeEnableAc := viper.GetBool(system.FlagTreeEnableAsyncCommit)
iavl.EnableAsyncCommit = treeEnableAc
mpttypes.EnableAsyncCommit = treeEnableAc

viper.Set(flatkv.FlagEnable, orgEnableFlatKV)
// load latest block height
}
Expand Down
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
Expand Down Expand Up @@ -135,7 +134,6 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jonboulle/clockwork v0.2.0 // indirect
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f // indirect
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
Expand All @@ -147,15 +145,13 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d h1:1aAija9gr0Hyv4KfQcRcwlmFIrhkDmIj2dz5bkg/s/8=
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d/go.mod h1:icNx/6QdFblhsEjZehARqbNumymUT/ydwlLojFdv7Sk=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -461,7 +460,6 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
Expand Down Expand Up @@ -594,9 +592,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.0 h1:J2SLSdy7HgElq8ekSl2Mxh6vrRNFxqbXGenYH2I02Vs=
github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -764,17 +761,14 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc=
github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696/go.mod h1:ym2A+zigScwkSEb/cVQB0/ZMpU3rqiH6X7WRRsxgOGw=
Expand Down Expand Up @@ -803,7 +797,6 @@ github.com/pierrec/lz4 v0.0.0-20190327172049-315a67e90e41/go.mod h1:3/3N9NVKO0je
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -868,9 +861,8 @@ github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRr
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
Expand Down
3 changes: 1 addition & 2 deletions libs/cosmos-sdk/server/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ func GetPruningOptionsFromFlags() (types.PruningOptions, error) {
case types.PruningOptionNothing:
tmiavl.EnablePruningHistoryState = false
tmiavl.CommitIntervalHeight = 1
mpt.TrieCommitGap = 1
iavlcfg.DynamicConfig.SetCommitGapHeight(1)
mpt.TrieDirtyDisabled = true
return types.NewPruningOptionsFromString(strategy), nil

case types.PruningOptionDefault, types.PruningOptionEverything:
mpt.TrieDirtyDisabled = false
return types.NewPruningOptionsFromString(strategy), nil

case types.PruningOptionCustom:
Expand Down
19 changes: 8 additions & 11 deletions libs/cosmos-sdk/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@ import (
"os"
"runtime/pprof"

app2 "github.com/okx/okbchain/libs/cosmos-sdk/server/types"

"github.com/okx/okbchain/libs/cosmos-sdk/server/grpc"
"github.com/okx/okbchain/libs/tendermint/consensus"

"github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"
"github.com/okx/okbchain/libs/tendermint/rpc/client"

"github.com/gogo/protobuf/jsonpb"
"github.com/okx/okbchain/libs/cosmos-sdk/baseapp"
"github.com/okx/okbchain/libs/cosmos-sdk/client/context"
"github.com/okx/okbchain/libs/cosmos-sdk/client/lcd"
"github.com/okx/okbchain/libs/cosmos-sdk/codec"
"github.com/okx/okbchain/libs/cosmos-sdk/server/grpc"
app2 "github.com/okx/okbchain/libs/cosmos-sdk/server/types"
"github.com/okx/okbchain/libs/cosmos-sdk/store/iavl"
mptstore "github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"
"github.com/okx/okbchain/libs/cosmos-sdk/x/auth/types"
"github.com/okx/okbchain/libs/system"
"github.com/okx/okbchain/libs/tendermint/consensus"
"github.com/okx/okbchain/libs/tendermint/libs/cli"
"github.com/okx/okbchain/libs/tendermint/libs/log"
"github.com/okx/okbchain/libs/tendermint/mempool"
"github.com/okx/okbchain/libs/tendermint/node"
"github.com/okx/okbchain/libs/tendermint/p2p"
"github.com/okx/okbchain/libs/tendermint/proxy"
"github.com/okx/okbchain/libs/tendermint/rpc/client"
"github.com/okx/okbchain/libs/tendermint/rpc/client/local"
"github.com/okx/okbchain/libs/tendermint/state"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -329,7 +326,9 @@ func SetExternalPackageValue(cmd *cobra.Command) {
tmiavl.MinCommitItemCount = viper.GetInt64(tmiavl.FlagIavlMinCommitItemCount)
tmiavl.HeightOrphansCacheSize = viper.GetInt(tmiavl.FlagIavlHeightOrphansCacheSize)
tmiavl.MaxCommittedHeightNum = viper.GetInt(tmiavl.FlagIavlMaxCommittedHeightNum)
tmiavl.EnableAsyncCommit = viper.GetBool(tmiavl.FlagIavlEnableAsyncCommit)
EnableTreeAsyncCommit := viper.GetBool(system.FlagTreeEnableAsyncCommit)
tmiavl.EnableAsyncCommit = EnableTreeAsyncCommit
mptstore.EnableAsyncCommit = EnableTreeAsyncCommit
if viper.GetBool(tmiavl.FlagIavlDiscardFastStorage) {
tmiavl.SetEnableFastStorage(false)
viper.Set(tmiavl.FlagIavlEnableFastStorage, false)
Expand All @@ -350,8 +349,6 @@ func SetExternalPackageValue(cmd *cobra.Command) {
tmtypes.BlockCompressFlag = viper.GetInt(tmtypes.FlagBlockCompressFlag)
tmtypes.BlockCompressThreshold = viper.GetInt(tmtypes.FlagBlockCompressThreshold)

mpt.TrieCommitGap = viper.GetInt64(FlagCommitGapHeight)

bcv0.MaxIntervalForFastSync = viper.GetInt64(FlagFastSyncGap)

consensus.SetActiveVC(viper.GetBool(FlagActiveViewChange))
Expand Down
3 changes: 2 additions & 1 deletion libs/cosmos-sdk/server/start_okchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func RegisterServerFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().Int64(tmiavl.FlagIavlMinCommitItemCount, 1000000, "Min nodes num to triggle node cache commit")
cmd.Flags().Int(tmiavl.FlagIavlHeightOrphansCacheSize, 8, "Max orphan version to cache in memory")
cmd.Flags().Int(tmiavl.FlagIavlMaxCommittedHeightNum, 30, "Max committed version to cache in memory")
cmd.Flags().Bool(tmiavl.FlagIavlEnableAsyncCommit, false, "Enable async commit")
cmd.Flags().Bool(system.FlagTreeEnableAsyncCommit, false, "Enable async commit")
cmd.Flags().Bool(tmiavl.FlagIavlDiscardFastStorage, false, "Discard fast storage")
cmd.Flags().MarkHidden(tmiavl.FlagIavlDiscardFastStorage)
cmd.Flags().Bool(tmiavl.FlagIavlEnableFastStorage, false, "Enable fast storage")
Expand Down Expand Up @@ -263,6 +263,7 @@ func RegisterServerFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().UintVar(&mpt.TrieNodesLimit, mpt.FlagTrieNodesLimit, 256, "Max node size (MB) cached in triedb")
cmd.Flags().UintVar(&mpt.TrieImgsLimit, mpt.FlagTrieImgsLimit, 4, "Max img size (MB) cached in triedb")
cmd.Flags().UintVar(&mpt.TrieAccStoreCache, mpt.FlagTrieAccStoreCache, 32, "Size (MB) to cache account")
cmd.Flags().UintVar(&mpt.TriesInMemory, mpt.FlagTrieInMemory, 100, "Max cache tire count in Memory")
cmd.Flags().Int64(FlagCommitGapHeight, 100, "Block interval to commit cached data into db, affects iavl & mpt")

cmd.Flags().Int64(FlagFastSyncGap, 20, "Block height interval to switch fast-sync mode")
Expand Down
1 change: 1 addition & 0 deletions libs/cosmos-sdk/store/mpt/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func InstanceOfMptStore() ethstate.Database {
panic("fail to open database: " + e.Error())
}
nkvstore := NewStatKeyValueStore(kvstore, gStatic)

db := rawdb.NewDatabase(nkvstore)
gMptDatabase = ethstate.NewDatabaseWithConfig(db, &trie.Config{
Cache: int(TrieCacheSize),
Expand Down
10 changes: 8 additions & 2 deletions libs/cosmos-sdk/store/mpt/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
const (
StoreTypeMPT = types.StoreTypeMPT

TriesInMemory = 100

// StoreKey is string representation of the store key for mpt
StoreKey = "mpt"
)
Expand All @@ -20,6 +18,7 @@ const (
FlagTrieCacheSize = "trie.cache-size"
FlagTrieNodesLimit = "trie.nodes-limit"
FlagTrieImgsLimit = "trie.imgs-limit"
FlagTrieInMemory = "trie.in-memory"
)

var (
Expand All @@ -28,6 +27,9 @@ var (
TrieNodesLimit uint = 256 // MB
TrieImgsLimit uint = 4 // MB
TrieCommitGap int64 = 100
TriesInMemory uint = 100

EnableAsyncCommit = false
)

var (
Expand All @@ -46,3 +48,7 @@ var (
EmptyCodeHash = crypto.Keccak256Hash(nil)
EmptyCodeHashBytes = crypto.Keccak256(nil)
)

func UpdateCommitGapHeight(gap int64) {
TrieCommitGap = gap
}
Loading

0 comments on commit 85c9256

Please sign in to comment.