diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5d73ab8bc..e707a24c5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,10 @@ jobs: with: path: ~/.cache/sccache key: ${{ runner.os }}-sccache - - run: rustup component add rust-src clippy + - run: | + rustup component add rust-src clippy + cd cosmwasm/enclaves/execute/ + rustup component add rust-src clippy - name: Install xargo run: | cargo --version @@ -56,7 +59,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v3 with: - go-version: "^1.18" # The Go version to download (if necessary) and use. + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Install Intel's SGX SDK run: | mkdir -p "$HOME/.sgxsdk" @@ -80,7 +83,10 @@ jobs: with: path: ~/.cache/sccache key: ${{ runner.os }}-sccache - - run: rustup component add rust-src clippy + - run: | + rustup component add rust-src clippy + cd cosmwasm/enclaves/execute/ + rustup component add rust-src clippy - name: Install xargo run: | cargo --version @@ -127,7 +133,15 @@ jobs: - uses: actions/upload-artifact@v3 with: name: contract.wasm - path: ./x/compute/internal/keeper/testdata/test-contract/contract.wasm + path: cosmwasm/contracts/v010/compute-tests/test-compute-contract/contract.wasm + - uses: actions/upload-artifact@v3 + with: + name: v1-contract.wasm + path: cosmwasm/contracts/v1/compute-tests/test-compute-contract/v1-contract.wasm + - uses: actions/upload-artifact@v3 + with: + name: ibc.wasm + path: cosmwasm/contracts/v1/compute-tests/ibc-test-contract/ibc.wasm - uses: actions/upload-artifact@v3 with: name: enclave @@ -139,15 +153,15 @@ jobs: - uses: actions/upload-artifact@v3 with: name: contract_with_floats.wasm - path: ./x/compute/internal/keeper/testdata/test-contract/contract_with_floats.wasm + path: cosmwasm/contracts/v010/compute-tests/test-compute-contract/contract_with_floats.wasm - uses: actions/upload-artifact@v3 with: name: too-high-initial-memory.wasm - path: ./x/compute/internal/keeper/testdata/test-contract/too-high-initial-memory.wasm + path: cosmwasm/contracts/v010/compute-tests/test-compute-contract/too-high-initial-memory.wasm - uses: actions/upload-artifact@v3 with: name: static-too-high-initial-memory.wasm - path: ./x/compute/internal/keeper/testdata/test-contract/static-too-high-initial-memory.wasm + path: cosmwasm/contracts/v010/compute-tests/test-compute-contract/static-too-high-initial-memory.wasm Go-Tests: runs-on: ubuntu-20.04 @@ -156,7 +170,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v3 with: - go-version: "^1.18" # The Go version to download (if necessary) and use. + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Install Intel's SGX SDK run: | mkdir -p "$HOME/.sgxsdk" @@ -174,6 +188,14 @@ jobs: - uses: actions/download-artifact@v3 with: name: contract.wasm + - uses: actions/download-artifact@v3 + with: + name: v1-contract.wasm + path: ./x/compute/internal/keeper/testdata/ + - uses: actions/download-artifact@v3 + with: + name: ibc.wasm + path: ./x/compute/internal/keeper/testdata/ - uses: actions/download-artifact@v3 with: name: contract_with_floats.wasm @@ -185,12 +207,14 @@ jobs: name: static-too-high-initial-memory.wasm - name: Setup Files run: | + find "$(pwd)" -name \*.wasm cp libgo_cosmwasm.so ./go-cosmwasm/api/libgo_cosmwasm.so cp librust_cosmwasm_enclave.signed.so ./go-cosmwasm/librust_cosmwasm_enclave.signed.so - cp contract.wasm ./x/compute/internal/keeper/testdata/test-contract/contract.wasm - cp too-high-initial-memory.wasm ./x/compute/internal/keeper/testdata/test-contract/too-high-initial-memory.wasm - cp contract_with_floats.wasm ./x/compute/internal/keeper/testdata/test-contract/contract_with_floats.wasm - cp static-too-high-initial-memory.wasm ./x/compute/internal/keeper/testdata/test-contract/static-too-high-initial-memory.wasm + cp contract.wasm ./x/compute/internal/keeper/testdata/contract.wasm + cp too-high-initial-memory.wasm ./x/compute/internal/keeper/testdata/too-high-initial-memory.wasm + cp contract_with_floats.wasm ./x/compute/internal/keeper/testdata/contract_with_floats.wasm + cp static-too-high-initial-memory.wasm ./x/compute/internal/keeper/testdata/static-too-high-initial-memory.wasm + find "$(pwd)" -name \*.wasm - name: Test x/registration run: | source "$HOME/.sgxsdk/sgxsdk/environment" @@ -205,7 +229,7 @@ jobs: echo "not_a_key" > ias_keys/develop/spid.txt echo "not_a_key" > ias_keys/develop/api_key.txt LOG_LEVEL=ERROR go test -v ./x/compute/client/... - LOG_LEVEL=ERROR go test -p 1 -timeout 20m -v ./x/compute/internal/... + LOG_LEVEL=ERROR go test -p 1 -timeout 90m -v ./x/compute/internal/... Clippy: runs-on: ubuntu-20.04 @@ -234,9 +258,13 @@ jobs: with: path: ~/.cache/sccache key: ${{ runner.os }}-sccache - - run: rustup component add rust-src clippy + - run: | + rustup component add rust-src clippy + cd cosmwasm/enclaves/execute/ + rustup component add rust-src clippy - name: Install xargo run: | + cd cosmwasm/enclaves/execute/ cargo --version rustc --version cargo +stable install xargo --version 0.3.25 @@ -260,7 +288,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v3 with: - go-version: "^1.18" # The Go version to download (if necessary) and use. + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Install xgo run: | go install github.com/crazy-max/xgo@v0.17.0 @@ -272,13 +300,24 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Build docker testnet + - name: Build LocalSecret run: | echo not_a_key | tee {api_key,spid}.txt DOCKER_TAG=v0.0.0 make build-localsecret + - name: Build Hermes + run: | + DOCKER_TAG=v0.0.0 make build-ibc-hermes + - name: Run integration tests + run: | + cd integration-tests + yarn + docker compose -f ../deployment/dockerfiles/ibc/docker-compose.yml up -d + # docker compose -f ../deployment/dockerfiles/ibc/docker-compose.yml logs -f & + yarn test + make kill-localsecret # next step needs the localsecret ports - name: Run secret.js tests run: | - git clone --depth 1 --branch lior-fix-based-on-rpc-2 https://github.com/scrtlabs/secret.js + git clone --depth 1 --branch cosmwasm-v1 https://github.com/scrtlabs/secret.js cd secret.js # Use the docker images that we built just a few steps above perl -i -pe 's/localsecret:.+?"/localsecret:v0.0.0"/' ./test/* diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 000000000..171fb04dd --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,66 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '35 19 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-20.04 + 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.18 + # 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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cee5e71bc..e6a025471 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -28,7 +28,7 @@ jobs: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - uses: actions/setup-go@v3 with: - go-version: "^1.18" # The Go version to download (if necessary) and use. + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Install Intel's SGX SDK run: | mkdir -p "$HOME/.sgxsdk" @@ -97,7 +97,7 @@ jobs: run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/} - uses: actions/setup-go@v3 with: - go-version: "^1.18" # The Go version to download (if necessary) and use. + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Create api keys run: | echo $SPID_MAINNET > spid.txt @@ -128,6 +128,9 @@ jobs: os: [ubuntu-20.04, windows-latest, macos-latest] steps: - uses: actions/checkout@v3 + - uses: actions/setup-go@v2 + with: + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Build CLI shell: bash run: | @@ -138,18 +141,18 @@ jobs: name: secretcli-${{runner.os}} path: secretcli-${{runner.os}} - x-build-cli: + MacOS-ARM64-CLI: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "^1.18" # The Go version to download (if necessary) and use. + go-version: 1.19 # The Go version to download (if necessary) and use. - name: Install xgo run: | - go install github.com/crazy-max/xgo@latest + go install github.com/crazy-max/xgo@v0.17.0 xgo || true # check installation - - name: Build CLI + - name: Build MacOS CLI shell: bash run: | make build_macos_arm64_cli @@ -188,7 +191,8 @@ jobs: run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} Release: - needs: [native-build-cli, build-deb-testnet, build-deb-mainnet, x-build-cli] + needs: + [native-build-cli, build-deb-testnet, build-deb-mainnet, MacOS-ARM64-CLI] runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 020611e5d..3c99d9456 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ librust_cosmwasm_enclave.signed.so SHA256SUMS* *.so /third_party/vendor -.vscode *.sealed *.der __debug_bin @@ -35,4 +34,10 @@ ias_bin_sw.go node_modules /secretjs /secret.js -tmp-swagger-gen \ No newline at end of file +tmp-swagger-gen +x/compute/internal/keeper/testdata/contract_with_floats.wasm +x/compute/internal/keeper/testdata/contract.wasm +x/compute/internal/keeper/testdata/ibc.wasm +x/compute/internal/keeper/testdata/static-too-high-initial-memory.wasm +x/compute/internal/keeper/testdata/too-high-initial-memory.wasm +x/compute/internal/keeper/testdata/v1-contract.wasm diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..24adf0886 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,47 @@ +run: + tests: false + # # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 5m + +linters: + disable-all: true + enable: + - depguard + - dogsled + - exportloopref + - errcheck + - goconst + - gocritic + - gofumpt + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - staticcheck + - stylecheck + - revive + - typecheck + - unconvert + - misspell + - nolintlint + +issues: + exclude-rules: + - text: "var-naming" + linters: + - revive + - text: "ST1003:" + linters: + - stylecheck + - text: "commentFormatting" + linters: + - stylecheck + - gocritic + - text: "dupSubExpr" + linters: + - gocritic + - text: "// nolint` should be written without leading space as `//nolint" + linters: + - nolintlint diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..f4b1b4c50 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["golang.go", "peterj.proto", "rust-lang.rust-analyzer"] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..86976b48d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,44 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "go-test", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${file}", + "cwd": "${workspaceFolder}/x/compute/internal/keeper", + "env": { "SGX_MODE": "SW", "RUST_BACKTRACE": "1" }, + "args": [ + "test", + "-timeout", + "1200s", + "-p", + "1", + "-v", + "./x/compute/internal/..." + ] + }, + { + "name": "secretcli", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/cmd/secretd", + "cwd": "${workspaceFolder}", + "args": [ + "q", + "compute", + "tx", + "9FAF715EA6671A17521FBC4D52AD391B72B6AADD102481B071DD80F34C50E79F", + "--node", + "http://localhost:26657", + "--chain-id", + "secretdev-1" + ] + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f19751d70 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,34 @@ +{ + "rust-analyzer.linkedProjects": [ + "cosmwasm/Cargo.toml", + "cosmwasm/enclaves/Cargo.toml", + "cosmwasm/contracts/v1/compute-tests/test-compute-contract/Cargo.toml", + "cosmwasm/contracts/v1/compute-tests/ibc-test-contract/Cargo.toml", + "cosmwasm/contracts/v010/compute-tests/test-compute-contract/Cargo.toml", + "integration-tests/contract-v1/Cargo.toml", + "integration-tests/contract-v0.10/Cargo.toml", + "go-cosmwasm/Cargo.toml" + ], + "rust-analyzer.diagnostics.experimental.enable": true, + "rust-analyzer.rustfmt.rangeFormatting.enable": true, + "rust-analyzer.diagnostics.disabled": ["unresolved-macro-call"], + "[rust]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "rust-lang.rust-analyzer" + }, + + "go.testEnvVars": { + "SGX_MODE": "SW", + "RUST_BACKTRACE": "1" + }, + "go.useLanguageServer": true, + "go.lintTool": "golangci-lint", + "go.lintOnSave": "workspace", + "gopls": { + "formatting.gofumpt": true + }, + "[go]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "golang.go" + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index a77443cbb..2b14054c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +# 1.4.0 +- CosmWasm v1 +- Bump WASM gas cost: + - Base WASM invocation 10k -> 100k + - WASM storage access 2k per access +- Support MetaMask pretty signing +- Ledger support for x/authz & x/feegrant +- USC module (disabled - needs a param-change proposal to enable) + # 1.3.1 - Use all available cores to serve queries. diff --git a/Makefile b/Makefile index 7e0a28c05..af1205b6d 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,18 @@ BRANCH ?= develop DEBUG ?= 0 DOCKER_TAG ?= latest +CW_CONTRACTS_V010_PATH = ./cosmwasm/contracts/v010/ +CW_CONTRACTS_V1_PATH = ./cosmwasm/contracts/v1/ + +TEST_CONTRACT_V010_PATH = ./cosmwasm/contracts/v010/compute-tests +TEST_CONTRACT_V1_PATH = ./cosmwasm/contracts/v1/compute-tests + +TEST_COMPUTE_MODULE_PATH = ./x/compute/internal/keeper/testdata/ + +ENCLAVE_PATH = cosmwasm/enclaves/ +EXECUTE_ENCLAVE_PATH = $(ENCLAVE_PATH)/execute/ +QUERY_ENCLAVE_PATH = $(ENCLAVE_PATH)/query/ + ifeq ($(SGX_MODE), HW) ext := hw else ifeq ($(SGX_MODE), SW) @@ -110,8 +122,6 @@ ifeq ($(DB_BACKEND),rocksdb) ldflags += -extldflags "-lrocksdb -llz4" endif - - ldflags += -s -w ldflags += $(LDFLAGS) ldflags := $(strip $(ldflags)) @@ -139,6 +149,8 @@ build_local_no_rust: bin-data-$(IAS_BUILD) cp go-cosmwasm/target/$(BUILD_PROFILE)/libgo_cosmwasm.so go-cosmwasm/api go build -mod=readonly -tags "$(GO_TAGS)" -ldflags '$(LD_FLAGS)' ./cmd/secretd +build-secret: build-linux + build-linux: _build-linux build_local_no_rust build_cli _build-linux: vendor BUILD_PROFILE=$(BUILD_PROFILE) FEATURES=$(FEATURES) FEATURES_U=$(FEATURES_U) $(MAKE) -C go-cosmwasm build-rust @@ -224,6 +236,9 @@ build-localsecret: docker build --build-arg SGX_MODE=SW --build-arg SECRET_NODE_TYPE=BOOTSTRAP --build-arg CHAIN_ID=secretdev-1 -f deployment/dockerfiles/release.Dockerfile -t build-release . docker build --build-arg SGX_MODE=SW --build-arg SECRET_NODE_TYPE=BOOTSTRAP --build-arg CHAIN_ID=secretdev-1 -f deployment/dockerfiles/dev-image.Dockerfile -t ghcr.io/scrtlabs/localsecret:${DOCKER_TAG} . +build-ibc-hermes: + docker build -f deployment/dockerfiles/ibc/hermes.Dockerfile -t hermes:v0.0.0 deployment/dockerfiles/ibc + build-custom-dev-image: # .dockerignore excludes .so files so we rename these so that the dockerfile can find them cd go-cosmwasm/api && cp libgo_cosmwasm.so libgo_cosmwasm.so.x @@ -231,7 +246,7 @@ build-custom-dev-image: docker build --build-arg SGX_MODE=SW --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/custom-node.Dockerfile -t enigmampc/secret-network-sw-dev-custom-bootstrap:${DOCKER_TAG} . docker build --build-arg SGX_MODE=SW --build-arg SECRET_NODE_TYPE=NODE -f deployment/dockerfiles/custom-node.Dockerfile -t enigmampc/secret-network-sw-dev-custom-node:${DOCKER_TAG} . # delete the copies created above - rm go-cosmwasm/api/libgo_cosmwasm.so.x cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so.x + rm go-cosmwasm/api/libgo_cosmwasm.so.x $(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so.x build-testnet: docker_base @mkdir build 2>&3 || true @@ -290,14 +305,6 @@ docker_base_go: docker_base: docker_base_rust docker_base_go -#ifeq ($(DB_BACKEND),rocksdb) -#docker_base: docker_base_rocksdb -#else -#docker_base: docker_base_goleveldb -#endif - - - docker_bootstrap: docker_base docker build --build-arg SGX_MODE=${SGX_MODE} --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/local-node.Dockerfile -t enigmampc/secret-network-bootstrap-${ext}:${DOCKER_TAG} . @@ -313,58 +320,63 @@ docker_enclave_test: # while developing: build-enclave: vendor - $(MAKE) -C cosmwasm/enclaves/execute enclave + $(MAKE) -C $(EXECUTE_ENCLAVE_PATH) enclave # while developing: check-enclave: - $(MAKE) -C cosmwasm/enclaves/execute check + $(MAKE) -C $(EXECUTE_ENCLAVE_PATH) check # while developing: clippy-enclave: - $(MAKE) -C cosmwasm/enclaves/execute clippy + $(MAKE) -C $(EXECUTE_ENCLAVE_PATH) clippy # while developing: clean-enclave: - $(MAKE) -C cosmwasm/enclaves/execute clean + $(MAKE) -C $(EXECUTE_ENCLAVE_PATH) clean sanity-test: SGX_MODE=SW $(MAKE) build-linux - cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so . + cp ./$(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so . SGX_MODE=SW ./cosmwasm/testing/sanity-test.sh sanity-test-hw: $(MAKE) build-linux - cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so . + cp ./$(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so . ./cosmwasm/testing/sanity-test.sh callback-sanity-test: SGX_MODE=SW $(MAKE) build-linux - cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so . + cp ./$(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so . SGX_MODE=SW ./cosmwasm/testing/callback-test.sh build-test-contract: # echo "" | sudo add-apt-repository ppa:hnakamur/binaryen # sudo apt update # sudo apt install -y binaryen - $(MAKE) -C ./x/compute/internal/keeper/testdata/test-contract + $(MAKE) -C $(TEST_CONTRACT_V010_PATH)/test-compute-contract + cp $(TEST_CONTRACT_V010_PATH)/test-compute-contract/*.wasm $(TEST_COMPUTE_MODULE_PATH)/ + $(MAKE) -C $(TEST_CONTRACT_V1_PATH)/test-compute-contract + cp $(TEST_CONTRACT_V1_PATH)/test-compute-contract/*.wasm $(TEST_COMPUTE_MODULE_PATH)/ + $(MAKE) -C $(TEST_CONTRACT_V1_PATH)/ibc-test-contract + cp $(TEST_CONTRACT_V1_PATH)/ibc-test-contract/*.wasm $(TEST_COMPUTE_MODULE_PATH)/ prep-go-tests: build-test-contract # empty BUILD_PROFILE means debug mode which compiles faster SGX_MODE=SW $(MAKE) build-linux - cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper + cp ./$(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper go-tests: build-test-contract - # empty BUILD_PROFILE means debug mode which compiles faster - SGX_MODE=SW $(MAKE) build-linux - cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper + SGX_MODE=SW $(MAKE) build-linux-with-query + cp ./$(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper + cp ./$(QUERY_ENCLAVE_PATH)/librust_cosmwasm_query_enclave.signed.so ./x/compute/internal/keeper rm -rf ./x/compute/internal/keeper/.sgx_secrets mkdir -p ./x/compute/internal/keeper/.sgx_secrets - GOMAXPROCS=8 SGX_MODE=SW SCRT_SGX_STORAGE='./' go test -failfast -timeout 1200s -v ./x/compute/internal/... $(GO_TEST_ARGS) + GOMAXPROCS=8 SGX_MODE=SW SCRT_SGX_STORAGE='./' go test -failfast -timeout 90m -v ./x/compute/internal/... $(GO_TEST_ARGS) go-tests-hw: build-test-contract # empty BUILD_PROFILE means debug mode which compiles faster SGX_MODE=HW $(MAKE) build-linux - cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper + cp ./$(EXECUTE_ENCLAVE_PATH)/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper rm -rf ./x/compute/internal/keeper/.sgx_secrets mkdir -p ./x/compute/internal/keeper/.sgx_secrets GOMAXPROCS=8 SGX_MODE=HW go test -v ./x/compute/internal/... $(GO_TEST_ARGS) @@ -377,37 +389,34 @@ enclave-tests: $(MAKE) -C cosmwasm/enclaves/test run build-all-test-contracts: build-test-contract - # echo "" | sudo add-apt-repository ppa:hnakamur/binaryen - # sudo apt update - # sudo apt install -y binaryen - cd ./cosmwasm/contracts/gov && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/gov/target/wasm32-unknown-unknown/release/gov.wasm -o ./x/compute/internal/keeper/testdata/gov.wasm + cd $(CW_CONTRACTS_V010_PATH)/gov && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os $(CW_CONTRACTS_V010_PATH)/gov/target/wasm32-unknown-unknown/release/gov.wasm -o $(TEST_CONTRACT_PATH)/gov.wasm - cd ./cosmwasm/contracts/dist && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/dist/target/wasm32-unknown-unknown/release/dist.wasm -o ./x/compute/internal/keeper/testdata/dist.wasm + cd $(CW_CONTRACTS_V010_PATH)/dist && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os $(CW_CONTRACTS_V010_PATH)/dist/target/wasm32-unknown-unknown/release/dist.wasm -o $(TEST_CONTRACT_PATH)/dist.wasm - cd ./cosmwasm/contracts/mint && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/mint/target/wasm32-unknown-unknown/release/mint.wasm -o ./x/compute/internal/keeper/testdata/mint.wasm + cd .$(CW_CONTRACTS_V010_PATH)/mint && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/mint/target/wasm32-unknown-unknown/release/mint.wasm -o $(TEST_CONTRACT_PATH)/mint.wasm - cd ./cosmwasm/contracts/staking && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/staking/target/wasm32-unknown-unknown/release/staking.wasm -o ./x/compute/internal/keeper/testdata/staking.wasm + cd .$(CW_CONTRACTS_V010_PATH)/staking && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/staking/target/wasm32-unknown-unknown/release/staking.wasm -o $(TEST_CONTRACT_PATH)/staking.wasm - cd ./cosmwasm/contracts/reflect && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/reflect/target/wasm32-unknown-unknown/release/reflect.wasm -o ./x/compute/internal/keeper/testdata/reflect.wasm + cd .$(CW_CONTRACTS_V010_PATH)/reflect && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/reflect/target/wasm32-unknown-unknown/release/reflect.wasm -o $(TEST_CONTRACT_PATH)/reflect.wasm - cd ./cosmwasm/contracts/burner && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/burner/target/wasm32-unknown-unknown/release/burner.wasm -o ./x/compute/internal/keeper/testdata/burner.wasm + cd .$(CW_CONTRACTS_V010_PATH)/burner && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/burner/target/wasm32-unknown-unknown/release/burner.wasm -o $(TEST_CONTRACT_PATH)/burner.wasm - cd ./cosmwasm/contracts/erc20 && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/erc20/target/wasm32-unknown-unknown/release/cw_erc20.wasm -o ./x/compute/internal/keeper/testdata/erc20.wasm + cd .$(CW_CONTRACTS_V010_PATH)/erc20 && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/erc20/target/wasm32-unknown-unknown/release/cw_erc20.wasm -o $(TEST_CONTRACT_PATH)/erc20.wasm - cd ./cosmwasm/contracts/hackatom && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/hackatom/target/wasm32-unknown-unknown/release/hackatom.wasm -o ./x/compute/internal/keeper/testdata/contract.wasm - cat ./x/compute/internal/keeper/testdata/contract.wasm | gzip > ./x/compute/internal/keeper/testdata/contract.wasm.gzip + cd .$(CW_CONTRACTS_V010_PATH)/hackatom && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/hackatom/target/wasm32-unknown-unknown/release/hackatom.wasm -o $(TEST_CONTRACT_PATH)/contract.wasm + cat $(TEST_CONTRACT_PATH)/contract.wasm | gzip > $(TEST_CONTRACT_PATH)/contract.wasm.gzip build-erc20-contract: build-test-contract - cd ./cosmwasm/contracts/erc20 && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked - wasm-opt -Os ./cosmwasm/contracts/erc20/target/wasm32-unknown-unknown/release/cw_erc20.wasm -o ./erc20.wasm + cd .$(CW_CONTRACTS_V010_PATH)/erc20 && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked + wasm-opt -Os .$(CW_CONTRACTS_V010_PATH)/erc20/target/wasm32-unknown-unknown/release/cw_erc20.wasm -o ./erc20.wasm bin-data: bin-data-sw bin-data-develop bin-data-production @@ -430,7 +439,7 @@ aesm-image: docker build -f deployment/dockerfiles/aesm.Dockerfile -t enigmampc/aesm . ############################################################################### -### Swagger ### +### Swagger & Protobuf ### ############################################################################### # Install the runsim binary with a temporary workaround of entering an outside @@ -451,22 +460,12 @@ update-swagger-openapi-docs: statik proto-swagger-openapi-gen echo "\033[92mSwagger docs are in sync\033[0m";\ fi -.PHONY: update-swagger-openapi-docs statik - -############################################################################### -### Protobuf ### -############################################################################### - -## proto-all: proto-gen proto-lint proto-check-breaking - -# proto-gen: -# @./scripts/protocgen.sh +# Example `CHAIN_VERSION=v1.4 make proto-swagger-openapi-gen` +proto-swagger-openapi-gen: + @./scripts/protoc-swagger-openapi-gen.sh -# proto-lint: -# @buf check lint --error-format=json +.PHONY: update-swagger-openapi-docs statik proto-swagger-openapi-gen -# proto-check-breaking: -# @buf check breaking --against-input '.git#branch=master' protoVer=v0.2 @@ -476,10 +475,7 @@ proto-gen: @echo "Generating Protobuf files" $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:$(protoVer) sh ./scripts/protocgen.sh -proto-swagger-openapi-gen: - @./scripts/protoc-swagger-openapi-gen.sh - proto-lint: @$(DOCKER_BUF) lint --error-format=json -.PHONY: proto-all proto-gen proto-swagger-openapi-gen proto-format proto-lint proto-check-breaking +.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking diff --git a/app/ante.go b/app/ante.go new file mode 100644 index 000000000..7fe1cac61 --- /dev/null +++ b/app/ante.go @@ -0,0 +1,58 @@ +package app + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/ibc-go/v3/modules/core/keeper" + + "github.com/enigmampc/SecretNetwork/x/compute" +) + +// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC +// channel keeper. +type HandlerOptions struct { + ante.HandlerOptions + + IBCKeeper *keeper.Keeper + WasmConfig *compute.WasmConfig + TXCounterStoreKey sdk.StoreKey +} + +func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { + if options.AccountKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") + } + + if options.BankKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") + } + + if options.SignModeHandler == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + } + + sigGasConsumer := options.SigGasConsumer + if sigGasConsumer == nil { + sigGasConsumer = ante.DefaultSigVerificationGasConsumer + } + + anteDecorators := []sdk.AnteDecorator{ + compute.NewCountTXDecorator(options.TXCounterStoreKey), + ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + ante.NewRejectExtensionOptionsDecorator(), + ante.NewMempoolFeeDecorator(), + ante.NewValidateBasicDecorator(), + ante.NewTxTimeoutHeightDecorator(), + ante.NewValidateMemoDecorator(options.AccountKeeper), + ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), + ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), + ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators + ante.NewValidateSigCountDecorator(options.AccountKeeper), + ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), + ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + } + + return sdk.ChainAnteDecorators(anteDecorators...), nil +} diff --git a/app/app.go b/app/app.go index cc2830b0a..550ec8211 100644 --- a/app/app.go +++ b/app/app.go @@ -7,7 +7,10 @@ import ( "os" "path/filepath" - store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/enigmampc/SecretNetwork/app/upgrades" + v1_3 "github.com/enigmampc/SecretNetwork/app/upgrades/v1.3" + v1_4 "github.com/enigmampc/SecretNetwork/app/upgrades/v1.4" + v1_4_fix "github.com/enigmampc/SecretNetwork/app/upgrades/v1.4-fix" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -37,7 +40,6 @@ import ( porttypes "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" - v1_3 "github.com/enigmampc/SecretNetwork/app/upgrades/v1.3" icaauth "github.com/enigmampc/SecretNetwork/x/mauth" icaauthtypes "github.com/enigmampc/SecretNetwork/x/mauth/types" @@ -136,6 +138,8 @@ var ( allowedReceivingModAcc = map[string]bool{ distrtypes.ModuleName: true, } + + Upgrades = []upgrades.Upgrade{v1_3.Upgrade, v1_4.Upgrade, v1_4_fix.Upgrade} ) // Verify app interface at compile time @@ -211,7 +215,7 @@ func (app *SecretNetworkApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper } func (app *SecretNetworkApp) GetTxConfig() client.TxConfig { - return app.GetTxConfig() + return MakeEncodingConfig().TxConfig } func (app *SecretNetworkApp) AppCodec() codec.Codec { @@ -296,6 +300,7 @@ func NewSecretNetworkApp( scopedICAControllerKeeper := app.capabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) scopedICAHostKeeper := app.capabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) scopedICAAuthKeeper := app.capabilityKeeper.ScopeToModule(icaauthtypes.ModuleName) + scopedCapabilityKeeper := app.capabilityKeeper.ScopeToModule(compute.ModuleName) // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` @@ -371,18 +376,6 @@ func NewSecretNetworkApp( app.accountKeeper, app.bankKeeper, scopedTransferKeeper, ) - // Create static IBC router, add ibc-tranfer module route, then set and seal it - ibcRouter := porttypes.NewRouter() - ibcRouter.AddRoute(ibctransfertypes.ModuleName, transfer.NewIBCModule(app.transferKeeper)) - ibcRouter. - AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule). - AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). - AddRoute(icaauthtypes.ModuleName, icaControllerIBCModule) - - // Setting Router will finalize all routes by sealing router - // No more routes can be added - app.ibcKeeper.SetRouter(ibcRouter) - // Create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( appCodec, keys[evidencetypes.StoreKey], &app.stakingKeeper, app.slashingKeeper, @@ -398,7 +391,6 @@ func NewSecretNetworkApp( AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper)) // Just re-use the full router - do we want to limit this more? - computeRouter := app.Router() regRouter := app.Router() // Replace with bootstrap flag when we figure out how to test properly and everything works @@ -418,7 +410,7 @@ func NewSecretNetworkApp( // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks - supportedFeatures := "staking" + supportedFeatures := "staking,stargate,ibc3" app.computeKeeper = compute.NewKeeper( appCodec, @@ -430,7 +422,13 @@ func NewSecretNetworkApp( app.distrKeeper, app.mintKeeper, app.stakingKeeper, - computeRouter, + scopedCapabilityKeeper, + app.ibcKeeper.PortKeeper, + app.transferKeeper, + app.ibcKeeper.ChannelKeeper, + app.Router(), + app.MsgServiceRouter(), + app.GRPCQueryRouter(), computeDir, computeConfig, supportedFeatures, @@ -438,6 +436,18 @@ func NewSecretNetworkApp( nil, ) + // Create static IBC router, add ibc-tranfer module route, then set and seal it + ibcRouter := porttypes.NewRouter() + ibcRouter.AddRoute(compute.ModuleName, compute.NewIBCHandler(app.computeKeeper, app.ibcKeeper.ChannelKeeper)). + AddRoute(ibctransfertypes.ModuleName, transfer.NewIBCModule(app.transferKeeper)). + AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule). + AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). + AddRoute(icaauthtypes.ModuleName, icaControllerIBCModule) + + // Setting Router will finalize all routes by sealing router + // No more routes can be added + app.ibcKeeper.SetRouter(ibcRouter) + // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment // we prefer to be more strict in what arguments the modules expect. skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) @@ -560,47 +570,30 @@ func NewSecretNetworkApp( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) + // setupUpgradeHandlers() shoulbe be called after app.mm is configured app.setupUpgradeHandlers(&icaModule) - // add test gRPC service for testing gRPC queries in isolation - // testdata.RegisterTestServiceServer(app.GRPCQueryRouter(), testdata.QueryImpl{}) // TODO: this is testdata !!! - - // create the simulation manager and define the order of the modules for deterministic simulations - // - // NOTE: This is not required for apps that don't use the simulator for fuzz testing - // transactions. - //app.sm = module.NewSimulationManager( - // auth.NewAppModule(appCodec, app.accountKeeper, authsims.RandomGenesisAccounts), - // bank.NewAppModule(appCodec, app.bankKeeper, app.accountKeeper), - // capability.NewAppModule(appCodec, *app.capabilityKeeper), - // gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.bankKeeper), - // mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper), - // staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper), - // distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), - // slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), - // params.NewAppModule(app.paramsKeeper), - // //compute.NewAppModule(app.computeKeeper), - // evidence.NewAppModule(app.evidenceKeeper), - //) - - // app.sm.RegisterStoreDecoders() - // initialize stores app.MountKVStores(keys) app.MountTransientStores(tKeys) app.MountMemoryStores(memKeys) - anteOptions := ante.HandlerOptions{ - AccountKeeper: app.accountKeeper, - BankKeeper: app.bankKeeper, - FeegrantKeeper: app.feeGrantKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + anteOptions := HandlerOptions{ + HandlerOptions: ante.HandlerOptions{ + AccountKeeper: app.accountKeeper, + BankKeeper: app.bankKeeper, + FeegrantKeeper: app.feeGrantKeeper, + SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + IBCKeeper: app.ibcKeeper, + WasmConfig: computeConfig, + TXCounterStoreKey: keys[compute.StoreKey], } - anteHandler, err := ante.NewAnteHandler(anteOptions) + anteHandler, err := NewAnteHandler(anteOptions) if err != nil { - panic(err) + panic(fmt.Errorf("failed to create AnteHandler: %s", err)) } // The AnteHandler handles signature verification and transaction pre-processing @@ -740,11 +733,15 @@ func (app *SecretNetworkApp) BlockedAddrs() map[string]bool { } func (app *SecretNetworkApp) setupUpgradeHandlers(icamodule *ica.AppModule) { - // this configures a no-op upgrade handler for the v4 upgrade, - // which improves the lockup module's store management. - app.upgradeKeeper.SetUpgradeHandler( - v1_3.UpgradeName, v1_3.CreateUpgradeHandler( - app.mm, icamodule, app.configurator)) + for _, upgradeDetails := range Upgrades { + app.upgradeKeeper.SetUpgradeHandler( + upgradeDetails.UpgradeName, + upgradeDetails.CreateUpgradeHandler( + app.mm, + app.configurator, + ), + ) + } } func (app *SecretNetworkApp) setupUpgradeStoreLoaders() { @@ -753,14 +750,14 @@ func (app *SecretNetworkApp) setupUpgradeStoreLoaders() { panic(fmt.Sprintf("Failed to read upgrade info from disk %s", err)) } - if upgradeInfo.Name == v1_3.UpgradeName && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - // @Frey do we do this for Cosmwasm? - storeUpgrades := store.StoreUpgrades{ - Added: []string{icahosttypes.StoreKey}, - } + if app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + return + } - // configure store loader that checks if version == upgradeHeight and applies store upgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + for _, upgradeDetails := range Upgrades { + if upgradeInfo.Name == upgradeDetails.UpgradeName { + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgradeDetails.StoreUpgrades)) + } } } diff --git a/app/export.go b/app/export.go index d1267e5bb..52d44d647 100644 --- a/app/export.go +++ b/app/export.go @@ -46,7 +46,8 @@ func (app *SecretNetworkApp) ExportAppStateAndValidators(forZeroHeight bool, jai // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// in favour of export at a block height +// +// in favour of export at a block height func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false diff --git a/app/legacy/migrate.go b/app/legacy/migrate.go index 53cafd533..02938a1dc 100644 --- a/app/legacy/migrate.go +++ b/app/legacy/migrate.go @@ -3,7 +3,7 @@ package legacy import ( "encoding/json" "fmt" - "io/ioutil" + "os" "time" "github.com/cosmos/cosmos-sdk/x/authz" @@ -53,7 +53,7 @@ $ secretd migrate /path/to/genesis.json --chain-id=secret-4 --genesis-time=2019- importGenesis := args[0] - jsonBlob, err := ioutil.ReadFile(importGenesis) + jsonBlob, err := os.ReadFile(importGenesis) if err != nil { return errors.Wrap(err, "failed to read provided genesis file") } diff --git a/app/upgrades/types.go b/app/upgrades/types.go new file mode 100644 index 000000000..595f21932 --- /dev/null +++ b/app/upgrades/types.go @@ -0,0 +1,32 @@ +package upgrades + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +// BaseAppParamManager defines an interrace that BaseApp is expected to fullfil +// that allows upgrade handlers to modify BaseApp parameters. +type BaseAppParamManager interface { + GetConsensusParams(ctx sdk.Context) *abci.ConsensusParams + StoreConsensusParams(ctx sdk.Context, cp *abci.ConsensusParams) +} + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +// must have written, in order for the state migration to go smoothly. +// An upgrade must implement this struct, and then set it in the app.go. +// The app.go will then define the handler. +type Upgrade struct { + // Upgrade version name, for the upgrade handler, e.g. `v1.4` + UpgradeName string + + // CreateUpgradeHandler defines the function that creates an upgrade handler + // mm *module.Manager, computeModule *computetypes.AppModule, configurator module.Configurator + CreateUpgradeHandler func(*module.Manager, module.Configurator) upgradetypes.UpgradeHandler + + // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. + StoreUpgrades store.StoreUpgrades +} diff --git a/app/upgrades/v1.3/upgrades.go b/app/upgrades/v1.3/upgrades.go index 41af2fca0..d17ea9d97 100644 --- a/app/upgrades/v1.3/upgrades.go +++ b/app/upgrades/v1.3/upgrades.go @@ -1,6 +1,7 @@ package v1_3 import ( + store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -8,23 +9,30 @@ import ( icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" + "github.com/enigmampc/SecretNetwork/app/upgrades" ) const UpgradeName = "v1.3" -func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, configurator module.Configurator, +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{Added: []string{icahosttypes.StoreKey}}, +} + +func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { // Assaf: Set version map for all modules because for some // reason it's not already set in upgradekeepr. // We upgrade from cosmos-sdk v0.44.5 to v0.45.4 and ibc-go v1.1.5 to v3.0.0 // There were no ConsensusVersion changes between these versions - // so we should be safe to use the curent ConsensusVersion() for each moudle + // so we should be safe to use the current ConsensusVersion() for each moudle for moduleName := range mm.Modules { vm[moduleName] = mm.Modules[moduleName].ConsensusVersion() } - vm[icatypes.ModuleName] = icamodule.ConsensusVersion() + vm[icatypes.ModuleName] = mm.Modules[icatypes.ModuleName].ConsensusVersion() // create ICS27 Controller submodule params controllerParams := icacontrollertypes.Params{ @@ -60,7 +68,15 @@ func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, co ctx.Logger().Info("Starting to init interchainaccount module...") // initialize ICS27 module - icamodule.InitModule(ctx, controllerParams, hostParams) + // icamodule.InitModule(ctx, controllerParams, hostParams) + + // initialize ICS27 module + icamoduleInstance, correctTypecast := mm.Modules[icatypes.ModuleName].(icamodule.AppModule) + if !correctTypecast { + panic("mm.Modules[icatypes.ModuleName] is not of type ica.AppModule") + } + + icamoduleInstance.InitModule(ctx, controllerParams, hostParams) ctx.Logger().Info("Starting to run module migrations...") diff --git a/app/upgrades/v1.4-fix/upgrades.go b/app/upgrades/v1.4-fix/upgrades.go new file mode 100644 index 000000000..bff69c2cb --- /dev/null +++ b/app/upgrades/v1.4-fix/upgrades.go @@ -0,0 +1,29 @@ +package v1_4_fix + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/enigmampc/SecretNetwork/app/upgrades" +) + +const UpgradeName = "v1.4-fix" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} + +func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // We're not upgrading cosmos-sdk, Tendermint or ibc-go, so no ConsensusVersion changes + // Therefore mm.RunMigrations() should not find any module to upgrade + + ctx.Logger().Info("Running module migrations for v1.4-fix...") + + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/app/upgrades/v1.4/upgrades.go b/app/upgrades/v1.4/upgrades.go new file mode 100644 index 000000000..27c23d59b --- /dev/null +++ b/app/upgrades/v1.4/upgrades.go @@ -0,0 +1,29 @@ +package v1_4 + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/enigmampc/SecretNetwork/app/upgrades" +) + +const UpgradeName = "v1.4" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} + +func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // We're not upgrading cosmos-sdk, Tendermint or ibc-go, so no ConsensusVersion changes + // Therefore mm.RunMigrations() should not find any module to upgrade + + ctx.Logger().Info("Running module migrations for v1.4...") + + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/client/docs/config.json b/client/docs/config.json index e1a5bc622..08cc424a1 100644 --- a/client/docs/config.json +++ b/client/docs/config.json @@ -1,9 +1,9 @@ { "swagger": "2.0", "info": { - "title": "Secret Network - gRPC Gateway docs", + "title": "Secret Network", "description": "A REST interface for queries and transactions", - "version": "v1.3.1" + "version": "v1.4" }, "apis": [ { @@ -126,6 +126,16 @@ } } }, + { + "url": "../../tmp-swagger-gen/cosmos/tx/v1beta1/fixed-service.swagger.json", + "operationIds": { + "rename": { + "Params": "../../tmp-swagger-gen/cosmos/tx/v1beta1/fixed-service.swagger.jsonParams", + "DelegatorValidators": "../../tmp-swagger-gen/cosmos/tx/v1beta1/fixed-service.swagger.jsonDelegatorValidators", + "UpgradedConsensusState": "../../tmp-swagger-gen/cosmos/tx/v1beta1/fixed-service.swagger.jsonUpgradedConsensusState" + } + } + }, { "url": "../../tmp-swagger-gen/cosmos/upgrade/v1beta1/query.swagger.json", "operationIds": { diff --git a/client/docs/package.json b/client/docs/package.json index 80c785748..764ab6ebd 100644 --- a/client/docs/package.json +++ b/client/docs/package.json @@ -5,7 +5,7 @@ "license": "MIT", "scripts": { "combine": "swagger-combine ./config.json -o static/swagger/swagger.yaml -f yaml --continueOnConflictingPaths --includeDefinitions", - "convert": "mkdir -p static/openapi && swagger2openapi static/swagger/swagger.yaml --outfile static/openapi/openapi.yaml --yaml", + "convert": "mkdir -p static/openapi && swagger2openapi --patch static/swagger/swagger.yaml --outfile static/openapi/openapi.yaml --yaml", "build": "redoc-cli build static/openapi/openapi.yaml --output ./static/openapi/index.html" }, "dependencies": { diff --git a/client/docs/static/openapi/index.html b/client/docs/static/openapi/index.html index 3c2936801..412e2811c 100644 --- a/client/docs/static/openapi/index.html +++ b/client/docs/static/openapi/index.html @@ -3,7 +3,7 @@
-