Skip to content

Commit

Permalink
feat: upgrade to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Feb 13, 2025
1 parent 47e46e7 commit e17cefa
Show file tree
Hide file tree
Showing 102 changed files with 5,497 additions and 429 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
with:
chain: mantrachain
chains-spec-file: chains.yaml
clone-key: ${{ secrets.GIT_CLONE_KEY }}
heighliner-owner: strangelove-ventures
heighliner-tag: v1.7.1
github-organization: ${{ github.repository_owner }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ on:
branches: main
pull_request:
branches: main


name: Run govulncheck
jobs:
govulncheck_job:
runs-on: ubuntu-latest
name: Run govulncheck
steps:
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-package: ./...
check-latest: true
go-package: ./...
check-latest: true
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
tags:
- "v*.*.*"
pull_request:
branches: [ "main" ]
branches: ["main"]
workflow_dispatch:
inputs:
release_tag:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '^1.23.0' # The Go version to download (if necessary) and use.
go-version: "^1.23.1" # The Go version to download (if necessary) and use.
- name: Checkout Git repo
uses: actions/checkout@v4
with:
Expand All @@ -55,7 +55,7 @@ jobs:
GORELEASER_CROSS_DISABLE: ${{ !matrix.platform.cross }}
GORELEASER_PLATFORM: ${{ matrix.platform.docker-platform || 'linux/amd64' }}
GORELEASER_SNAPSHOT: ${{ github.event_name == 'pull_request' && 'true' || 'false' }}

- name: Store artifact
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion api/osmosis/tokenfactory/v1beta1/genesis.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/osmosis/tokenfactory/v1beta1/query.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/osmosis/tokenfactory/v1beta1/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
type HandlerOptions struct {
BaseOptions ante.HandlerOptions
IBCKeeper *keeper.Keeper
WasmConfig *wasmTypes.WasmConfig
WasmConfig *wasmTypes.NodeConfig
WasmKeeper *wasmkeeper.Keeper
TXCounterStoreService corestoretypes.KVStoreService
CircuitKeeper *circuitkeeper.Keeper
Expand Down
77 changes: 61 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
_ "github.com/MANTRA-Chain/mantrachain/app/params"
queries "github.com/MANTRA-Chain/mantrachain/app/queries"
_ "github.com/MANTRA-Chain/mantrachain/client/docs/statik"
taxkeeper "github.com/MANTRA-Chain/mantrachain/x/tax/keeper"
tax "github.com/MANTRA-Chain/mantrachain/x/tax/module"
taxtypes "github.com/MANTRA-Chain/mantrachain/x/tax/types"
"github.com/MANTRA-Chain/mantrachain/x/tokenfactory"
tokenfactorykeeper "github.com/MANTRA-Chain/mantrachain/x/tokenfactory/keeper"
tokenfactorytypes "github.com/MANTRA-Chain/mantrachain/x/tokenfactory/types"
xfeemarkettypes "github.com/MANTRA-Chain/mantrachain/x/xfeemarket/types"
_ "github.com/MANTRA-Chain/mantrachain/v2/app/params"
queries "github.com/MANTRA-Chain/mantrachain/v2/app/queries"
"github.com/MANTRA-Chain/mantrachain/v2/app/upgrades"
v2 "github.com/MANTRA-Chain/mantrachain/v2/app/upgrades/v2"
_ "github.com/MANTRA-Chain/mantrachain/v2/client/docs/statik"
taxkeeper "github.com/MANTRA-Chain/mantrachain/v2/x/tax/keeper"
tax "github.com/MANTRA-Chain/mantrachain/v2/x/tax/module"
taxtypes "github.com/MANTRA-Chain/mantrachain/v2/x/tax/types"
"github.com/MANTRA-Chain/mantrachain/v2/x/tokenfactory"
tokenfactorykeeper "github.com/MANTRA-Chain/mantrachain/v2/x/tokenfactory/keeper"
tokenfactorytypes "github.com/MANTRA-Chain/mantrachain/v2/x/tokenfactory/types"
xfeemarkettypes "github.com/MANTRA-Chain/mantrachain/v2/x/xfeemarket/types"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -186,12 +188,15 @@ var maccPerms = map[string][]string{
ratelimittypes.ModuleName: nil,
wasmtypes.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
taxtypes.ModuleName: nil,

feemarkettypes.ModuleName: {authtypes.Burner},
feemarkettypes.FeeCollectorName: {authtypes.Burner},
oracletypes.ModuleName: nil,
}

var Upgrades = []upgrades.Upgrade{v2.Upgrade}

var (
_ runtime.AppI = (*App)(nil)
_ servertypes.Application = (*App)(nil)
Expand Down Expand Up @@ -644,11 +649,13 @@ func New(
)

// Create IBC modules with ratelimit middleware
// channel.RecvPacket -> ratelimit.OnRecvPacket -> ibcfee.OnRecvPacket -> transfer.OnRecvPacket var transferStack porttypes.IBCModule
// channel.RecvPacket -> ratelimit.OnRecvPacket -> ibcfee.OnRecvPacket -> transfer.OnRecvPacket
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
transferStack = ratelimit.NewIBCMiddleware(app.RateLimitKeeper, transferStack)
// register escrow address for tokenfactory when channel opens
transferStack = tokenfactory.NewIBCModule(transferStack, app.TokenFactoryKeeper)

// Create fee enabled wasm ibc Stack
var wasmStack porttypes.IBCModule
Expand All @@ -661,7 +668,7 @@ func New(
AddRoute(wasmtypes.ModuleName, wasmStack)
app.IBCKeeper.SetRouter(ibcRouter)

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
wasmConfig, err := wasm.ReadNodeConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}
Expand Down Expand Up @@ -692,6 +699,7 @@ func New(
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
wasmtypes.VMConfig{},
AllCapabilities(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
Expand Down Expand Up @@ -895,9 +903,6 @@ func New(
panic(err)
}

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.ModuleManager` and `app.configurator` are set.

autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules))

reflectionSvc, err := runtimeservices.NewReflectionService()
Expand Down Expand Up @@ -966,6 +971,10 @@ func New(

app.initializeABCIExtensions(client, metrics)

// Register any on-chain upgrades.
app.setupUpgradeHandlers()
app.setupUpgradeStoreLoaders()

// At startup, after all modules have been registered, check that all proto
// annotations are correct.
protoFiles, err := proto.MergedRegistry()
Expand Down Expand Up @@ -996,7 +1005,7 @@ func New(
return app
}

func (app *App) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.WasmConfig, txCounterStoreKey *storetypes.KVStoreKey) {
func (app *App) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.NodeConfig, txCounterStoreKey *storetypes.KVStoreKey) {
anteHandler, err := NewAnteHandler(
HandlerOptions{
BaseOptions: authante.HandlerOptions{
Expand Down Expand Up @@ -1230,6 +1239,42 @@ func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config)
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
func (app *App) 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 {
storeUpgrades := upgrade.StoreUpgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
}

func (app *App) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.ModuleManager,
app.configurator,
&upgrades.UpgradeKeepers{
ChannelKeeper: &app.IBCKeeper.ChannelKeeper,
TransferKeeper: app.TransferKeeper,
TokenFactoryKeeper: &app.TokenFactoryKeeper,
},
),
)
}
}

// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"cosmossdk.io/log"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/MANTRA-Chain/mantrachain/app/params"
"github.com/MANTRA-Chain/mantrachain/v2/app/params"
dbm "github.com/cosmos/cosmos-db"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
)
Expand Down
2 changes: 1 addition & 1 deletion app/post_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
errorsmod "cosmossdk.io/errors"
xfeemarketpost "github.com/MANTRA-Chain/mantrachain/x/xfeemarket/post"
xfeemarketpost "github.com/MANTRA-Chain/mantrachain/v2/x/xfeemarket/post"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion app/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
tokenfactorytypes "github.com/MANTRA-Chain/mantrachain/x/tokenfactory/types"
tokenfactorytypes "github.com/MANTRA-Chain/mantrachain/v2/x/tokenfactory/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
48 changes: 48 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package upgrades

import (
store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
tokenfactorykeeper "github.com/MANTRA-Chain/mantrachain/v2/x/tokenfactory/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
transferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
// must have written, in order for the state migration to go smoothly.
// An upgrade must implement this struct, and then set it in the app.go.
// The app.go will then define the handler.
type Upgrade struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator, *UpgradeKeepers) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

// Fork defines a struct containing the requisite fields for a non-software upgrade proposal
// Hard Fork at a given height to implement.
// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`.
// Any other change in the code should be height-gated, if the goal is to have old and new binaries
// to be compatible prior to the upgrade height.
type Fork struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// height the upgrade occurs at
UpgradeHeight int64

// Function that runs some custom state transition code at the beginning of a fork.
BeginForkLogic func(ctx sdk.Context)
}

type UpgradeKeepers struct {
// keepers
ChannelKeeper *channelkeeper.Keeper
TransferKeeper transferkeeper.Keeper
TokenFactoryKeeper *tokenfactorykeeper.Keeper
}
15 changes: 15 additions & 0 deletions app/upgrades/v2/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v2

import (
"github.com/MANTRA-Chain/mantrachain/v2/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v2"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
}
38 changes: 38 additions & 0 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v2

import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/MANTRA-Chain/mantrachain/v2/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *upgrades.UpgradeKeepers,
) upgradetypes.UpgradeHandler {
return func(c context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx.Logger().Info("Starting module migrations...")

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

transferChannels := keepers.ChannelKeeper.GetAllChannelsWithPortPrefix(ctx, keepers.TransferKeeper.GetPort(ctx))
for _, channel := range transferChannels {
escrowAddress := transfertypes.GetEscrowAddress(channel.PortId, channel.ChannelId)
ctx.Logger().Info("Saving escrow address", "port_id", channel.PortId, "channel_id",
channel.ChannelId, "address", escrowAddress.String())
keepers.TokenFactoryKeeper.StoreEscrowAddress(ctx, escrowAddress)
}

ctx.Logger().Info("Upgrade v2 complete")
return vm, nil
}
}
1 change: 1 addition & 0 deletions app/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ func AllCapabilities() []string {
"cosmwasm_1_4",
"cosmwasm_2_0",
"cosmwasm_2_1",
"cosmwasm_2_2",
}
}
2 changes: 1 addition & 1 deletion cmd/mantrachaind/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/MANTRA-Chain/mantrachain/app"
"github.com/MANTRA-Chain/mantrachain/v2/app"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand Down
Loading

0 comments on commit e17cefa

Please sign in to comment.