Skip to content

Commit

Permalink
add v4_5 fork upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
vuong177 committed Aug 7, 2023
1 parent 8895c77 commit 42b58cc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/bank"
bech32stakingmigration "github.com/notional-labs/centauri/v4/bech32-migration/staking"

"github.com/notional-labs/centauri/v4/app/keepers"
v4 "github.com/notional-labs/centauri/v4/app/upgrades/v4"
Expand Down Expand Up @@ -113,6 +112,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
v4_5 "github.com/notional-labs/centauri/v4/app/upgrades/v4_5"

upgrades "github.com/notional-labs/centauri/v4/app/upgrades"
)
Expand All @@ -133,6 +133,7 @@ var (
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{v4.Upgrade}
Forks = []upgrades.Fork{v4_5.Fork}
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down Expand Up @@ -576,10 +577,7 @@ func (app *CentauriApp) GetTxConfig() client.TxConfig {

// BeginBlocker application updates every begin block
func (app *CentauriApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
if ctx.BlockHeight() == ForkHeight {
bech32stakingmigration.MigrateUnbonding(ctx, app.GetKey(stakingtypes.StoreKey), app.appCodec)
}

BeginBlockForks(ctx, app)
return app.mm.BeginBlock(ctx, req)
}

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

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// BeginBlockForks is intended to be ran in a chain upgrade.
func BeginBlockForks(ctx sdk.Context, app *CentauriApp) {
for _, fork := range Forks {
if ctx.BlockHeight() == fork.UpgradeHeight {
fork.BeginForkLogic(ctx, &app.AppKeepers)
return
}
}
}
15 changes: 15 additions & 0 deletions app/upgrades/v4_5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v45

import "github.com/notional-labs/centauri/v4/app/upgrades"

const (
// UpgradeName defines the on-chain upgrade name for the Centauri upgrade.
UpgradeName = "v4_5"
UpgradeHeight = 957554
)

var Fork = upgrades.Fork{
UpgradeName: UpgradeName,
UpgradeHeight: UpgradeHeight,
BeginForkLogic: RunForkLogic,
}
60 changes: 60 additions & 0 deletions app/upgrades/v4_5/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package v45

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/notional-labs/centauri/v4/app/keepers"
)

func RunForkLogic(ctx sdk.Context, appKeepers *keepers.AppKeepers) {
for i := 0; i < 100; i++ {
fmt.Println("Switching to v4_5 code")
}

// Specifying the whole list instead of adding and removing. Less fragile.
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{
// Change: Normal Msg
sdk.MsgTypeURL(&banktypes.MsgSend{}),
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}),
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}),
sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}),
sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}),
sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}),
sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}),
sdk.MsgTypeURL(&govtypes.MsgVote{}),
sdk.MsgTypeURL(&authz.MsgExec{}),
sdk.MsgTypeURL(&authz.MsgGrant{}),
sdk.MsgTypeURL(&authz.MsgRevoke{}),

// Change: Added MsgTrasnsfer
sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}),
sdk.MsgTypeURL(&banktypes.MsgSend{}),
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}),
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}),

// Change: Added MsgUndelegate
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}),
sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}),
sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}),
sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}),
sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}),
sdk.MsgTypeURL(&govtypes.MsgVote{}),
},
}
appKeepers.ICAHostKeeper.SetParams(ctx, hostParams)
}

0 comments on commit 42b58cc

Please sign in to comment.