Skip to content

Commit

Permalink
refactor(store/v2): human readable ss/sc types (#21645)
Browse files Browse the repository at this point in the history
Co-authored-by: auricom <27022259+auricom@users.noreply.github.com>
  • Loading branch information
julienrbrt and auricom authored Sep 11, 2024
1 parent 1d4ecd5 commit 071aa50
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: ./.github/scripts/install-rocksdb.sh
- name: Saves rocksdb libraries cache
if: matrix.go-arch == 'amd64' && steps.install_rocksdb.outcome == 'success'
uses: actions/cache/restore@v4
uses: actions/cache/save@v4
with:
path: |
/usr/local/lib/librocksdb.*
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: ./.github/scripts/install-rocksdb.sh
- name: Saves rocksdb libraries cache
if: steps.install_rocksdb.outcome == 'success'
uses: actions/cache/restore@v4
uses: actions/cache/save@v4
with:
path: |
/usr/local/lib/librocksdb.*
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,16 @@ jobs:
/usr/local/lib/librocksdb.*
/usr/local/include/rocksdb
key: ${{ runner.os }}-rocksdb-${{ env.ROCKSDB_VERSION }}-amd64
- name: Install rocksdb deps
run: |
sudo apt-get update && sudo apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev
- name: Install rocksdb
if: env.GIT_DIFF && steps.cache-rocksdb.outputs.cache-hit != 'true'
if: steps.cache-rocksdb.outputs.cache-hit != 'true'
id: install_rocksdb
run: ./.github/scripts/install-rocksdb.sh
- name: Saves rocksdb libraries cache
if: steps.install_rocksdb.outcome == 'success'
uses: actions/cache/restore@v4
uses: actions/cache/save@v4
with:
path: |
/usr/local/lib/librocksdb.*
Expand All @@ -816,7 +819,7 @@ jobs:
if: env.GIT_DIFF
run: |
cd store
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb' ./...
go test -ldflags "-r /usr/local/lib" -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
Expand Down Expand Up @@ -855,13 +858,16 @@ jobs:
/usr/local/lib/librocksdb.*
/usr/local/include/rocksdb
key: ${{ runner.os }}-rocksdb-${{ env.ROCKSDB_VERSION }}-amd64
- name: Install rocksdb deps
run: |
sudo apt-get update && sudo apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev
- name: Install rocksdb
if: env.GIT_DIFF && steps.cache-rocksdb.outputs.cache-hit != 'true'
id: install_rocksdb
run: ./.github/scripts/install-rocksdb.sh
- name: Saves rocksdb libraries cache
if: steps.install_rocksdb.outcome == 'success'
uses: actions/cache/restore@v4
uses: actions/cache/save@v4
with:
path: |
/usr/local/lib/librocksdb.*
Expand All @@ -871,7 +877,7 @@ jobs:
if: env.GIT_DIFF
run: |
cd store/v2
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb' ./...
go test -ldflags "-r /usr/local/lib" -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
Expand Down
6 changes: 6 additions & 0 deletions server/v2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
serverv2 "cosmossdk.io/server/v2"
grpc "cosmossdk.io/server/v2/api/grpc"
"cosmossdk.io/server/v2/appmanager"
"cosmossdk.io/server/v2/store"
)

type mockInterfaceRegistry struct{}
Expand Down Expand Up @@ -61,12 +62,17 @@ func TestServer(t *testing.T) {
err = grpcServer.Init(&mockApp[transaction.Tx]{}, v, logger)
require.NoError(t, err)

storeServer := store.New[transaction.Tx](nil /* nil appCreator as not using CLI commands */)
err = storeServer.Init(&mockApp[transaction.Tx]{}, v, logger)
require.NoError(t, err)

mockServer := &mockServer{name: "mock-server-1", ch: make(chan string, 100)}

server := serverv2.NewServer(
logger,
serverv2.DefaultServerConfig(),
grpcServer,
storeServer,
mockServer,
)

Expand Down
20 changes: 10 additions & 10 deletions server/v2/testdata/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ max-recv-msg-size = 10485760
# The default value is math.MaxInt32.
max-send-msg-size = 2147483647

[mock-server-1]
# Mock field
mock_field = 'default'
# Mock field two
mock_field_two = 1

[server]
# minimum-gas-prices defines the price which a validator is willing to accept for processing a transaction. A transaction's fees must meet the minimum of any denomination specified in this config (e.g. 0.25token1;0.0001token2).
minimum-gas-prices = '0stake'
Expand All @@ -19,10 +25,10 @@ minimum-gas-prices = '0stake'
app-db-backend = 'goleveldb'

[store.options]
# State storage database type. Currently we support: 0 for SQLite, 1 for Pebble
ss-type = 0
# State commitment database type. Currently we support:0 for iavl, 1 for iavl v2
sc-type = 0
# SState storage database type. Currently we support: "sqlite" and "pebble"
ss-type = 'sqlite'
# State commitment database type. Currently we support: "iavl" and "iavl-v2"
sc-type = 'iavl'

# Pruning options for state storage
[store.options.ss-pruning-option]
Expand All @@ -43,9 +49,3 @@ interval = 100
cache-size = 100000
# If true, the tree will work like no fast storage and always not upgrade fast storage.
skip-fast-storage-upgrade = true

[mock-server-1]
# Mock field
mock_field = 'default'
# Mock field two
mock_field_two = 1
24 changes: 13 additions & 11 deletions store/v2/root/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ import (
)

type (
SSType int
SCType int
SSType string
SCType string
)

const (
SSTypeSQLite SSType = 0
SSTypePebble SSType = 1
SSTypeRocks SSType = 2
SCTypeIavl SCType = 0
SCTypeIavlV2 SCType = 1
SSTypeSQLite SSType = "sqlite"
SSTypePebble SSType = "pebble"
SSTypeRocks SSType = "rocksdb"
SCTypeIavl SCType = "iavl"
SCTypeIavlV2 SCType = "iavl-v2"
)

// app.toml config options
type Options struct {
SSType SSType `mapstructure:"ss-type" toml:"ss-type" comment:"State storage database type. Currently we support: 0 for SQLite, 1 for Pebble"`
SCType SCType `mapstructure:"sc-type" toml:"sc-type" comment:"State commitment database type. Currently we support:0 for iavl, 1 for iavl v2"`
SSType SSType `mapstructure:"ss-type" toml:"ss-type" comment:"SState storage database type. Currently we support: \"sqlite\" and \"pebble\""`
SCType SCType `mapstructure:"sc-type" toml:"sc-type" comment:"State commitment database type. Currently we support: \"iavl\" and \"iavl-v2\""`
SSPruningOption *store.PruningOption `mapstructure:"ss-pruning-option" toml:"ss-pruning-option" comment:"Pruning options for state storage"`
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"`
}

// FactoryOptions are the options for creating a root store.
type FactoryOptions struct {
Logger log.Logger
RootDir string
Expand All @@ -49,10 +50,11 @@ type FactoryOptions struct {
SCRawDB corestore.KVStoreWithBatch
}

// DefaultStoreOptions returns the default options for creating a root store.
func DefaultStoreOptions() Options {
return Options{
SSType: 0,
SCType: 0,
SSType: SSTypeSQLite,
SCType: SCTypeIavl,
SCPruningOption: &store.PruningOption{
KeepRecent: 2,
Interval: 100,
Expand Down

0 comments on commit 071aa50

Please sign in to comment.