-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
External feegrants #1338
Merged
Merged
External feegrants #1338
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7ea0c47
Allow feegrants where granter is external (relayer does not have key)
453d51d
Merge branch 'main' of ssh://github.com/cosmos/relayer
91883e4
linting/logging
89584b4
Added feegrant command gas flag
9b7af82
merged with upstream
122efcb
Added doc for external feegrant config
f525e88
Fix logging to conform to style guide
77bcf26
Merge upstream
46dbb93
Lock on read bech32 address map
d17f1c6
Lock on read bech32 address map
8d9de86
Lock on read bech32 address map
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 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 |
---|---|---|
|
@@ -4,8 +4,11 @@ import ( | |
"errors" | ||
"fmt" | ||
|
||
sdkflags "github.com/cosmos/cosmos-sdk/client/flags" | ||
|
||
"github.com/cosmos/relayer/v2/relayer/chains/cosmos" | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// feegrantConfigureCmd returns the fee grant configuration commands for this module | ||
|
@@ -52,18 +55,27 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | |
if len(args) > 1 { | ||
granterKeyOrAddr = args[1] | ||
} else if prov.PCfg.FeeGrants != nil { | ||
granterKeyOrAddr = prov.PCfg.FeeGrants.GranterKey | ||
granterKeyOrAddr = prov.PCfg.FeeGrants.GranterKeyOrAddr | ||
} else { | ||
granterKeyOrAddr = prov.PCfg.Key | ||
} | ||
|
||
externalGranter := false | ||
|
||
granterKey, err := prov.KeyFromKeyOrAddress(granterKeyOrAddr) | ||
if err != nil { | ||
return fmt.Errorf("could not get granter key from '%s'", granterKeyOrAddr) | ||
externalGranter = true | ||
} | ||
|
||
if externalGranter { | ||
_, err := prov.DecodeBech32AccAddr(granterKeyOrAddr) | ||
if err != nil { | ||
return fmt.Errorf("an unknown granter was specified: '%s' is not a valid bech32 address", granterKeyOrAddr) | ||
} | ||
} | ||
|
||
if delete { | ||
fmt.Printf("Deleting %s feegrant configuration\n", chain) | ||
a.log.Info("deleting feegrant configuration", zap.String("chain", chain)) | ||
|
||
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
chain := a.config.Chains[chain] | ||
|
@@ -75,11 +87,12 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | |
return nil | ||
} | ||
|
||
if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKey && !update { | ||
return fmt.Errorf("you specified granter '%s' which is different than configured feegranter '%s', but you did not specify the --overwrite-granter flag", granterKeyOrAddr, prov.PCfg.FeeGrants.GranterKey) | ||
} else if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKey && update { | ||
if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKeyOrAddr && !update { | ||
return fmt.Errorf("you specified granter '%s' which is different than configured feegranter '%s', but you did not specify the --overwrite-granter flag", granterKeyOrAddr, prov.PCfg.FeeGrants.GranterKeyOrAddr) | ||
} else if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKeyOrAddr && update { | ||
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
prov.PCfg.FeeGrants.GranterKey = granterKey | ||
prov.PCfg.FeeGrants.GranterKeyOrAddr = granterKey | ||
prov.PCfg.FeeGrants.IsExternalGranter = externalGranter | ||
return nil | ||
}) | ||
cobra.CheckErr(cfgErr) | ||
|
@@ -88,11 +101,16 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | |
if prov.PCfg.FeeGrants == nil || updateGrantees || len(grantees) > 0 { | ||
var feegrantErr error | ||
|
||
//No list of grantees was provided, so we will use the default naming convention "grantee1, ... granteeN" | ||
// No list of grantees was provided, so we will use the default naming convention "grantee1, ... granteeN" | ||
if grantees == nil { | ||
if externalGranter { | ||
return fmt.Errorf("external granter %s was specified, pre-authorized grantees must also be specified", granterKeyOrAddr) | ||
} | ||
feegrantErr = prov.ConfigureFeegrants(numGrantees, granterKey) | ||
} else { | ||
} else if !externalGranter { | ||
feegrantErr = prov.ConfigureWithGrantees(grantees, granterKey) | ||
} else { | ||
feegrantErr = prov.ConfigureWithExternalGranter(grantees, granterKeyOrAddr) | ||
} | ||
|
||
if feegrantErr != nil { | ||
|
@@ -102,6 +120,7 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | |
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
chain := a.config.Chains[chain] | ||
oldProv := chain.ChainProvider.(*cosmos.CosmosProvider) | ||
prov.PCfg.FeeGrants.IsExternalGranter = externalGranter | ||
oldProv.PCfg.FeeGrants = prov.PCfg.FeeGrants | ||
return nil | ||
}) | ||
|
@@ -113,25 +132,32 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | |
return err | ||
} | ||
|
||
gas := uint64(0) | ||
gasStr, _ := cmd.Flags().GetString(sdkflags.FlagGas) | ||
if gasStr != "" { | ||
gasSetting, _ := sdkflags.ParseGasSetting(gasStr) | ||
gas = gasSetting.Gas | ||
} | ||
|
||
ctx := cmd.Context() | ||
_, err = prov.EnsureBasicGrants(ctx, memo) | ||
_, err = prov.EnsureBasicGrants(ctx, memo, gas) | ||
if err != nil { | ||
return fmt.Errorf("error writing grants on chain: '%s'", err.Error()) | ||
} | ||
|
||
//Get latest height from the chain, mark feegrant configuration as verified up to that height. | ||
//This means we've verified feegranting is enabled on-chain and TXs can be sent with a feegranter. | ||
// Get latest height from the chain, mark feegrant configuration as verified up to that height. | ||
// This means we've verified feegranting is enabled on-chain and TXs can be sent with a feegranter. | ||
if prov.PCfg.FeeGrants != nil { | ||
fmt.Printf("Querying latest chain height to mark FeeGrant height... \n") | ||
h, err := prov.QueryLatestHeight(ctx) | ||
cobra.CheckErr(err) | ||
|
||
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
chain := a.config.Chains[chain] | ||
oldProv := chain.ChainProvider.(*cosmos.CosmosProvider) | ||
prov.PCfg.FeeGrants.IsExternalGranter = externalGranter | ||
oldProv.PCfg.FeeGrants = prov.PCfg.FeeGrants | ||
oldProv.PCfg.FeeGrants.BlockHeightVerified = h | ||
fmt.Printf("Feegrant chain height marked: %d\n", h) | ||
a.log.Info("feegrant configured", zap.Int64("height", h)) | ||
return nil | ||
}) | ||
cobra.CheckErr(cfgErr) | ||
|
@@ -147,6 +173,7 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | |
cmd.Flags().IntVar(&numGrantees, "num-grantees", 10, "number of grantees that will be feegranted with basic allowances") | ||
cmd.Flags().StringSliceVar(&grantees, "grantees", nil, "comma separated list of grantee key names (keys are created if they do not exist)") | ||
cmd.MarkFlagsMutuallyExclusive("num-grantees", "grantees", "delete") | ||
cmd.Flags().String(sdkflags.FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", sdkflags.GasFlagAuto, sdkflags.DefaultGasLimit)) | ||
|
||
memoFlag(a.viper, cmd) | ||
return cmd | ||
|
@@ -169,18 +196,6 @@ func feegrantBasicGrantsCmd(a *appState) *cobra.Command { | |
return errors.New("only CosmosProvider can be feegranted") | ||
} | ||
|
||
// TODO fix pagination | ||
// pageReq, err := client.ReadPageRequest(cmd.Flags()) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
//TODO fix height | ||
// height, err := lensCmd.ReadHeight(cmd.Flags()) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
keyNameOrAddress := "" | ||
if len(args) == 0 { | ||
keyNameOrAddress = prov.PCfg.Key | ||
|
@@ -190,7 +205,7 @@ func feegrantBasicGrantsCmd(a *appState) *cobra.Command { | |
|
||
granterAcc, err := prov.AccountFromKeyOrAddress(keyNameOrAddress) | ||
if err != nil { | ||
fmt.Printf("Error retrieving account from key '%s'\n", keyNameOrAddress) | ||
a.log.Error("unknown account", zap.String("key or address", keyNameOrAddress)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: logs should begin with an uppercase letter. Also, should we log the returned error here as well? |
||
return err | ||
} | ||
granterAddr := prov.MustEncodeAccAddr(granterAcc) | ||
|
@@ -203,7 +218,7 @@ func feegrantBasicGrantsCmd(a *appState) *cobra.Command { | |
for _, grant := range res { | ||
allowance, e := prov.Sprint(grant.Allowance) | ||
cobra.CheckErr(e) | ||
fmt.Printf("Granter: %s, Grantee: %s, Allowance: %s\n", grant.Granter, grant.Grantee, allowance) | ||
a.log.Info("feegrant", zap.String("granter", grant.Granter), zap.String("grantee", grant.Grantee), zap.String("allowance", allowance)) | ||
} | ||
|
||
return nil | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
nit: logs should begin with an uppercase letter https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage