refactor(v2): proper iavl v2 config (#23463)

This commit is contained in:
Julien Robert 2025-01-20 11:28:33 +01:00 committed by GitHub
parent 5359c8f9e5
commit 0440a13dd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 92 additions and 27 deletions

View File

@ -3,10 +3,10 @@ module cosmossdk.io/server/v2
go 1.23
// server v2 integration (uncomment during development, but comment before release)
// replace (
// cosmossdk.io/server/v2/appmanager => ./appmanager
// cosmossdk.io/store/v2 => ../../store/v2
// )
replace (
cosmossdk.io/server/v2/appmanager => ./appmanager
cosmossdk.io/store/v2 => ../../store/v2
)
require (
cosmossdk.io/api v0.8.2
@ -43,7 +43,9 @@ require (
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bvinc/go-sqlite-lite v0.6.1 // indirect
github.com/bytedance/sonic v1.12.6 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@ -55,8 +57,10 @@ require (
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cosmos/iavl v1.3.4 // indirect
github.com/cosmos/iavl/v2 v2.0.0-alpha.4 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/dot v1.6.2 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
@ -74,9 +78,9 @@ require (
github.com/jhump/protoreflect v1.17.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kocubinski/costor-api v1.1.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.9.3 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect

View File

@ -12,10 +12,6 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g=
cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI=
cosmossdk.io/schema v1.0.0 h1:/diH4XJjpV1JQwuIozwr+A4uFuuwanFdnw2kKeiXwwQ=
cosmossdk.io/schema v1.0.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2/appmanager v1.0.0-beta.2 h1:58xH7Evpy/+9XbVwVf2+h009UN28NrDyXyr5wytD0Z8=
cosmossdk.io/server/v2/appmanager v1.0.0-beta.2/go.mod h1:l6oCGNcucF6/U949UwRj+RemNzq5475ovNHohcvN1YM=
cosmossdk.io/store/v2 v2.0.0-beta.1 h1:p1fdZ9uNijhpXZXdqs0QS6NmXNDVPNyT4DHV4yQnF64=
cosmossdk.io/store/v2 v2.0.0-beta.1/go.mod h1:qHQmf/9mnsXwo/Ypp2u2Zs6BmkYcx1R/Jrpyn9Ro13A=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
@ -31,12 +27,16 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e h1:dSeuFcs4WAJJnswS8vXy7YY1+fdlbVPuEVmDAfqvFOQ=
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e/go.mod h1:uh71c5Vc3VNIplXOFXsnDy21T1BepgT32c5X/YPrOyc=
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=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
github.com/bvinc/go-sqlite-lite v0.6.1 h1:JU8Rz5YAOZQiU3WEulKF084wfXpytRiqD2IaW2QjPz4=
github.com/bvinc/go-sqlite-lite v0.6.1/go.mod h1:2GiE60NUdb0aNhDdY+LXgrqAVDpi2Ijc6dB6ZMp9x6s=
github.com/bytedance/sonic v1.12.6 h1:/isNmCUF2x3Sh8RAp/4mh4ZGkcFAX/hLrzrK3AvpRzk=
github.com/bytedance/sonic v1.12.6/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
@ -85,6 +85,10 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.3.4 h1:A0RUAms7TZ0L6EFrrBIPg4Dy7qD9vvD5lJKUxEXURLM=
github.com/cosmos/iavl v1.3.4/go.mod h1:T6SfBcyhulVIY2G/ZtAtQm/QiJvsuhIos52V4dWYk88=
github.com/cosmos/iavl-bench/bench v0.0.4 h1:J6zQPiBqF4CXMM3QBsLqZgQEBGY0taX85vLIZMhmAfQ=
github.com/cosmos/iavl-bench/bench v0.0.4/go.mod h1:j2rLae77EffacWcp7mmj3Uaa4AOAmZA7ymvhsuBQKKI=
github.com/cosmos/iavl/v2 v2.0.0-alpha.4 h1:PfpQt7xl4hojw2UFS2JdJppJnx8sjlmcxRQ7Hxk7Cl0=
github.com/cosmos/iavl/v2 v2.0.0-alpha.4/go.mod h1:7RSm0aeApe3S1x4TrLffvUL6pjOtMYV4glYnpAhr2lw=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@ -93,6 +97,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/emicklei/dot v1.6.2 h1:08GN+DD79cy/tzN6uLCT84+2Wk9u+wvqP+Hkx/dIR8A=
github.com/emicklei/dot v1.6.2/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@ -225,6 +231,8 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kocubinski/costor-api v1.1.1 h1:sgfJA7T/8IfZ59zxiMrED0xdjerAFuPNBTqyO90GiEE=
github.com/kocubinski/costor-api v1.1.1/go.mod h1:ESMBMDkKfN+9vvvhhNVdKLhbOmzI3O/i16iXvRM9Tuc=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
@ -235,8 +243,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/linxGnu/grocksdb v1.9.3 h1:s1cbPcOd0cU2SKXRG1nEqCOWYAELQjdqg3RVI2MH9ik=
github.com/linxGnu/grocksdb v1.9.3/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA=
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=

View File

@ -37,6 +37,22 @@ interval = 100
[store.options.iavl-config]
# CacheSize set the size of the iavl tree cache.
cache-size = 100000
cache-size = 500000
# If true, the tree will work like no fast storage and always not upgrade fast storage.
skip-fast-storage-upgrade = true
[store.options.iavl-v2-config]
# CheckpointInterval set the interval of the checkpoint.
checkpoint-interval = 0
# CheckpointMemory set the memory of the checkpoint.
checkpoint-memory = 0
# StateStorage set the state storage.
state-storage = false
# HeightFilter set the height filter.
height-filter = 0
# EvictionDepth set the eviction depth.
eviction-depth = 0
# PruneRatio set the prune ratio.
prune-ratio = 0.0
# MinimumKeepVersions set the minimum keep versions.
minimum-keep-versions = 0

View File

@ -226,7 +226,8 @@ func ProvideRootStoreConfig(config runtime.GlobalConfig) (*root.Config, error) {
if err != nil {
return nil, err
}
cfg.Options.IavlV2Config = iavlv2.DefaultOptions(int64(cfg.Options.SCPruningOption.KeepRecent))
cfg.Options.IavlV2Config = iavlv2.DefaultConfig()
cfg.Options.IavlV2Config.MinimumKeepVersions = int64(cfg.Options.SCPruningOption.KeepRecent)
iavlv2.SetGlobalPruneLimit(1)
return cfg, err
}

View File

@ -0,0 +1,48 @@
package iavlv2
import (
"github.com/cosmos/iavl/v2"
"github.com/cosmos/iavl/v2/metrics"
)
// Config is the configuration for the IAVL v2 tree.
type Config struct {
CheckpointInterval int64 `mapstructure:"checkpoint-interval" toml:"checkpoint-interval" comment:"CheckpointInterval set the interval of the checkpoint."`
CheckpointMemory uint64 `mapstructure:"checkpoint-memory" toml:"checkpoint-memory" comment:"CheckpointMemory set the memory of the checkpoint."`
StateStorage bool `mapstructure:"state-storage" toml:"state-storage" comment:"StateStorage set the state storage."`
HeightFilter int8 `mapstructure:"height-filter" toml:"height-filter" comment:"HeightFilter set the height filter."`
EvictionDepth int8 `mapstructure:"eviction-depth" toml:"eviction-depth" comment:"EvictionDepth set the eviction depth."`
MetricsProxy metrics.Proxy `mapstructure:"metrics-proxy" toml:"metrics-proxy" comment:"MetricsProxy set the metrics proxy."`
PruneRatio float64 `mapstructure:"prune-ratio" toml:"prune-ratio" comment:"PruneRatio set the prune ratio."`
MinimumKeepVersions int64 `mapstructure:"minimum-keep-versions" toml:"minimum-keep-versions" comment:"MinimumKeepVersions set the minimum keep versions."`
}
// ToTreeOptions converts the configuration to IAVL v2 tree options.
func (c *Config) ToTreeOptions() iavl.TreeOptions {
return iavl.TreeOptions{
CheckpointInterval: c.CheckpointInterval,
CheckpointMemory: c.CheckpointMemory,
StateStorage: c.StateStorage,
HeightFilter: c.HeightFilter,
EvictionDepth: c.EvictionDepth,
MetricsProxy: c.MetricsProxy,
PruneRatio: c.PruneRatio,
MinimumKeepVersions: c.MinimumKeepVersions,
}
}
// DefaultConfig returns the default configuration for the IAVL tree.
func DefaultConfig() Config {
defaultOptions := iavl.DefaultTreeOptions()
return Config{
CheckpointInterval: 200,
CheckpointMemory: defaultOptions.CheckpointMemory,
StateStorage: defaultOptions.StateStorage,
HeightFilter: 1,
EvictionDepth: 22,
MetricsProxy: defaultOptions.MetricsProxy,
PruneRatio: 1,
MinimumKeepVersions: defaultOptions.MinimumKeepVersions,
}
}

View File

@ -25,7 +25,7 @@ type Tree struct {
}
func NewTree(
treeOptions iavl.TreeOptions,
cfg Config,
dbOptions iavl.SqliteDbOptions,
log log.Logger,
) (*Tree, error) {
@ -34,7 +34,7 @@ func NewTree(
if err != nil {
return nil, err
}
tree := iavl.NewTree(sql, pool, treeOptions)
tree := iavl.NewTree(sql, pool, cfg.ToTreeOptions())
return &Tree{tree: tree, log: log, path: dbOptions.Path}, nil
}
@ -198,16 +198,6 @@ func isHighBitSet(version uint64) error {
return nil
}
func DefaultOptions(keepVersions int64) iavl.TreeOptions {
opts := iavl.DefaultTreeOptions()
opts.MinimumKeepVersions = keepVersions
opts.CheckpointInterval = 200
opts.PruneRatio = 1
opts.HeightFilter = 1
opts.EvictionDepth = 22
return opts
}
func SetGlobalPruneLimit(limit int) {
iavl.SetGlobalPruneLimit(limit)
}

View File

@ -25,7 +25,7 @@ func TestCommitterSuite(t *testing.T) {
multiTrees := make(map[string]commitment.Tree)
mountTreeFn := func(storeKey string) (commitment.Tree, error) {
path := fmt.Sprintf("%s/%s", dbDir, storeKey)
tree, err := NewTree(iavl.DefaultTreeOptions(), iavl.SqliteDbOptions{Path: path}, logger)
tree, err := NewTree(DefaultConfig(), iavl.SqliteDbOptions{Path: path}, logger)
require.NoError(t, err)
return tree, nil
}

View File

@ -37,7 +37,7 @@ type Options struct {
SCType SCType `mapstructure:"sc-type" toml:"sc-type" comment:"State commitment database type. Currently we support: \"iavl\" and \"iavl-v2\""`
SCPruningOption *store.PruningOption `mapstructure:"sc-pruning-option" toml:"sc-pruning-option" comment:"Pruning options for state commitment"`
IavlConfig *iavl.Config `mapstructure:"iavl-config" toml:"iavl-config"`
IavlV2Config iavl_v2.TreeOptions
IavlV2Config iavlv2.Config `mapstructure:"iavl-v2-config" toml:"iavl-v2-config"`
}
// FactoryOptions are the options for creating a root store.