Skip to content

Commit

Permalink
fix!: Fix group amino codec (cosmos#13307)
Browse files Browse the repository at this point in the history
* fix!: Fix group amino codec

* changelog
  • Loading branch information
amaury1093 authored and ryanchristo committed Dec 14, 2022
1 parent 152a9f7 commit 4b46d09
Show file tree
Hide file tree
Showing 21 changed files with 154 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

<<<<<<< HEAD
<<<<<<< HEAD
* (x/gov) [#14214](https://github.com/cosmos/cosmos-sdk/pull/14214) Fix gov v0.46 migration to v1 votes.
* Also provide a helper function `govv046.Migrate_V0466_To_V0467` for migrating a chain already on v0.46 with versions <=v0.46.6 to the latest v0.46.7 correct state.
Expand Down Expand Up @@ -131,6 +132,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#13656](https://github.com/cosmos/cosmos-sdk/pull/13659) Rename `server.FlagIAVLFastNode` to `server.FlagDisableIAVLFastNode` for clarity.
=======
=======
* (codec) [#13307](https://github.com/cosmos/cosmos-sdk/pull/13307) Register all modules' `Msg`s with group's ModuleCdc so that Amino sign bytes are correctly generated.
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
* (codec) [#13196](https://github.com/cosmos/cosmos-sdk/pull/13196) Register all modules' `Msg`s with gov's ModuleCdc so that Amino sign bytes are correctly generated.
* (x/distribution) [#12852](https://github.com/cosmos/cosmos-sdk/pull/12852) Deprecate `CommunityPoolSpendProposal`. Please execute a `MsgCommunityPoolSpend` message via the new v1 `x/gov` module instead. This message can be used to directly fund the `x/gov` module account.
* (x/bank) [#12610](https://github.com/cosmos/cosmos-sdk/pull/12610) `MsgMultiSend` now allows only a single input.
Expand Down
6 changes: 4 additions & 2 deletions docs/core/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,24 @@ Note, there are length-prefixed variants of the above functionality and this is
typically used for when the data needs to be streamed or grouped together
(e.g. `ResponseDeliverTx.Data`)

#### Authz authorizations and Gov proposals
#### Authz authorizations and Gov/Group proposals

Since authz's `MsgExec` and `MsgGrant` message types, as well as gov's `MsgSubmitProposal`, can contain different messages instances, it is important that developers
Since authz's `MsgExec` and `MsgGrant` message types, as well as gov's and group's `MsgSubmitProposal`, can contain different messages instances, it is important that developers
add the following code inside the `init` method of their module's `codec.go` file:

```go
import (
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
)

init() {
// Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
}
```

Expand Down
8 changes: 8 additions & 0 deletions x/auth/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the account interfaces and concrete types on the
Expand Down Expand Up @@ -58,8 +62,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/auth/vesting/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the vesting interfaces and concrete types on the
Expand Down Expand Up @@ -83,8 +87,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/authz/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types
Expand Down Expand Up @@ -47,8 +51,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types
Expand Down Expand Up @@ -51,8 +55,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/crisis/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types
Expand Down Expand Up @@ -43,8 +47,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the necessary x/distribution interfaces and concrete types
Expand Down Expand Up @@ -57,8 +61,12 @@ func init() {
// instances.
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/evidence/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
Expand Down Expand Up @@ -49,8 +53,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/feegrant/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers the necessary x/feegrant interfaces and concrete types
Expand Down Expand Up @@ -66,8 +70,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
1 change: 1 addition & 0 deletions x/gov/codec/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ codec.go file as follows:
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
}
Expand Down
8 changes: 8 additions & 0 deletions x/gov/types/v1/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
Expand Down Expand Up @@ -41,8 +45,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
8 changes: 8 additions & 0 deletions x/gov/types/v1beta1/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
Expand Down Expand Up @@ -46,8 +50,12 @@ func init() {
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
11 changes: 11 additions & 0 deletions x/group/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
<<<<<<< HEAD
<<<<<<< HEAD
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers all the necessary group module concrete
Expand Down Expand Up @@ -68,18 +72,25 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

func init() {
<<<<<<< HEAD
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
sdk.RegisterLegacyAminoCodec(amino)

>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
// Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
<<<<<<< HEAD
<<<<<<< HEAD
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
>>>>>>> d9972c4dd (fix!: Fix gov amino codec (#13196))
=======
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
11 changes: 11 additions & 0 deletions x/group/codec/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
Package codec provides a singleton instance of Amino codec that should be used to register
any concrete type that can later be referenced inside a MsgSubmitProposal instance so that they
can be (de)serialized properly.
<<<<<<< HEAD
=======
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
Amino types should be ideally registered inside this codec within the init function of each module's
codec.go file as follows:
func init() {
// ...
<<<<<<< HEAD
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
The codec instance is put inside this package and not the x/gov/types package in order to avoid any dependency cycle.
Expand Down
Loading

0 comments on commit 4b46d09

Please sign in to comment.