Skip to content

Commit

Permalink
feat: v3 upgrade (#471)
Browse files Browse the repository at this point in the history
Co-authored-by: Dong Lieu <[email protected]>
Co-authored-by: Anh Minh <[email protected]>
Co-authored-by: expertdicer <[email protected]>
Co-authored-by: StrathCole <[email protected]>
  • Loading branch information
5 people authored May 24, 2024
1 parent 7f39730 commit 0381591
Show file tree
Hide file tree
Showing 318 changed files with 4,251 additions and 5,771 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \

# Cosmwasm - Download correct libwasmvm version and verify checksum
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 5) && \
WASMVM_DOWNLOADS="https://github.com/classic-terra/wasmvm/releases/download/${WASMVM_VERSION}"; \
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}"; \
wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt; \
if [ ${BUILDPLATFORM} = "linux/amd64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a"; \
Expand Down
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,8 @@ format:
### Protobuf ###
###############################################################################

CONTAINER_PROTO_VER=v0.7
CONTAINER_PROTO_IMAGE=tendermintdev/sdk-proto-gen:$(CONTAINER_PROTO_VER)
CONTAINER_PROTO_FMT=cosmos-sdk-proto-fmt-$(CONTAINER_PROTO_VER)
CONTAINER_PROTO_VER=0.13.1
CONTAINER_PROTO_IMAGE=ghcr.io/cosmos/proto-builder:$(CONTAINER_PROTO_VER)

proto-all: proto-format proto-lint proto-gen

Expand All @@ -312,8 +311,7 @@ proto-gen:

proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_PROTO_FMT}$$"; then docker start -a $(CONTAINER_PROTO_FMT); else docker run --name $(CONTAINER_PROTO_FMT) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./proto -name "*.proto" -exec clang-format -i {} \; ; fi
@$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(CONTAINER_PROTO_IMAGE) find ./proto -name "*.proto" -exec clang-format -i {} \;

proto-lint:
@$(DOCKER_BUF) lint --error-format=json
Expand Down
97 changes: 65 additions & 32 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"encoding/json"
"fmt"
"io"
stdlog "log"
Expand All @@ -12,22 +13,24 @@ import (
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

abci "github.com/tendermint/tendermint/abci/types"
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"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand All @@ -38,28 +41,31 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/classic-terra/core/v2/app/keepers"
terraappparams "github.com/classic-terra/core/v2/app/params"
"github.com/classic-terra/core/v3/app/keepers"
terraappparams "github.com/classic-terra/core/v3/app/params"

// upgrades
"github.com/classic-terra/core/v2/app/upgrades"
v2 "github.com/classic-terra/core/v2/app/upgrades/v2"
v3 "github.com/classic-terra/core/v2/app/upgrades/v3"
v4 "github.com/classic-terra/core/v2/app/upgrades/v4"
v5 "github.com/classic-terra/core/v2/app/upgrades/v5"
v6 "github.com/classic-terra/core/v2/app/upgrades/v6"
v6_1 "github.com/classic-terra/core/v2/app/upgrades/v6_1"
v7 "github.com/classic-terra/core/v2/app/upgrades/v7"
v7_1 "github.com/classic-terra/core/v2/app/upgrades/v7_1"

customante "github.com/classic-terra/core/v2/custom/auth/ante"
custompost "github.com/classic-terra/core/v2/custom/auth/post"
customauthtx "github.com/classic-terra/core/v2/custom/auth/tx"
"github.com/classic-terra/core/v3/app/upgrades"
v2 "github.com/classic-terra/core/v3/app/upgrades/v2"
v3 "github.com/classic-terra/core/v3/app/upgrades/v3"
v4 "github.com/classic-terra/core/v3/app/upgrades/v4"
v5 "github.com/classic-terra/core/v3/app/upgrades/v5"
v6 "github.com/classic-terra/core/v3/app/upgrades/v6"
v6_1 "github.com/classic-terra/core/v3/app/upgrades/v6_1"
v7 "github.com/classic-terra/core/v3/app/upgrades/v7"
v7_1 "github.com/classic-terra/core/v3/app/upgrades/v7_1"
v8 "github.com/classic-terra/core/v3/app/upgrades/v8"

customante "github.com/classic-terra/core/v3/custom/auth/ante"
custompost "github.com/classic-terra/core/v3/custom/auth/post"
customauthtx "github.com/classic-terra/core/v3/custom/auth/tx"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

// unnamed import of statik for swagger UI support
_ "github.com/classic-terra/core/v2/client/docs/statik"
_ "github.com/classic-terra/core/v3/client/docs/statik"
)

const appName = "TerraApp"
Expand All @@ -69,15 +75,15 @@ var (
DefaultNodeHome string

// Upgrades defines upgrades to be applied to the network
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade, v6.Upgrade, v6_1.Upgrade, v7.Upgrade, v7_1.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade, v6.Upgrade, v6_1.Upgrade, v7.Upgrade, v7_1.Upgrade, v8.Upgrade}

// Forks defines forks to be applied to the network
Forks = []upgrades.Fork{}
)

// Verify app interface at compile time
var (
_ simapp.App = (*TerraApp)(nil)
_ runtime.AppI = (*TerraApp)(nil)
_ servertypes.Application = (*TerraApp)(nil)
)

Expand All @@ -90,6 +96,7 @@ type TerraApp struct {

legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry

invCheckPeriod uint
Expand All @@ -116,14 +123,17 @@ func init() {
// NewTerraApp returns a reference to an initialized TerraApp.
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,
wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp),
homePath string, encodingConfig terraappparams.EncodingConfig, appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option, baseAppOptions ...func(*baseapp.BaseApp),
) *TerraApp {
appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))

bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand All @@ -133,6 +143,7 @@ func NewTerraApp(
legacyAmino: legacyAmino,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
txConfig: txConfig,
invCheckPeriod: invCheckPeriod,
}

Expand Down Expand Up @@ -172,8 +183,7 @@ func NewTerraApp(
// NOTE: Treasury must occur after bank module so that initial supply is properly set
app.mm.SetOrderInitGenesis(orderInitGenesis()...)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)
app.setupUpgradeHandlers()
Expand Down Expand Up @@ -211,10 +221,11 @@ func NewTerraApp(
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
IBCKeeper: *app.IBCKeeper,
WasmKeeper: &app.WasmKeeper,
DistributionKeeper: app.DistrKeeper,
GovKeeper: app.GovKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: app.GetKey(wasm.StoreKey),
TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey),
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
Cdc: app.appCodec,
Expand All @@ -237,6 +248,18 @@ func NewTerraApp(
app.SetPostHandler(postHandler)
app.SetEndBlocker(app.EndBlocker)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand All @@ -255,6 +278,11 @@ func NewTerraApp(
// Name returns the name of the App
func (app *TerraApp) Name() string { return app.BaseApp.Name() }

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (app *TerraApp) DefaultGenesis() map[string]json.RawMessage {
return ModuleBasics.DefaultGenesis(app.appCodec)
}

// BeginBlocker application updates every begin block
func (app *TerraApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
BeginBlockForks(ctx, app)
Expand Down Expand Up @@ -371,6 +399,10 @@ func (app *TerraApp) RegisterTendermintService(clientCtx client.Context) {
)
}

func (app *TerraApp) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down Expand Up @@ -403,7 +435,8 @@ func (app *TerraApp) setupUpgradeStoreLoaders() {

for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
storeUpgrades := upgrade.StoreUpgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/std"

"github.com/classic-terra/core/v2/app/params"
"github.com/classic-terra/core/v3/app/params"
)

var legacyCodecRegistered = false
Expand Down
8 changes: 4 additions & 4 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"encoding/json"
"log"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

oracletypes "github.com/classic-terra/core/v2/x/oracle/types"
oracletypes "github.com/classic-terra/core/v3/x/oracle/types"
)

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *TerraApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
forZeroHeight bool, jailAllowedAddrs, modulesToExport []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
Expand All @@ -31,7 +31,7 @@ func (app *TerraApp) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.mm.ExportGenesis(ctx, app.appCodec)
genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down
Loading

0 comments on commit 0381591

Please sign in to comment.