Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: whitelist addresses param for setting fee tokens #7855

Merged
merged 10 commits into from
Apr 1, 2024
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#7785](https://github.com/osmosis-labs/osmosis/pull/7785) Remove reward claiming during position transfers
* [#7839](https://github.com/osmosis-labs/osmosis/pull/7839) Add ICA controller
* [#7527](https://github.com/osmosis-labs/osmosis/pull/7527) Add 30M gas limit to CW pool contract calls
* [#7855](https://github.com/osmosis-labs/osmosis/pull/7855) Whitelist address parameter for setting fee tokens

### SDK

Expand All @@ -87,6 +88,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#514](https://github.com/osmosis-labs/cosmos-sdk/pull/514) Let gov hooks return an error
* [#580](https://github.com/osmosis-labs/cosmos-sdk/pull/580) Less time intensive slashing migration

### CometBFT

* [#5](https://github.com/osmosis-labs/cometbft/pull/5) Batch verification
* [#11](https://github.com/osmosis-labs/cometbft/pull/11) Skip verification of commit sigs
* [#13](https://github.com/osmosis-labs/cometbft/pull/13) Avoid double-saving ABCI responses
* [#20](https://github.com/osmosis-labs/cometbft/pull/20) Fix the rollback command

Comment on lines +94 to +100
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the update in a separate PR.

#7865

## v23.0.8-iavl-v1 & v23.0.8

* [#7769](https://github.com/osmosis-labs/osmosis/pull/7769) Set and default timeout commit to 3s. Add flag to prevent custom overrides if not desired.
Expand Down
3 changes: 3 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"

appparams "github.com/osmosis-labs/osmosis/v23/app/params"
"github.com/osmosis-labs/osmosis/v23/x/cosmwasmpool"
cosmwasmpooltypes "github.com/osmosis-labs/osmosis/v23/x/cosmwasmpool/types"
Expand Down Expand Up @@ -442,6 +443,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.DistrKeeper,
appKeepers.ConsensusParamsKeeper,
dataDir,
appKeepers.GetSubspace(txfeestypes.ModuleName),
)
appKeepers.TxFeesKeeper = &txFeesKeeper

Expand Down Expand Up @@ -752,6 +754,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(cosmwasmpooltypes.ModuleName)
paramsKeeper.Subspace(ibchookstypes.ModuleName)
paramsKeeper.Subspace(txfeestypes.ModuleName)

return paramsKeeper
}
Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/v24/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"

cwpooltypes "github.com/osmosis-labs/osmosis/v23/x/cosmwasmpool/types"

"github.com/osmosis-labs/osmosis/v23/app/keepers"
Expand Down Expand Up @@ -80,6 +81,9 @@ func CreateUpgradeHandler(
keepers.CosmwasmPoolKeeper.SetPool(ctx, cwPool)
}

// Set whitelistedFeeTokenSetters param
// keepers.TxFeesKeeper.SetParam(ctx, txfeestypes.KeyWhitelistedFeeTokenSetters, "osmo1...")

return migrations, nil
}
}
14 changes: 14 additions & 0 deletions proto/osmosis/txfees/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package osmosis.txfees.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/osmosis-labs/osmosis/v23/x/txfees/types";

// Params holds parameters for the txfees module
message Params {
repeated string whitelisted_fee_token_setters = 1 [
(gogoproto.moretags) = "yaml:\"whitelisted_fee_token_setters\"",
(gogoproto.nullable) = false
];
}
25 changes: 25 additions & 0 deletions proto/osmosis/txfees/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package osmosis.txfees.v1beta1;

import "gogoproto/gogo.proto";
import "amino/amino.proto";
import "osmosis/txfees/v1beta1/feetoken.proto";

option go_package = "github.com/osmosis-labs/osmosis/v23/x/txfees/types";

service Msg {
rpc SetFeeTokens(MsgSetFeeTokens) returns (MsgSetFeeTokensResponse);
}

// ===================== MsgSetFeeTokens
message MsgSetFeeTokens {
option (amino.name) = "osmosis/set-fee-tokens";

repeated FeeToken fee_tokens = 1 [
(gogoproto.moretags) = "yaml:\"fee_tokens\"",
(gogoproto.nullable) = false
];
string sender = 2 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
}

message MsgSetFeeTokensResponse {}
3 changes: 3 additions & 0 deletions x/txfees/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/osmosis-labs/osmosis/osmoutils/osmocli"
"github.com/osmosis-labs/osmosis/v23/x/twap/client/queryproto"
"github.com/osmosis-labs/osmosis/v23/x/txfees/types"
)

Expand All @@ -15,6 +16,8 @@ func GetQueryCmd() *cobra.Command {
GetCmdFeeTokens(),
GetCmdDenomPoolID(),
GetCmdBaseDenom(),
osmocli.GetParams[*queryproto.ParamsRequest](
types.ModuleName, queryproto.NewQueryClient),
)

osmocli.AddQueryCmd(cmd, types.NewQueryClient, GetCmdQueryBaseFee)
Expand Down
19 changes: 19 additions & 0 deletions x/txfees/keeper/feetokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,22 @@ func (k Keeper) SetFeeTokens(ctx sdk.Context, feetokens []types.FeeToken) error
}
return nil
}

// SenderValidationSetFeeTokens first checks to see if the sender is whitelisted to set fee tokens.
// If the sender is whitelisted, it sets the fee tokens.
// If the sender is not whitelisted, it returns an error.
func (k Keeper) SenderValidationSetFeeTokens(ctx sdk.Context, sender string, feetokens []types.FeeToken) error {
whitelistedAddresses := k.GetParams(ctx).WhitelistedFeeTokenSetters
isWhitelisted := false
for _, admin := range whitelistedAddresses {
if admin == sender {
isWhitelisted = true
break
}
}
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
if !isWhitelisted {
return errorsmod.Wrapf(types.ErrNotWhitelistedFeeTokenSetter, "%s", sender)
}

return k.SetFeeTokens(ctx, feetokens)
}
26 changes: 26 additions & 0 deletions x/txfees/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/osmosis-labs/osmosis/v23/x/txfees/types"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
)
Expand All @@ -25,6 +26,8 @@ type Keeper struct {
distributionKeeper types.DistributionKeeper
consensusKeeper types.ConsensusKeeper
dataDir string

paramSpace paramtypes.Subspace
}

var _ types.TxFeesKeeper = (*Keeper)(nil)
Expand All @@ -38,7 +41,13 @@ func NewKeeper(
distributionKeeper types.DistributionKeeper,
consensusKeeper types.ConsensusKeeper,
dataDir string,
paramSpace paramtypes.Subspace,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
Expand All @@ -48,9 +57,26 @@ func NewKeeper(
distributionKeeper: distributionKeeper,
consensusKeeper: consensusKeeper,
dataDir: dataDir,
paramSpace: paramSpace,
}
}

// GetParams returns the total set of txfees parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, &params)
return params
}

// SetParams sets the total set of txfees parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

// SetParam sets a specific txfees module's parameter with the provided parameter.
func (k Keeper) SetParam(ctx sdk.Context, key []byte, value interface{}) {
k.paramSpace.Set(ctx, key, value)
}

func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
Expand Down
31 changes: 31 additions & 0 deletions x/txfees/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package keeper

import (
"context"

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

"github.com/osmosis-labs/osmosis/v23/x/txfees/types"
)

type msgServer struct {
keeper *Keeper
}

func NewMsgServerImpl(keeper *Keeper) types.MsgServer {
return &msgServer{
keeper: keeper,
}
}

// SetFeeTokens sets the provided fee tokens for the chain. The sender must be whitelisted to set fee tokens.
func (server msgServer) SetFeeTokens(goCtx context.Context, msg *types.MsgSetFeeTokens) (*types.MsgSetFeeTokensResponse, error) {
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
ctx := sdk.UnwrapSDKContext(goCtx)

err := server.keeper.SenderValidationSetFeeTokens(ctx, msg.Sender, msg.FeeTokens)
if err != nil {
return nil, err
}

return &types.MsgSetFeeTokensResponse{}, nil
}
1 change: 1 addition & 0 deletions x/txfees/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (AppModule) QuerierRoute() string { return "" }
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
}

Expand Down
21 changes: 21 additions & 0 deletions x/txfees/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,43 @@ package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&UpdateFeeTokenProposal{}, "osmosis/UpdateFeeTokenProposal", nil)
legacy.RegisterAminoMsg(cdc, &MsgSetFeeTokens{}, "osmosis/txfees/set-fee-tokens")
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*govtypesv1.Content)(nil),
&UpdateFeeTokenProposal{},
)
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgSetFeeTokens{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
sdk.RegisterLegacyAminoCodec(amino)

// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
amino.Seal()
}
7 changes: 4 additions & 3 deletions x/txfees/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (

// x/txfees module errors.
var (
ErrNoBaseDenom = errorsmod.Register(ModuleName, 1, "no base denom was set")
ErrTooManyFeeCoins = errorsmod.Register(ModuleName, 2, "too many fee coins. only accepts fees in one denom")
ErrInvalidFeeToken = errorsmod.Register(ModuleName, 3, "invalid fee token")
ErrNoBaseDenom = errorsmod.Register(ModuleName, 1, "no base denom was set")
ErrTooManyFeeCoins = errorsmod.Register(ModuleName, 2, "too many fee coins. only accepts fees in one denom")
ErrInvalidFeeToken = errorsmod.Register(ModuleName, 3, "invalid fee token")
ErrNotWhitelistedFeeTokenSetter = errorsmod.Register(ModuleName, 4, "not whitelisted fee token setter")
)
41 changes: 41 additions & 0 deletions x/txfees/types/msgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package types

import (
"fmt"

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

// constants.
const (
TypeMsgSetFeeTokens = "set-fee-tokens"
)

var _ sdk.Msg = &MsgSetFeeTokens{}

func (msg MsgSetFeeTokens) Route() string { return RouterKey }
func (msg MsgSetFeeTokens) Type() string { return TypeMsgSetFeeTokens }
func (msg MsgSetFeeTokens) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return fmt.Errorf("Invalid sender address (%s)", err)
}

if len(msg.FeeTokens) == 0 {
return fmt.Errorf("Fee tokens must not be empty")
}

return nil
}

func (msg MsgSetFeeTokens) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgSetFeeTokens) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
46 changes: 46 additions & 0 deletions x/txfees/types/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package types

import (
"github.com/osmosis-labs/osmosis/osmoutils"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// Parameter store keys.
var (
KeyWhitelistedFeeTokenSetters = []byte("WhitelistedFeeTokenSetters")
)

// ParamTable for txfees module.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}

func NewParams(whitelistedFeeTokenSetters []string) Params {
return Params{
WhitelistedFeeTokenSetters: whitelistedFeeTokenSetters,
}
}

// DefaultParams are the default txfees module parameters.
func DefaultParams() Params {
return Params{
WhitelistedFeeTokenSetters: []string{},
}
}

// validate params.
func (p Params) Validate() error {
if err := osmoutils.ValidateAddressList(p.WhitelistedFeeTokenSetters); err != nil {
return err
}

return nil
}

// Implements params.ParamSet.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyWhitelistedFeeTokenSetters, &p.WhitelistedFeeTokenSetters, osmoutils.ValidateAddressList),
}
}
Loading