-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(sims): rm usage of GetSignBytes from NewOperationMsg #16036
Changes from 4 commits
09d9e6b
82ca71f
3091b43
e7bf7bb
4a367d4
5d45211
f28eda3
53b1522
38c95b8
bbf9a4e
01e92b9
2c120b5
b7e7c22
1370739
a9e188d
3986662
0e4559d
5a92828
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package simulation | ||
|
||
import ( | ||
// NewOperationMsg (in this package) requires all the types to be imported for the amionJSON marshal to properly | ||
// handle any types, and any types are required to support gogo types being generated, since they are not | ||
// proto reflect capable. | ||
_ "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" | ||
_ "cosmossdk.io/api/cosmos/app/v1alpha1" | ||
_ "cosmossdk.io/api/cosmos/auth/module/v1" | ||
_ "cosmossdk.io/api/cosmos/auth/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/authz/module/v1" | ||
_ "cosmossdk.io/api/cosmos/authz/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/autocli/v1" | ||
_ "cosmossdk.io/api/cosmos/bank/module/v1" | ||
_ "cosmossdk.io/api/cosmos/bank/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/base/abci/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/base/node/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/base/query/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/base/reflection/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/base/reflection/v2alpha1" | ||
_ "cosmossdk.io/api/cosmos/base/tendermint/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/base/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/consensus/module/v1" | ||
_ "cosmossdk.io/api/cosmos/consensus/v1" | ||
_ "cosmossdk.io/api/cosmos/crisis/module/v1" | ||
_ "cosmossdk.io/api/cosmos/crisis/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/crypto/ed25519" | ||
_ "cosmossdk.io/api/cosmos/crypto/hd/v1" | ||
_ "cosmossdk.io/api/cosmos/crypto/multisig" | ||
_ "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/crypto/secp256k1" | ||
_ "cosmossdk.io/api/cosmos/crypto/secp256r1" | ||
_ "cosmossdk.io/api/cosmos/distribution/module/v1" | ||
_ "cosmossdk.io/api/cosmos/distribution/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/evidence/module/v1" | ||
_ "cosmossdk.io/api/cosmos/evidence/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/feegrant/module/v1" | ||
_ "cosmossdk.io/api/cosmos/feegrant/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/genutil/module/v1" | ||
_ "cosmossdk.io/api/cosmos/genutil/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/gov/module/v1" | ||
_ "cosmossdk.io/api/cosmos/gov/v1" | ||
_ "cosmossdk.io/api/cosmos/gov/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/group/module/v1" | ||
_ "cosmossdk.io/api/cosmos/group/v1" | ||
_ "cosmossdk.io/api/cosmos/mint/module/v1" | ||
_ "cosmossdk.io/api/cosmos/mint/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/msg/textual/v1" | ||
_ "cosmossdk.io/api/cosmos/msg/v1" | ||
_ "cosmossdk.io/api/cosmos/nft/module/v1" | ||
_ "cosmossdk.io/api/cosmos/nft/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/orm/module/v1alpha1" | ||
_ "cosmossdk.io/api/cosmos/orm/query/v1alpha1" | ||
_ "cosmossdk.io/api/cosmos/orm/v1" | ||
_ "cosmossdk.io/api/cosmos/orm/v1alpha1" | ||
_ "cosmossdk.io/api/cosmos/params/module/v1" | ||
_ "cosmossdk.io/api/cosmos/params/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/query/v1" | ||
_ "cosmossdk.io/api/cosmos/reflection/v1" | ||
_ "cosmossdk.io/api/cosmos/slashing/module/v1" | ||
_ "cosmossdk.io/api/cosmos/slashing/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/staking/module/v1" | ||
_ "cosmossdk.io/api/cosmos/staking/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/store/snapshots/v1" | ||
_ "cosmossdk.io/api/cosmos/store/streaming/abci" | ||
_ "cosmossdk.io/api/cosmos/store/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/tx/config/v1" | ||
_ "cosmossdk.io/api/cosmos/tx/signing/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/tx/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/upgrade/module/v1" | ||
_ "cosmossdk.io/api/cosmos/upgrade/v1beta1" | ||
_ "cosmossdk.io/api/cosmos/vesting/module/v1" | ||
_ "cosmossdk.io/api/cosmos/vesting/v1beta1" | ||
) | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,11 +5,14 @@ import ( | |||||
"math/rand" | ||||||
"time" | ||||||
|
||||||
"google.golang.org/protobuf/types/known/anypb" | ||||||
|
||||||
"cosmossdk.io/x/tx/signing/aminojson" | ||||||
"github.com/cosmos/cosmos-sdk/baseapp" | ||||||
"github.com/cosmos/cosmos-sdk/codec" | ||||||
"github.com/cosmos/cosmos-sdk/codec/types" | ||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
"github.com/cosmos/cosmos-sdk/types/kv" | ||||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" | ||||||
) | ||||||
|
||||||
// Deprecated: Use WeightedProposalMsg instead. | ||||||
|
@@ -95,11 +98,20 @@ func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec | |||||
moduleName = msgType | ||||||
} | ||||||
|
||||||
if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { | ||||||
return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes()) | ||||||
anyMsg, err := types.NewAnyWithValue(msg) | ||||||
if err != nil { | ||||||
panic(err) | ||||||
} | ||||||
encoder := aminojson.NewAminoJSON() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The constructor name should match the type name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. This should be a separate PR since it necessitates an x/tx release, please review when you get a chance. |
||||||
msgBytes, err := encoder.Marshal(&anypb.Any{ | ||||||
TypeUrl: anyMsg.TypeUrl, | ||||||
Value: anyMsg.Value, | ||||||
}) | ||||||
if err != nil { | ||||||
panic(err) | ||||||
} | ||||||
|
||||||
return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg)) | ||||||
return NewOperationMsgBasic(moduleName, msgType, comment, ok, msgBytes) | ||||||
} | ||||||
|
||||||
// NoOpMsg - create a no-operation message | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of this should be necessary. This is only needed because the amino JSON encoder isn't properly setup to take a custom file resolver and use dynamicpb when there are is no concrete type. It should be possible to pass in
proto.HybridResolver
as an option toaminojson.NewEncoder
and be done, without all these importsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following your suggestion. The usage in question in the aminojson package requires a
protoregistry.MessageTypeResolver
, not aProtoFileResolver
which is what aphoto.HybridResolver
is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the type resolution step up into this sims package to prevent passing an any to aminojson.Encoder, it would need an exclusion with types without amino.name. But I still need a typeResolver to get a protoreflect enabled msg for aminojson.Encoder. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use dyncamicpb + the file resolver if the typeresolver doesn't have the type like I was saying above. Also the encoder should be parameterized by both file resolver and type resolver. See what autocli does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we tackle this in a separate PR? I don't think any change is required here for sims to remove this last usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so but addressing this issue with aminojson takes priority in my opinion. We said that it would work dynamically without depending on the API module. This PR has uncovered that this is not true. So we need to address that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge both, I don't see them as blocking, but all right.