-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing subspaces authz migration (#981)
## Description This PR adds the `x/subspaces` authorization migrations that was missing from `v4.2.0`. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [x] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
- Loading branch information
Showing
10 changed files
with
702 additions
and
11 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changeset/entries/949c3ef6e6aaea51b5bb253dc3eedc16e6f3b9dd6dfbf0cbb7406719d61285d8.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type: fix | ||
module: x/subspaces | ||
pull_request: 981 | ||
description: Added missing subspaces authorizations migration | ||
backward_compatible: true | ||
date: 2022-07-29T08:13:00.050919588Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
package desmos.subspaces.v2.authz; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/desmos-labs/desmos/v4/x/subspaces/legacy/v2"; | ||
|
||
// GenericSubspaceAuthorization defines an authorization to perform any | ||
// operation only inside a specific subspace. | ||
message GenericSubspaceAuthorization { | ||
option (cosmos_proto.implements_interface) = "Authorization"; | ||
|
||
// Ids of the subspaces inside which to grant the permission | ||
repeated uint64 subspaces_ids = 1 [ (gogoproto.customname) = "SubspacesIDs" ]; | ||
|
||
// Msg, identified by it's type URL, to grant unrestricted permissions to | ||
// execute within the subspace | ||
string msg = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package v2 | ||
|
||
// DONTCOVER | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/authz" | ||
|
||
"github.com/desmos-labs/desmos/v4/x/subspaces/types" | ||
) | ||
|
||
// TODO: Revisit this once we have proper gas fee framework. | ||
// Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072 | ||
const gasCostPerIteration = uint64(10) | ||
|
||
var ( | ||
_ authz.Authorization = &GenericSubspaceAuthorization{} | ||
) | ||
|
||
// NewGenericSubspaceAuthorization creates a new GenericSubspaceAuthorization object. | ||
func NewGenericSubspaceAuthorization(subspacesIDs []uint64, msgTypeURL string) *GenericSubspaceAuthorization { | ||
return &GenericSubspaceAuthorization{ | ||
SubspacesIDs: subspacesIDs, | ||
Msg: msgTypeURL, | ||
} | ||
} | ||
|
||
// MsgTypeURL implements Authorization.MsgTypeURL. | ||
func (a GenericSubspaceAuthorization) MsgTypeURL() string { | ||
return a.Msg | ||
} | ||
|
||
// Accept implements Authorization.Accept. | ||
func (a GenericSubspaceAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { | ||
switch msg := msg.(type) { | ||
|
||
case types.SubspaceMsg: | ||
for _, subspaceID := range a.SubspacesIDs { | ||
ctx.GasMeter().ConsumeGas(gasCostPerIteration, "generic subspace authorization") | ||
if subspaceID == msg.GetSubspaceID() { | ||
return authz.AcceptResponse{Accept: true}, nil | ||
} | ||
} | ||
return authz.AcceptResponse{Accept: false}, nil | ||
|
||
default: | ||
return authz.AcceptResponse{}, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown msg type") | ||
} | ||
} | ||
|
||
// ValidateBasic implements Authorization.ValidateBasic. | ||
func (a GenericSubspaceAuthorization) ValidateBasic() error { | ||
if a.SubspacesIDs == nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "at least one subspace id is required") | ||
} | ||
|
||
for _, subspaceID := range a.SubspacesIDs { | ||
if subspaceID == 0 { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid subspace id") | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.