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

Remove ServiceMsgs from ADR-031 #9139

Merged
merged 56 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f1398cb
wip
aaronc Apr 12, 2021
b54d71f
wip
aaronc Apr 12, 2021
03a358d
wip
aaronc Apr 12, 2021
2a6223e
wip on refactoring adr 031 type URLs
aaronc Apr 12, 2021
559fc54
Fix msg_service_router
amaury1093 Apr 19, 2021
f2d8355
Fix gov client queries
amaury1093 Apr 19, 2021
d5c6ce9
Fix some modules tests
amaury1093 Apr 19, 2021
569f777
Remove all instances of "*.Msg/*"
amaury1093 Apr 19, 2021
19720e7
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 19, 2021
c52587c
Uncomment code
amaury1093 Apr 19, 2021
aa30868
Remove commented code
amaury1093 Apr 19, 2021
2919375
// simulation.NewWeightedOperation(
amaury1093 Apr 19, 2021
488dc62
Fix CopyTx
amaury1093 Apr 19, 2021
72c0cbc
Fix more tests
amaury1093 Apr 19, 2021
04ba707
Fix x/gov test
amaury1093 Apr 19, 2021
5f543a4
proto.MessageName->sdk.MsgName
amaury1093 Apr 20, 2021
6d1b1cc
Fix authz tests
amaury1093 Apr 20, 2021
16b72f1
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 20, 2021
d4130c2
Use MsgRoute in feegrant and staking/authz
amaury1093 Apr 20, 2021
5f4a19c
Fix more tests
amaury1093 Apr 20, 2021
d5a2982
Fix sims?
amaury1093 Apr 20, 2021
9743b9e
Add norace tag
amaury1093 Apr 20, 2021
a323bff
Add CL
amaury1093 Apr 20, 2021
14acc84
rebuild rosetta api test data
Apr 20, 2021
0e57b6f
Update ADR
amaury1093 Apr 21, 2021
0840c18
Rename MsgRoute -> MsgTypeURL
amaury1093 Apr 21, 2021
5cb4301
Fix codec registration
amaury1093 Apr 21, 2021
fc37733
Remove sdk.GetLegacySignBytes
amaury1093 Apr 21, 2021
5d1836b
Update types/tx_msg.go
amaury1093 Apr 21, 2021
fcaedf9
Update x/authz/simulation/operations.go
amaury1093 Apr 21, 2021
7904aef
Move LegacyMsg to legacytx
amaury1093 Apr 21, 2021
b2bf609
Merge branch 'am/adr-31-type-url' of ssh://github.com/cosmos/cosmos-s…
amaury1093 Apr 21, 2021
77e20c2
Update CHANGELOG.md
amaury1093 Apr 22, 2021
3cac0e6
Remove NewAnyWithCustomTypeURL
amaury1093 Apr 22, 2021
113ef64
Keep support for ServiceMsgs
amaury1093 Apr 22, 2021
1c3886d
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 22, 2021
09e81a2
Fix TxBody UnpackInterfaces
amaury1093 Apr 22, 2021
7e05b80
Fix test
amaury1093 Apr 22, 2021
68b7e5f
Address review
amaury1093 Apr 23, 2021
bb33c2b
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 23, 2021
c2a024d
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 27, 2021
f25b2c6
Remove support for ServiceMsg typeURLs
amaury1093 Apr 27, 2021
31e5c2a
Fix lint
amaury1093 Apr 27, 2021
d6ab3eb
Update changelog
amaury1093 Apr 27, 2021
3e7d3ae
Fix tests
amaury1093 Apr 27, 2021
2000ebf
Use sdk.MsgTypeURL everywhere
amaury1093 Apr 27, 2021
a688c73
Fix tests
amaury1093 Apr 27, 2021
666fe92
Fix rosetta, run make rosetta-data
amaury1093 Apr 27, 2021
aa2b26c
Fix rosetta thanks to froydi
amaury1093 Apr 27, 2021
249f857
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 27, 2021
d2a8ae5
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 29, 2021
cd4bc02
Address reviews
amaury1093 Apr 29, 2021
774a4ab
Fix test
amaury1093 Apr 29, 2021
d3c3381
Remove stray log
amaury1093 Apr 30, 2021
98ad2b7
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 30, 2021
e95ae32
Update CL
amaury1093 Apr 30, 2021
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
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
* [\#9205](https://github.com/cosmos/cosmos-sdk/pull/9205) Improve readability in `abci` handleQueryP2P

## Features
### Features

* [\#8965](https://github.com/cosmos/cosmos-sdk/pull/8965) cosmos reflection now provides more information on the application such as: deliverable msgs, sdk.Config info etc (still in alpha stage).
* [\#8559](https://github.com/cosmos/cosmos-sdk/pull/8559) Added Protobuf compatible secp256r1 ECDSA signatures.
* [\#8786](https://github.com/cosmos/cosmos-sdk/pull/8786) Enabled secp256r1 in x/auth.
Expand All @@ -48,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [\#9214](https://github.com/cosmos/cosmos-sdk/pull/9214) Added `new_shares` attribute inside `EventTypeDelegate` event.

### Client Breaking Changes

* [\#8363](https://github.com/cosmos/cosmos-sdk/pull/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
* [\#8346](https://github.com/cosmos/cosmos-sdk/pull/8346) All CLI `tx` commands generate ServiceMsgs by default. Graceful Amino support has been added to ServiceMsgs to support signing legacy Msgs.
* (crypto/ed25519) [\#8690] Adopt zip1215 ed2559 verification rules.
Expand All @@ -59,6 +61,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* CLI: removed `--text` flag from `show-node-id` command; the text format for public keys is not used any more - instead we use ProtoJSON.
* (types) [\#9079](https://github.com/cosmos/cosmos-sdk/issues/9079) Add `AddAmount`/`SubAmount` methods to `sdk.Coin`.
* [\#8628](https://github.com/cosmos/cosmos-sdk/issues/8628) Commands no longer print outputs using `stderr` by default
* [\#9139](https://github.com/cosmos/cosmos-sdk/pull/9139) Querying events:
* via `ServiceMsg` TypeURLs (e.g. `message.action='/cosmos.bank.v1beta1.Msg/Send'`) does not work anymore,
* via legacy `msg.Type()` (e.g. `message.action='send'`) is being deprecated, new `Msg`s won't emit these events.
* Please use concrete `Msg` TypeURLs instead (e.g. `message.action='/cosmos.bank.v1beta1.MsgSend'`).

### API Breaking Changes

Expand Down Expand Up @@ -92,6 +98,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* `codec.JSONMarshaler` → `codec.JSONCodec`
* Removed `BinaryBare` suffix from `BinaryCodec` methods (`MarshalBinaryBare`, `UnmarshalBinaryBare`, ...)
* Removed `Binary` infix from `BinaryCodec` methods (`MarshalBinaryLengthPrefixed`, `UnmarshalBinaryLengthPrefixed`, ...)
* [\#9139](https://github.com/cosmos/cosmos-sdk/pull/9139) `ServiceMsg` TypeURLs (e.g. `/cosmos.bank.v1beta1.Msg/Send`) have been removed, as they don't comply to the Probobuf `Any` spec. Please use `Msg` type TypeURLs (e.g. `/cosmos.bank.v1beta1.MsgSend`). This has multiple consequences:
* The `sdk.ServiceMsg` struct has been removed.
* `sdk.Msg` now only contains `ValidateBasic` and `GetSigners` methods. The remaining methods `GetSignBytes`, `Route` and `Type` are moved to `legacytx.LegacyMsg`.
* The `RegisterCustomTypeURL` function and the `cosmos.base.v1beta1.ServiceMsg` interface have been removed from the interface registry.



Expand Down
37 changes: 20 additions & 17 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)

const (
Expand Down Expand Up @@ -703,37 +704,39 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
}

var (
msgEvents sdk.Events
msgResult *sdk.Result
msgFqName string
err error
msgResult *sdk.Result
eventMsgName string // name to use as value in event `message.action`
err error
)

if svcMsg, ok := msg.(sdk.ServiceMsg); ok {
msgFqName = svcMsg.MethodName
Copy link
Contributor

Choose a reason for hiding this comment

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

The message.action is very important for relayers as it is used to distinguish when the next message event starts/ends and what type of event is occurring. Relayers may be connected to chains on the old version and the new version and thus need to be aware of this change to ensure IBC continues to work between chains with different versions

Does the svcMsg.MethodName != sdk.MsgTypeURL(msg)? Or is there no breaking change here for Msgs migrated to proto messages registered on a Msg service (which from my understanding is the case for the current IBC Msgs). I'm a little fuzzy on the exact differences between the legacy messages, the proto message req/resp types and the msg service router, so please excuse me if I used the terminology wrong

Copy link
Contributor Author

@amaury1093 amaury1093 May 7, 2021

Choose a reason for hiding this comment

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

It's just confusing, to me too. I tried to simplify it like this:

In v0.42, these message.actions were emitted:

  1. either message.action='/cosmos.bank.v1beta1.Msg/Send' if the user explicity sent a ServiceMsg tx (note the 2 /)
  2. or message.action='send' for all other messages (99% of the messages)

After this PR:

  • (1) is completely removed
  • (2) has been converted to message.action='/cosmos.bank.v1beta1.MsgSend' (note only 1 /), so legacy message.action='send' are not emitted anymore (unless the app developer didn't wire up proto registration correctly). This is not retroactive though.

Let me know if that works for IBC.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for the response! This makes sense. This should be fine for relayers, but it will likely require a small change. Relayer should now check for message.action='send' || message.action='/cosmos.bank.v1beta1.MsgSend'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the approach I'm taking too, e.g. if querying deposits here.

handler := app.msgServiceRouter.Handler(msgFqName)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message service method: %s; message index: %d", msgFqName, i)
}
msgResult, err = handler(ctx, svcMsg.Request)
} else {
if handler := app.msgServiceRouter.Handler(msg); handler != nil {
// ADR 031 request type routing
msgResult, err = handler(ctx, msg)
eventMsgName = sdk.MsgTypeURL(msg)
} else if legacyMsg, ok := msg.(legacytx.LegacyMsg); ok {
// legacy sdk.Msg routing
msgRoute := msg.Route()
msgFqName = msg.Type()
// Assuming that the app developer has migrated all their Msgs to
// proto messages and has registered all `Msg services`, then this
// path should never be called, because all those Msgs should be
// registered within the `msgServiceRouter` already.
msgRoute := legacyMsg.Route()
eventMsgName = legacyMsg.Type()
Comment on lines 717 to +723
Copy link
Contributor

Choose a reason for hiding this comment

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

Also a sanity check, ledger signed transactions would not end up here if there is a registered proto message? This would be because the difference between the transaction/message layer?

Copy link
Contributor

Choose a reason for hiding this comment

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

For the modules in the SDK is this ever reached? Docs indicate that the handler type will be deprecated, but it seems like now all the SDK modules could remove their legacy Handler if it is no longer used? Just trying to get a better grasp of what is occurring

Copy link
Contributor Author

@amaury1093 amaury1093 May 7, 2021

Choose a reason for hiding this comment

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

For the modules in the SDK is this ever reached?

For SDK modules, this is never reached. I just confirmed by adding a panic in this else if branch, all simapp/integration/CLI tests pass (only some baseapp unit tests panic, because these tests don't register proto msgs).

but it seems like now all the SDK modules could remove their legacy Handler if it is no longer used?

That's also correct, but we're thinking a better AppModule in general, so it might make sense to remove the legacy Handler with that in one go. ref: #9139 (comment)

handler := app.router.Route(ctx, msgRoute)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i)
}

msgResult, err = handler(ctx, msg)
} else {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg)
}

if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i)
}

msgEvents = sdk.Events{
sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, msgFqName)),
msgEvents := sdk.Events{
sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)),
}
msgEvents = msgEvents.AppendEvents(msgResult.GetEvents())

Expand All @@ -743,7 +746,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
// separate each result.
events = events.AppendEvents(msgEvents)

txMsgData.Data = append(txMsgData.Data, &sdk.MsgData{MsgType: msg.Type(), Data: msgResult.Data})
txMsgData.Data = append(txMsgData.Data, &sdk.MsgData{MsgType: sdk.MsgTypeURL(msg), Data: msgResult.Data})
msgLogs = append(msgLogs, sdk.NewABCIMessageLog(uint32(i), msgResult.Log, msgEvents))
}

Expand Down
44 changes: 35 additions & 9 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ func NewMsgServiceRouter() *MsgServiceRouter {
}

// MsgServiceHandler defines a function type which handles Msg service message.
type MsgServiceHandler = func(ctx sdk.Context, req sdk.MsgRequest) (*sdk.Result, error)
type MsgServiceHandler = func(ctx sdk.Context, req sdk.Msg) (*sdk.Result, error)

// Handler returns the MsgServiceHandler for a given query route path or nil
// Handler returns the MsgServiceHandler for a given msg or nil if not found.
func (msr *MsgServiceRouter) Handler(msg sdk.Msg) MsgServiceHandler {
return msr.routes[sdk.MsgTypeURL(msg)]
}

// HandlerbyTypeURL returns the MsgServiceHandler for a given query route path or nil
// if not found.
func (msr *MsgServiceRouter) Handler(methodName string) MsgServiceHandler {
return msr.routes[methodName]
func (msr *MsgServiceRouter) HandlerbyTypeURL(typeURL string) MsgServiceHandler {
return msr.routes[typeURL]
}

// RegisterService implements the gRPC Server.RegisterService method. sd is a gRPC
Expand All @@ -50,20 +55,38 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
fqMethod := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
methodHandler := method.Handler

var requestTypeName string

// NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry.
// This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself.
// We use a no-op interceptor to avoid actually calling into the handler itself.
_, _ = methodHandler(nil, context.Background(), func(i interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there context available in sd? We should use it instead of context.Background

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not, sd is just a descriptor.

msg, ok := i.(sdk.Msg)
if !ok {
// We panic here because there is no other alternative and the app cannot be initialized correctly
// this should only happen if there is a problem with code generation in which case the app won't
// work correctly anyway.
panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod))
Copy link
Collaborator

Choose a reason for hiding this comment

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

why we don't return an error?

Copy link
Contributor Author

@amaury1093 amaury1093 Apr 29, 2021

Choose a reason for hiding this comment

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

If we return an error, then the app will continue running, with potential encoding errors that are hard to debug down the road.

}

requestTypeName = sdk.MsgTypeURL(msg)
return nil
}, noopInterceptor)

// Check that the service Msg fully-qualified method name has already
// been registered (via RegisterInterfaces). If the user registers a
// service without registering according service Msg type, there might be
// some unexpected behavior down the road. Since we can't return an error
// (`Server.RegisterService` interface restriction) we panic (at startup).
serviceMsg, err := msr.interfaceRegistry.Resolve(fqMethod)
if err != nil || serviceMsg == nil {
reqType, err := msr.interfaceRegistry.Resolve(requestTypeName)
if err != nil || reqType == nil {
panic(
fmt.Errorf(
"type_url %s has not been registered yet. "+
"Before calling RegisterService, you must register all interfaces by calling the `RegisterInterfaces` "+
"method on module.BasicManager. Each module should call `msgservice.RegisterMsgServiceDesc` inside its "+
"`RegisterInterfaces` method with the `_Msg_serviceDesc` generated by proto-gen",
fqMethod,
requestTypeName,
),
)
}
Expand All @@ -72,7 +95,7 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
// registered more than once, then we should error. Since we can't
// return an error (`Server.RegisterService` interface restriction) we
// panic (at startup).
_, found := msr.routes[fqMethod]
Copy link
Collaborator

Choose a reason for hiding this comment

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

whenever I see it I always read FAQ method 🤣

_, found := msr.routes[requestTypeName]
if found {
panic(
fmt.Errorf(
Expand All @@ -83,7 +106,7 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
)
}

msr.routes[fqMethod] = func(ctx sdk.Context, req sdk.MsgRequest) (*sdk.Result, error) {
msr.routes[requestTypeName] = func(ctx sdk.Context, req sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
interceptor := func(goCtx context.Context, _ interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
goCtx = context.WithValue(goCtx, sdk.SdkContextKey, ctx)
Expand Down Expand Up @@ -112,3 +135,6 @@ func (msr *MsgServiceRouter) SetInterfaceRegistry(interfaceRegistry codectypes.I
}

func noopDecoder(_ interface{}) error { return nil }
func noopInterceptor(_ context.Context, _ interface{}, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (interface{}, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions baseapp/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func TestMsgService(t *testing.T) {
)
_ = app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})

msg := testdata.NewServiceMsgCreateDog(&testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}})
msg := testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}}
txBuilder := encCfg.TxConfig.NewTxBuilder()
txBuilder.SetFeeAmount(testdata.NewTestFeeAmount())
txBuilder.SetGasLimit(testdata.NewTestGasLimit())
err := txBuilder.SetMsgs(msg)
err := txBuilder.SetMsgs(&msg)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

// First round: we gather all the signer infos. We use the "set empty
Expand Down
12 changes: 4 additions & 8 deletions client/tx/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand All @@ -39,10 +38,7 @@ var (
},
}
msg0 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 1)))
msg1 = sdk.ServiceMsg{
MethodName: "/cosmos.bank.v1beta1.Msg/Send",
Request: banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2))),
}
msg1 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2)))
)

func buildTestTx(t *testing.T, builder client.TxBuilder) {
Expand Down Expand Up @@ -88,7 +84,7 @@ func (s *TestSuite) TestCopyTx() {
s.Require().Equal(sigsV2_1, sigsV2_2)
s.Require().Equal(protoBuilder.GetTx().GetSigners(), protoBuilder2.GetTx().GetSigners())
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[0], protoBuilder2.GetTx().GetMsgs()[0])
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1].(sdk.ServiceMsg).Request, protoBuilder2.GetTx().GetMsgs()[1]) // We lose the "ServiceMsg" information
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1], protoBuilder2.GetTx().GetMsgs()[1])

// amino -> proto -> amino
aminoBuilder = s.aminoCfg.NewTxBuilder()
Expand Down Expand Up @@ -120,7 +116,7 @@ func (s *TestSuite) TestConvertTxToStdTx() {
s.Require().Equal(gas, stdTx.Fee.Gas)
s.Require().Equal(fee, stdTx.Fee.Amount)
s.Require().Equal(msg0, stdTx.Msgs[0])
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
s.Require().Equal(msg1, stdTx.Msgs[1])
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
s.Require().Equal(sig.PubKey, stdTx.Signatures[0].PubKey)
s.Require().Equal(sig.Data.(*signing2.SingleSignatureData).Signature, stdTx.Signatures[0].Signature)
Expand All @@ -140,7 +136,7 @@ func (s *TestSuite) TestConvertTxToStdTx() {
s.Require().Equal(gas, stdTx.Fee.Gas)
s.Require().Equal(fee, stdTx.Fee.Amount)
s.Require().Equal(msg0, stdTx.Msgs[0])
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
s.Require().Equal(msg1, stdTx.Msgs[1])
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
s.Require().Empty(stdTx.Signatures)

Expand Down
10 changes: 2 additions & 8 deletions codec/types/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,14 @@ func NewAnyWithValue(v proto.Message) (*Any, error) {
if v == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, "Expecting non nil value to create a new Any")
}
return NewAnyWithCustomTypeURL(v, "/"+proto.MessageName(v))
}

// NewAnyWithCustomTypeURL same as NewAnyWithValue, but sets a custom type url, instead
// using the one from proto.Message.
// NOTE: This functions should be only used for types with additional logic bundled
// into the protobuf Any serialization. For simple marshaling you should use NewAnyWithValue.
func NewAnyWithCustomTypeURL(v proto.Message, typeURL string) (*Any, error) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
bz, err := proto.Marshal(v)
if err != nil {
return nil, err
}

return &Any{
TypeUrl: typeURL,
TypeUrl: "/" + proto.MessageName(v),
Value: bz,
cachedValue: v,
}, nil
Expand Down
6 changes: 2 additions & 4 deletions codec/types/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro
return nil, errAlways
}

const fauxURL = "/anyhere"

var eom = &errOnMarshal{}

// Ensure that returning an error doesn't suddenly allocate and waste bytes.
// See https://github.com/cosmos/cosmos-sdk/issues/8537
func TestNewAnyWithCustomTypeURLWithErrorNoAllocation(t *testing.T) {
var ms1, ms2 runtime.MemStats
runtime.ReadMemStats(&ms1)
any, err := types.NewAnyWithCustomTypeURL(eom, fauxURL)
any, err := types.NewAnyWithValue(eom)
runtime.ReadMemStats(&ms2)
// Ensure that no fresh allocation was made.
if diff := ms2.HeapAlloc - ms1.HeapAlloc; diff > 0 {
Expand All @@ -52,7 +50,7 @@ func BenchmarkNewAnyWithCustomTypeURLWithErrorReturned(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
any, err := types.NewAnyWithCustomTypeURL(eom, fauxURL)
any, err := types.NewAnyWithValue(eom)
if err == nil {
b.Fatal("err wasn't returned")
}
Expand Down
11 changes: 0 additions & 11 deletions codec/types/interface_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ type InterfaceRegistry interface {
// registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{})
RegisterImplementations(iface interface{}, impls ...proto.Message)

// RegisterCustomTypeURL allows a protobuf message to be registered as a
// google.protobuf.Any with a custom typeURL (besides its own canonical
// typeURL). iface should be an interface as type, as in RegisterInterface
// and RegisterImplementations.
//
// Ex:
// This will allow us to pack service methods in Any's using the full method name
// as the type URL and the request body as the value, and allow us to unpack
// such packed methods using the normal UnpackAny method for the interface iface.
RegisterCustomTypeURL(iface interface{}, typeURL string, impl proto.Message)

// ListAllInterfaces list the type URLs of all registered interfaces.
ListAllInterfaces() []string

Expand Down
Loading