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

[SeiDB] Memiavl Prototype #998

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
32af00f
Fix go mod
Jul 26, 2023
377eee8
Bump golang version to 1.20
Jul 26, 2023
22d4e2d
Bump to 1.20
Jul 26, 2023
b1ffe57
Fix go version
Jul 26, 2023
c1dc10d
Enable memaiavl
Jul 31, 2023
6c4aa64
Bump mmap ival version
Jul 31, 2023
d8a283d
Fix version
yzang2019 Aug 8, 2023
96b0c9a
Fix chain race condition
yzang2019 Aug 9, 2023
753b050
Merge branch 'main' into yzang/memiavl-prototype
yzang2019 Aug 9, 2023
93453ca
Fix go mod
yzang2019 Aug 9, 2023
ad9f2b3
Bump memIavl to 1.0.6
yzang2019 Aug 9, 2023
fec801c
Fix go mod
yzang2019 Aug 9, 2023
98543c4
Add more testing
yzang2019 Aug 30, 2023
fa8d7cf
Fix memIAVL app hash bug
yzang2019 Sep 1, 2023
25c3b1e
Merge branch 'main' into yzang/memiavl-prototype
yzang2019 Sep 1, 2023
6cd9098
Fix snapshot intervals
yzang2019 Sep 2, 2023
d878fdf
Bump cosmos version
yzang2019 Sep 2, 2023
3d1f854
Bump iavl and cosmos version
yzang2019 Sep 2, 2023
4d30e87
Bump cosmos version
yzang2019 Sep 2, 2023
6dd23d2
Bump cosmos version for snapshot fix
yzang2019 Sep 3, 2023
55213eb
Bump iavl version to fix db close issue
yzang2019 Sep 4, 2023
5ddfb34
Fix snapshot interval
yzang2019 Sep 4, 2023
dc53c8d
Close cachemultistore in abci query
yzang2019 Sep 6, 2023
76cf734
Bump iavl
yzang2019 Sep 6, 2023
7af79ee
Bump iavl
yzang2019 Sep 6, 2023
b4d994f
Bump cosmos for more logs
yzang2019 Sep 7, 2023
33cf014
Bump sei-wasmd version
yzang2019 Sep 7, 2023
31e8b7c
Add SS commit logic
yzang2019 Oct 30, 2023
070bac2
Fix go mod
yzang2019 Oct 31, 2023
20cd0fa
Add QMS
yzang2019 Nov 1, 2023
4c7d3f5
Add snapshot maanger for SS
yzang2019 Nov 3, 2023
8053e00
Merge latest main
yzang2019 Nov 3, 2023
c8e9a89
Bump seidb version
yzang2019 Nov 6, 2023
4c73f5b
Bump seidb version
yzang2019 Nov 7, 2023
0be7ed8
Merge with latest master
yzang2019 Nov 15, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: '1.20'
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compatiblity_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: '1.20'

- name: Check Latest Dependencies
run: |
Expand Down
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.20'

- 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.20'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.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.19"
go-version: '1.20'
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: '1.20'

# Download all coverage reports from the 'tests' job
- name: Download coverage reports
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ run-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 \
Expand All @@ -163,6 +164,7 @@ run-rpc-node-skipbuild: 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 \
Expand Down
86 changes: 47 additions & 39 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
"sync"
"time"

"github.com/sei-protocol/sei-chain/app/antedecorators"

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

"github.com/sei-protocol/sei-chain/aclmapping"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
appparams "github.com/sei-protocol/sei-chain/app/params"
"github.com/sei-protocol/sei-chain/app/upgrades"
v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/wasmbinding"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -35,29 +23,29 @@
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol"
aclclient "github.com/cosmos/cosmos-sdk/x/accesscontrol/client"
aclconstants "github.com/cosmos/cosmos-sdk/x/accesscontrol/constants"
aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper"
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -108,37 +96,42 @@
ibcporttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/sei-protocol/sei-chain/x/mint"
mintclient "github.com/sei-protocol/sei-chain/x/mint/client/cli"
mintkeeper "github.com/sei-protocol/sei-chain/x/mint/keeper"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/sei-protocol/sei-chain/aclmapping"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
"github.com/sei-protocol/sei-chain/app/antedecorators"
appparams "github.com/sei-protocol/sei-chain/app/params"
"github.com/sei-protocol/sei-chain/app/upgrades"
v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/utils/metrics"

"github.com/sei-protocol/sei-chain/wasmbinding"
dexmodule "github.com/sei-protocol/sei-chain/x/dex"
dexcache "github.com/sei-protocol/sei-chain/x/dex/cache"
dexmodulekeeper "github.com/sei-protocol/sei-chain/x/dex/keeper"
dexmoduletypes "github.com/sei-protocol/sei-chain/x/dex/types"
dexutils "github.com/sei-protocol/sei-chain/x/dex/utils"

oraclemodule "github.com/sei-protocol/sei-chain/x/oracle"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"

epochmodule "github.com/sei-protocol/sei-chain/x/epoch"
epochmodulekeeper "github.com/sei-protocol/sei-chain/x/epoch/keeper"
epochmoduletypes "github.com/sei-protocol/sei-chain/x/epoch/types"

"github.com/sei-protocol/sei-chain/x/mint"
mintclient "github.com/sei-protocol/sei-chain/x/mint/client/cli"
mintkeeper "github.com/sei-protocol/sei-chain/x/mint/keeper"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
oraclemodule "github.com/sei-protocol/sei-chain/x/oracle"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"
tokenfactorymodule "github.com/sei-protocol/sei-chain/x/tokenfactory"
tokenfactorykeeper "github.com/sei-protocol/sei-chain/x/tokenfactory/keeper"
tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types"
"github.com/sei-protocol/sei-db/sc"
"github.com/sei-protocol/sei-db/ss"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

// this line is used by starport scaffolding # stargate/app/moduleImport

Expand Down Expand Up @@ -375,7 +368,10 @@
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), tmConfig, appOpts, baseAppOptions...)
// setup seiDB if it's enabled in config
bAppOptions, scStore := sc.SetupStateCommit(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 Expand Up @@ -781,6 +777,14 @@
app.ProcessProposalMemState = dexcache.NewMemState(app.GetMemKey(dexmoduletypes.MemStoreKey))
app.MemState = dexcache.NewMemState(app.GetMemKey(dexmoduletypes.MemStoreKey))

qms, err := ss.SetupStateStore(logger, homePath, app.CommitMultiStore(), scStore, appOpts, keys, tkeys, memKeys)
if err != nil {
panic(err)

Check warning on line 782 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L782

Added line #L782 was not covered by tests
}
if qms != nil {
app.SetQueryMultiStore(qms)
}

Check warning on line 786 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L785-L786

Added lines #L785 - L786 were not covered by tests

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
Expand Down Expand Up @@ -824,6 +828,8 @@

// Register snapshot extensions to enable state-sync for wasm.
if manager := app.SnapshotManager(); manager != nil {
manager.SetStateCommitStore(app.CommitMultiStore())
manager.SetStateStore(app.QueryMultiStore())

Check warning on line 832 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L831-L832

Added lines #L831 - L832 were not covered by tests
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
Expand All @@ -832,6 +838,7 @@
}
}

fmt.Println("Loading latest version at time: ", time.Now().Format(time.RFC3339))

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
loadVersionHandler := func() error {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand All @@ -851,6 +858,7 @@
} else {
app.SetLoadVersionHandler(loadVersionHandler)
}
fmt.Println("Finished loading latest version at time: ", time.Now().Format(time.RFC3339))

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 @@ -42,6 +43,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 @@ -65,6 +67,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 @@ -88,6 +91,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
5 changes: 4 additions & 1 deletion docker/localnode/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y make git golang jq python3 curl vim uuid-runtime
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"]


Expand Down
34 changes: 33 additions & 1 deletion docker/localnode/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,36 @@ snapshot-directory = ""
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

[state-commit]

# Enable defines if the memiavl should be enabled.
enable = true

# ZeroCopy defines if the 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.
zero-copy = false

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

# SnapshotKeepRecent defines what many old snapshots (excluding the latest one) to keep after new snapshots are
# taken, defaults to 1 to make sure ibc relayers work.
snapshot-keep-recent = 2

# SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 1000.
snapshot-interval = 200

# CacheSize defines the size of the cache for each memiavl store, default to 1000.
cache-size = 1000

[state-store]

enable = true

backend = "pebbledb"

async-writer-buffer = 10
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
34 changes: 33 additions & 1 deletion docker/rpcnode/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,36 @@ 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

[state-commit]

# Enable defines if the memiavl should be enabled.
enable = true

# ZeroCopy defines if the 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.
zero-copy = false

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

# SnapshotKeepRecent defines what many old snapshots (excluding the latest one) to keep after new snapshots are
# taken, defaults to 1 to make sure ibc relayers work.
snapshot-keep-recent = 2

# SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 1000.
snapshot-interval = 200

# CacheSize defines the size of the cache for each memiavl store, default to 1000.
cache-size = 1000

[state-store]

enable = true

backend = "pebbledb"

async-writer-buffer = 10
2 changes: 1 addition & 1 deletion docker/rpcnode/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
Loading
Loading