Skip to content

Commit

Permalink
Merge branch 'temporary'
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Jun 23, 2023
2 parents 9827bac + a0c54d1 commit bdbc84a
Show file tree
Hide file tree
Showing 30 changed files with 1,596 additions and 482 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ jobs:
key: integration-test-cache-{hash}
restore-keys: |
integration-test-cache-
- name: Test Pleiades upgrade
run: tests/run-upgrade-test.sh v1.8.2
- name: Test Antares upgrade
run: tests/run-upgrade-test.sh v1.9.3
env:
NO_IMAGE_BUILD: True
ibc_auto_forward_test:
Expand Down Expand Up @@ -402,3 +402,17 @@ jobs:
run: tests/all-up-test.sh SEND_TO_ETH_FEES
env:
NO_IMAGE_BUILD: True
ica_host_happy_path:
runs-on: ubuntu-latest
needs: happy-path-geth
steps:
- uses: actions/checkout@v2
- uses: jpribyl/[email protected]
with:
key: integration-test-cache-{hash}
restore-keys: |
integration-test-cache-
- name: Test the Interchain Accounts Host module functionality with Gravity
run: tests/all-up-test.sh ICA_HOST_HAPPY_PATH
env:
NO_IMAGE_BUILD: True
7 changes: 6 additions & 1 deletion module/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' -gcflags="all=-N -l"

all: install

install: go.sum
# First run `go mod verify` then `go install`
install: go.sum install-no-verify

# Runs go install without verifying dependencies, used to make testing faster
install-no-verify:
export GOFLAGS='-buildmode=pie'
export CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2"
export CGO_LDFLAGS="-Wl,-z,relro,-z,now -fstack-protector"
CGO_CFLAGS="-Wno-deprecated-declarations" go install $(BUILD_FLAGS) ./cmd/gravity

# Verifies the go modules
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
Expand Down
109 changes: 79 additions & 30 deletions module/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -30,6 +31,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -86,6 +88,11 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

// Cosmos IBC-Go
ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
icahost "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
Expand All @@ -112,6 +119,8 @@ import (
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/ante"
gravityparams "github.com/Gravity-Bridge/Gravity-Bridge/module/app/params"
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades"
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/antares"
v2 "github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/v2"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/exported"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/keeper"
Expand Down Expand Up @@ -155,6 +164,7 @@ var (
vesting.AppModuleBasic{},
gravity.AppModuleBasic{},
bech32ibc.AppModuleBasic{},
ica.AppModuleBasic{},
)

// module account permissions
Expand All @@ -168,6 +178,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -228,11 +239,13 @@ type Gravity struct {
ibcTransferKeeper *ibctransferkeeper.Keeper
gravityKeeper *keeper.Keeper
bech32IbcKeeper *bech32ibckeeper.Keeper
icaHostKeeper *icahostkeeper.Keeper

// make scoped keepers public for test purposes
// NOTE: If you add anything to this struct, add a nil check to ValidateMembers below!
ScopedIBCKeeper *capabilitykeeper.ScopedKeeper
ScopedTransferKeeper *capabilitykeeper.ScopedKeeper
ScopedIcaHostKeeper *capabilitykeeper.ScopedKeeper

// Module Manager
mm *module.Manager
Expand Down Expand Up @@ -302,6 +315,9 @@ func (app Gravity) ValidateMembers() {
if app.bech32IbcKeeper == nil {
panic("Nil bech32IbcKeeper!")
}
if app.icaHostKeeper == nil {
panic("Nil icaHostKeeper!")
}

// scoped keepers
if app.ScopedIBCKeeper == nil {
Expand Down Expand Up @@ -350,6 +366,7 @@ func NewGravityApp(
ibchost.StoreKey, upgradetypes.StoreKey, evidencetypes.StoreKey,
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
gravitytypes.StoreKey, bech32ibctypes.StoreKey,
icahosttypes.StoreKey,
)
tKeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -386,6 +403,9 @@ func NewGravityApp(
scopedTransferKeeper := capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
app.ScopedTransferKeeper = &scopedTransferKeeper

scopedIcaHostKeeper := capabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
app.ScopedIcaHostKeeper = &scopedIcaHostKeeper

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
capabilityKeeper.Seal()
Expand Down Expand Up @@ -476,6 +496,13 @@ func NewGravityApp(
)
app.bech32IbcKeeper = &bech32IbcKeeper

icaHostKeeper := icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
ibcKeeper.ChannelKeeper, &ibcKeeper.PortKeeper,
accountKeeper, scopedIcaHostKeeper, app.MsgServiceRouter(),
)
app.icaHostKeeper = &icaHostKeeper

gravityKeeper := keeper.NewKeeper(
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.DefaultParamspace),
Expand Down Expand Up @@ -542,12 +569,15 @@ func NewGravityApp(
ibcTransferAppModule := transfer.NewAppModule(ibcTransferKeeper)

// create IBC module from top to bottom of stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(ibcTransferKeeper)
transferStack = gravity.NewIBCMiddleware(transferStack, *app.gravityKeeper)
var ibcTransferIBCModule porttypes.IBCModule
ibcTransferIBCModule = transfer.NewIBCModule(ibcTransferKeeper)
ibcTransferIBCModule = gravity.NewIBCMiddleware(ibcTransferIBCModule, *app.gravityKeeper)
icaAppModule := ica.NewAppModule(nil, &icaHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(icaHostKeeper)

ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcTransferIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)
ibcKeeper.SetRouter(ibcRouter)

evidenceKeeper := *evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -642,6 +672,7 @@ func NewGravityApp(
appCodec,
bech32IbcKeeper,
),
icaAppModule,
)
app.mm = &mm

Expand All @@ -666,11 +697,13 @@ func NewGravityApp(
authz.ModuleName,
govtypes.ModuleName,
paramstypes.ModuleName,
icatypes.ModuleName,
)
mm.SetOrderEndBlockers(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
icatypes.ModuleName,
gravitytypes.ModuleName,
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
Expand Down Expand Up @@ -708,6 +741,7 @@ func NewGravityApp(
crisistypes.ModuleName,
vestingtypes.ModuleName,
paramstypes.ModuleName,
icatypes.ModuleName,
)

mm.RegisterInvariants(&crisisKeeper)
Expand Down Expand Up @@ -970,6 +1004,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(gravitytypes.DefaultParamspace)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)

return paramsKeeper
}
Expand All @@ -982,29 +1017,43 @@ func (app *Gravity) registerUpgradeHandlers() {
)
}

// // Sets up the StoreLoader for new, deleted, or renamed modules
// func (app *Gravity) registerStoreLoaders() {
// // Read the upgrade height and name from previous execution
// upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
// if err != nil {
// panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
// }

// // v1->v2 STORE LOADER SETUP
// // Register the new v2 modules and the special StoreLoader to add them
// if upgradeInfo.Name == v2.V1ToV2PlanName {
// if !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) { // Recognized the plan, need to skip this one though
// storeUpgrades := storetypes.StoreUpgrades{
// Added: []string{bech32ibctypes.ModuleName}, // We are adding these modules
// // Check upgrade docs to see which type of store loader is necessary for deletes/renames
// // Renamed: []storetypes.StoreRename{{"foo", "bar"}}, example foo to bar rename
// // Deleted: []string{"bazmodule"}, example deleted bazmodule
// Renamed: nil,
// Deleted: nil,
// }

// // configure store loader that checks if version == upgradeHeight and applies store upgrades
// app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
// }
// }
// }
// Sets up the StoreLoader for new, deleted, or renamed modules
func (app *Gravity) registerStoreLoaders() {
// Read the upgrade height and name from previous execution
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
}

// STORE LOADER CONFIGURATION:
// Added: []string{"newmodule"}, // We are adding these modules
// Renamed: []storetypes.StoreRename{{"foo", "bar"}}, example foo to bar rename
// Deleted: []string{"bazmodule"}, example deleted bazmodule

// v1->v2 STORE LOADER SETUP
// Register the new v2 modules and the special StoreLoader to add them
if upgradeInfo.Name == v2.V1ToV2PlanName {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{bech32ibctypes.ModuleName},
Renamed: nil,
Deleted: nil,
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
// ANTARES ICA Host module store loader setup
if upgradeInfo.Name == antares.OrionToAntaresPlanName {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{icahosttypes.StoreKey},
Renamed: nil,
Deleted: nil,
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
10 changes: 10 additions & 0 deletions module/app/upgrades/antares/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Antares UPGRADE
The *Antares* upgrade contains the following changes.

## Summary of Changes

* Updating Cosmos SDK version to v0.45.16, which is the end of the v0.45 line. A migration to v0.46 will happen in the next upgrade.
* Updating IBC version to v4.3.1, since IBC v3 is no longer supported.
* Adding Interchain Accounts Host module:
* By enabling ICA it will be possible to send tokens to and from chains without interacting with your Gravity Bridge account. Combining Interchain Accounts and IBC Auto Forwarding, users on an ICA Controller chain will be able to send tokens to Cosmos via Gravity or transfer tokens to Ethereum through Gravity while only submitting messages to Ethereum and the Controller chain. That means a sophisticated UI can present all transactions through Metamask for convenience!
* ICA will also enable Liquid Staking using platforms like Persistence, Quicksilver, Stride, and more!
3 changes: 3 additions & 0 deletions module/app/upgrades/antares/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package antares

var OrionToAntaresPlanName = "antares"
51 changes: 51 additions & 0 deletions module/app/upgrades/antares/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package antares

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"
)

func GetAntaresUpgradeHandler(
mm *module.Manager, configurator *module.Configurator, crisisKeeper *crisiskeeper.Keeper,
) func(
ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap,
) (module.VersionMap, error) {
if mm == nil {
panic("Nil argument to GetAntaresUpgradeHandler")
}
return func(ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Antares upgrade: Starting upgrade")

vmap[icatypes.ModuleName] = mm.Modules[icatypes.ModuleName].ConsensusVersion()
icaHostParams := icahosttypes.Params{
HostEnabled: false,
AllowMessages: []string{},
}
icaControllerParams := icacontrollertypes.Params{
ControllerEnabled: false,
}

icaModule, ok := mm.Modules[icatypes.ModuleName].(ica.AppModule)
if !ok {
panic("module manager's ica module is not an ica.AppModule")
}
icaModule.InitModule(ctx, icaControllerParams, icaHostParams)
ctx.Logger().Info("Antares Upgrade: Running any configured module migrations")
out, outErr := mm.RunMigrations(ctx, *configurator, vmap)
if outErr != nil {
return out, outErr
}
ctx.Logger().Info("Asserting invariants after upgrade")
crisisKeeper.AssertInvariants(ctx)

ctx.Logger().Info("Antares Upgrade Successful")
return out, nil
}
}
8 changes: 8 additions & 0 deletions module/app/upgrades/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"

"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/antares"
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/orion"
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/singlestep"
)
Expand Down Expand Up @@ -78,8 +79,15 @@ func RegisterUpgradeHandlers(
orion.GetOrionUpgradeHandler(mm, configurator, crisisKeeper),
)

// Orion upgrade handler
upgradeKeeper.SetUpgradeHandler(
orion.PleiadesPart2ToOrionPlanName,
orion.GetOrionUpgradeHandler(mm, configurator, crisisKeeper),
)

// Antares upgrade handler
upgradeKeeper.SetUpgradeHandler(
antares.OrionToAntaresPlanName,
antares.GetAntaresUpgradeHandler(mm, configurator, crisisKeeper),
)
}
Loading

0 comments on commit bdbc84a

Please sign in to comment.