Skip to content

Commit

Permalink
feat: reintegrate globalfee, upgraded and improved (#415)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Kanefsky <56059752+boojamya@users.noreply.github.com>
  • Loading branch information
johnletey and boojamya authored Nov 5, 2024
1 parent 411a17a commit ea3adaf
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
_ "github.com/monerium/module-noble/v2"
_ "github.com/noble-assets/authority"
_ "github.com/noble-assets/forwarding/v2/x/forwarding"
"github.com/noble-assets/globalfee"
_ "github.com/noble-assets/halo/v2"
_ "github.com/ondoprotocol/usdy-noble/v2"

Expand Down Expand Up @@ -90,6 +91,7 @@ import (
// Noble Modules
authoritykeeper "github.com/noble-assets/authority/keeper"
forwardingkeeper "github.com/noble-assets/forwarding/v2/x/forwarding/keeper"
globalfeekeeper "github.com/noble-assets/globalfee/keeper"
)

var DefaultNodeHome string
Expand Down Expand Up @@ -140,6 +142,7 @@ type App struct {
// Noble Modules
AuthorityKeeper *authoritykeeper.Keeper
ForwardingKeeper *forwardingkeeper.Keeper
GlobalFeeKeeper *globalfeekeeper.Keeper
}

func init() {
Expand Down Expand Up @@ -215,6 +218,7 @@ func NewApp(
// Noble Modules
&app.AuthorityKeeper,
&app.ForwardingKeeper,
&app.GlobalFeeKeeper,
); err != nil {
return nil, err
}
Expand All @@ -231,6 +235,7 @@ func NewApp(
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
TxFeeChecker: globalfee.TxFeeChecker(app.GlobalFeeKeeper),
},
cdc: app.appCodec,
FTFKeeper: app.FTFKeeper,
Expand Down Expand Up @@ -288,6 +293,7 @@ func (app *App) RegisterUpgradeHandler() error {
app.ModuleManager,
app.Configurator(),
app.appCodec,
app.interfaceRegistry,
app.Logger(),
app.GetKey(capabilitytypes.StoreKey),
app.AccountKeeper,
Expand All @@ -296,6 +302,7 @@ func (app *App) RegisterUpgradeHandler() error {
app.CapabilityKeeper,
app.IBCKeeper.ClientKeeper,
app.ConsensusKeeper,
app.GlobalFeeKeeper,
app.ParamsKeeper,
app.StakingKeeper,
),
Expand Down
6 changes: 5 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ modules:
pre_blockers: [ upgrade ]
begin_blockers: [ capability, authority, slashing, evidence, staking, ibc, authz ]
end_blockers: [ crisis, staking, feegrant, forwarding ]
init_genesis: [ capability, transfer, auth, bank, staking, slashing, crisis, fiat-tokenfactory, genutil, ibc, interchainaccounts, packetfowardmiddleware, evidence, authz, feegrant, params, upgrade, vesting, cctp, forwarding, aura, halo, florin, authority ]
init_genesis: [ capability, transfer, auth, bank, staking, slashing, crisis, fiat-tokenfactory, globalfee, genutil, ibc, interchainaccounts, packetfowardmiddleware, evidence, authz, feegrant, params, upgrade, vesting, cctp, forwarding, aura, halo, florin, authority ]
override_store_keys:
- module_name: auth
kv_store_key: acc
Expand Down Expand Up @@ -118,3 +118,7 @@ modules:
config:
"@type": noble.forwarding.module.v1.Module
authority: authority # Utilize our custom x/authority module.
- name: globalfee
config:
"@type": noble.globalfee.module.v1.Module
authority: authority # Utilize our custom x/authority module.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/monerium/module-noble/v2 v2.0.0-rc.3.0.20241009233532-f2109c84b6c1
github.com/noble-assets/authority v1.0.0-rc.0
github.com/noble-assets/forwarding/v2 v2.0.0-20241017154500-56685530d602
github.com/noble-assets/globalfee v1.0.0-rc.0
github.com/noble-assets/halo/v2 v2.0.0-20240928083543-bd3392537219
github.com/ondoprotocol/usdy-noble/v2 v2.0.0-20241008190859-099f72833941
github.com/spf13/cobra v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ github.com/noble-assets/authority v1.0.0-rc.0 h1:mrMhEK3+F2lNRMGJalydAt0gTEK+WGt
github.com/noble-assets/authority v1.0.0-rc.0/go.mod h1:AyCyM1iP73dHxBsulw0GpZNgPIQvSndWp30pK87nmog=
github.com/noble-assets/forwarding/v2 v2.0.0-20241017154500-56685530d602 h1:yNN1TU1qSAWfWUZBBVK2qQgVoKG4z/Q4JuUXgzyQUcE=
github.com/noble-assets/forwarding/v2 v2.0.0-20241017154500-56685530d602/go.mod h1:OGbKgjHf/4HHthbilK9RCPsBXUS40LFxRl4cAcNhqwk=
github.com/noble-assets/globalfee v1.0.0-rc.0 h1:O1+XpEBe9eaSaZhgO5+G9NDyThL87xp1nANXcqoxzg8=
github.com/noble-assets/globalfee v1.0.0-rc.0/go.mod h1:DmNoTJ2LqGP4KpJuz+IEKp/5uf/3hRu3GSNBGhNUZkA=
github.com/noble-assets/halo/v2 v2.0.0-20240928083543-bd3392537219 h1:kFPNHaKQ6L6FY/qcXVe5guZnBmpbx1YVApyxywMSpAs=
github.com/noble-assets/halo/v2 v2.0.0-20240928083543-bd3392537219/go.mod h1:DY4GCfZ/7S3IEjoJBCCh7HRTxirPBOLMVwkT0N6n3bA=
github.com/nunnatsa/ginkgolinter v0.16.2 h1:8iLqHIZvN4fTLDC0Ke9tbSZVcyVHoBs0HIbnVSxfHJk=
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354/go.mod h1:KSVJ
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/nishanths/exhaustive v0.9.5/go.mod h1:IbwrGdVMizvDcIxPYGVdQn5BqWJaOwpCvg4RGb8r/TA=
github.com/nishanths/predeclared v0.0.0-20190419143655-18a43bb90ffc/go.mod h1:62PewwiQTlm/7Rj+cxVYqZvDIUc+JjZq6GHAC1fsObQ=
github.com/noble-assets/globalfee v1.0.0-rc.0/go.mod h1:DmNoTJ2LqGP4KpJuz+IEKp/5uf/3hRu3GSNBGhNUZkA=
github.com/noble-assets/halo v1.0.1 h1:Fndy4JaAAvEd5SDGECnkoWJ2uVG1XCF47L67Px9ickE=
github.com/nunnatsa/ginkgolinter v0.9.0/go.mod h1:FHaMLURXP7qImeH6bvxWJUpyH+2tuqe5j4rW1gxJRmI=
github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
Expand Down
2 changes: 2 additions & 0 deletions upgrade/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
authoritytypes "github.com/noble-assets/authority/types"
globalfeetypes "github.com/noble-assets/globalfee/types"
)

func CreateStoreLoader(upgradeHeight int64) baseapp.StoreLoader {
Expand All @@ -31,6 +32,7 @@ func CreateStoreLoader(upgradeHeight int64) baseapp.StoreLoader {
crisistypes.StoreKey,
// Noble Modules
authoritytypes.ModuleName,
globalfeetypes.ModuleName,
},
}

Expand Down
54 changes: 53 additions & 1 deletion upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package upgrade

import (
"context"
"sort"
"strings"

"cosmossdk.io/errors"
"cosmossdk.io/log"
Expand All @@ -24,6 +26,7 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand All @@ -43,16 +46,21 @@ 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"
authoritytypes "github.com/noble-assets/authority/types"
globalfeekeeper "github.com/noble-assets/globalfee/keeper"
globalfeetypes "github.com/noble-assets/globalfee/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
cdc codec.Codec,
registry codectypes.InterfaceRegistry,
logger log.Logger,
capabilityStoreKey *storetypes.KVStoreKey,
accountKeeper authkeeper.AccountKeeper,
Expand All @@ -61,6 +69,7 @@ func CreateUpgradeHandler(
capabilityKeeper *capabilitykeeper.Keeper,
clientKeeper clientkeeper.Keeper,
consensusKeeper consensuskeeper.Keeper,
globalFeeKeeper *globalfeekeeper.Keeper,
paramsKeeper paramskeeper.Keeper,
stakingKeeper *stakingkeeper.Keeper,
) upgradetypes.UpgradeHandler {
Expand All @@ -84,7 +93,8 @@ func CreateUpgradeHandler(
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck

case globalfeetypes.ModuleName:
keyTable = globalfeetypes.ParamKeyTable() //nolint:staticcheck
}

if !subspace.HasKeyTable() {
Expand Down Expand Up @@ -139,12 +149,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")
}

// 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 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 @@ -214,3 +254,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 ea3adaf

Please sign in to comment.