Skip to content

Commit

Permalink
Merge branch 'update-sdk47' into feat/admin-module-sdk47
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Sep 6, 2023
2 parents 1016569 + 7d3052e commit 71dd6d4
Show file tree
Hide file tree
Showing 43 changed files with 1,936 additions and 572 deletions.
19 changes: 10 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func New(
)

app.CronKeeper = *cronkeeper.NewKeeper(appCodec, keys[crontypes.StoreKey], keys[crontypes.MemStoreKey], app.AccountKeeper)
wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.InterchainTxsKeeper, &app.InterchainQueriesKeeper, app.TransferKeeper, &app.AdminmoduleKeeper, app.FeeBurnerKeeper, app.FeeKeeper, &app.BankKeeper, app.TokenFactoryKeeper, &app.CronKeeper), wasmOpts...)
wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.InterchainTxsKeeper, &app.InterchainQueriesKeeper, app.TransferKeeper, &app.AdminmoduleKeeper, app.FeeBurnerKeeper, app.FeeKeeper, &app.BankKeeper, app.TokenFactoryKeeper, &app.CronKeeper, &app.ContractManagerKeeper), wasmOpts...)

queryPlugins := wasmkeeper.WithQueryPlugins(
&wasmkeeper.QueryPlugins{Stargate: wasmkeeper.AcceptListStargateQuerier(wasmbinding.AcceptedStargateQueries(), app.GRPCQueryRouter(), appCodec)})
Expand Down Expand Up @@ -995,14 +995,15 @@ func (app *App) setupUpgradeHandlers() {
app.mm,
app.configurator,
&upgrades.UpgradeKeepers{
FeeBurnerKeeper: app.FeeBurnerKeeper,
CronKeeper: app.CronKeeper,
IcqKeeper: app.InterchainQueriesKeeper,
TokenFactoryKeeper: app.TokenFactoryKeeper,
SlashingKeeper: app.SlashingKeeper,
ParamsKeeper: app.ParamsKeeper,
CapabilityKeeper: app.CapabilityKeeper,
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
FeeBurnerKeeper: app.FeeBurnerKeeper,
CronKeeper: app.CronKeeper,
IcqKeeper: app.InterchainQueriesKeeper,
TokenFactoryKeeper: app.TokenFactoryKeeper,
SlashingKeeper: app.SlashingKeeper,
ParamsKeeper: app.ParamsKeeper,
CapabilityKeeper: app.CapabilityKeeper,
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
CcvConsumerSubspace: app.GetSubspace(ccvconsumertypes.ModuleName),
},
app,
app.AppCodec(),
Expand Down
103 changes: 71 additions & 32 deletions app/upgrades/nextupgrade/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package nextupgrade
import (
"errors"

"github.com/cosmos/cosmos-sdk/codec"
ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"

ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand All @@ -28,48 +30,85 @@ func CreateUpgradeHandler(
return vm, err
}

ctx.Logger().Info("Implementing GlobalFee Params...")

if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMinGasPrices) {
return vm, errors.New("minimum_gas_prices param not found")
err = migrateGlobalFees(ctx, keepers)
if err != nil {
ctx.Logger().Error("failed to migrate GlobalFees", "err", err)
return vm, err
}

if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) {
return vm, errors.New("bypass_min_fee_msg_types param not found")
err = migrateRewardDenoms(ctx, keepers)
if err != nil {
ctx.Logger().Error("failed to migrate reward denoms", "err", err)
return vm, err
}

if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) {
return vm, errors.New("max_total_bypass_min_fee_msg_gas_usage param not found")
}
ctx.Logger().Info("Upgrade complete")
return vm, err
}
}

// global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin
// As of June 22nd, 2023 this is
// 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349
requiredGlobalFees := sdk.DecCoins{
sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")),
sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")),
sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")),
}
requiredGlobalFees = requiredGlobalFees.Sort()
func migrateGlobalFees(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error {
ctx.Logger().Info("Implementing GlobalFee Params...")

keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMinGasPrices, &requiredGlobalFees)
if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMinGasPrices) {
return errors.New("minimum_gas_prices param not found")
}

ctx.Logger().Info("Global fees was set successfully")
if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) {
return errors.New("bypass_min_fee_msg_types param not found")
}

defaultBypassFeeMessages := []string{
sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}),
sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}),
}
keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &defaultBypassFeeMessages)
if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) {
return errors.New("max_total_bypass_min_fee_msg_gas_usage param not found")
}

ctx.Logger().Info("Bypass min fee msg types was set successfully")
// global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin
// As of June 22nd, 2023 this is
// 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349
requiredGlobalFees := sdk.DecCoins{
sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")),
sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")),
sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")),
}
requiredGlobalFees = requiredGlobalFees.Sort()

keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, types.DefaultmaxTotalBypassMinFeeMsgGasUsage)
keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMinGasPrices, &requiredGlobalFees)

ctx.Logger().Info("Max total bypass min fee msg gas usage set successfully")
ctx.Logger().Info("Global fees was set successfully")

ctx.Logger().Info("Upgrade complete")
return vm, err
defaultBypassFeeMessages := []string{
sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}),
sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}),
}
keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &defaultBypassFeeMessages)

ctx.Logger().Info("Bypass min fee msg types was set successfully")

keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &types.DefaultmaxTotalBypassMinFeeMsgGasUsage)

ctx.Logger().Info("Max total bypass min fee msg gas usage set successfully")

return nil
}

func migrateRewardDenoms(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error {
ctx.Logger().Info("Migrating reword denoms...")

if !keepers.CcvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms) {
return errors.New("key_reward_denoms param not found")
}

var denoms []string
keepers.CcvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denoms)

// add new axlr usdc denom
axlrDenom := "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349"
denoms = append(denoms, axlrDenom)

keepers.CcvConsumerSubspace.Set(ctx, ccvconsumertypes.KeyRewardDenoms, &denoms)

ctx.Logger().Info("Finished migrating reward denoms")

return nil
}
38 changes: 36 additions & 2 deletions app/upgrades/nextupgrade/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package nextupgrade_test
import (
"testing"

ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/neutron-org/neutron/app/params"

ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"

sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/gaia/v11/x/globalfee"
globalfeetypes "github.com/cosmos/gaia/v11/x/globalfee/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/neutron-org/neutron/app/upgrades/nextupgrade"
"github.com/neutron-org/neutron/testutil"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -68,3 +71,34 @@ func (suite *UpgradeTestSuite) TestGlobalFeesUpgrade() {
requiredTotalBypassMinFeeMsgGasUsage := uint64(1_000_000)
suite.Require().Equal(requiredTotalBypassMinFeeMsgGasUsage, actualTotalBypassMinFeeMsgGasUsage)
}

func (suite *UpgradeTestSuite) TestRewardDenomsUpgrade() {
var (
app = suite.GetNeutronZoneApp(suite.ChainA)
ccvConsumerSubspace = app.GetSubspace(ccvconsumertypes.ModuleName)
ctx = suite.ChainA.GetContext()
)

suite.Require().True(ccvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms))

// emulate mainnet/testnet state
ccvConsumerSubspace.Set(ctx, ccvconsumertypes.KeyRewardDenoms, &[]string{params.DefaultDenom})

var denomsBefore []string
ccvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denomsBefore)
suite.Require().Equal(denomsBefore, []string{params.DefaultDenom})

upgrade := upgradetypes.Plan{
Name: nextupgrade.UpgradeName,
Info: "some text here",
Height: 100,
}
app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade)

suite.Require().True(ccvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms))

var denoms []string
ccvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denoms)
requiredDenoms := []string{params.DefaultDenom, "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349"}
suite.Require().Equal(requiredDenoms, denoms)
}
3 changes: 2 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type UpgradeKeepers struct {
CapabilityKeeper *capabilitykeeper.Keeper
BuilderKeeper builderkeeper.Keeper
// subspaces
GlobalFeeSubspace paramtypes.Subspace
GlobalFeeSubspace paramtypes.Subspace
CcvConsumerSubspace paramtypes.Subspace
}

type StoreKeys interface {
Expand Down
12 changes: 7 additions & 5 deletions cmd/neutrond/util.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package main

import (
"cosmossdk.io/log"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"cosmossdk.io/log"

tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
tmlog "github.com/cometbft/cometbft/libs/log"
Expand All @@ -14,10 +20,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"os"
"path"
"path/filepath"
"strings"
)

// NOTE: The functions below are copy-pasted from cosmos-sdk@v0.47.3 (see https://github.com/cosmos/cosmos-sdk/blob/v0.47.3/server/util.go#L122)
Expand Down
22 changes: 22 additions & 0 deletions proto/neutron/contractmanager/failure.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package neutron.contractmanager;

import "ibc/core/channel/v1/channel.proto";

option go_package = "github.com/neutron-org/neutron/x/contractmanager/types";

// Failure message contains information about ACK failures and can be used to
// replay ACK in case of requirement.
// Note that Failure means that sudo handler to cosmwasm contract failed for some reason
message Failure {
// Address of the failed contract
string address = 1;
// Id of the failure under specific address
uint64 id = 2;
// Acknowledgement type
string ack_type = 3;
// IBC Packet
ibc.core.channel.v1.Packet packet = 4;
// Acknowledgement
ibc.core.channel.v1.Acknowledgement ack = 5;
}
16 changes: 1 addition & 15 deletions proto/neutron/contractmanager/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,11 @@ package neutron.contractmanager;

import "gogoproto/gogo.proto";
import "neutron/contractmanager/params.proto";
import "neutron/contractmanager/failure.proto";
// this line is used by starport scaffolding # genesis/proto/import

option go_package = "github.com/neutron-org/neutron/x/contractmanager/types";

// Failure message contains information about ACK failures and can be used to
// replay ACK in case of requirement.
message Failure {
// ChannelId
string channel_id = 1;
// Address of the failed contract
string address = 2;
// id of the failure under specific address
uint64 id = 3;
// ACK id to restore
uint64 ack_id = 4;
// Acknowledgement type
string ack_type = 5;
}

// GenesisState defines the contractmanager module's genesis state.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
Expand Down
2 changes: 1 addition & 1 deletion proto/neutron/contractmanager/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "neutron/contractmanager/params.proto";
import "neutron/contractmanager/genesis.proto";
import "neutron/contractmanager/failure.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/neutron-org/neutron/x/contractmanager/types";
Expand Down
18 changes: 18 additions & 0 deletions proto/neutron/contractmanager/v1/failure.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";
package neutron.contractmanager.v1;

option go_package = "github.com/neutron-org/neutron/x/contractmanager/types/v1";

// Deprecated. Used only for migration purposes.
message Failure {
// ChannelId
string channel_id = 1;
// Address of the failed contract
string address = 2;
// id of the failure under specific address
uint64 id = 3;
// ACK id to restore
uint64 ack_id = 4;
// Acknowledgement type
string ack_type = 5;
}
8 changes: 4 additions & 4 deletions testutil/mocks/interchaintxs/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions testutil/mocks/transfer/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type NeutronMsg struct {
// Cron types
AddSchedule *AddSchedule `json:"add_schedule,omitempty"`
RemoveSchedule *RemoveSchedule `json:"remove_schedule,omitempty"`

// Contractmanager types
/// A contract that has failed acknowledgement can resubmit it
ResubmitFailure *ResubmitFailure `json:"resubmit_failure,omitempty"`
}

// SubmitTx submits interchain transaction on a remote chain.
Expand Down Expand Up @@ -200,3 +204,11 @@ type MsgExecuteContract struct {
// Msg json encoded message to be passed to the contract
Msg string `json:"msg,omitempty"`
}

type ResubmitFailure struct {
FailureId uint64 `json:"failure_id"`
}

type ResubmitFailureResponse struct {
FailureId uint64 `json:"failure_id"`
}
Loading

0 comments on commit 71dd6d4

Please sign in to comment.