Skip to content

Commit

Permalink
Canonical wasm (#193)
Browse files Browse the repository at this point in the history
Co-authored-by: nghuyenthevinh2000 <[email protected]>
Co-authored-by: vincent <[email protected]>
Co-authored-by: chengwenxi <[email protected]>
Co-authored-by: alchemist-ti <[email protected]>
  • Loading branch information
5 people authored May 31, 2023
1 parent b8f9652 commit d616e24
Show file tree
Hide file tree
Showing 171 changed files with 2,829 additions and 26,401 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
**/**.go
go.mod
go.sum
# Enable BuildKit
- name: Set BuildKit environment variable
run: |
echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV
- name: start localnet
run: |
make clean localnet-start
Expand All @@ -67,6 +71,10 @@ jobs:
app/upgrades/**/*.go
- name: echo diff
run: echo '${{ env.GIT_DIFF }}'
# Enable BuildKit
- name: Set BuildKit environment variable
run: |
echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV
- name: start localnet
run: |
make clean localnet-start-upgrade
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# syntax=docker/dockerfile:1

ARG source=./
ARG GO_VERSION="1.18"
ARG ALPINE_VERSION="3.17"
ARG BUILDPLATFORM=linux/amd64
Expand All @@ -12,6 +13,7 @@ FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base

FROM base as builder-stage-1

ARG source
ARG GIT_COMMIT
ARG GIT_VERSION
ARG BUILDPLATFORM
Expand Down Expand Up @@ -44,7 +46,7 @@ RUN set -eux &&\

# download dependencies to cache as layer
WORKDIR ${GOPATH}/src/app
COPY go.mod go.sum ./
COPY ${source}go.mod ${source}go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download -x
Expand All @@ -71,14 +73,15 @@ RUN set -eux &&\

FROM builder-stage-1 as builder-stage-2

ARG source
ARG GOOS=linux \
GOARCH=amd64

ENV GOOS=$GOOS \
GOARCH=$GOARCH

# Copy the remaining files
COPY . .
COPY ${source} .

# Build app binary
RUN --mount=type=cache,target=/root/.cache/go-build \
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ benchmark:
###############################################################################

lint:
sudo golangci-lint run --out-format=tab
golangci-lint run --out-format=tab

lint-fix:
sudo golangci-lint run --fix --out-format=tab --issues-exit-code=0
golangci-lint run --fix --out-format=tab --issues-exit-code=0

lint-strict:
find . -path './_build' -prune -o -type f -name '*.go' -exec gofumpt -w -l {} +
Expand Down Expand Up @@ -342,4 +342,4 @@ build-operator-img-node:
@if ! docker image inspect public.ecr.aws/classic-terra/core:${NODE_VERSION} &>/dev/null ; then make build-operator-img-core ; fi
docker-compose -f contrib/terra-operator/docker-compose.build.yml build node --no-cache

.PHONY: build-operator-img-all build-operator-img-core build-operator-img-node
.PHONY: build-operator-img-all build-operator-img-core build-operator-img-node
48 changes: 41 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -40,6 +41,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/classic-terra/core/app/keepers"
terraappparams "github.com/classic-terra/core/app/params"
Expand All @@ -48,13 +50,14 @@ import (
"github.com/classic-terra/core/app/upgrades"
v2 "github.com/classic-terra/core/app/upgrades/v2"
v3 "github.com/classic-terra/core/app/upgrades/v3"
v4 "github.com/classic-terra/core/app/upgrades/v4"

customante "github.com/classic-terra/core/custom/auth/ante"
customauthrest "github.com/classic-terra/core/custom/auth/client/rest"
customauthtx "github.com/classic-terra/core/custom/auth/tx"
core "github.com/classic-terra/core/types"

wasmconfig "github.com/classic-terra/core/x/wasm/config"
"github.com/CosmWasm/wasmd/x/wasm"

// unnamed import of statik for swagger UI support
_ "github.com/classic-terra/core/client/docs/statik"
Expand All @@ -67,7 +70,7 @@ var (
DefaultNodeHome string

// Upgrades defines upgrades to be applied to the network
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade}
)

// Verify app interface at compile time
Expand Down Expand Up @@ -112,7 +115,7 @@ func init() {
func NewTerraApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig terraappparams.EncodingConfig, appOpts servertypes.AppOptions,
wasmConfig *wasmconfig.Config, baseAppOptions ...func(*baseapp.BaseApp),
wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp),
) *TerraApp {
appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
Expand Down Expand Up @@ -142,7 +145,7 @@ func NewTerraApp(
skipUpgradeHeights,
homePath,
invCheckPeriod,
wasmConfig,
wasmOpts,
appOpts,
)

Expand Down Expand Up @@ -173,6 +176,7 @@ func NewTerraApp(
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)
app.setupUpgradeHandlers()
app.setupUpgradeStoreLoaders()

// create the simulation manager and define the order of the modules for deterministic simulations
//
Expand All @@ -191,6 +195,11 @@ func NewTerraApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic("error while reading wasm config: " + err.Error())
}

anteHandler, err := customante.NewAnteHandler(
customante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
Expand All @@ -200,10 +209,12 @@ func NewTerraApp(
TreasuryKeeper: app.TreasuryKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
IBCChannelKeeper: app.IBCKeeper.ChannelKeeper,
IBCKeeper: *app.IBCKeeper,
DistributionKeeper: app.DistrKeeper,
FeeShareKeeper: app.FeeShareKeeper,
GovKeeper: app.GovKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: app.GetKey(wasm.StoreKey),
},
)
if err != nil {
Expand All @@ -217,6 +228,12 @@ func NewTerraApp(
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}

ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
// Initialize pinned codes in wasmvm as they are not persisted there
if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}
}

return app
Expand Down Expand Up @@ -408,6 +425,23 @@ func GetMaccPerms() map[string][]string {
return dupMaccPerms
}

func (app *TerraApp) setupUpgradeStoreLoaders() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
}
}

func (app *TerraApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
Expand Down
Loading

0 comments on commit d616e24

Please sign in to comment.