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

fix: add x/wasm feature to simapp #430

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#545](https://github.com/line/lbm-sdk/pull/545) fix genesis and support abstain
* (x/auth) [\#563](https://github.com/line/lbm-sdk/pull/563) fix unmarshal bug of `BaseAccountJSON`
* (client) [\#565](https://github.com/line/lbm-sdk/pull/565) fix the data race problem in `TestQueryABCIHeight`
* (simapp) [\#430](https://github.com/line/lbm-sdk/pull/430) add x/wasm feature to simapp

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
44 changes: 37 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Simple usage with a mounted data directory:
# > docker build -t simapp .
# > docker build --platform="linux/amd64" -t simapp .
#
# Server:
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simapp:/root/.simapp simapp simd init test-chain
Expand All @@ -12,27 +12,57 @@
# TODO: demo connecting rest-server (or is this in server now?)
FROM golang:alpine AS build-env

ARG LBM_BUILD_OPTIONS=""

# Install minimum necessary dependencies,
ENV PACKAGES curl make git libc-dev bash gcc g++ linux-headers eudev-dev python3
RUN apk add --no-cache $PACKAGES
ENV PACKAGES curl make cmake git libc-dev bash gcc g++ linux-headers eudev-dev python3
RUN apk add --update --no-cache $PACKAGES

# Set working directory for the build
WORKDIR /go/src/github.com/line/lbm-sdk

# prepare dbbackend before building; this can be cached
COPY ./Makefile ./
COPY ./contrib ./contrib
RUN make dbbackend LBM_BUILD_OPTIONS="$LBM_BUILD_OPTIONS"

# Install GO dependencies
COPY ./go.mod /go/src/github.com/line/lbm-sdk/go.mod
COPY ./go.sum /go/src/github.com/line/lbm-sdk/go.sum
RUN go mod download

# Build cosmwasm
ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=$CARGO_HOME/bin:$PATH

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/rustup-init"
RUN chmod +x rustup-init
RUN ./rustup-init -y --no-modify-path --default-toolchain 1.57.0; rm rustup-init
RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME
RUN cd $(go list -f "{{ .Dir }}" -m github.com/line/wasmvm) && \
cd ./libwasmvm && \
RUSTFLAGS='-C target-feature=-crt-static' cargo build --release --example staticlib && \
mv -f target/release/examples/libstaticlib.a /usr/lib/libwasmvm_static.a && \
rm -rf target

#-------

# Add source files
COPY . .

# install simapp, remove packages
RUN make build-linux

#RUN make build-linux
RUN BUILD_TAGS=static make build CGO_ENABLED=1 LBM_BUILD_OPTIONS="$LBM_BUILD_OPTIONS"

# Final image
FROM alpine:edge

# Install ca-certificates
RUN apk add --update ca-certificates libstdc++
WORKDIR /root

# Set up OS dependencies
RUN apk add --update --no-cache ca-certificates libstdc++

# Copy over binaries from the build-env
COPY --from=build-env /go/src/github.com/line/lbm-sdk/build/simd /usr/bin/simd

Expand Down
57 changes: 54 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/line/lbm-sdk.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
CGO_ENABLED ?= 1

export GO111MODULE = on

Expand Down Expand Up @@ -50,6 +51,9 @@ else
CGO_ENABLED=1
BUILD_TAGS += gcc cleveldb
DB_BACKEND = cleveldb
CLEVELDB_DIR = leveldb
CGO_CFLAGS=-I$(shell pwd)/$(CLEVELDB_DIR)/include
CGO_LDFLAGS="-L$(shell pwd)/$(CLEVELDB_DIR)/build -L$(shell pwd)/snappy/build -lleveldb -lm -lstdc++ -lsnappy"
endif
ifeq (badgerdb,$(findstring badgerdb,$(LBM_BUILD_OPTIONS)))
BUILD_TAGS += badgerdb
Expand All @@ -59,6 +63,9 @@ else
CGO_ENABLED=1
BUILD_TAGS += gcc rocksdb
DB_BACKEND = rocksdb
ROCKSDB_DIR=$(shell pwd)/rocksdb
CGO_CFLAGS=-I$(ROCKSDB_DIR)/include
CGO_LDFLAGS="-L$(ROCKSDB_DIR) -lrocksdb -lm -lstdc++ $(shell awk '/PLATFORM_LDFLAGS/ {sub("PLATFORM_LDFLAGS=", ""); print}' < $(ROCKSDB_DIR)/make_config.mk)"
endif
ifeq (boltdb,$(findstring boltdb,$(LBM_BUILD_OPTIONS)))
BUILD_TAGS += boltdb
Expand Down Expand Up @@ -113,6 +120,12 @@ include contrib/devtools/Makefile
BUILD_TARGETS := build install

build: BUILD_ARGS=-o $(BUILDDIR)/
CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

#build: go.sum $(BUILDDIR)/ dbbackend
# CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

# todo: should be fix
build-linux:
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build

Expand All @@ -122,6 +135,42 @@ $(BUILD_TARGETS): go.sum $(BUILDDIR)/
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

.PHONY: dbbackend
# for more faster building use -j8; but it will be failed in docker building because of low memory
ifeq ($(DB_BACKEND), rocksdb)
dbbackend:
@if [ ! -e $(ROCKSDB_DIR) ]; then \
sh ./contrib/get_rocksdb.sh; \
fi
@if [ ! -e $(ROCKSDB_DIR)/librocksdb.a ]; then \
cd $(ROCKSDB_DIR) && make -j2 static_lib; \
fi
@if [ ! -e $(ROCKSDB_DIR)/libsnappy.a ]; then \
cd $(ROCKSDB_DIR) && make libsnappy.a DEBUG_LEVEL=0; \
fi
else ifeq ($(DB_BACKEND), cleveldb)
dbbackend:
@if [ ! -e $(CLEVELDB_DIR) ]; then \
sh contrib/get_cleveldb.sh; \
fi
@if [ ! -e $(CLEVELDB_DIR)/libcleveldb.a ]; then \
cd $(CLEVELDB_DIR); \
mkdir build; \
cd build; \
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLEVELDB_BUILD_TESTS=OFF -DLEVELDB_BUILD_BENCHMARKS=OFF ..; \
make; \
fi
@if [ ! -e snappy ]; then \
sh contrib/get_snappy.sh; \
cd snappy; \
mkdir build && cd build; \
cmake -DBUILD_SHARED_LIBS=OFF -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_REQUIRE_AVX2=ON ..;\
make; \
fi
else
dbbackend:
endif

build-simd-all: go.sum
$(DOCKER) rm latest-build || true
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
Expand Down Expand Up @@ -361,11 +410,13 @@ benchmark:
###############################################################################

lint: golangci-lint
golangci-lint run --out-format=tab
find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -d -s
@golangci-lint run --out-format=tab
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofmt -d -s

golangci-lint:
@go get github.com/golangci/golangci-lint/cmd/golangci-lint
ifneq (,$(shell which golangci-lint>/dev/null))
@go install github.com/golangci/golangci-lint/cmd/[email protected]
endif

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
Expand Down
2 changes: 1 addition & 1 deletion crypto/ledger/ledger_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/cosmos/go-bip39"
secp256k1 "github.com/tendermint/btcd/btcec"

"github.com/line/ostracon/crypto"

"github.com/line/lbm-sdk/crypto/hd"
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ require (
github.com/magiconair/properties v1.8.6
github.com/mailru/easyjson v0.7.7
github.com/mattn/go-isatty v0.0.14
github.com/onsi/gomega v1.18.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.35.0
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/rs/zerolog v1.27.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.4.0
Expand All @@ -63,6 +61,5 @@ require (
replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
13 changes: 3 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
Expand Down Expand Up @@ -829,18 +828,14 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.16.2 h1:HFB2fbVIlhIfCfOW81bZFbiC/RvnpXSdhbF2/DJr134=
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down Expand Up @@ -887,7 +882,6 @@ github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -962,9 +956,8 @@ github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRr
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
Expand Down
2 changes: 1 addition & 1 deletion init_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ redirect() {
fi
}

BINARY=simd
BINARY=./build/simd
BASE_DIR=~/.simapp
CHAIN_DIR_PREFIX="${BASE_DIR}/simapp"
GENTXS_DIR="${BASE_DIR}/gentxs"
Expand Down
6 changes: 3 additions & 3 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *o
logger := log.NewOCLogger(log.NewSyncWriter(os.Stdout))
db := memdb.NewDB()
encCfg := simapp.MakeTestEncodingConfig()
app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, simapp.EmptyAppOptions{})
app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, simapp.EmptyAppOptions{}, nil)

serverCtx := server.NewDefaultContext()
serverCtx.Config.RootDir = tempDir
Expand All @@ -155,13 +155,13 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *o

var simApp *simapp.SimApp
if height != -1 {
simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg, appOptons)
simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg, appOptons, nil)

if err := simApp.LoadHeight(height); err != nil {
return types.ExportedApp{}, err
}
} else {
simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg, appOptons)
simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg, appOptons, nil)
}

return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
Expand Down
Loading