-
Notifications
You must be signed in to change notification settings - Fork 870
Add msg send dynamic access ops #303
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,82 @@ | ||
| package aclbankmapping | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" | ||
| aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" | ||
| acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
| utils "github.com/sei-protocol/sei-chain/aclmapping/utils" | ||
| ) | ||
|
|
||
| var ErrorInvalidMsgType = fmt.Errorf("invalid message received for bank module") | ||
|
|
||
| func GetBankDepedencyGenerator() aclkeeper.DependencyGeneratorMap { | ||
| dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) | ||
|
|
||
| // dex place orders | ||
| placeOrdersKey := acltypes.GenerateMessageKey(&banktypes.MsgSend{}) | ||
| dependencyGeneratorMap[placeOrdersKey] = MsgSendDependencyGenerator | ||
|
|
||
| return dependencyGeneratorMap | ||
| } | ||
|
|
||
| // TODO:: we can make resource types more granular (e.g KV_PARAM or KV_BANK_BALANCE) | ||
| func MsgSendDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { | ||
| msgSend, ok := msg.(*banktypes.MsgSend) | ||
| if !ok { | ||
| return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType | ||
| } | ||
|
|
||
| accessOperations := []sdkacltypes.AccessOperation{ | ||
| // MsgSend also checks if the coin denom is enabled, but the information is from the params. | ||
| // Changing the param would require a gov proposal, which is synchrounos by default | ||
|
|
||
| // Checks balance of sender | ||
| { | ||
| AccessType: sdkacltypes.AccessType_READ, | ||
| ResourceType: sdkacltypes.ResourceType_KV, | ||
| IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.FromAddress), | ||
| }, | ||
| // Reduce the amount from the sender's balance | ||
| { | ||
| AccessType: sdkacltypes.AccessType_WRITE, | ||
| ResourceType: sdkacltypes.ResourceType_KV, | ||
| IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.FromAddress), | ||
| }, | ||
|
|
||
| // Checks balance for receiver | ||
| { | ||
| AccessType: sdkacltypes.AccessType_READ, | ||
| ResourceType: sdkacltypes.ResourceType_KV, | ||
| IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.ToAddress), | ||
| }, | ||
| { | ||
| AccessType: sdkacltypes.AccessType_WRITE, | ||
| ResourceType: sdkacltypes.ResourceType_KV, | ||
| IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.ToAddress), | ||
| }, | ||
|
|
||
| // Tries to create the reciever's account if it doesn't exist | ||
| { | ||
| AccessType: sdkacltypes.AccessType_READ, | ||
| ResourceType: sdkacltypes.ResourceType_KV, | ||
| IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, msgSend.ToAddress), | ||
| }, | ||
| { | ||
| AccessType: sdkacltypes.AccessType_WRITE, | ||
| ResourceType: sdkacltypes.ResourceType_KV, | ||
| IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, msgSend.ToAddress), | ||
| }, | ||
|
|
||
| // Last Operation should always be a commit | ||
| { | ||
| ResourceType: sdkacltypes.ResourceType_ANY, | ||
| AccessType: sdkacltypes.AccessType_COMMIT, | ||
| IdentifierTemplate: utils.DefaultIDTemplate, | ||
| }, | ||
| } | ||
| return accessOperations, nil | ||
| } | ||
This file contains hidden or 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 hidden or 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,13 @@ | ||
| package util | ||
|
|
||
| import "fmt" | ||
|
|
||
| const ( | ||
| BANK = "bank" | ||
| AUTH = "auth" | ||
| DefaultIDTemplate = "*" | ||
| ) | ||
|
|
||
| func GetIdentifierTemplatePerModule(module string, identifier string) string { | ||
| return fmt.Sprintf("%s/%s", module, identifier) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having the identifier template be per module, we should create more resource types to further segment the population. For example, under KV, we can have resource type
KV_BANK, and thenKV_BANK_BALANCEandKV_BANK_PARAMS, and then for the specific account we could have another resource type calledKV_BANK_BALANCE_ACCOUNT. This way its much easier to have static dependencies that are granular enough to still allow for parallelization, and then the static read for this would be resourceKV_BANK_BALANCEwhereas the dynamic resource would beKV_BANK_BALANCE_ACCOUNTwith the account identifier. We can represent this hierarchy in the resource hierarchy tree in resource.go insei-cosmos.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BrandonWeng lets leave a TODO at the top of the generator function to make the resources more granular down the road
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yessir, thanks! As discussed offline - we want to unblock the work first and this can be something we address later once we get the concurrency working