Skip to content

Commit

Permalink
Merge branch 'main' into nguyen/ic-for-ibc-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Aug 28, 2023
2 parents c0ff186 + 6f6352c commit fbc92b1
Show file tree
Hide file tree
Showing 71 changed files with 1,294 additions and 620 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/interchaintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
Expand All @@ -29,7 +27,7 @@ jobs:
file: Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
tags: |
ghcr.io/notional-labs/centauri-ictest:latest
test-start-cosmos-chain:
Expand Down
20 changes: 10 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ 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"
v5 "github.com/notional-labs/centauri/v4/app/upgrades/v5"

// bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -113,6 +113,8 @@ 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"
v4_5_1 "github.com/notional-labs/centauri/v4/app/upgrades/v4_5_1"

upgrades "github.com/notional-labs/centauri/v4/app/upgrades"
)
Expand All @@ -132,7 +134,8 @@ var (
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

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

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down Expand Up @@ -576,10 +579,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 Expand Up @@ -702,10 +702,10 @@ func (app *CentauriApp) setupUpgradeStoreLoaders() {
}
}

func (app *CentauriApp) customPreUpgradeHandler(upgradeInfo upgradetypes.Plan) {
switch upgradeInfo.Name {
default:
}
func (app *CentauriApp) customPreUpgradeHandler(_ upgradetypes.Plan) {
// switch upgradeInfo.Name {
// default:
// }
}

func (app *CentauriApp) setupUpgradeHandlers() {
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
}
}
}
4 changes: 2 additions & 2 deletions app/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (chain *TestChain) StoreContractCode(suite *suite.Suite, path string) {
wasmCode, err := os.ReadFile(path)
suite.Require().NoError(err)

src := wasmtypes.StoreCodeProposalFixture(func(p *wasmtypes.StoreCodeProposal) {
src := wasmtypes.StoreCodeProposalFixture(func(p *wasmtypes.StoreCodeProposal) { //nolint: staticcheck
p.RunAs = govModuleAddress.String()
p.WASMByteCode = wasmCode
checksum := sha256.Sum256(wasmCode)
Expand Down Expand Up @@ -685,7 +685,7 @@ func mustSubmitAndExecuteLegacyProposal(t *testing.T, ctx sdk.Context, content v
}

// does not fail on submit proposal
func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress string, govAuthority string, msgServer v1.MsgServer) (*v1.MsgExecLegacyContent, error) {
func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress, govAuthority string, msgServer v1.MsgServer) (*v1.MsgExecLegacyContent, error) {
t.Helper()
contentMsg, err := v1.NewLegacyContent(content, govAuthority)
require.NoError(t, err)
Expand Down
18 changes: 9 additions & 9 deletions app/ibctesting/event_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,40 @@ func ParsePacketFromEvents(events sdk.Events) (channeltypes.Packet, error) {
if ev.Type == channeltypes.EventTypeSendPacket {
packet := channeltypes.Packet{}
for _, attr := range ev.Attributes {
switch string(attr.Key) {
case channeltypes.AttributeKeyData:
switch attr.Key {
case channeltypes.AttributeKeyData: //nolint: staticcheck
packet.Data = []byte(attr.Value)

case channeltypes.AttributeKeySequence:
seq, err := strconv.ParseUint(string(attr.Value), 10, 64)
seq, err := strconv.ParseUint(attr.Value, 10, 64)
if err != nil {
return channeltypes.Packet{}, err
}

packet.Sequence = seq

case channeltypes.AttributeKeySrcPort:
packet.SourcePort = string(attr.Value)
packet.SourcePort = attr.Value

case channeltypes.AttributeKeySrcChannel:
packet.SourceChannel = string(attr.Value)
packet.SourceChannel = attr.Value

case channeltypes.AttributeKeyDstPort:
packet.DestinationPort = string(attr.Value)
packet.DestinationPort = attr.Value

case channeltypes.AttributeKeyDstChannel:
packet.DestinationChannel = string(attr.Value)
packet.DestinationChannel = attr.Value

case channeltypes.AttributeKeyTimeoutHeight:
height, err := clienttypes.ParseHeight(string(attr.Value))
height, err := clienttypes.ParseHeight(attr.Value)
if err != nil {
return channeltypes.Packet{}, err
}

packet.TimeoutHeight = height

case channeltypes.AttributeKeyTimeoutTimestamp:
timestamp, err := strconv.ParseUint(string(attr.Value), 10, 64)
timestamp, err := strconv.ParseUint(attr.Value, 10, 64)
if err != nil {
return channeltypes.Packet{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (appKeepers *AppKeepers) InitSpecialKeepers(
appCodec codec.Codec,
cdc *codec.LegacyAmino,
bApp *baseapp.BaseApp,
invCheckPeriod uint,
_ uint, // invCheckPeriod
skipUpgradeHeights map[int64]bool,
homePath string,
) {
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
_ upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand Down
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 = 967554
)

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"

Check failure on line 15 in app/upgrades/v4_5/fork.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/notional-labs/centauri/v4/app/keepers (-: # 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)
}
18 changes: 18 additions & 0 deletions app/upgrades/v4_5_1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v4_5_1

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

const (
// UpgradeName defines the on-chain upgrade name for the Composable v5 upgrade.
UpgradeName = "v4_5_1"

// UpgradeHeight defines the block height at which the Composable v6 upgrade is
// triggered.
UpgradeHeight = 1127000
)

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

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

"github.com/notional-labs/centauri/v4/app/keepers"
rateLimitKeeper "github.com/notional-labs/centauri/v4/x/ratelimit/keeper"
)

func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) {
ctx.Logger().Info("Applying v5 upgrade" +
"Remove Rate Limit",
)

RemoveRateLimit(ctx, &keepers.RatelimitKeeper)
}

func RemoveRateLimit(ctx sdk.Context, rlKeeper *rateLimitKeeper.Keeper) {
// Get all current rate limit
rateLimits := rlKeeper.GetAllRateLimits(ctx)
// Remove Rate limit
for _, rateLimit := range rateLimits {
err := rlKeeper.RemoveRateLimit(ctx, rateLimit.Path.Denom, rateLimit.Path.ChannelID)
if err != nil {
panic(err)
}
}
}
19 changes: 19 additions & 0 deletions app/upgrades/v5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v5

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/notional-labs/centauri/v4/app/upgrades"
)

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

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

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/notional-labs/centauri/v4/app/keepers"
"github.com/notional-labs/centauri/v4/app/upgrades"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}
Loading

0 comments on commit fbc92b1

Please sign in to comment.