Skip to content

Commit

Permalink
refactor: improve bypass messages set in upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Nov 1, 2024
1 parent bb7b2a3 commit ed4834e
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package upgrade

import (
"context"
"sort"
"strings"

"cosmossdk.io/errors"
"cosmossdk.io/log"
Expand Down Expand Up @@ -30,6 +32,8 @@ import (
v6 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/migrations/v6"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations"
authoritykeeper "github.com/noble-assets/authority/keeper"
Expand Down Expand Up @@ -131,33 +135,42 @@ func CreateUpgradeHandler(
var authority string
subspace = paramsKeeper.Subspace(paramstypes.ModuleName).WithKeyTable(authoritytypes.ParamKeyTable()) //nolint:staticcheck
subspace.Get(sdkCtx, authoritytypes.AuthorityKey, &authority)

err = authorityKeeper.Owner.Set(ctx, authority)
if err != nil {
return vm, errors.Wrap(err, "failed to migrate authority address")
}

// Remove unsupported messages from GlobalFee bypass list.
oldBypassMessages, err := globalFeeKeeper.GetBypassMessages(ctx)
if err != nil {
return vm, err
// Override migrated list of bypass messages, ensuring that IBC relaying
// remains free, and enable all current asset issuers (Circle, Ondo,
// Hashnote, and Monerium) to interact with the protocol for free.
bypassMessages := []string{
sdk.MsgTypeURL(&clienttypes.MsgUpdateClient{}),
sdk.MsgTypeURL(&channeltypes.MsgRecvPacket{}),
sdk.MsgTypeURL(&channeltypes.MsgTimeout{}),
sdk.MsgTypeURL(&channeltypes.MsgAcknowledgement{}),
}
bypassMessages = append(bypassMessages, GetModuleMessages(registry, "circle")...)
bypassMessages = append(bypassMessages, GetModuleMessages(registry, "aura")...)
bypassMessages = append(bypassMessages, GetModuleMessages(registry, "halo")...)
bypassMessages = append(bypassMessages, GetModuleMessages(registry, "florin")...)
sort.Strings(bypassMessages)

err = globalFeeKeeper.BypassMessages.Clear(ctx, nil)
if err != nil {
return vm, err
}
for _, bypassMessage := range oldBypassMessages {
resolved, err := registry.Resolve(bypassMessage)
if err != nil || resolved == nil {
continue
}

for _, bypassMessage := range bypassMessages {
err = globalFeeKeeper.BypassMessages.Set(ctx, bypassMessage)
if err != nil {
return vm, err
}
}

// Migrate validator accounts to permanently locked vesting.
MigrateValidatorAccounts(ctx, accountKeeper, stakingKeeper)

// Safely burn surplus staking token supply.
err = BurnSurplusSupply(ctx, authority, accountKeeper, bankKeeper)
if err != nil {
return vm, err
Expand Down Expand Up @@ -227,3 +240,15 @@ func BurnSurplusSupply(ctx context.Context, authority string, accountKeeper auth
err = bankKeeper.BurnCoins(ctx, upgradetypes.ModuleName, sdk.NewCoins(surplus))
return err
}

// GetModuleMessages is a utility that returns all messages registered by a module.
func GetModuleMessages(registry codectypes.InterfaceRegistry, name string) (messages []string) {
for _, message := range registry.ListImplementations(sdk.MsgInterfaceProtoName) {
if strings.HasPrefix(message, "/"+name) {
messages = append(messages, message)
}
}

sort.Strings(messages)
return
}

0 comments on commit ed4834e

Please sign in to comment.