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

R4R: Message & Codec Registration Consistency #3673

Merged
merged 12 commits into from
Feb 25, 2019
3 changes: 3 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

### SDK

* [\#3669] Ensure consistency in message naming, codec registration, and JSON
tags.

### Tendermint

<!--------------------------------- FEATURES --------------------------------->
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/ibc/mvp/mvp1.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type IBCPacket struct {
}

// Implements sdk.Msg
type IBCTransferMsg struct {
type MsgIBCTransfer struct {
IBCPacket
}

// Implements sdk.Msg
type IBCReceiveMsg struct {
type MsgIBCReceive struct {
IBCPacket
Relayer sdk.Address
Sequence int64
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/ibc/mvp/mvp2.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ type TransferPayload struct {
}

// Implements sdk.Msg
type IBCTransferMsg struct {
type MsgIBCTransfer struct {
Packet
}

// Implements sdk.Msg
type IBCReceiveMsg struct {
type MsgIBCReceive struct {
Packet
Relayer sdk.Address
Sequence int64
Expand Down
8 changes: 4 additions & 4 deletions docs/spec/ibc/mvp/mvp3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


// Implements sdk.Msg
type IBCTransferMsg struct {
type MsgIBCTransfer struct {
Packet
}

// Implements sdk.Msg
type IBCReceiveMsg struct {
type MsgIBCReceive struct {
Packet
}

Expand Down Expand Up @@ -42,12 +42,12 @@ type TransferPayload struct {
}

// Implements sdk.Msg
type IBCTransferMsg struct {
type MsgIBCTransfer struct {
Packet
}

// Implements sdk.Msg
type IBCReceiveMsg struct {
type MsgIBCReceive struct {
Packet
Proof iavl.Proof
FromChainID string
Expand Down
4 changes: 2 additions & 2 deletions x/bank/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

// Register concrete types on codec codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil)
cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MultiSend", nil)
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/MsgSend", nil)
cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil)
}

var msgCdc = codec.New()
Expand Down
4 changes: 2 additions & 2 deletions x/bank/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestMsgSendGetSignBytes(t *testing.T) {
var msg = NewMsgSend(addr1, addr2, coins)
res := msg.GetSignBytes()

expected := `{"type":"cosmos-sdk/Send","value":{"amount":[{"amount":"10","denom":"atom"}],"from_address":"cosmos1d9h8qat57ljhcm","to_address":"cosmos1da6hgur4wsmpnjyg"}}`
expected := `{"type":"cosmos-sdk/MsgSend","value":{"amount":[{"amount":"10","denom":"atom"}],"from_address":"cosmos1d9h8qat57ljhcm","to_address":"cosmos1da6hgur4wsmpnjyg"}}`
require.Equal(t, expected, string(res))
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func TestMsgMultiSendGetSignBytes(t *testing.T) {
}
res := msg.GetSignBytes()

expected := `{"type":"cosmos-sdk/MultiSend","value":{"inputs":[{"address":"cosmos1d9h8qat57ljhcm","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmos1da6hgur4wsmpnjyg","coins":[{"amount":"10","denom":"atom"}]}]}}`
expected := `{"type":"cosmos-sdk/MsgMultiSend","value":{"inputs":[{"address":"cosmos1d9h8qat57ljhcm","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmos1da6hgur4wsmpnjyg","coins":[{"amount":"10","denom":"atom"}]}]}}`
require.Equal(t, expected, string(res))
}

Expand Down
4 changes: 2 additions & 2 deletions x/ibc/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func TestIBCMsgs(t *testing.T) {
DestChain: destChain,
}

transferMsg := IBCTransferMsg{
transferMsg := MsgIBCTransfer{
IBCPacket: packet,
}

receiveMsg := IBCReceiveMsg{
receiveMsg := MsgIBCReceive{
IBCPacket: packet,
Relayer: addr1,
Sequence: 0,
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/client/cli/ibctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func buildMsg(from sdk.AccAddress) (sdk.Msg, error) {
packet := ibc.NewIBCPacket(from, to, coins, viper.GetString(client.FlagChainID),
viper.GetString(flagChain))

msg := ibc.IBCTransferMsg{
msg := ibc.MsgIBCTransfer{
IBCPacket: packet,
}

Expand Down
2 changes: 1 addition & 1 deletion x/ibc/client/cli/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (c relayCommander) refine(bz []byte, ibcSeq, accSeq uint64, passphrase stri
panic(err)
}

msg := ibc.IBCReceiveMsg{
msg := ibc.MsgIBCReceive{
IBCPacket: packet,
Relayer: c.address,
Sequence: ibcSeq,
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/client/rest/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
}

packet := ibc.NewIBCPacket(fromAddr, to, req.Amount, req.BaseReq.ChainID, destChainID)
msg := ibc.IBCTransferMsg{IBCPacket: packet}
msg := ibc.MsgIBCTransfer{IBCPacket: packet}

if req.BaseReq.GenerateOnly {
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (

// Register concrete types on codec codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(IBCTransferMsg{}, "cosmos-sdk/IBCTransferMsg", nil)
cdc.RegisterConcrete(IBCReceiveMsg{}, "cosmos-sdk/IBCReceiveMsg", nil)
cdc.RegisterConcrete(MsgIBCTransfer{}, "cosmos-sdk/MsgIBCTransfer", nil)
cdc.RegisterConcrete(MsgIBCReceive{}, "cosmos-sdk/MsgIBCReceive", nil)
}
12 changes: 6 additions & 6 deletions x/ibc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
func NewHandler(ibcm Mapper, ck BankKeeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case IBCTransferMsg:
case MsgIBCTransfer:
return handleIBCTransferMsg(ctx, ibcm, ck, msg)
case IBCReceiveMsg:
case MsgIBCReceive:
return handleIBCReceiveMsg(ctx, ibcm, ck, msg)
default:
errMsg := "Unrecognized IBC Msg type: " + msg.Type()
Expand All @@ -18,8 +18,8 @@ func NewHandler(ibcm Mapper, ck BankKeeper) sdk.Handler {
}
}

// IBCTransferMsg deducts coins from the account and creates an egress IBC packet.
func handleIBCTransferMsg(ctx sdk.Context, ibcm Mapper, ck BankKeeper, msg IBCTransferMsg) sdk.Result {
// MsgIBCTransfer deducts coins from the account and creates an egress IBC packet.
func handleIBCTransferMsg(ctx sdk.Context, ibcm Mapper, ck BankKeeper, msg MsgIBCTransfer) sdk.Result {
packet := msg.IBCPacket

_, _, err := ck.SubtractCoins(ctx, packet.SrcAddr, packet.Coins)
Expand All @@ -35,8 +35,8 @@ func handleIBCTransferMsg(ctx sdk.Context, ibcm Mapper, ck BankKeeper, msg IBCTr
return sdk.Result{}
}

// IBCReceiveMsg adds coins to the destination address and creates an ingress IBC packet.
func handleIBCReceiveMsg(ctx sdk.Context, ibcm Mapper, ck BankKeeper, msg IBCReceiveMsg) sdk.Result {
// MsgIBCReceive adds coins to the destination address and creates an ingress IBC packet.
func handleIBCReceiveMsg(ctx sdk.Context, ibcm Mapper, ck BankKeeper, msg MsgIBCReceive) sdk.Result {
packet := msg.IBCPacket

seq := ibcm.GetIngressSequence(ctx, packet.SrcChain)
Expand Down
8 changes: 4 additions & 4 deletions x/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func makeCodec() *codec.Codec {
// Register Msgs
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.MsgSend{}, "test/ibc/Send", nil)
cdc.RegisterConcrete(IBCTransferMsg{}, "test/ibc/IBCTransferMsg", nil)
cdc.RegisterConcrete(IBCReceiveMsg{}, "test/ibc/IBCReceiveMsg", nil)
cdc.RegisterConcrete(MsgIBCTransfer{}, "test/ibc/MsgIBCTransfer", nil)
cdc.RegisterConcrete(MsgIBCReceive{}, "test/ibc/MsgIBCReceive", nil)

// Register AppAccount
cdc.RegisterInterface((*auth.Account)(nil), nil)
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestIBC(t *testing.T) {
egl = ibcm.getEgressLength(store, chainid)
require.Equal(t, egl, uint64(0))

msg = IBCTransferMsg{
msg = MsgIBCTransfer{
IBCPacket: packet,
}
res = h(ctx, msg)
Expand All @@ -137,7 +137,7 @@ func TestIBC(t *testing.T) {
igs = ibcm.GetIngressSequence(ctx, chainid)
require.Equal(t, igs, uint64(0))

msg = IBCReceiveMsg{
msg = MsgIBCReceive{
IBCPacket: packet,
Relayer: src,
Sequence: 0,
Expand Down
32 changes: 16 additions & 16 deletions x/ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,53 @@ func (p IBCPacket) ValidateBasic() sdk.Error {
}

// ----------------------------------
// IBCTransferMsg
// MsgIBCTransfer

// nolint - TODO rename to TransferMsg as folks will reference with ibc.TransferMsg
// IBCTransferMsg defines how another module can send an IBCPacket.
type IBCTransferMsg struct {
// MsgIBCTransfer defines how another module can send an IBCPacket.
type MsgIBCTransfer struct {
IBCPacket
}

// nolint
func (msg IBCTransferMsg) Route() string { return "ibc" }
func (msg IBCTransferMsg) Type() string { return "transfer" }
func (msg MsgIBCTransfer) Route() string { return "ibc" }
func (msg MsgIBCTransfer) Type() string { return "transfer" }

// x/bank/tx.go MsgSend.GetSigners()
func (msg IBCTransferMsg) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.SrcAddr} }
func (msg MsgIBCTransfer) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.SrcAddr} }

// get the sign bytes for ibc transfer message
func (msg IBCTransferMsg) GetSignBytes() []byte {
func (msg MsgIBCTransfer) GetSignBytes() []byte {
return msg.IBCPacket.GetSignBytes()
}

// validate ibc transfer message
func (msg IBCTransferMsg) ValidateBasic() sdk.Error {
func (msg MsgIBCTransfer) ValidateBasic() sdk.Error {
return msg.IBCPacket.ValidateBasic()
}

// ----------------------------------
// IBCReceiveMsg
// MsgIBCReceive

// nolint - TODO rename to ReceiveMsg as folks will reference with ibc.ReceiveMsg
// IBCReceiveMsg defines the message that a relayer uses to post an IBCPacket
// MsgIBCReceive defines the message that a relayer uses to post an IBCPacket
// to the destination chain.
type IBCReceiveMsg struct {
type MsgIBCReceive struct {
IBCPacket
Relayer sdk.AccAddress
Sequence uint64
}

// nolint
func (msg IBCReceiveMsg) Route() string { return "ibc" }
func (msg IBCReceiveMsg) Type() string { return "receive" }
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() }
func (msg MsgIBCReceive) Route() string { return "ibc" }
func (msg MsgIBCReceive) Type() string { return "receive" }
func (msg MsgIBCReceive) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() }

// x/bank/tx.go MsgSend.GetSigners()
func (msg IBCReceiveMsg) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Relayer} }
func (msg MsgIBCReceive) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Relayer} }

// get the sign bytes for ibc receive message
func (msg IBCReceiveMsg) GetSignBytes() []byte {
func (msg MsgIBCReceive) GetSignBytes() []byte {
b, err := msgCdc.MarshalJSON(struct {
IBCPacket json.RawMessage
Relayer sdk.AccAddress
Expand Down
20 changes: 10 additions & 10 deletions x/ibc/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func TestIBCPacketValidation(t *testing.T) {
}

// -------------------------------
// IBCTransferMsg Tests
// MsgIBCTransfer Tests

func TestIBCTransferMsg(t *testing.T) {
packet := constructIBCPacket(true)
msg := IBCTransferMsg{packet}
msg := MsgIBCTransfer{packet}

require.Equal(t, msg.Route(), "ibc")
}
Expand All @@ -46,10 +46,10 @@ func TestIBCTransferMsgValidation(t *testing.T) {

cases := []struct {
valid bool
msg IBCTransferMsg
msg MsgIBCTransfer
}{
{true, IBCTransferMsg{validPacket}},
{false, IBCTransferMsg{invalidPacket}},
{true, MsgIBCTransfer{validPacket}},
{false, MsgIBCTransfer{invalidPacket}},
}

for i, tc := range cases {
Expand All @@ -63,11 +63,11 @@ func TestIBCTransferMsgValidation(t *testing.T) {
}

// -------------------------------
// IBCReceiveMsg Tests
// MsgIBCReceive Tests

func TestIBCReceiveMsg(t *testing.T) {
packet := constructIBCPacket(true)
msg := IBCReceiveMsg{packet, sdk.AccAddress([]byte("relayer")), 0}
msg := MsgIBCReceive{packet, sdk.AccAddress([]byte("relayer")), 0}

require.Equal(t, msg.Route(), "ibc")
}
Expand All @@ -78,10 +78,10 @@ func TestIBCReceiveMsgValidation(t *testing.T) {

cases := []struct {
valid bool
msg IBCReceiveMsg
msg MsgIBCReceive
}{
{true, IBCReceiveMsg{validPacket, sdk.AccAddress([]byte("relayer")), 0}},
{false, IBCReceiveMsg{invalidPacket, sdk.AccAddress([]byte("relayer")), 0}},
{true, MsgIBCReceive{validPacket, sdk.AccAddress([]byte("relayer")), 0}},
{false, MsgIBCReceive{invalidPacket, sdk.AccAddress([]byte("relayer")), 0}},
}

for i, tc := range cases {
Expand Down
4 changes: 2 additions & 2 deletions x/staking/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil)
cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil)
cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil)
cdc.RegisterConcrete(MsgUndelegate{}, "cosmos-sdk/Undelegate", nil)
cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/BeginRedelegate", nil)
cdc.RegisterConcrete(MsgUndelegate{}, "cosmos-sdk/MsgUndelegate", nil)
cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil)
}

// generic sealed codec to be used throughout sdk
Expand Down
14 changes: 7 additions & 7 deletions x/staking/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ func (msg MsgEditValidator) ValidateBasic() sdk.Error {

// MsgDelegate - struct for bonding transactions
type MsgDelegate struct {
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
DelegatorAddr sdk.AccAddress `json:"delegator_address"`
ValidatorAddr sdk.ValAddress `json:"validator_address"`
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
Value sdk.Coin `json:"value"`
}

Expand Down Expand Up @@ -253,9 +253,9 @@ func (msg MsgDelegate) ValidateBasic() sdk.Error {

// MsgDelegate - struct for bonding transactions
type MsgBeginRedelegate struct {
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
ValidatorSrcAddr sdk.ValAddress `json:"validator_src_addr"`
ValidatorDstAddr sdk.ValAddress `json:"validator_dst_addr"`
DelegatorAddr sdk.AccAddress `json:"delegator_address"`
ValidatorSrcAddr sdk.ValAddress `json:"validator_src_address"`
ValidatorDstAddr sdk.ValAddress `json:"validator_dst_address"`
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
SharesAmount sdk.Dec `json:"shares_amount"`
}

Expand Down Expand Up @@ -302,8 +302,8 @@ func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error {

// MsgUndelegate - struct for unbonding transactions
type MsgUndelegate struct {
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
DelegatorAddr sdk.AccAddress `json:"delegator_address"`
ValidatorAddr sdk.ValAddress `json:"validator_address"`
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
SharesAmount sdk.Dec `json:"shares_amount"`
}

Expand Down