-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check if operator is allowed to join on msg execution (#16)
## Description This PR adds a missing check to make sure that an operator is allowed to join a service while executing `MsgJoinService` messages. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### 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/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] 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/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [x] 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) (cherry picked from commit f5815d3)
- Loading branch information
Showing
5 changed files
with
330 additions
and
12 deletions.
There are no files selected for viewing
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
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,11 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type Keeper interface { | ||
IterateAllOperatorsJoinedServices(ctx context.Context, action func(operatorID uint32, serviceID uint32) (stop bool, err error)) error | ||
CanOperatorValidateService(ctx context.Context, serviceID uint32, operatorID uint32) (bool, error) | ||
RemoveServiceFromOperatorJoinedServices(ctx context.Context, operatorID uint32, serviceID uint32) error | ||
} |
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,52 @@ | ||
package v2 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// MigrateStore performs in-place store migrations from v1 to v2. The migrations include: | ||
// - Removing joined operators that are not allowed by the services they have joined | ||
func MigrateStore(ctx sdk.Context, keeper Keeper) error { | ||
return removeNotAllowedJoinedServices(ctx, keeper) | ||
} | ||
|
||
type operatorJoinedService struct { | ||
operatorID uint32 | ||
serviceID uint32 | ||
} | ||
|
||
func removeNotAllowedJoinedServices(ctx sdk.Context, keeper Keeper) error { | ||
// Get the list of deletable operators (i.e. operators that have joined services that they should not have joined) | ||
var operatorsToDelete []operatorJoinedService | ||
err := keeper.IterateAllOperatorsJoinedServices(ctx, func(operatorID uint32, serviceID uint32) (stop bool, err error) { | ||
canOperatorValidator, err := keeper.CanOperatorValidateService(ctx, serviceID, operatorID) | ||
if err != nil { | ||
return true, err | ||
} | ||
|
||
if canOperatorValidator { | ||
// Skip if the operator is allowed to join the service | ||
return false, nil | ||
} | ||
|
||
// Add the service to the list of deletable services if the operator should have not been allowed to join it | ||
operatorsToDelete = append(operatorsToDelete, operatorJoinedService{ | ||
operatorID: operatorID, | ||
serviceID: serviceID, | ||
}) | ||
|
||
return false, nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, service := range operatorsToDelete { | ||
err = keeper.RemoveServiceFromOperatorJoinedServices(ctx, service.operatorID, service.serviceID) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.