Skip to content

Commit

Permalink
Upgrade to wasmd 1.0 (#20)
Browse files Browse the repository at this point in the history
* Upgrade to wasmd 1.0

* Review feedback
  • Loading branch information
jinmannwong committed Aug 27, 2020
1 parent 7a2926f commit 45f0af7
Show file tree
Hide file tree
Showing 281 changed files with 5,489 additions and 30,424 deletions.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ WORKDIR /cosmwasm
COPY . .
RUN make install

# we also (temporarily?) build the testnet binaries here
RUN LEDGER_ENABLED=false make build-coral
RUN LEDGER_ENABLED=false make build-gaiaflex

# ##################################

FROM debian:buster as hub
Expand All @@ -27,6 +31,12 @@ COPY --from=builder /go/bin/fetchd /usr/bin/fetchd
COPY --from=builder /usr/local/lib/libmcl.so /usr/lib
COPY entrypoints/entrypoint.sh /usr/bin/entrypoint.sh

# testnet
COPY --from=builder /cosmwasm/build/coral /usr/bin/coral
COPY --from=builder /cosmwasm/build/corald /usr/bin/corald
COPY --from=builder /cosmwasm/build/gaiaflex /usr/bin/gaiaflex
COPY --from=builder /cosmwasm/build/gaiaflexd /usr/bin/gaiaflexd

VOLUME /root/.fetchd
VOLUME /root/secret-temp-config

Expand Down
124 changes: 51 additions & 73 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,38 @@ endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(ldflags)' -trimpath
coral_ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=coral \
-X github.com/cosmos/cosmos-sdk/version.ServerName=corald \
-X github.com/cosmos/cosmos-sdk/version.ClientName=coral \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/CosmWasm/wasmd/app.CLIDir=.coral \
-X github.com/CosmWasm/wasmd/app.NodeDir=.corald \
-X github.com/CosmWasm/wasmd/app.Bech32Prefix=coral \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"
# we could consider enabling governance override?
# -X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin \
coral_ldflags += $(LDFLAGS)
coral_ldflags := $(strip $(coral_ldflags))

flex_ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=gaiaflex \
-X github.com/cosmos/cosmos-sdk/version.ServerName=gaiaflexd \
-X github.com/cosmos/cosmos-sdk/version.ClientName=gaiaflex \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true \
-X github.com/CosmWasm/wasmd/app.CLIDir=.gaiaflex \
-X github.com/CosmWasm/wasmd/app.NodeDir=.gaiaflexd \
-X github.com/CosmWasm/wasmd/app.Bech32Prefix=cosmos \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

flex_ldflags += $(LDFLAGS)
flex_ldflags := $(strip $(flex_ldflags))

# The below include contains the tools target.
include contrib/devtools/Makefile
BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(ldflags)' -trimpath
CORAL_BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(coral_ldflags)' -trimpath
FLEX_BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(flex_ldflags)' -trimpath

all: install lint test

Expand All @@ -76,6 +104,24 @@ else
go build -mod=readonly $(BUILD_FLAGS) -o build/fetchcli ./cmd/fetchcli
endif

build-coral: go.sum
ifeq ($(OS),Windows_NT)
# wasmd nodes not supported on windows, maybe the cli?
go build -mod=readonly $(CORAL_BUILD_FLAGS) -o build/coral.exe ./cmd/fetchcli
else
go build -mod=readonly $(CORAL_BUILD_FLAGS) -o build/corald ./cmd/fetchd
go build -mod=readonly $(CORAL_BUILD_FLAGS) -o build/coral ./cmd/fetchcli
endif

build-gaiaflex: go.sum
ifeq ($(OS),Windows_NT)
# wasmd nodes not supported on windows, maybe the cli?
go build -mod=readonly $(FLEX_BUILD_FLAGS) -o build/gaiaflex.exe ./cmd/fetchcli
else
go build -mod=readonly $(FLEX_BUILD_FLAGS) -o build/gaiaflexd ./cmd/fetchd
go build -mod=readonly $(FLEX_BUILD_FLAGS) -o build/gaiaflex ./cmd/fetchcli
endif

build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build

Expand All @@ -90,26 +136,6 @@ install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/fetchd
go install -mod=readonly $(BUILD_FLAGS) ./cmd/fetchcli

########################################
### Documentation

build-docs:
@cd docs && \
while read p; do \
(git checkout $${p} && npm install && VUEPRESS_BASE="/$${p}/" npm run build) ; \
mkdir -p ~/output/$${p} ; \
cp -r .vuepress/dist/* ~/output/$${p}/ ; \
cp ~/output/$${p}/index.html ~/output ; \
done < versions ;

sync-docs:
cd ~/output && \
echo "role_arn = ${DEPLOYMENT_ROLE_ARN}" >> /root/.aws/config ; \
echo "CI job = ${CIRCLE_BUILD_URL}" >> version.html ; \
aws s3 sync . s3://${WEBSITE_BUCKET} --profile terraform --delete ; \
aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
.PHONY: sync-docs

########################################
### Tools & dependencies

Expand Down Expand Up @@ -151,63 +177,15 @@ test-cover:
test-build: build
@go test -mod=readonly -p 4 `go list ./cli_test/...` -tags=cli_test -v


lint: golangci-lint
golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/CosmWasm/wasmd

benchmark:
@go test -mod=readonly -bench=. ./...


########################################
### Local validator nodes using docker and docker-compose

build-docker-fetchdnode:
$(MAKE) -C networks/local

# Run a 4-node testnet locally
localnet-start: build-linux localnet-stop
@if ! [ -f build/node0/fetchd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/fetchd:Z tendermint/fetchdnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 ; fi
docker-compose up -d

# Stop testnet
localnet-stop:
docker-compose down

setup-contract-tests-data:
echo 'Prepare data for the contract tests'
rm -rf /tmp/contract_tests ; \
mkdir /tmp/contract_tests ; \
cp "${GOPATH}/pkg/mod/${SDK_PACK}/client/lcd/swagger-ui/swagger.yaml" /tmp/contract_tests/swagger.yaml ; \
./build/fetchd init --home /tmp/contract_tests/.fetchd --chain-id lcd contract-tests ; \
tar -xzf lcd_test/testdata/state.tar.gz -C /tmp/contract_tests/

start-gaia: setup-contract-tests-data
./build/fetchd --home /tmp/contract_tests/.fetchd start &
@sleep 2s

setup-transactions: start-gaia
@bash ./lcd_test/testdata/setup.sh

run-lcd-contract-tests:
@echo "Running Gaia LCD for contract tests"
./build/fetchcli rest-server --laddr tcp://0.0.0.0:8080 --home /tmp/contract_tests/.fetchcli --node http://localhost:26657 --chain-id lcd --trust-node true

contract-tests: setup-transactions
@echo "Running Gaia LCD for contract tests"
dredd && pkill fetchd

# include simulations
include sims.mk

.PHONY: all build-linux install install-debug \
go-mod-cache draw-deps clean build \
setup-transactions setup-contract-tests-data start-gaia run-lcd-contract-tests contract-tests \
go-mod-cache draw-deps clean build format \
test test-all test-build test-cover test-unit test-race
50 changes: 43 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

This repository is the fork from the original [fetchd](https://github.com/fetchai/fetchd). It contains Fetch.ai specific updates required for the test networks. For this reason it is versioned independantly. Please refer to the [releases](https://github.com/fetchai/cosmos-sdk/releases) section for the compatiblity with upstream versions.

This code was originally from the `cosmos/gaia` repository and the majority of the codebase is the same as `gaia`.
This repository hosts `Wasmd`, the first implementation of a cosmos zone with wasm smart contracts enabled.

**Note**: Requires [Go 1.13+](https://golang.org/dl/)
This code was forked from the `cosmos/gaia` repository as a basis and then we added `x/wasm` and cleaned up
many gaia-specific files. However, the `wasmd` binary should function just like `gaiad` except for the
addition of the `x/wasm` module.

**Compatibility**: Last merge from `cosmos/gaia` was `090c545347b03e59415a18107a0a279c703c8f40` (Jan 23, 2020)
**Note**: Requires [Go 1.13+](https://golang.org/dl/)

## Supported Systems

Expand All @@ -31,16 +33,21 @@ and everything with `v0.7.x` tags is compatible with each other.
We will have a series of minor version updates prior to `v1.0.0`,
where we offer strong backwards compatibility guarantees.

We are currently on `v0.9` and targeting `v0.10` for late July, at which point
we will have feature freeze for the `v1` tag and only perform needed bugfixes
(which may be API breaking).
We released `v0.10` on July 31, 2020, and have a `v1.0` feature freeze now.
We will be performing bug fixes, security patches, and performance improvements,
but the API should be stable and compatible with `v1.0`.

Thank you to all projects who have run this code in your testnets and
given feedback to improve stability.

## Encoding

We use standard cosmos-sdk encoding (amino) for all sdk Messages. However, the message body sent to all contracts, as well as the internal state is encoded using JSON. Cosmwasm allows arbitrary bytes with the contract itself responsible for decodng. For better UX, we often use `json.RawMessage` to contain these bytes, which enforces that it is valid json, but also give a much more readable interface. If you want to use another encoding in the contracts, that is a relatively minor change to fetchd but would currently require a fork. Please open in issue if this is important for your use case.
We use standard cosmos-sdk encoding (amino) for all sdk Messages. However, the message body sent to all contracts,
as well as the internal state is encoded using JSON. Cosmwasm allows arbitrary bytes with the contract itself
responsible for decodng. For better UX, we often use `json.RawMessage` to contain these bytes, which enforces that it is
valid json, but also give a much more readable interface. If you want to use another encoding in the contracts, that is
a relatively minor change to wasmd but would currently require a fork. Please open in issue if this is important for
your use case.

## Quick Start

Expand Down Expand Up @@ -122,4 +129,33 @@ docker run --rm -it \
fetchai/fetchd:latest ./logs.sh
```

## Runtime flags

We provide a number of variables in `app/app.go` that are intended to be set via `-ldflags -X ...`
compile-time flags. This enables us to avoid copying a new binary directory over for each small change
to the configuration.

Available flags:

* `-X github.com/CosmWasm/wasmd/app.CLIDir=.coral` - set the config directory for the cli (default `~/.fetchcli`)
* `-X github.com/CosmWasm/wasmd/app.NodeDir=.corald` - set the config/data directory for the node (default `~/.fetchd`)
* `-X github.com/CosmWasm/wasmd/app.Bech32Prefix=coral` - set the bech32 prefix for all accounts (default `cosmos`)
* `-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true` - enable all x/wasm governance proposals (default `false`)
* `-X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin` -
enable a subset of the x/wasm governance proposal types (overrides `ProposalsEnabled`)

Examples:

* [`fetchd`](./Makefile#L50-L55) is a generic, permissionless version using the `cosmos` bech32 prefix
* [`gaiaflex`](./Makefile#L78-L87) is a generic, *permissioned* version using the `cosmos` bech32 prefix
* [`coral`](./Makefile#L63-L71) is a permissionless version designed for a specific testnet, with a `coral` bech32 prefix

## Genesis Configuration

@alpe we should document all the genesis config for x/wasm even more.

Tip: if you want to lock this down to a permisisoned network, the following script can edit the genesis file
to only allow permissioned use of code upload or instantiating. (Make sure you set `app.ProposalsEnabled=true`
in this binary):

`sed -i 's/permission": "Everybody"/permission": "Nobody"/' .../config/genesis.json`
Loading

0 comments on commit 45f0af7

Please sign in to comment.