Skip to content

Commit

Permalink
V3.0.0 - testnet version (#722)
Browse files Browse the repository at this point in the history
## 1. Overview

This PR upgrades the Quasar chain from Cosmos SDK version 0.47 to
version 0.50.x. This includes updating dependencies, modifying import
paths, and adjusting the codebase to align with the changes and
improvements introduced in the newer SDK version.

## 2. Implementation details
Ref for the cosmos-sdk upgrade -
https://github.com/cosmos/cosmos-sdk/blob/release/v0.50.x/UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/release/v0.50.x/UPGRADING.md

## 3. How to test/use

TODO. 

## 4. Checklist

<!-- Checklist for PR author(s). -->

- [ ] Does the Readme need to be updated? YES

## 5. Limitations (optional)

The upgrade may introduce breaking changes requiring dependent services
or module modifications.
Extensive testing is needed to ensure compatibility with existing data
and user workflows.

## 6. Future Work (optional)

<!-- Describe follow up work, if any. -->

---------

Co-authored-by: akure <[email protected]>
Co-authored-by: Ajaz Ahmed Ansari <[email protected]>
Co-authored-by: Ajaz Ahmed <[email protected]>
Co-authored-by: Ajaz Ahmed Ansari <[email protected]>
  • Loading branch information
5 people authored Aug 26, 2024
1 parent 40cd118 commit e568865
Show file tree
Hide file tree
Showing 187 changed files with 9,448 additions and 29,115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
if: env.GIT_DIFF
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.22
- name: Display go version
if: env.GIT_DIFF
run: go version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: env.GIT_DIFF
uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.22
- name: Display go version
if: env.GIT_DIFF
run: go version
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ vue/
**/**/target
**/**/test-tube-build
local_testnet_run-*nodes/
*.out
coverage.txt

containers_homes/

Expand Down
77 changes: 23 additions & 54 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.20"
ARG GO_VERSION="1.22"
ARG RUNNER_IMAGE="gcr.io/distroless/static-debian11"
ARG BUILD_TAGS="netgo,ledger,muslc"

# --------------------------------------------------------
# Builder
# --------------------------------------------------------

FROM golang:${GO_VERSION}-alpine3.18 as builder
FROM golang:${GO_VERSION}-alpine3.20 as builder

ARG GIT_VERSION
ARG GIT_COMMIT
ARG BUILD_TAGS

RUN apk add --no-cache \
ca-certificates \
build-base \
linux-headers
linux-headers \
binutils-gold

# Download go dependencies
WORKDIR /quasar
Expand All @@ -25,80 +28,46 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
go mod download

# Cosmwasm - Download correct libwasmvm version
RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \
-O /lib/libwasmvm_muslc.a && \
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.$(uname -m).a && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1)
sha256sum /lib/libwasmvm_muslc.$(uname -m).a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$(uname -m) | cut -d ' ' -f 1)

# Copy the remaining files
COPY . .

# Build quasard binary
# force it to use static lib (from above) not standard libgo_cosmwasm.so file
# then log output of file /quasar/build/quasard
# then ensure static linking
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
GOWORK=off go build \
-mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags \
"-X github.com/cosmos/cosmos-sdk/version.Name="quasar" \
-X github.com/cosmos/cosmos-sdk/version.AppName="quasard" \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags='netgo,ledger,muslc' \
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-trimpath \
-o build/quasard \
-mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags \
"-X github.com/cosmos/cosmos-sdk/version.Name="quasar" \
-X github.com/cosmos/cosmos-sdk/version.AppName="quasard" \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=${BUILD_TAGS} \
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-trimpath \
-o /quasar/build/quasard \
/quasar/cmd/quasard/main.go


# --------------------------------------------------------
# Runner
# --------------------------------------------------------

FROM ${RUNNER_IMAGE} as runner

COPY --from=builder /quasar/build/quasard /bin/quasard

ENV HOME /quasar
WORKDIR $HOME

EXPOSE 26656
EXPOSE 26657
EXPOSE 1317

CMD ["quasard"]

# --------------------------------------------------------
# Development
# --------------------------------------------------------

FROM ubuntu:22.04 as dev

ENV PACKAGES jq

RUN rm -f /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && apt-get install -y $PACKAGES

FROM ${RUNNER_IMAGE}

COPY --from=builder /quasar/build/quasard /bin/quasard


ENV HOME /quasar
WORKDIR $HOME

COPY tests/docker/bootstrap-scripts/entrypoint.sh /quasar/entrypoint.sh
COPY tests/docker/bootstrap-scripts/quasar_localnet.sh /quasar/app_init.sh
RUN chmod +x entrypoint.sh && chmod +x app_init.sh && mkdir logs

EXPOSE 26656
EXPOSE 26657
EXPOSE 1317

CMD ["quasard"]
ENTRYPOINT ["./entrypoint.sh"]
ENTRYPOINT ["quasard"]
2 changes: 1 addition & 1 deletion LOCALNET.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Then make sure the upgrade is registered in the `app.go`:
```golang
// imports
// ...
dummy "github.com/quasarlabs/quasarnode/app/upgrades/dummy"
dummy "github.com/quasar-finance/quasar/app/upgrades/dummy"

// var block declaration
// ...
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ x/qtransfer, x/epochs and x/tokenfactory module are utilised from the osmosis x/
### Rust
In order to run test-tube the following dependencies are required:
* `sudo apt update && sudo apt install -y build-essential pkg-config libssl-dev curl clang libclang-dev`
* go1.21 ([see here](https://go.dev/doc/install))
* go1.22 ([see here](https://go.dev/doc/install))
* libwasmvm ([see here](https://github.com/CosmWasm/wasmvm) -- !Instructions don't cover installation, copy the files to your desired install location or add the subfolder `wasmvm/internal/api` to your library paths)

## Pre-commit hook
Expand Down
37 changes: 37 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Upgrading Quasar to v3

This guide provides instructions for upgrading to specific versions of Quasar.

## [v3.x](https://github.com/quasar-finance/quasar/releases/tag/v3.0.0)

### `Binary Name Change`
- This version contains binary name change from `quasarnoded` to `quasard` which requires changes in Cosmovisor settings.

### `Feemarket Module Addition and Relayer Config Changes`

- It contains Feemarket module addition with min gas fee.
This needs changes on relayer `gas-prices` to be set equal to params set in feemarket module.

- Feemarket brings in variable gas depending on past few block usage which in turn will affect the `gas-adjustment` parameter as well.
It should ideally be set to 2 or above.

### Packages

New modules added :
- PFM v8
- Ibc-hooks v8
- Rate-limiting v8
- Feemarket v1

Updates :
- Wasmd v0.45 to v0.51
- Wasmvm from v1 to v2
- Cosmos-SDK from v47.12 to v50.9
- Ibc-go v7 to ibc-go v8
- Contains updates of Async ICQ, wasm light clients and capability module.

Upgrade removes old unused modules :
- `qVesting`
- `qOracle`
- `qTransfer`

62 changes: 51 additions & 11 deletions ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,61 @@
package ante

import (
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"

ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

corestoretypes "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

quasarerrors "github.com/quasar-finance/quasar/types/errors"
)

// UseFeeMarketDecorator to make the integration testing easier: we can switch off its ante and post decorators with this flag
var UseFeeMarketDecorator = true

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
FeeMarketKeeper *feemarketkeeper.Keeper
TxFeeChecker ante.TxFeeChecker
TXCounterStoreService corestoretypes.KVStoreService
WasmConfig *wasmtypes.WasmConfig
}

func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.AccountKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errorsmod.Wrap(quasarerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if opts.BankKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errorsmod.Wrap(quasarerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if opts.SignModeHandler == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for AnteHandler")
return nil, errorsmod.Wrap(quasarerrors.ErrLogic, "sign mode handler is required for AnteHandler")
}
if opts.IBCkeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for AnteHandler")
return nil, errorsmod.Wrap(quasarerrors.ErrLogic, "IBC keeper is required for AnteHandler")
}
if opts.FeeMarketKeeper == nil {
return nil, errorsmod.Wrap(quasarerrors.ErrLogic, "FeeMarket keeper is required for AnteHandler")
}

if opts.StakingKeeper == nil {
return nil, errorsmod.Wrap(quasarerrors.ErrNotFound, "staking param store is required for AnteHandler")
}

sigGasConsumer := opts.SigGasConsumer
Expand All @@ -38,13 +64,16 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(opts.TXCounterStoreService),
ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
NewGovVoteDecorator(opts.Codec, opts.StakingKeeper),
NewGovExpeditedProposalsDecorator(opts.Codec),
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
Expand All @@ -53,5 +82,16 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
}

if UseFeeMarketDecorator {
anteDecorators = append(anteDecorators,
feemarketante.NewFeeMarketCheckDecorator(
opts.FeeMarketKeeper,
ante.NewDeductFeeDecorator(
opts.AccountKeeper,
opts.BankKeeper,
opts.FeegrantKeeper,
opts.TxFeeChecker)))
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
}
79 changes: 79 additions & 0 deletions ante/gov_expedited_ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ante

import (
errorsmod "cosmossdk.io/errors"
quasarerrors "github.com/quasar-finance/quasar/types/errors"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

var expeditedPropDecoratorEnabled = true

// SetExpeditedProposalsEnabled toggles the expedited proposals decorator on/off.
// Should only be used in testing - this is to allow simtests to pass.
func SetExpeditedProposalsEnabled(val bool) {
expeditedPropDecoratorEnabled = val
}

var expeditedPropsWhitelist = map[string]struct{}{
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade": {},
"/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {},
}

// Check if the proposal is whitelisted for expedited voting.
type GovExpeditedProposalsDecorator struct {
cdc codec.BinaryCodec
}

func NewGovExpeditedProposalsDecorator(cdc codec.BinaryCodec) GovExpeditedProposalsDecorator {
return GovExpeditedProposalsDecorator{
cdc: cdc,
}
}

// AnteHandle checks if the proposal is whitelisted for expedited voting.
// Only proposals submitted using "quasard tx gov submit-proposal" can be expedited.
// Legacy proposals submitted using "quasard tx gov submit-legacy-proposal" cannot be marked as expedited.
func (g GovExpeditedProposalsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if expeditedPropDecoratorEnabled {
for _, msg := range tx.GetMsgs() {
prop, ok := msg.(*govv1.MsgSubmitProposal)
if !ok {
continue
}
if prop.Expedited {
if err := g.validateExpeditedGovProp(prop); err != nil {
return ctx, err
}
}
}
}
return next(ctx, tx, simulate)
}

func (g GovExpeditedProposalsDecorator) isWhitelisted(msgType string) bool {
_, ok := expeditedPropsWhitelist[msgType]
return ok
}

func (g GovExpeditedProposalsDecorator) validateExpeditedGovProp(prop *govv1.MsgSubmitProposal) error {
msgs := prop.GetMessages()
if len(msgs) == 0 {
return quasarerrors.ErrInvalidExpeditedProposal
}
for _, message := range msgs {
// in case of legacy content submitted using govv1.MsgSubmitProposal
if sdkMsg, isLegacy := message.GetCachedValue().(*govv1.MsgExecLegacyContent); isLegacy {
if !g.isWhitelisted(sdkMsg.Content.TypeUrl) {
return errorsmod.Wrapf(quasarerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", sdkMsg.Content.TypeUrl)
}
continue
}
if !g.isWhitelisted(message.TypeUrl) {
return errorsmod.Wrapf(quasarerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", message.TypeUrl)
}
}
return nil
}
Loading

0 comments on commit e568865

Please sign in to comment.