Skip to content

2.0.48beta seidb #2115

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
57 changes: 57 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "CodeQL"

on:
pull_request:
paths:
- "**.go"
push:
branches:
- main
- release/**
paths:
- "**.go"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: "go"
queries: crypto-com/cosmos-sdk-codeql@main,security-and-quality
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19

- name: Fuzz Place Order Msg
run: go test github.com/sei-protocol/sei-chain/x/dex/keeper/msgserver -fuzz FuzzPlaceOrders -fuzztime 30s
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Start 4 node docker cluster
run: make clean && make docker-cluster-start &
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,29 @@ run-rpc-node: kill-rpc-node build-rpc-node
-v $(PROJECT_HOME):/sei-protocol/sei-chain:Z \
-v $(PROJECT_HOME)/../sei-tendermint:/sei-protocol/sei-tendermint:Z \
-v $(PROJECT_HOME)/../sei-cosmos:/sei-protocol/sei-cosmos:Z \
-v $(PROJECT_HOME)/../sei-db:/sei-protocol/sei-db:Z \
-v $(GO_PKG_PATH)/mod:/root/go/pkg/mod:Z \
-p 26668-26670:26656-26658 \
--platform linux/x86_64 \
sei-chain/rpcnode
.PHONY: run-rpc-node


run-rpc-node-skipbuild: build-rpc-node
docker run --rm \
--name sei-rpc-node \
--network docker_localnet \
-v $(PROJECT_HOME):/sei-protocol/sei-chain:Z \
-v $(PROJECT_HOME)/../sei-tendermint:/sei-protocol/sei-tendermint:Z \
-v $(PROJECT_HOME)/../sei-cosmos:/sei-protocol/sei-cosmos:Z \
-v $(PROJECT_HOME)/../sei-db:/sei-protocol/sei-db:Z \
-v $(GO_PKG_PATH)/mod:/root/go/pkg/mod:Z \
-p 26668-26670:26656-26658 \
--platform linux/x86_64 \
--env SKIP_BUILD=true \
sei-chain/rpcnode
.PHONY: run-rpc-node

kill-sei-node:
docker ps --filter name=sei-node --filter status=running -aq | xargs docker kill

Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ func New(
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), tmConfig, appOpts, baseAppOptions...)
bAppOptions := SetupSeiDB(logger, homePath, appOpts, baseAppOptions)
bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), tmConfig, appOpts, bAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down
104 changes: 104 additions & 0 deletions app/seidb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package app

import (
"fmt"

"github.com/cosmos/cosmos-sdk/baseapp"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/storev2/rootmulti"
"github.com/sei-protocol/sei-db/config"
"github.com/spf13/cast"
"github.com/tendermint/tendermint/libs/log"
)

const (
// SC Store configs
FlagSCEnable = "state-commit.sc-enable"
FlagSCDirectory = "state-commit.sc-directory"
FlagSCAsyncCommitBuffer = "state-commit.sc-async-commit-buffer"
FlagSCZeroCopy = "state-commit.sc-zero-copy"
FlagSCSnapshotKeepRecent = "state-commit.sc-keep-recent"
FlagSCSnapshotInterval = "state-commit.sc-snapshot-interval"
FlagSCSnapshotWriterLimit = "state-commit.sc-snapshot-writer-limit"
FlagSCCacheSize = "state-commit.sc-cache-size"

// SS Store configs
FlagSSEnable = "state-store.ss-enable"
FlagSSDirectory = "state-store.ss-db-directory"
FlagSSBackend = "state-store.ss-backend"
FlagSSAsyncWriterBuffer = "state-store.ss-async-write-buffer"
FlagSSKeepRecent = "state-store.ss-keep-recent"
FlagSSPruneInterval = "state-store.ss-prune-interval"
FlagSSImportNumWorkers = "state-store.ss-import-num-workers"

// Other configs
FlagSnapshotInterval = "state-sync.snapshot-interval"
)

func SetupSeiDB(
logger log.Logger,
homePath string,
appOpts servertypes.AppOptions,
baseAppOptions []func(*baseapp.BaseApp),
) []func(*baseapp.BaseApp) {
scEnabled := cast.ToBool(appOpts.Get(FlagSCEnable))
if !scEnabled {
logger.Info("SeiDB is disabled, falling back to IAVL")
return baseAppOptions
}
logger.Info("SeiDB SC is enabled, running node with StoreV2 commit store")
scConfig := parseSCConfigs(appOpts)
ssConfig := parseSSConfigs(appOpts)
if ssConfig.Enable {
logger.Info(fmt.Sprintf("SeiDB StateStore is enabled, running %s for historical state", ssConfig.Backend))
}
validateConfigs(appOpts)

// cms must be overridden before the other options, because they may use the cms,
// make sure the cms aren't be overridden by the other options later on.
cms := rootmulti.NewStore(homePath, logger, scConfig, ssConfig)
baseAppOptions = append([]func(*baseapp.BaseApp){
func(baseApp *baseapp.BaseApp) {
baseApp.SetCMS(cms)
},
}, baseAppOptions...)

return baseAppOptions
}

func parseSCConfigs(appOpts servertypes.AppOptions) config.StateCommitConfig {
return config.StateCommitConfig{
Enable: cast.ToBool(appOpts.Get(FlagSCEnable)),
Directory: cast.ToString(appOpts.Get(FlagSCDirectory)),
ZeroCopy: cast.ToBool(appOpts.Get(FlagSCZeroCopy)),
AsyncCommitBuffer: cast.ToInt(appOpts.Get(FlagSCAsyncCommitBuffer)),
SnapshotKeepRecent: cast.ToUint32(appOpts.Get(FlagSCSnapshotKeepRecent)),
SnapshotInterval: cast.ToUint32(appOpts.Get(FlagSCSnapshotInterval)),
SnapshotWriterLimit: cast.ToInt(appOpts.Get(FlagSCSnapshotWriterLimit)),
CacheSize: cast.ToInt(appOpts.Get(FlagSCCacheSize)),
}
}

func parseSSConfigs(appOpts servertypes.AppOptions) config.StateStoreConfig {
return config.StateStoreConfig{
Enable: cast.ToBool(appOpts.Get(FlagSSEnable)),
Backend: cast.ToString(appOpts.Get(FlagSSBackend)),
AsyncWriteBuffer: cast.ToInt(appOpts.Get(FlagSSAsyncWriterBuffer)),
KeepRecent: cast.ToInt(appOpts.Get(FlagSSKeepRecent)),
PruneIntervalSeconds: cast.ToInt(appOpts.Get(FlagSSPruneInterval)),
ImportNumWorkers: cast.ToInt(appOpts.Get(FlagSSImportNumWorkers)),
DBDirectory: cast.ToString(appOpts.Get(FlagSSDirectory)),
}
}

func validateConfigs(appOpts servertypes.AppOptions) {
scEnabled := cast.ToBool(appOpts.Get(FlagSCEnable))
ssEnabled := cast.ToBool(appOpts.Get(FlagSSEnable))
snapshotExportInterval := cast.ToUint64(appOpts.Get(FlagSnapshotInterval))
// Make sure when snapshot is enabled, we should enable SS store
if snapshotExportInterval > 0 && scEnabled {
if !ssEnabled {
panic(fmt.Sprintf("Config validation failed, SeiDB SS store needs to be enabled when snapshot interval %d > 0", snapshotExportInterval))
}
}
}
4 changes: 2 additions & 2 deletions cmd/seid/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func dumpIavlCmdHandler(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
lines = append(lines, []byte(fmt.Sprintf("Hash: %X\n", hash))...)
lines = append(lines, []byte(fmt.Sprintf("Size: %X\n", tree.Size()))...)
lines = append(lines, []byte(fmt.Sprintf("Size: %X\n", tree.ITree.Size()))...)
// write lines to file
err = os.WriteFile(fmt.Sprintf("%s/%s.data", outputDir, module), lines, os.ModePerm)
if err != nil {
Expand Down Expand Up @@ -267,7 +267,7 @@ func encodeID(id []byte) string {

func PrintShape(tree *iavl.MutableTree) ([]byte, error) {
// shape := tree.RenderShape(" ", nil)
shape, err := tree.RenderShape(" ", nodeEncoder)
shape, err := tree.ITree.RenderShape(" ", nodeEncoder)
if err != nil {
return []byte{}, err
}
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- "${PROJECT_HOME}:/sei-protocol/sei-chain:Z"
- "${PROJECT_HOME}/../sei-tendermint:/sei-protocol/sei-tendermint:Z"
- "${PROJECT_HOME}/../sei-cosmos:/sei-protocol/sei-cosmos:Z"
- "${PROJECT_HOME}/../sei-db:/sei-protocol/sei-db:Z"
- "${GO_PKG_PATH}/mod:/root/go/pkg/mod:Z"
networks:
localnet:
Expand All @@ -38,6 +39,7 @@ services:
- "${PROJECT_HOME}:/sei-protocol/sei-chain:Z"
- "${PROJECT_HOME}/../sei-tendermint:/sei-protocol/sei-tendermint:Z"
- "${PROJECT_HOME}/../sei-cosmos:/sei-protocol/sei-cosmos:Z"
- "${PROJECT_HOME}/../sei-db:/sei-protocol/sei-db:Z"
- "${GO_PKG_PATH}/mod:/root/go/pkg/mod:Z"
networks:
localnet:
Expand All @@ -59,6 +61,7 @@ services:
- "${PROJECT_HOME}:/sei-protocol/sei-chain:Z"
- "${PROJECT_HOME}/../sei-tendermint:/sei-protocol/sei-tendermint:Z"
- "${PROJECT_HOME}/../sei-cosmos:/sei-protocol/sei-cosmos:Z"
- "${PROJECT_HOME}/../sei-db:/sei-protocol/sei-db:Z"
- "${GO_PKG_PATH}/mod:/root/go/pkg/mod:Z"
networks:
localnet:
Expand All @@ -80,6 +83,7 @@ services:
- "${PROJECT_HOME}:/sei-protocol/sei-chain:Z"
- "${PROJECT_HOME}/../sei-tendermint:/sei-protocol/sei-tendermint:Z"
- "${PROJECT_HOME}/../sei-cosmos:/sei-protocol/sei-cosmos:Z"
- "${PROJECT_HOME}/../sei-db:/sei-protocol/sei-db:Z"
- "${GO_PKG_PATH}/mod:/root/go/pkg/mod:Z"
networks:
localnet:
Expand Down
7 changes: 6 additions & 1 deletion docker/localnode/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y make git golang jq python3 curl vim
apt-get install -y make git wget build-essential jq python3 curl vim uuid-runtime
RUN rm -rf build/generated
RUN wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
RUN tar -xvf go1.20.6.linux-amd64.tar.gz
RUN mv go /usr/local/
SHELL ["/bin/bash", "-c"]


VOLUME [ "/sei-protocol" ]
VOLUME [ "/root/go/pkg/mod" ]
Expand Down
66 changes: 65 additions & 1 deletion docker/localnode/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,68 @@ snapshot-keep-recent = 2
query_gas_limit = 300000
# This is the number of wasm vm instances we keep cached in memory for speed-up
# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
lru_size = 0
lru_size = 0

###############################################################################
### SeiDB Configuration ###
###############################################################################

[state-commit]

# Enable defines if the state-commit (memiavl) should be enabled to override existing IAVL db backend.
sc-enable = true

sc-directory = ""

# ZeroCopy defines if memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
# the zero-copied slices must not be retained beyond current block's execution.
# the sdk address cache will be disabled if zero-copy is enabled.
sc-zero-copy = false

# AsyncCommitBuffer defines the size of asynchronous commit queue, this greatly improve block catching-up
# performance, <=0 means synchronous commit.
sc-async-commit-buffer = 100

# SnapshotKeepRecent defines how many state-commit snapshots (besides the latest one) to keep
# defaults to 1 to make sure ibc relayers work.
sc-keep-recent = 1

# SnapshotInterval defines the block interval the snapshot is taken, default to 10000 blocks.
sc-snapshot-interval = 1000

# SnapshotWriterLimit defines the max concurrency for taking commit store snapshot
sc-snapshot-writer-limit = 2

# CacheSize defines the size of the LRU cache for each store on top of the tree, default to 100000.
sc-cache-size = 1000

[state-store]

# Enable defines if the state-store should be enabled for historical queries.
# In order to use state-store, you need to make sure to enable state-commit at the same time
ss-enable = true

ss-db-directory = ""

# DBBackend defines the backend database used for state-store.
# Supported backends: pebbledb, rocksdb, sqlite
# defaults to pebbledb (recommended)
ss-backend = "pebbledb"

# AsyncWriteBuffer defines the async queue length for commits to be applied to State Store
# Set <= 0 for synchronous writes, which means commits also need to wait for data to be persisted in State Store.
# defaults to 100
ss-async-write-buffer = 100

# KeepRecent defines the number of versions to keep in state store
# Setting it to 0 means keep everything, default to 0
ss-keep-recent = 10000

# PruneIntervalSeconds defines the minimum interval in seconds + some random delay to trigger pruning.
# It is more efficient to trigger pruning less frequently with large interval.
# default to 600 seconds
ss-prune-interval = 60

# ImportNumWorkers defines the concurrency for state sync import
# defaults to 1
ss-import-num-workers = 1
2 changes: 1 addition & 1 deletion docker/localnode/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ db-backend = "goleveldb"
db-dir = "data"

# Output level for logging, including package level options
log-level = "debug"
log-level = "info"

# Output format: 'plain' (colored text) or 'json'
log-format = "plain"
Expand Down
6 changes: 5 additions & 1 deletion docker/rpcnode/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y make git golang jq python3 curl vim
apt-get install -y make git wget build-essential jq python3 curl vim
RUN wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
RUN tar -xvf go1.20.6.linux-amd64.tar.gz
RUN mv go /usr/local/
SHELL ["/bin/bash", "-c"]

VOLUME [ "/sei-protocol" ]
VOLUME [ "/root/go/pkg/mod" ]
Expand Down
Loading