Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: no compact storage for archive node #791

Merged
merged 6 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,63 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-22.11
yihuang marked this conversation as resolved.
Show resolved Hide resolved
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: technote-space/get-diff-action@v6
id: git_diff
- id: changed-files
uses: tj-actions/changed-files@v34
with:
SUFFIX_FILTER: |
.go
.mod
.sum
files: |
*.go
*.mod
*.sum
- run: |
# without rocksdb
make build
if: "env.GIT_DIFF != ''"
# with rocksdb and enable versiondb
nix profile install nixpkgs#rocksdb
export PKG_CONFIG_PATH=$HOME/.nix-profile/lib/pkgconfig
export CGO_CFLAGS="$(pkg-config --cflags rocksdb)" CGO_LDFLAGS="$(pkg-config --libs rocksdb)"
COSMOS_BUILD_OPTIONS=rocksdb make build
if: steps.changed-files.outputs.any_changed == 'true'

unittest:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: technote-space/get-diff-action@v6
id: git_diff
- id: changed-files
uses: tj-actions/changed-files@v34
with:
SUFFIX_FILTER: |
.go
.mod
.sum
files: |
*.go
*.mod
*.sum
- name: test & coverage report creation
run: make test
if: "env.GIT_DIFF != ''"
run: |
make test

# run versiondb tests
nix profile install nixpkgs#rocksdb
export PKG_CONFIG_PATH=$HOME/.nix-profile/lib/pkgconfig
export CGO_CFLAGS="$(pkg-config --cflags rocksdb)" CGO_LDFLAGS="$(pkg-config --libs rocksdb)"
export LD_LIBRARY_PATH=$HOME/.nix-profile/lib
cd ./versiondb
go test -v -mod=readonly ./... -tags rocksdb,grocksdb_clean_link -coverprofile=coverage.txt
if: steps.changed-files.outputs.any_changed == 'true'
- name: filter out proto files
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
Expand All @@ -55,13 +80,13 @@ jobs:
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
if: "env.GIT_DIFF != ''"
- uses: codecov/codecov-action@v2.0.2
if: steps.changed-files.outputs.any_changed == 'true'
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
files: ./coverage.txt,./versiondb/coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
if: steps.changed-files.outputs.any_changed == 'true'

gomod2nix:
runs-on: ubuntu-latest
Expand All @@ -77,7 +102,7 @@ jobs:
go.sum
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.any_changed == 'true'
Expand Down Expand Up @@ -111,7 +136,7 @@ jobs:
contracts
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.any_changed == 'true'
Expand Down
38 changes: 25 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,32 @@ jobs:
with:
go-version: 1.18
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
- uses: cachix/install-nix-action@v18
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: golangci/golangci-lint-action@v3
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- id: changed-files
uses: tj-actions/changed-files@v34
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.50
args: --timeout 10m
github-token: ${{ secrets.GITHUB_TOKEN }}
files: |
*.go
*.mod
*.sum
- name: run golangci-lint
run: |
nix profile install nixpkgs#rocksdb nixpkgs#golangci-lint
export PKG_CONFIG_PATH=$HOME/.nix-profile/lib/pkgconfig
export CGO_CFLAGS="$(pkg-config --cflags rocksdb)" CGO_LDFLAGS="$(pkg-config --libs rocksdb)"
golangci-lint version

BUILD_TAGS=rocksdb,grocksdb_clean_link
go build -tags $BUILD_TAGS ./cmd/cronosd
golangci-lint run --out-format=github-actions --path-prefix=./ --timeout 10m --build-tags $BUILD_TAGS
cd versiondb
golangci-lint run --out-format=github-actions --path-prefix=./versiondb --timeout 10m --build-tags $BUILD_TAGS
# Check only if there are differences in the source code
if: "env.GIT_DIFF"
if: steps.changed-files.outputs.any_changed == 'true'

lint-python:
name: Lint python
Expand All @@ -54,7 +66,7 @@ jobs:
**/*.py
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.any_changed == 'true'
Expand All @@ -80,7 +92,7 @@ jobs:
**/*.nix
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.any_changed == 'true'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand All @@ -24,7 +24,7 @@ jobs:
breakage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand All @@ -35,7 +35,7 @@ jobs:
protogen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand All @@ -46,4 +46,4 @@ jobs:
make proto-gen # proto-swagger-gen FIXME swagger-gen result is not reproducible in CI
git checkout -- go.mod go.sum docs/api/proto-docs.md # FIXME doc gen not reproducible in CI
- name: check working directory is clean
uses: numtide/clean-git-action@v1
uses: numtide/clean-git-action@main
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: apple-actions/import-codesign-certs@v1
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
steps:
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- run: |
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
go version
wget https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-rocksdb-6.26.1-1-any.pkg.tar.zst
pacman -U mingw-w64-x86_64-rocksdb-6.26.1-1-any.pkg.tar.zst --noconfirm
ENABLE_ROCKSDB=true COSMOS_BUILD_OPTIONS=rocksdb make build
COSMOS_BUILD_OPTIONS=rocksdb make build
ls -la ./build/
mv ./build/cronosd ./build/cronosd.exe
cp /mingw64/bin/libbz2-1.dll ./build
Expand All @@ -178,7 +178,7 @@ jobs:
tar cvfz ../cronos.tar.gz *
cd ..
mv ./cronos.tar.gz cronos_${GITHUB_REF_NAME:1}_${PLATFORM}.tar.gz
NETWORK=testnet ENABLE_ROCKSDB=true COSMOS_BUILD_OPTIONS=rocksdb make build
NETWORK=testnet COSMOS_BUILD_OPTIONS=rocksdb make build
mv ./build/cronosd ./build/cronosd.exe
cd ./build
tar cvfz ../cronos.tar.gz *
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
**/*.md
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.only_changed == 'false'
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
**/*.md
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-21.11
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.only_changed == 'false'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Improvements

- [#813](https://github.com/crypto-org-chain/cronos/pull/813) Tune up rocksdb options.
- [#791](https://github.com/crypto-org-chain/cronos/pull/791) Implement versiondb and migration commands.

*Jan 04, 2023*

Expand Down
20 changes: 20 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"

"github.com/crypto-org-chain/cronos/x/cronos/middleware"
"golang.org/x/exp/slices"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -352,6 +353,17 @@ func New(
os.Exit(1)
}

// wire up the versiondb's `StreamingService` and `MultiStore`.
streamers := cast.ToStringSlice(appOpts.Get("store.streamers"))
var qms sdk.MultiStore
if slices.Contains(streamers, "versiondb") {
var err error
qms, err = setupVersionDB(homePath, bApp, keys, tkeys, memKeys)
if err != nil {
panic(err)
}
}

app := &App{
BaseApp: bApp,
cdc: cdc,
Expand Down Expand Up @@ -739,6 +751,14 @@ func New(
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}

if qms != nil {
v1 := qms.LatestVersion()
v2 := app.LastBlockHeight()
if v1 > 0 && v1 != v2 {
tmos.Exit(fmt.Sprintf("versiondb lastest version %d don't match iavl latest version %d", v1, v2))
}
}
}

app.ScopedIBCKeeper = scopedIBCKeeper
Expand Down
48 changes: 48 additions & 0 deletions app/versiondb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build rocksdb
// +build rocksdb

package app

import (
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/crypto-org-chain/cronos/versiondb/tsrocksdb"
)

func setupVersionDB(
homePath string,
app *baseapp.BaseApp,
keys map[string]*storetypes.KVStoreKey,
tkeys map[string]*storetypes.TransientStoreKey,
memKeys map[string]*storetypes.MemoryStoreKey,
) (sdk.MultiStore, error) {
dataDir := filepath.Join(homePath, "data", "versiondb")
if err := os.MkdirAll(dataDir, os.ModePerm); err != nil {
return nil, err
}
versionDB, err := tsrocksdb.NewStore(dataDir)
if err != nil {
return nil, err
}

// default to exposing all
exposeStoreKeys := make([]storetypes.StoreKey, 0, len(keys))
for _, storeKey := range keys {
exposeStoreKeys = append(exposeStoreKeys, storeKey)
}

service := versiondb.NewStreamingService(versionDB, exposeStoreKeys)
app.SetStreamingService(service)

verDB := versiondb.NewMultiStore(versionDB, exposeStoreKeys)
verDB.MountTransientStores(tkeys)
verDB.MountMemoryStores(memKeys)

app.SetQueryMultiStore(verDB)
return verDB, nil
}
22 changes: 22 additions & 0 deletions app/versiondb_placeholder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !rocksdb
// +build !rocksdb

package app

import (
"errors"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func setupVersionDB(
homePath string,
app *baseapp.BaseApp,
keys map[string]*storetypes.KVStoreKey,
tkeys map[string]*storetypes.TransientStoreKey,
memKeys map[string]*storetypes.MemoryStoreKey,
) (sdk.MultiStore, error) {
return nil, errors.New("versiondb is not supported in this binary")
}
5 changes: 5 additions & 0 deletions cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
// this line is used by starport scaffolding # stargate/root/commands
)

changeSetCmd := ChangeSetCmd()
if changeSetCmd != nil {
rootCmd.AddCommand(changeSetCmd)
}

opts := ethermintserver.StartOptions{
AppCreator: a.newApp,
DefaultNodeHome: app.DefaultNodeHome,
Expand Down
Loading