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

Add CosmWasm smart contract support with the wasmd module #531

Merged
merged 45 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a666f3f
initial integration
jhernandezb Jan 7, 2022
2aab937
run integration test
jhernandezb Jan 7, 2022
2afe329
fix test and branch
jhernandezb Jan 7, 2022
cc335fb
make linter happy
jhernandezb Jan 7, 2022
b7b87c5
fix branch name
jhernandezb Jan 7, 2022
24b402d
update libwasmvm_muslc
jhernandezb Jan 7, 2022
6736f8b
add wasm to upgrade handler
jhernandezb Jan 7, 2022
bb60b01
update drone
jhernandezb Jan 30, 2022
f1a409b
fix drone.yml
jhernandezb Jan 30, 2022
b992d5d
fix missing begin,end blockers
jhernandezb Jan 30, 2022
0922c04
fix download
jhernandezb Jan 30, 2022
a65856d
udpate Dockerfile
jhernandezb Feb 2, 2022
5b797f7
v3 upgrade
jhernandezb Feb 2, 2022
ba692e2
add v3 upgrade handler and fix upgrade script
jhernandezb Feb 2, 2022
6960a95
add testnet faucet
jhernandezb Feb 2, 2022
89d1eea
use latest fix
jhernandezb Feb 7, 2022
b39a1bd
gov prop not a const
jhernandezb Feb 8, 2022
90620da
Upload script (#541)
JakeHartnell Feb 10, 2022
6f5afb0
bump proto go package, add custom handler, add claim for message
jhernandezb Feb 16, 2022
62bccf3
Merge branch 'jhernandez/add-wasmd' of github.com:public-awesome/star…
jhernandezb Feb 16, 2022
0027ed8
handle claim for message
jhernandezb Feb 16, 2022
f6c4860
clean up custom registry
jhernandezb Feb 16, 2022
cfeeaf0
cleanup
jhernandezb Feb 16, 2022
5f4ed63
claim
jhernandezb Feb 17, 2022
3ca09ca
register msg server
jhernandezb Feb 17, 2022
eac8386
update wasmvm
jhernandezb Feb 17, 2022
1ca9389
genwasm
jhernandezb Feb 17, 2022
91e46a3
update testnet params
jhernandezb Feb 18, 2022
e6120da
add default seed
jhernandezb Feb 18, 2022
bde6597
update genesis creation params
jhernandezb Feb 18, 2022
ba8e715
fix genesis prepare
jhernandezb Feb 18, 2022
7291cf0
Updated default contract tag
shanev Feb 18, 2022
9a949cd
Updated script permissions
shanev Feb 18, 2022
8e3e380
Updated default contract tag (#542)
shanev Feb 18, 2022
9bf34b8
Updated minter and added royalty group contract
shanev Feb 18, 2022
5cea086
Merge pull request #543 from public-awesome/shanev/update-wasm-2
shanev Feb 18, 2022
24cc5a3
Fix contract name
shanev Feb 18, 2022
bc7f5be
Merge pull request #544 from public-awesome/shanev/fix-contract
shanev Feb 18, 2022
b68a887
address review comments
jhernandezb Feb 20, 2022
37986d9
Merge branch 'jhernandez/add-wasmd' of github.com:public-awesome/star…
jhernandezb Feb 20, 2022
2def337
update ci
jhernandezb Feb 20, 2022
c7a6c90
add ante tests
jhernandezb Feb 21, 2022
ec962c9
claim for tests
jhernandezb Feb 21, 2022
d68aa1b
add telemetry option
jhernandezb Feb 22, 2022
3ff6802
update ci
jhernandezb Feb 22, 2022
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
27 changes: 14 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 @@ -254,6 +254,7 @@ steps:
trigger:
branch:
- main
- jhernandez/add-wasmd
event:
- pull_request
- push
Expand Down Expand Up @@ -289,7 +290,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 +315,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 +349,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 +398,6 @@ depends_on:
- ibc-integration-test
---
kind: signature
hmac: 2afdd67fa7a871d8ff1b9412f304cc7908b029f47f92f184c197e0c4bd0b7efe
hmac: a361652545fd1121c71d82e8294ae4612c0aef6e8ef3d61dc1f4a9988ea781fb

...
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),
jhernandezb marked this conversation as resolved.
Show resolved Hide resolved
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
Expand Down
Loading