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

chore: remove x/gov dependencies in x/distr #16587

Merged
merged 15 commits into from
Jun 19, 2023
Merged
2 changes: 1 addition & 1 deletion tests/integration/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func TestMsgSetSendEnabled(t *testing.T) {
"invalid authority",
"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
addr1Str,
"invalid signer",
"expected authority account as only signer for proposal message",
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ var (
ErrInvalidKey = errors.Register(ModuleName, 7, "invalid key")
ErrDuplicateEntry = errors.Register(ModuleName, 8, "duplicate entry")
ErrMultipleSenders = errors.Register(ModuleName, 9, "multiple senders not allowed")
ErrInvalidSigner = errors.Register(ModuleName, 10, "invalid signer")
ErrInvalidSigner = errors.Register(ModuleName, 10, "expected authority account as only signer for proposal message")
)
3 changes: 1 addition & 2 deletions x/distribution/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

type msgServer struct {
Expand Down Expand Up @@ -214,7 +213,7 @@ func (k *Keeper) validateAuthority(authority string) error {
}

if k.authority != authority {
return errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, authority)
return errors.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, authority)
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/simulation"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
staking "github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand Down Expand Up @@ -249,7 +248,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
}

// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
authority := authtypes.NewModuleAddress(types.GovModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
Expand Down
6 changes: 0 additions & 6 deletions x/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// RegisterLegacyAminoCodec registers the necessary x/distribution interfaces
Expand Down Expand Up @@ -36,10 +35,5 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgDepositValidatorRewardsPool{},
)

registry.RegisterImplementations(
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
(*govtypes.Content)(nil),
&CommunityPoolSpendProposal{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
1 change: 1 addition & 0 deletions x/distribution/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ var (
ErrNoValidatorExists = errors.Register(ModuleName, 12, "validator does not exist")
ErrNoDelegationExists = errors.Register(ModuleName, 13, "delegation does not exist")
ErrInvalidProposalContent = errors.Register(ModuleName, 14, "invalid proposal content")
ErrInvalidSigner = errors.Register(ModuleName, 15, "expected authority account as only signer for proposal message")
Copy link
Member

Choose a reason for hiding this comment

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

Some existing ErrInvalidSigner have a different message, could we standardize them?

)
3 changes: 3 additions & 0 deletions x/distribution/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (

// RouterKey is the message route for distribution
RouterKey = ModuleName

// GovModuleName is the name of the gov module
GovModuleName = "gov"
)

// Keys for distribution store
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (csp *CommunityPoolSpendProposal) ValidateBasic() error {
}

// validateAbstract is semantically duplicated from x/gov/types/v1beta1/proposal.go to avoid a cyclic dependency
// between these two modules, x/distribution and x/gov.
// between these two modules (x/distribution and x/gov).
// See: https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/x/gov/types/v1beta1/proposal.go#L196-L214
func validateAbstract(c *CommunityPoolSpendProposal) error {
const (
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() {
)
},
expErr: true,
expErrMsg: "expected gov account as only signer for proposal message",
expErrMsg: "expected authority account as only signer for proposal message",
},
"signer isn't gov account": {
preRun: func() (*v1.MsgSubmitProposal, error) {
Expand All @@ -175,7 +175,7 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() {
)
},
expErr: true,
expErrMsg: "expected gov account as only signer for proposal message",
expErrMsg: "expected authority account as only signer for proposal message",
},
"invalid msg handler": {
preRun: func() (*v1.MsgSubmitProposal, error) {
Expand Down
2 changes: 1 addition & 1 deletion x/gov/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
ErrUnroutableProposalMsg = errors.Register(ModuleName, 10, "proposal message not recognized by router")
ErrNoProposalMsgs = errors.Register(ModuleName, 11, "no messages proposed")
ErrInvalidProposalMsg = errors.Register(ModuleName, 12, "invalid proposal message")
ErrInvalidSigner = errors.Register(ModuleName, 13, "expected gov account as only signer for proposal message")
ErrInvalidSigner = errors.Register(ModuleName, 13, "expected authority account as only signer for proposal message")
ErrMetadataTooLong = errors.Register(ModuleName, 15, "metadata too long")
ErrMinDepositTooSmall = errors.Register(ModuleName, 16, "minimum deposit is too small")
ErrInvalidProposer = errors.Register(ModuleName, 18, "invalid proposer")
Expand Down
5 changes: 5 additions & 0 deletions x/gov/types/v1beta1/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
)

// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
Expand All @@ -32,6 +33,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*Content)(nil),
&TextProposal{},
)
registry.RegisterImplementations(
Copy link
Member

Choose a reason for hiding this comment

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

are we fine with introducing this dependency?

Copy link
Member

Choose a reason for hiding this comment

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

Gov already depends on distribution so it isn't a new dependency introduction.

(*Content)(nil),
&distrtypes.CommunityPoolSpendProposal{}, // nolint: staticcheck // avoid using `CommunityPoolSpendProposal`, might be reomved in future.
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
2 changes: 1 addition & 1 deletion x/mint/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package types

import "cosmossdk.io/errors"

var ErrInvalidSigner = errors.Register(ModuleName, 1, "invalid signer")
var ErrInvalidSigner = errors.Register(ModuleName, 1, "expected authority account as only signer for proposal message")