Skip to content

Commit

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

* changelog

(cherry picked from commit 340c01b)

# Conflicts:
#	CHANGELOG.md
#	docs/core/encoding.md
#	x/auth/types/codec.go
#	x/auth/vesting/types/codec.go
#	x/authz/codec.go
#	x/bank/types/codec.go
#	x/crisis/types/codec.go
#	x/distribution/types/codec.go
#	x/evidence/types/codec.go
#	x/feegrant/codec.go
#	x/gov/codec/doc.go
#	x/gov/types/v1/codec.go
#	x/gov/types/v1beta1/codec.go
#	x/group/codec.go
#	x/group/simulation/operations_test.go
#	x/mint/types/codec.go
#	x/slashing/types/codec.go
#	x/staking/types/codec.go
#	x/upgrade/types/codec.go
  • Loading branch information
amaury1093 authored and mergify[bot] committed Nov 30, 2022
1 parent 72699f7 commit 05e27cb
Show file tree
Hide file tree
Showing 23 changed files with 329 additions and 36 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,25 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

<<<<<<< HEAD
* (x/group) [#13876](https://github.com/cosmos/cosmos-sdk/pull/13876) Fix group MinExecutionPeriod that is checked on execution now, instead of voting period end.
=======
* (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.
* (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.
* (x/bank) [#12630](https://github.com/cosmos/cosmos-sdk/pull/12630) Migrate `x/bank` to self-managed parameters and deprecate its usage of `x/params`.
* (x/auth) [#12475](https://github.com/cosmos/cosmos-sdk/pull/12475) Migrate `x/auth` to self-managed parameters and deprecate its usage of `x/params`.
* (x/slashing) [#12399](https://github.com/cosmos/cosmos-sdk/pull/12399) Migrate `x/slashing` to self-managed parameters and deprecate its usage of `x/params`.
* (x/mint) [#12363](https://github.com/cosmos/cosmos-sdk/pull/12363) Migrate `x/mint` to self-managed parameters and deprecate it's usage of `x/params`.
* (x/distribution) [#12434](https://github.com/cosmos/cosmos-sdk/pull/12434) Migrate `x/distribution` to self-managed parameters and deprecate it's usage of `x/params`.
* (x/crisis) [#12445](https://github.com/cosmos/cosmos-sdk/pull/12445) Migrate `x/crisis` to self-managed parameters and deprecate it's usage of `x/params`.
* (x/gov) [#12631](https://github.com/cosmos/cosmos-sdk/pull/12631) Migrate `x/gov` to self-managed parameters and deprecate it's usage of `x/params`.
* (x/staking) [#12409](https://github.com/cosmos/cosmos-sdk/pull/12409) Migrate `x/staking` to self-managed parameters and deprecate it's usage of `x/params`.
* (x/bank) [#11859](https://github.com/cosmos/cosmos-sdk/pull/11859) Move the SendEnabled information out of the Params and into the state store directly.
* (x/gov) [#12771](https://github.com/cosmos/cosmos-sdk/pull/12771) Initial deposit requirement for proposals at submission time.
* (x/staking) [#12967](https://github.com/cosmos/cosmos-sdk/pull/12967) `unbond` now creates only one unbonding delegation entry when multiple unbondings exist at a single height (e.g. through multiple messages in a transaction).
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
### API Breaking Changes

Expand Down
19 changes: 19 additions & 0 deletions docs/core/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,37 @@ 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`)

<<<<<<< HEAD
#### Authz authorizations

Since the `MsgExec` message type 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"
=======
#### Authz authorizations and Gov/Group proposals

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"
)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
```

Expand Down
10 changes: 10 additions & 0 deletions x/auth/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -52,4 +57,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/auth/vesting/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -77,4 +82,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/authz/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -41,4 +46,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/x/authz"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -45,4 +50,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/crisis/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -37,4 +42,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -50,4 +55,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/evidence/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -43,4 +48,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/feegrant/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -60,4 +65,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
19 changes: 19 additions & 0 deletions x/gov/codec/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
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.
Amino types should be ideally registered inside this codec within the init function of each module's
codec.go file as follows:
func init() {
// ...
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
}
The codec instance is put inside this package and not the x/gov/types package in order to avoid any dependency cycle.
*/
package codec
10 changes: 10 additions & 0 deletions x/gov/types/v1/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -47,4 +52,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
10 changes: 10 additions & 0 deletions x/gov/types/v1beta1/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
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 @@ -50,4 +55,9 @@ func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
<<<<<<< HEAD
=======
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
23 changes: 15 additions & 8 deletions x/group/codec.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package group

import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
<<<<<<< HEAD
=======
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
)

// RegisterLegacyAminoCodec registers all the necessary group module concrete
// types and interfaces with the provided codec reference.
// These types are used for Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func RegisterLegacyAminoCodec(cdc *codectypes.LegacyAmino) {
cdc.RegisterInterface((*DecisionPolicy)(nil), nil)
cdc.RegisterConcrete(&ThresholdDecisionPolicy{}, "cosmos-sdk/ThresholdDecisionPolicy", nil)
cdc.RegisterConcrete(&PercentageDecisionPolicy{}, "cosmos-sdk/PercentageDecisionPolicy", nil)
Expand Down Expand Up @@ -62,17 +66,20 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
)
}

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

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

// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
=======
// 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)
>>>>>>> 340c01bf5 (fix!: Fix group amino codec (#13307))
}
18 changes: 18 additions & 0 deletions x/group/codec/cdc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package codec

import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
cryptocodec.RegisterCrypto(Amino)
codec.RegisterEvidences(Amino)
sdk.RegisterLegacyAminoCodec(Amino)
}
19 changes: 19 additions & 0 deletions x/group/codec/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
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.
Amino types should be ideally registered inside this codec within the init function of each module's
codec.go file as follows:
func init() {
// ...
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
}
The codec instance is put inside this package and not the x/gov/types package in order to avoid any dependency cycle.
*/
package codec
Loading

0 comments on commit 05e27cb

Please sign in to comment.