-
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
Merged
Merged
feegrant PR #1140
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
1c42b99
Feegrant support
KyleMoser 48af330
Test case for address caching bugfix
KyleMoser 106bfb5
Bugfix for SDK account prefix. Feegrant test passing.
KyleMoser d0602c6
Mutex for signer expanded to include feegrantees
KyleMoser 7acfe7d
Cleaned up feegrant test case
KyleMoser 2f29f09
Cleaned up feegrant test case
KyleMoser 78ee03f
Cleaned up feegrant test case
KyleMoser aeb19b5
merge feegrant test cases with v0.47.0-rc3 changes
KyleMoser 99f45c4
check round robin feegrant behavior by counting number of TXs each gr…
KyleMoser 181487b
merge latest with feegrant changes
KyleMoser 8cddf85
module updates from merge
KyleMoser b64c4c2
Merge branch 'main' of ssh://github.com/cosmos/relayer
KyleMoser b18575d
v0.47.0 with bech32 address cache fix
KyleMoser 06faa54
Move SetAddrCacheEnabled to NewRelayer func for full coverage
KyleMoser c3953b9
Merge remote-tracking branch 'upstream/main'
KyleMoser 85c30e7
Do not hardcode chain id in feegrant test case
KyleMoser edf2225
Wait more blocks for ibc transfers
KyleMoser 99fa49e
Merge branch 'main' into main
KyleMoser 7a86b77
disable cosmos SDK bech32 address cache for rly start command
KyleMoser 92a2e68
Merge branch 'main' of ssh://github.com/KyleMoser/relayer-1
KyleMoser d0978dd
Fix sloppy comments/remove unnecessary code
KyleMoser 16528e0
Faster acc caching unit test
KyleMoser 6a2174d
Merge branch 'main' into main
agouin 00e0b67
Merge remote-tracking branch 'upstream/main'
KyleMoser 0da87e8
Penumbra provider feegrant support
KyleMoser d27d78a
Merge upstream
KyleMoser eeaea62
Merge upstream
KyleMoser b4cda04
Fixed merge issue where feegrant config wasn't being written to file
KyleMoser ea0d30f
merging updates from main
KyleMoser 9932b8f
feegrant patch for cosmos-sdk v0.47.1
KyleMoser 38024a7
Merge branch 'main' into main
agouin 3f4d30a
Merge remote-tracking branch 'upstream/main'
KyleMoser 0756463
Merge branch 'main' of ssh://github.com/KyleMoser/relayer-1
KyleMoser ee14a21
merge from main
KyleMoser da3746b
Update to cosmos-sdk v0.47.2
KyleMoser f09dc7d
Increase test case blocks to wait
KyleMoser b59f98a
Merging from upstream
KyleMoser cc86dd2
Merge branch 'main' into main
KyleMoser 15e292f
merged main branch. feegrant tests passing, scenario tests failing
KyleMoser 2de6911
Merge remote-tracking branch 'upstream/main'
KyleMoser eeb8724
Fixed data race by moving test parallelization after relayer wallet b…
KyleMoser 62485a6
Increased TestScenarioICAChannelClose timeout height
KyleMoser 6057498
Cleanup feegrant test case
KyleMoser 2bdc5ae
Fixed race condition in sequence guard w/ mutex
KyleMoser 3febd1b
Automatic retry for TX lookup in feegrant test case
KyleMoser e6f6475
Merge branch 'main' into main
agouin b22f408
Merge branch 'main' into main
agouin 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
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,197 @@ | ||
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 { | ||
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
prov.PCfg.FeeGrants.GranterKey = granterKey | ||
return nil | ||
}) | ||
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 | ||
} | ||
|
||
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
chain := a.config.Chains[chain] | ||
oldProv := chain.ChainProvider.(*cosmos.CosmosProvider) | ||
oldProv.PCfg.FeeGrants = prov.PCfg.FeeGrants | ||
return nil | ||
}) | ||
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) | ||
|
||
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error { | ||
chain := a.config.Chains[chain] | ||
oldProv := chain.ChainProvider.(*cosmos.CosmosProvider) | ||
oldProv.PCfg.FeeGrants = prov.PCfg.FeeGrants | ||
oldProv.PCfg.FeeGrants.BlockHeightVerified = h | ||
fmt.Printf("Feegrant chain height marked: %d\n", h) | ||
return nil | ||
}) | ||
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()) | ||
// 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") | ||
} |
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.
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.
are these TODOs still relevant?
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.
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.