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

Authz redesign: CLI implementation #1079

Merged
merged 41 commits into from
Nov 14, 2022
Merged

Authz redesign: CLI implementation #1079

merged 41 commits into from
Nov 14, 2022

Conversation

pinosu
Copy link
Contributor

@pinosu pinosu commented Nov 7, 2022

Follow up on #1077

@codecov
Copy link

codecov bot commented Nov 7, 2022

Codecov Report

Merging #1079 (0164d85) into main (ef9a84d) will decrease coverage by 0.54%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1079      +/-   ##
==========================================
- Coverage   60.33%   59.79%   -0.55%     
==========================================
  Files          54       54              
  Lines        7211     7273      +62     
==========================================
- Hits         4351     4349       -2     
- Misses       2549     2612      +63     
- Partials      311      312       +1     
Impacted Files Coverage Δ
x/wasm/client/cli/tx.go 22.94% <0.00%> (-5.12%) ⬇️
x/wasm/keeper/keeper.go 87.40% <0.00%> (-0.32%) ⬇️

@alpe alpe changed the base branch from main to 966_grants_redesign November 7, 2022 14:05
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Great start. The CLI will be hard to come with a good UX. I have added some notes to help. My gut feeling is that more concrete parameter may be better to guide the user than overloading max-calls and amount for the different cases. But other opinions are welcome, too.


var filter types.ContractAuthzFilterX
switch len(msgs) {
case 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit worried that this becomes the default without giving notice to people. What do you think about an extra parameter that must be set for this option? Something like: --allow-all-messages-wildcard

return fmt.Errorf("max funds: %s", err)
}
limit = types.NewMaxFundsLimit(maxFunds)
case maxCalls != 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

This option does not allow any token transfers. It would be nice if we can be explicit in the cli like --max-calls=1 --no-token-transfer. WDYT?

case maxFundsStr != "":
maxFunds, err := sdk.ParseCoinsNormalized(maxFundsStr)
if err != nil {
return fmt.Errorf("max funds: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

filter = types.NewAllowAllMessagesFilter()
default:
filter = types.NewAcceptedMessageKeysFilter(msgs...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The third option is to set the concrete json message(s) (byte equal).

}

var authorization authz.Authorization
switch args[1] {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 this works

coordinator *ibctesting.Coordinator
providerChain *ibctesting.TestChain
consumerChain *ibctesting.TestChain
// coordinator *ibctesting.Coordinator
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I have removed this file on a local branch already. These changes will cause merge conflicts for you when I push.

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Good progress. I added some notes to unblock you. I will do a deeper review tomorrow.

@@ -379,9 +385,9 @@ func parseExecuteArgs(contractAddr string, execMsg string, sender sdk.AccAddress

func GrantAuthorizationCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "grant [grantee] [contract_addr_bech32] --allow-msgs [msg1,msg2,...]",
Use: "grant [grantee] [authorization_type=\"execution\"|\"migration\"] [contract_addr_bech32] --allow-raw-msgs `[msg1,msg2,...]` --allow-msg-keys [key1,key2,...]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make authorization_type message type. It it the wasmd tx message that can be executed

The ' in "`[msg1,msg2,...]`" were confusing. it is not a json array content but a list of strings

How about adding --allow-all-messages here to have the filters complete? I think some full examples in the Long description would be very useful. The filter + limits model needs to be explained a bit for people to configure this.

if err != nil {
return err
}

once, err := cmd.Flags().GetBool(flagRunOnce)
rawMsgsStr, err := cmd.Flags().GetString(flagAllowedRawMsgs)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be GetStringSlice as well.

cmd.Flags().StringSlice(flagAllowedMsgs, []string{}, "Allowed msgs")
cmd.Flags().Bool(flagRunOnce, false, "Allow to execute only once")
cmd.Flags().StringSlice(flagAllowedMsgKeys, []string{}, "Allowed msg keys")
cmd.Flags().String(flagAllowedRawMsgs, "", "Allowed raw msgs")
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, this should be a StringSlice

}

var filter types.ContractAuthzFilterX
switch {
Copy link
Contributor

Choose a reason for hiding this comment

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

Filters are mutual exclusive within one grant. Better fail fast if more than one is set.

@pinosu pinosu marked this pull request as ready for review November 11, 2022 09:06
Base automatically changed from 966_grants_redesign to main November 11, 2022 12:39
@alpe
Copy link
Contributor

alpe commented Nov 14, 2022

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Nov 14, 2022

rebase

❌ Base branch update has failed

Git reported the following error:

Rebasing (7/37)
error: could not apply 9ae2fd3... Add contract authz proto
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 9ae2fd3... Add contract authz proto
CONFLICT (add/add): Merge conflict in x/wasm/types/authz.pb.go
Auto-merging x/wasm/types/authz.pb.go
CONFLICT (add/add): Merge conflict in proto/cosmwasm/wasm/v1/authz.proto
Auto-merging proto/cosmwasm/wasm/v1/authz.proto
Auto-merging docs/proto/proto-docs.md
CONFLICT (content): Merge conflict in docs/proto/proto-docs.md

err-code: FB22C

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Good work! I added some nits and personal preferences. But nothing blocking!


var limit types.ContractAuthzLimitX
switch {
case maxFundsStr != "" && maxCalls != 0 && !noTokenTransfer:
Copy link
Contributor

Choose a reason for hiding this comment

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

good check

return fmt.Errorf("max funds: %s", err)
}
limit = types.NewCombinedLimit(maxCalls, maxFunds...)
case maxFundsStr != "" && !noTokenTransfer:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: To be on the safe side, I would be very explicit: case maxFundsStr != "" && maxCalls == 0 && !noTokenTransfer:

return fmt.Errorf("max funds: %s", err)
}
limit = types.NewMaxFundsLimit(maxFunds...)
case maxCalls != 0 && noTokenTransfer:
Copy link
Contributor

Choose a reason for hiding this comment

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

to be on the safe side: maxCalls != 0 && noTokenTransfer && maxFundsStr == ""

case maxCalls != 0 && noTokenTransfer:
limit = types.NewMaxCallsLimit(maxCalls)
default:
limit = types.UndefinedLimit{}
Copy link
Contributor

Choose a reason for hiding this comment

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

you can fail fast here already

Suggested change
limit = types.UndefinedLimit{}
limit = errors.New("invalid limit setup")


var filter types.ContractAuthzFilterX
switch {
case allowAllMsgs && len(msgKeys) > 0 || allowAllMsgs && len(rawMsgs) > 0 || len(msgKeys) > 0 && len(rawMsgs) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 you cover all 3 cases here. I am a bit more used to read len(x) != 0 instead but all correct

var filter types.ContractAuthzFilterX
switch {
case allowAllMsgs && len(msgKeys) > 0 || allowAllMsgs && len(rawMsgs) > 0 || len(msgKeys) > 0 && len(rawMsgs) > 0:
return fmt.Errorf("cannot set more than one filter within one grant")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
return fmt.Errorf("cannot set more than one filter within one grant")
return errors.New("cannot set more than one filter within one grant")

}
filter = types.NewAcceptedMessagesFilter(msgs...)
default:
filter = &types.UndefinedFilter{}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: as above, just return an error here

Long: fmt.Sprintf(`Grant authorization to an address.
Examples:
$ %s tx grant <grantee_addr> execution <contract_addr> --allow-all-messages --maxCalls 1 --no-token-transfer --expiration 1667979596
`, version.AppName),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to have some more concrete examples for the limits and filters? I think you can cover all in 3 examples

@pinosu pinosu force-pushed the 966-grants_redesign_cli branch from 73c401b to 0164d85 Compare November 14, 2022 14:40
@pinosu pinosu merged commit c0a482e into main Nov 14, 2022
@pinosu pinosu deleted the 966-grants_redesign_cli branch November 14, 2022 15:06
NoahSaso pushed a commit to NoahSaso/wasmd that referenced this pull request Dec 2, 2022
* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Add cli implementation for signle grant case

* Restore file to avoid merge conflicts

* Test filter and limits

* Add allow-al-messages flag

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Test accept

* Fix description

* No linter warning

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Fix comments

Co-authored-by: Giancarlos Salas <me@giansalex.dev>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
Magicloud pushed a commit to fpco/wasmd that referenced this pull request Jan 13, 2023
* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Add cli implementation for signle grant case

* Restore file to avoid merge conflicts

* Test filter and limits

* Add allow-al-messages flag

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Test accept

* Fix description

* No linter warning

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Fix comments

Co-authored-by: Giancarlos Salas <me@giansalex.dev>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
conorpp pushed a commit to wormhole-foundation/wasmd that referenced this pull request Feb 1, 2023
* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Add cli implementation for signle grant case

* Restore file to avoid merge conflicts

* Test filter and limits

* Add allow-al-messages flag

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Test accept

* Fix description

* No linter warning

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Add cli implementation for signle grant case

* Add allow-al-messages flag

* Implement comments fixes

* Fix flags and add example command

* Fix lint error

* Fix limits cli

* Fix comments

Co-authored-by: Giancarlos Salas <me@giansalex.dev>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants