Skip to content

Commit

Permalink
Merge branch 'release/v3.0.x' into ducnt/ictestv3
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 authored Oct 10, 2023
2 parents 581dd5d + ec3f882 commit 4464b10
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ bin
.ash_history
go.work.sum
go.work
*/.DS_Store

79 changes: 60 additions & 19 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ import (
ibcmock "github.com/cosmos/ibc-go/v6/testing/mock"
bank "github.com/terra-money/alliance/custom/bank"
custombankkeeper "github.com/terra-money/alliance/custom/bank/keeper"

// use TFL's ibc-hooks from Osmosis' ibc-hooks
ibchooks "github.com/terra-money/core/v2/x/ibc-hooks"
ibchookskeeper "github.com/terra-money/core/v2/x/ibc-hooks/keeper"
ibchookstypes "github.com/terra-money/core/v2/x/ibc-hooks/types"

alliancemodule "github.com/terra-money/alliance/x/alliance"
alliancemoduleclient "github.com/terra-money/alliance/x/alliance/client"
alliancemodulekeeper "github.com/terra-money/alliance/x/alliance/keeper"
Expand Down Expand Up @@ -131,15 +137,16 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmappparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params"
appparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"

// Upgrade Handler
upgrades "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades"
v2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades/v2"
v2_2_5 "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades/v2_2_5"
upgrades "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades"
v2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades/v2"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades/v2_2_5"
v3 "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades/v3"
)

const (
Expand All @@ -158,7 +165,7 @@ var (
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{v2.Upgrade, v2_2_5.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v2_2_5.Upgrade, v3.Upgrade}
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down Expand Up @@ -227,6 +234,7 @@ var (
ica.AppModuleBasic{},
intertx.AppModuleBasic{},
ibcfee.AppModuleBasic{},
ibchooks.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -292,6 +300,12 @@ type MigalooApp struct {
WasmKeeper wasm.Keeper
RouterKeeper routerkeeper.Keeper

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
TransferStack *ibchooks.IBCMiddleware
Ics20WasmHooks *ibchooks.WasmHooks
HooksICS4Wrapper ibchooks.ICS4Middleware

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -319,7 +333,7 @@ func NewMigalooApp(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig wasmappparams.EncodingConfig,
encodingConfig appparams.EncodingConfig,
enabledProposals []wasm.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
Expand All @@ -339,7 +353,7 @@ func NewMigalooApp(
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, intertxtypes.StoreKey, ibcfeetypes.StoreKey, tokenfactorytypes.StoreKey,
alliancemoduletypes.StoreKey,
alliancemoduletypes.StoreKey, ibchookstypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -516,6 +530,19 @@ func NewMigalooApp(
app.IBCKeeper.ChannelKeeper,
)

// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
keys[ibchookstypes.StoreKey],
)
app.IBCHooksKeeper = &hooksKeeper
migalooPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(&hooksKeeper, nil, migalooPrefix) // The contract keeper needs to be set later
app.Ics20WasmHooks = &wasmHooks
app.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
app.IBCKeeper.ChannelKeeper,
app.Ics20WasmHooks,
)

// IBC Fee Module keeper
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, keys[ibcfeetypes.StoreKey],
Expand All @@ -537,6 +564,8 @@ func NewMigalooApp(
scopedTransferKeeper,
)

app.RouterKeeper.SetTransferKeeper(app.TransferKeeper)

// ICA Host keeper
app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
Expand Down Expand Up @@ -598,6 +627,9 @@ func NewMigalooApp(
wasmOpts...,
)

contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper)
app.Ics20WasmHooks.ContractKeeper = contractKeeper

// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
Expand All @@ -607,6 +639,16 @@ func NewMigalooApp(
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
transferStack = router.NewIBCMiddleware(
transferStack,
&app.RouterKeeper,
0,
routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
// Hooks Middleware
hooksTransferStack := ibchooks.NewIBCMiddleware(transferStack, &app.HooksICS4Wrapper)
app.TransferStack = &hooksTransferStack

// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
Expand Down Expand Up @@ -705,6 +747,7 @@ func NewMigalooApp(
intertx.NewAppModule(appCodec, app.InterTxKeeper),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
router.NewAppModule(&app.RouterKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), // always be last to make sure that it checks for all invariants and not only part of them
)

Expand Down Expand Up @@ -736,6 +779,7 @@ func NewMigalooApp(
icatypes.ModuleName,
ibcfeetypes.ModuleName,
intertxtypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
alliancemoduletypes.ModuleName,
Expand Down Expand Up @@ -765,6 +809,7 @@ func NewMigalooApp(
icatypes.ModuleName,
ibcfeetypes.ModuleName,
intertxtypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
alliancemoduletypes.ModuleName,
Expand Down Expand Up @@ -803,6 +848,7 @@ func NewMigalooApp(
intertxtypes.ModuleName,
tokenfactorytypes.ModuleName,
// wasm after ibc transfer
ibchookstypes.ModuleName,
wasm.ModuleName,
routertypes.ModuleName,
alliancemoduletypes.ModuleName,
Expand Down Expand Up @@ -1052,22 +1098,17 @@ func (app *MigalooApp) setupUpgradeHandlers(cfg module.Configurator) {
return
}

currentHeight := app.CommitMultiStore().LastCommitID().Version

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

Check failure on line 1103 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

G601: Implicit memory aliasing in for loop. (gosec)
}
if upgradeInfo.Height == currentHeight+1 {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
cfg,
),
)
}
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
cfg,
),
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"github.com/cosmos/cosmos-sdk/std"

"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"
)

// MakeEncodingConfig creates a new EncodingConfig with all modules registered
Expand Down
2 changes: 1 addition & 1 deletion app/test_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"

"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"

"github.com/cosmos/cosmos-sdk/codec"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v2/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v2

import (
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
)
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v2_2_5/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v2_2_5 //nolint:revive // skip linter for this package name

import (
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
)

Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v3

import (
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
ibchookstypes "github.com/terra-money/core/v2/x/ibc-hooks/types"
)

// UpgradeName defines the on-chain upgrade name for the Migaloo v3 upgrade.
const UpgradeName = "v3.0.0"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{ibchookstypes.StoreKey},
},
}
19 changes: 19 additions & 0 deletions app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// We set the app version to pre-upgrade because it will be incremented by one
// after the upgrade is applied by the handler.

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}
4 changes: 2 additions & 2 deletions cmd/migalood/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/stretchr/testify/require"

"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/cmd/migalood/cmd"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/cmd/migalood/cmd"
"github.com/cosmos/cosmos-sdk/client/flags"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/cosmos/cosmos-sdk/simapp"
Expand Down
4 changes: 2 additions & 2 deletions cmd/migalood/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down
4 changes: 2 additions & 2 deletions cmd/migalood/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"os"

"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v2/cmd/migalood/cmd"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/cmd/migalood/cmd"
"github.com/cosmos/cosmos-sdk/server"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
)
Expand Down
Loading

0 comments on commit 4464b10

Please sign in to comment.