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

llama/feat-add-fee-denom-change-proposal #270

Merged
merged 23 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5b5bb75
Add proposal to update fee denom to bank module
llama-del-rey Oct 6, 2022
1819ad3
gofmt
llama-del-rey Oct 6, 2022
3240055
proto lint
llama-del-rey Oct 6, 2022
3c9d9c9
fix broken test
llama-del-rey Oct 6, 2022
a0b5bd4
Use 0.46 gov proposal mechanics
llama-del-rey Oct 10, 2022
4c8245e
Validate metadata
llama-del-rey Oct 10, 2022
b23d384
revert local testing changes
llama-del-rey Oct 10, 2022
8668248
Update proto/cosmos/bank/v1beta1/tx.proto
llama-del-rey Oct 11, 2022
42d20a9
Add authority to bank keeper
llama-del-rey Oct 13, 2022
f869c8c
Merge branch 'llama/add-fee-denom-change-proposal' of github.com:prov…
llama-del-rey Oct 13, 2022
0643904
remove whitespace only changes
llama-del-rey Oct 13, 2022
ea9393c
Add unit test for the method. metadata_test contains tests for metada…
llama-del-rey Oct 13, 2022
8c011dc
remove print statement
llama-del-rey Oct 18, 2022
627909d
fix changelog
llama-del-rey Oct 28, 2022
f19c111
fix conflict
llama-del-rey Oct 28, 2022
a91eeef
Add tests for proposal submission
llama-del-rey Nov 4, 2022
c383a27
Merge branch 'release-pio/v0.46.x' into llama/add-fee-denom-change-pr…
llama-del-rey Nov 4, 2022
c049aa3
Increase initial balance for accounts
llama-del-rey Nov 4, 2022
2e457d1
Hardcode authority since transitive dependencies break
llama-del-rey Nov 8, 2022
a800a03
remove print statements
llama-del-rey Nov 8, 2022
a9b2f5e
typos and such
llama-del-rey Nov 8, 2022
c21fa35
group imports
llama-del-rey Nov 9, 2022
4c4f85f
gofmt
llama-del-rey Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

* Add functionality to update denom metadata via gov proposal [#270](https://github.com/provenance-io/cosmos-sdk/pull/270)
* nothing

---
Expand Down
17 changes: 17 additions & 0 deletions proto/cosmos/bank/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ service Msg {

// MultiSend defines a method for sending coins from some accounts to other accounts.
rpc MultiSend(MsgMultiSend) returns (MsgMultiSendResponse);

// UpdateDenomMetadata defines a method for updating the denom metadata. Only usable in x/gov proposal.
rpc UpdateDenomMetadata(MsgUpdateDenomMetadata) returns (MsgUpdateDenomMetadataResponse);
}

// MsgSend represents a message to send coins from one account to another.
Expand Down Expand Up @@ -47,3 +50,17 @@ message MsgMultiSend {
// MsgMultiSendResponse defines the Msg/MultiSend response type.
message MsgMultiSendResponse {}

message MsgUpdateDenomMetadata {

Choose a reason for hiding this comment

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

Needs a comment.

Copy link
Author

Choose a reason for hiding this comment

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

// MsgUpdateDenomMetadata represents a message to update denom metadata

option (cosmos.msg.v1.signer) = "from_address";

option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string from_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string title = 2;
string description = 3;
Metadata metadata = 4;
}

// MsgUpdateDenomMetadataResponse defines the Msg/UpdateDenomMetadata response type.
message MsgUpdateDenomMetadataResponse {}
2 changes: 2 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ func NewSimApp(
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
)

// set the governance module account as the authority
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
)
Expand Down
9 changes: 9 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved

nullpointer0x00 marked this conversation as resolved.
Show resolved Hide resolved
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -47,6 +48,8 @@ type Keeper interface {
DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error

GetAuthority() string

types.QueryServer
}

Expand All @@ -59,6 +62,7 @@ type BaseKeeper struct {
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
mintCoinsRestrictionFn MintingRestrictionFn
authority string
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
}

type MintingRestrictionFn func(ctx sdk.Context, coins sdk.Coins) error
Expand Down Expand Up @@ -113,6 +117,7 @@ func NewBaseKeeper(
storeKey: storeKey,
paramSpace: paramSpace,
mintCoinsRestrictionFn: func(ctx sdk.Context, coins sdk.Coins) error { return nil },
authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), // hardcoded till all transitive dependencies can be updated to pass in the constructor instead
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -550,3 +555,7 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bo
}
}
}

func (k BaseKeeper) GetAuthority() string {
return k.authority
}
16 changes: 14 additions & 2 deletions x/bank/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@ package keeper

import (
"context"

"cosmossdk.io/errors"
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
"github.com/armon/go-metrics"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/bank/types"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
)

type msgServer struct {
Keeper
}

// UpdateDenomMetadata updates the denom metadata if the message is signed by gov module account
func (k msgServer) UpdateDenomMetadata(goCtx context.Context, msg *types.MsgUpdateDenomMetadata) (*types.MsgUpdateDenomMetadataResponse, error) {
arnabmitra marked this conversation as resolved.
Show resolved Hide resolved
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
if k.GetAuthority() != msg.FromAddress {
return nil, errors.Wrapf(gov.ErrInvalidSigner, "expected %s got %s", k.GetAuthority(), msg.FromAddress)
}

ctx := sdk.UnwrapSDKContext(goCtx)
k.Keeper.SetDenomMetaData(ctx, *msg.Metadata)
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
return &types.MsgUpdateDenomMetadataResponse{}, nil
}

// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
Expand Down Expand Up @@ -102,3 +113,4 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t

return &types.MsgMultiSendResponse{}, nil
}

2 changes: 1 addition & 1 deletion x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (k BaseSendKeeper) subUnlockedCoins(ctx sdk.Context, addr sdk.AccAddress, a

_, hasNeg := sdk.Coins{spendable}.SafeSub(coin)
if hasNeg {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin)
arnabmitra marked this conversation as resolved.
Show resolved Hide resolved
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, balance)
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
}

newBalance := balance.Sub(coin)
Expand Down
2 changes: 2 additions & 0 deletions x/bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import (
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgSend{}, "cosmos-sdk/MsgSend")
legacy.RegisterAminoMsg(cdc, &MsgMultiSend{}, "cosmos-sdk/MsgMultiSend")
legacy.RegisterAminoMsg(cdc, &MsgUpdateDenomMetadata{}, "cosmos-sdk/MsgUpdateDenomMetadata")
cdc.RegisterConcrete(&SendAuthorization{}, "cosmos-sdk/SendAuthorization", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSend{},
&MsgMultiSend{},
&MsgUpdateDenomMetadata{},
)
registry.RegisterImplementations(
(*authz.Authorization)(nil),
Expand Down
48 changes: 46 additions & 2 deletions x/bank/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

// bank message types
const (
TypeMsgSend = "send"
TypeMsgMultiSend = "multisend"
TypeMsgSend = "send"
TypeMsgMultiSend = "multisend"
TypeMsgUpdateDenomMetadata = "updatedenommetada"
)

var _ sdk.Msg = &MsgSend{}
Expand Down Expand Up @@ -184,3 +185,46 @@ func ValidateInputsOutputs(inputs []Input, outputs []Output) error {

return nil
}


var _ sdk.Msg = &MsgUpdateDenomMetadata{}

// NewMsgUpdateDenomMetadata - construct a message to update denom metadata
func NewMsgUpdateDenomMetadata(fromAddr, title string, description string, metadata *Metadata) *MsgUpdateDenomMetadata {
return &MsgUpdateDenomMetadata{
FromAddress: fromAddr,
Title: title,
Description: description,
Metadata: metadata,
}
}

// Route Implements Msg
func (msg MsgUpdateDenomMetadata) Route() string {
return RouterKey
}

// Type Implements Msg
func (msg MsgUpdateDenomMetadata) Type() string {
return TypeMsgUpdateDenomMetadata
}

// ValidateBasic Implements Msg.
func (msg MsgUpdateDenomMetadata) ValidateBasic() error {
err := msg.Metadata.Validate()
if err != nil {
return err
}
return nil
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
}

// GetSignBytes Implements Msg.
func (msg MsgUpdateDenomMetadata) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

// GetSigners Implements Msg.
func (msg MsgUpdateDenomMetadata) GetSigners() []sdk.AccAddress {
fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress)
return []sdk.AccAddress{fromAddress}
}
32 changes: 32 additions & 0 deletions x/bank/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,35 @@ func TestMsgSendGetSigners(t *testing.T) {
require.Equal(t, 1, len(res))
require.True(t, from.Equals(res[0]))
}

func TestUpdateDenomMetadataGetSignBytes(t *testing.T) {
//from := sdk.AccAddress("input")
//coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10))
msg := MsgUpdateDenomMetadata{
Title: "title",
Description: "description",
Metadata: &Metadata {
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
},
},
}
res := msg.GetSignBytes()

expected := `{"type":"cosmos-sdk/MsgUpdateDenomMetadata","value":{"description":"description","metadata":{"denom_units":[{"aliases":["microatom"],"denom":"uatom"}],"description":"The native staking token of the Cosmos Hub.","name":"Cosmos Hub Atom","symbol":"ATOM"},"title":"title"}}`
require.Equal(t, expected, string(res))
}

func TestUpdateDenomMetadataGetSigners(t *testing.T) {
from := sdk.AccAddress("input111111111111111")
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
title := "Proposal Title"
description := "Proposal description"
metadata := Metadata{}
msg := NewMsgUpdateDenomMetadata(from.String(), title, description, &metadata)
res := msg.GetSigners()
require.Equal(t, 1, len(res))
require.True(t, from.Equals(res[0]))
}
Loading