Skip to content

Commit

Permalink
Add CosmWasm smart contract support with the wasmd module (#531)
Browse files Browse the repository at this point in the history
* initial integration

* run integration test

* fix test and branch

* make linter happy

* fix branch name

* update libwasmvm_muslc

* add wasm to upgrade handler

* update drone

* fix drone.yml

* fix missing begin,end blockers

* fix download

* udpate Dockerfile

* v3 upgrade

* add v3 upgrade handler and fix upgrade script

* add testnet faucet

* use latest fix

* gov prop not a const

* Upload script (#541)

* Script to upload contracts

* Clean out old scripts

* bump proto go package, add custom handler, add claim for message

* handle claim for message

* clean up custom registry

* cleanup

* claim

* register msg server

* update wasmvm

* genwasm

* update testnet params

* add default seed

* update genesis creation params

* fix genesis prepare

* Updated default contract tag

* Updated script permissions

* Updated default contract tag (#542)

* Updated default contract tag

* Updated script permissions

* Updated minter and added royalty group contract

* Fix contract name

* address review comments

* update ci

* add ante tests

* claim for tests

* add telemetry option

* update ci

Co-authored-by: Jake Hartnell <[email protected]>
Co-authored-by: Shane Vitarana <[email protected]>
  • Loading branch information
3 people authored Feb 22, 2022
1 parent 7240d6b commit 096897c
Show file tree
Hide file tree
Showing 70 changed files with 11,754 additions and 7,219 deletions.
26 changes: 13 additions & 13 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ steps:
- '/go/pkg/mod'

- name: test
image: publicawesome/golang:1.17.6-devtooling
image: publicawesome/golang:1.17.7-devtooling
volumes:
- name: cache
path: /go
Expand All @@ -40,14 +40,14 @@ steps:
environment:
GOPROXY: http://goproxy
- name: build
image: golang:1.17-alpine3.14
image: golang:1.17-alpine3.15
volumes:
- name: cache
path: /go
commands:
- apk add --no-cache ca-certificates build-base git
- wget https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-beta/libwasmvm_muslc.a -O /lib/libwasmvm_muslc.a
- sha256sum /lib/libwasmvm_muslc.a | grep 2ea10ad5e489b5ede1aa4061d4afa8b2ddd39718ba7b8689690b9c07a41d678e
- wget https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-beta6/libwasmvm_muslc.a -O /lib/libwasmvm_muslc.a
- echo "e9cb9517585ce3477905e2d4e37553d85f6eac29bdc3b9c25c37c8f5e554045c /lib/libwasmvm_muslc.a" | sha256sum -c
- LEDGER_ENABLED=false BUILD_TAGS=muslc make build
environment:
GOPROXY: http://goproxy
Expand All @@ -74,7 +74,7 @@ steps:
password:
from_secret: docker_password
tags:
- v2-alpha
- v3-alpha
when:
event:
- push
Expand All @@ -90,12 +90,12 @@ steps:
password:
from_secret: docker_password
tags:
- develop
- wasm
when:
event:
- push
branch:
- develop
- jhernandez/add-wasmd
- name: trigger
image: plugins/downstream
settings:
Expand Down Expand Up @@ -128,7 +128,7 @@ steps:
- tag

- name: release
image: golang:1.17.0
image: golang:1.17.7
environment:
GITHUB_TOKEN:
from_secret: github_token
Expand Down Expand Up @@ -209,7 +209,7 @@ steps:
environment:
GOPROXY: http://goproxy
- name: stargaze
image: publicawesome/golang:1.17.6-devtooling
image: publicawesome/golang:1.17.7-devtooling
volumes:
- name: cache
path: /go
Expand Down Expand Up @@ -289,7 +289,7 @@ steps:
mount:
- '/go/pkg/mod'
- name: build-wrapper
image: publicawesome/golang:1.17.6-devtooling
image: publicawesome/golang:1.17.7-devtooling
volumes:
- name: cache
path: /go
Expand All @@ -314,7 +314,7 @@ steps:
environment:
GOPROXY: http://goproxy
- name: stargaze
image: publicawesome/stargaze:1.1.3
image: publicawesome/stargaze:2.0.0
commands:
- ./scripts/ci/upgrade/setup-preinstalled-stargaze.sh
environment:
Expand Down Expand Up @@ -348,7 +348,7 @@ steps:
commands:
- ./scripts/ci/upgrade/proposal.sh
- name: stargaze-upgraded
image: publicawesome/stargaze:2.0.0
image: publicawesome/stargaze:wasm
commands:
- ./scripts/ci/upgrade/run-upgrade.sh
environment:
Expand Down Expand Up @@ -397,6 +397,6 @@ depends_on:
- ibc-integration-test
---
kind: signature
hmac: 2afdd67fa7a871d8ff1b9412f304cc7908b029f47f92f184c197e0c4bd0b7efe
hmac: 06d4eea0c6a7033aed5da61ddce082dade980ef159d33fec40a25db483f9e7ef

...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ coverage.txt
vue/node_modules
vue/dist
release/
mytestnet/
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.16-alpine3.14 AS go-builder
FROM golang:1.17-alpine3.15 AS go-builder

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
Expand All @@ -15,15 +15,15 @@ WORKDIR /code
COPY . /code/

# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v0.14.0/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep 220b85158d1ae72008f099a7ddafe27f6374518816dd5873fd8be272c5418026
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-beta5/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep d16a2cab22c75dbe8af32265b9346c6266070bdcf9ed5aa9b7b39a7e32e25fe0

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN FAUCET_ENABLED=true LEDGER_ENABLED=false BUILD_TAGS=muslc make build


# --------------------------------------------------------
FROM alpine:3.14
FROM alpine:3.15

COPY --from=go-builder /code/bin/starsd /usr/bin/starsd
RUN apk add -U --no-cache ca-certificates
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ endif

all: install

install: build
install:
go install -mod=readonly $(BUILD_FLAGS) ./cmd/starsd

build:
Expand Down Expand Up @@ -109,7 +109,7 @@ docker-test: build-linux


test:
go test -v -race github.com/public-awesome/stargaze/x/...
go test -v -race github.com/public-awesome/stargaze/v3/x/...

.PHONY: test build-linux docker-test lint build install

Expand Down
56 changes: 20 additions & 36 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
package app

import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
"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"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"
stargazeante "github.com/public-awesome/stargaze/v3/internal/ante"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCChannelkeeper channelkeeper.Keeper
}

type MinCommissionDecorator struct{}

func NewMinCommissionDecorator() MinCommissionDecorator {
return MinCommissionDecorator{}
}

func (MinCommissionDecorator) AnteHandle(
ctx sdk.Context, tx sdk.Tx,
simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
msgs := tx.GetMsgs()
for _, m := range msgs {
switch msg := m.(type) {
case *stakingtypes.MsgCreateValidator:
c := msg.Commission
if c.Rate.LT(sdk.NewDecWithPrec(5, 2)) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
}
case *stakingtypes.MsgEditValidator:
// if commission rate is nil, it means only other fields gets updated and skip
if msg.CommissionRate == nil {
continue
}
if msg.CommissionRate.LT(sdk.NewDecWithPrec(5, 2)) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
}
default:
continue
}
}
return next(ctx, tx, simulate)
IBCChannelkeeper channelkeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreKey sdk.StoreKey
Codec codec.BinaryCodec
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -65,14 +38,25 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

if options.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}

if options.TXCounterStoreKey == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

var sigGasConsumer = options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewMinCommissionDecorator(),
// limit simulation gas
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
stargazeante.NewMinCommissionDecorator(options.Codec),
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
Expand Down
Loading

0 comments on commit 096897c

Please sign in to comment.