-
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
feegrant PR #1140
feegrant PR #1140
Changes from 20 commits
1c42b99
48af330
106bfb5
d0602c6
7acfe7d
2f29f09
78ee03f
aeb19b5
99f45c4
181487b
8cddf85
b64c4c2
b18575d
06faa54
c3953b9
85c30e7
edf2225
99fa49e
7a86b77
92a2e68
d0978dd
16528e0
6a2174d
00e0b67
0da87e8
d27d78a
eeaea62
b4cda04
ea0d30f
9932b8f
38024a7
3f4d30a
0756463
ee14a21
da3746b
f09dc7d
b59f98a
cc86dd2
15e292f
2de6911
eeb8724
62485a6
6057498
2bdc5ae
3febd1b
e6f6475
b22f408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/cosmos/relayer/v2/relayer/chains/cosmos" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// feegrantConfigureCmd returns the fee grant configuration commands for this module | ||
func feegrantConfigureBaseCmd(a *appState) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "feegrant", | ||
Short: "Configure the client to use round-robin feegranted accounts when sending TXs", | ||
Long: "Use round-robin feegranted accounts when sending TXs. Useful for relayers and applications where sequencing is important", | ||
} | ||
|
||
cmd.AddCommand( | ||
feegrantConfigureBasicCmd(a), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func feegrantConfigureBasicCmd(a *appState) *cobra.Command { | ||
var numGrantees int | ||
var update bool | ||
var updateGrantees bool | ||
var grantees []string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "basicallowance [chain-name] [granter] --num-grantees [int] --overwrite-granter --overwrite-grantees", | ||
Short: "feegrants for the given chain and granter (if granter is unspecified, use the default key)", | ||
Long: "feegrants for the given chain. 10 grantees by default, all with an unrestricted BasicAllowance.", | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
chain := args[0] | ||
cosmosChain, ok := a.Config.Chains[chain] | ||
if !ok { | ||
return errChainNotFound(args[0]) | ||
} | ||
|
||
prov, ok := cosmosChain.ChainProvider.(*cosmos.CosmosProvider) | ||
if !ok { | ||
return errors.New("only CosmosProvider can be feegranted") | ||
} | ||
|
||
granterKeyOrAddr := "" | ||
|
||
if len(args) > 1 { | ||
granterKeyOrAddr = args[1] | ||
} else if prov.PCfg.FeeGrants != nil { | ||
granterKeyOrAddr = prov.PCfg.FeeGrants.GranterKey | ||
} else { | ||
granterKeyOrAddr = prov.PCfg.Key | ||
} | ||
|
||
granterKey, err := prov.KeyFromKeyOrAddress(granterKeyOrAddr) | ||
if err != nil { | ||
return fmt.Errorf("could not get granter key from '%s'", granterKeyOrAddr) | ||
} | ||
|
||
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 { | ||
prov.PCfg.FeeGrants.GranterKey = granterKey | ||
cfgErr := a.OverwriteConfig(a.Config) | ||
cobra.CheckErr(cfgErr) | ||
} | ||
|
||
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" | ||
if grantees == nil { | ||
feegrantErr = prov.ConfigureFeegrants(numGrantees, granterKey) | ||
} else { | ||
feegrantErr = prov.ConfigureWithGrantees(grantees, granterKey) | ||
} | ||
|
||
if feegrantErr != nil { | ||
return feegrantErr | ||
} | ||
|
||
if feegrantErr != nil { | ||
return feegrantErr | ||
} | ||
|
||
cfgErr := a.OverwriteConfig(a.Config) | ||
cobra.CheckErr(cfgErr) | ||
} | ||
|
||
memo, err := cmd.Flags().GetString(flagMemo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx := cmd.Context() | ||
_, err = prov.EnsureBasicGrants(ctx, memo) | ||
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. | ||
if prov.PCfg.FeeGrants != nil { | ||
fmt.Printf("Querying latest chain height to mark FeeGrant height... \n") | ||
h, err := prov.QueryLatestHeight(ctx) | ||
cobra.CheckErr(err) | ||
prov.PCfg.FeeGrants.BlockHeightVerified = h | ||
fmt.Printf("Feegrant chain height marked: %d\n", h) | ||
cfgErr := a.OverwriteConfig(a.Config) | ||
cobra.CheckErr(cfgErr) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
cmd.Flags().BoolVar(&update, "overwrite-granter", false, "allow overwriting the existing granter") | ||
cmd.Flags().BoolVar(&updateGrantees, "overwrite-grantees", false, "allow overwriting existing grantees") | ||
cmd.Flags().IntVar(&numGrantees, "num-grantees", 10, "number of grantees that will be feegranted with basic allowances") | ||
cmd.Flags().StringSliceVar(&grantees, "grantees", []string{}, "comma separated list of grantee key names (keys are created if they do not exist)") | ||
cmd.MarkFlagsMutuallyExclusive("num-grantees", "grantees") | ||
|
||
memoFlag(a.Viper, cmd) | ||
return cmd | ||
} | ||
|
||
func feegrantBasicGrantsCmd(a *appState) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "basic chain-name [granter]", | ||
Short: "query the grants for an account (if none is specified, the default account is returned)", | ||
Args: cobra.RangeArgs(1, 2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
chain := args[0] | ||
cosmosChain, ok := a.Config.Chains[chain] | ||
if !ok { | ||
return errChainNotFound(args[0]) | ||
} | ||
|
||
prov, ok := cosmosChain.ChainProvider.(*cosmos.CosmosProvider) | ||
if !ok { | ||
return errors.New("only CosmosProvider can be feegranted") | ||
} | ||
|
||
// TODO fix pagination | ||
// pageReq, err := client.ReadPageRequest(cmd.Flags()) | ||
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. are these TODOs still relevant? 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. I think so. Most other funcs in the relayer have the same TODOs/issue. For good default behavior its probably OK, but it should be fixed. |
||
// 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 | ||
} else { | ||
keyNameOrAddress = args[0] | ||
} | ||
|
||
granterAcc, err := prov.AccountFromKeyOrAddress(keyNameOrAddress) | ||
if err != nil { | ||
fmt.Printf("Error retrieving account from key '%s'\n", keyNameOrAddress) | ||
return err | ||
} | ||
granterAddr := prov.MustEncodeAccAddr(granterAcc) | ||
|
||
res, err := prov.QueryFeegrantsByGranter(granterAddr, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
return paginationFlags(a.Viper, cmd, "feegrant") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
go 1.19 | ||
|
||
use ( | ||
. | ||
./interchaintest | ||
) |
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.
duplicate from above.