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

feegrant PR #1140

Merged
merged 47 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1c42b99
Feegrant support
KyleMoser Mar 8, 2023
48af330
Test case for address caching bugfix
KyleMoser Mar 9, 2023
106bfb5
Bugfix for SDK account prefix. Feegrant test passing.
KyleMoser Mar 9, 2023
d0602c6
Mutex for signer expanded to include feegrantees
KyleMoser Mar 16, 2023
7acfe7d
Cleaned up feegrant test case
KyleMoser Mar 22, 2023
2f29f09
Cleaned up feegrant test case
KyleMoser Mar 22, 2023
78ee03f
Cleaned up feegrant test case
KyleMoser Mar 22, 2023
aeb19b5
merge feegrant test cases with v0.47.0-rc3 changes
KyleMoser Mar 23, 2023
99f45c4
check round robin feegrant behavior by counting number of TXs each gr…
KyleMoser Mar 23, 2023
181487b
merge latest with feegrant changes
KyleMoser Mar 23, 2023
8cddf85
module updates from merge
KyleMoser Mar 23, 2023
b64c4c2
Merge branch 'main' of ssh://github.com/cosmos/relayer
KyleMoser Mar 25, 2023
b18575d
v0.47.0 with bech32 address cache fix
KyleMoser Mar 25, 2023
06faa54
Move SetAddrCacheEnabled to NewRelayer func for full coverage
KyleMoser Mar 27, 2023
c3953b9
Merge remote-tracking branch 'upstream/main'
KyleMoser Mar 27, 2023
85c30e7
Do not hardcode chain id in feegrant test case
KyleMoser Mar 27, 2023
edf2225
Wait more blocks for ibc transfers
KyleMoser Mar 27, 2023
99fa49e
Merge branch 'main' into main
KyleMoser Mar 28, 2023
7a86b77
disable cosmos SDK bech32 address cache for rly start command
KyleMoser Mar 28, 2023
92a2e68
Merge branch 'main' of ssh://github.com/KyleMoser/relayer-1
KyleMoser Mar 28, 2023
d0978dd
Fix sloppy comments/remove unnecessary code
KyleMoser Mar 30, 2023
16528e0
Faster acc caching unit test
KyleMoser Mar 30, 2023
6a2174d
Merge branch 'main' into main
agouin Mar 31, 2023
00e0b67
Merge remote-tracking branch 'upstream/main'
KyleMoser Apr 5, 2023
0da87e8
Penumbra provider feegrant support
KyleMoser Apr 5, 2023
d27d78a
Merge upstream
KyleMoser Apr 10, 2023
eeaea62
Merge upstream
KyleMoser Apr 10, 2023
b4cda04
Fixed merge issue where feegrant config wasn't being written to file
KyleMoser Apr 11, 2023
ea0d30f
merging updates from main
KyleMoser Apr 11, 2023
9932b8f
feegrant patch for cosmos-sdk v0.47.1
KyleMoser Apr 12, 2023
38024a7
Merge branch 'main' into main
agouin Apr 18, 2023
3f4d30a
Merge remote-tracking branch 'upstream/main'
KyleMoser May 1, 2023
0756463
Merge branch 'main' of ssh://github.com/KyleMoser/relayer-1
KyleMoser May 1, 2023
ee14a21
merge from main
KyleMoser May 1, 2023
da3746b
Update to cosmos-sdk v0.47.2
KyleMoser May 1, 2023
f09dc7d
Increase test case blocks to wait
KyleMoser May 1, 2023
b59f98a
Merging from upstream
KyleMoser Jun 19, 2023
cc86dd2
Merge branch 'main' into main
KyleMoser Jun 28, 2023
15e292f
merged main branch. feegrant tests passing, scenario tests failing
KyleMoser Jul 6, 2023
2de6911
Merge remote-tracking branch 'upstream/main'
KyleMoser Jul 11, 2023
eeb8724
Fixed data race by moving test parallelization after relayer wallet b…
KyleMoser Jul 11, 2023
62485a6
Increased TestScenarioICAChannelClose timeout height
KyleMoser Jul 11, 2023
6057498
Cleanup feegrant test case
KyleMoser Jul 11, 2023
2bdc5ae
Fixed race condition in sequence guard w/ mutex
KyleMoser Jul 12, 2023
3febd1b
Automatic retry for TX lookup in feegrant test case
KyleMoser Jul 12, 2023
e6f6475
Merge branch 'main' into main
agouin Jul 25, 2023
b22f408
Merge branch 'main' into main
agouin Jul 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func chainsCmd(a *appState) *cobra.Command {
chainsShowCmd(a),
chainsAddrCmd(a),
chainsAddDirCmd(a),
cmdChainsConfigure(a),
)

return cmd
Expand Down Expand Up @@ -141,6 +142,19 @@ $ %s ch d ibc-0`, appName, appName)),
return cmd
}

func cmdChainsConfigure(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "configure",
Short: "manage local chain configurations",
}

cmd.AddCommand(
feegrantConfigureBaseCmd(a),
)

return cmd
}

func chainsRegistryList(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "registry-list",
Expand Down
188 changes: 188 additions & 0 deletions cmd/feegrant.go
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 {
Copy link
Member

Choose a reason for hiding this comment

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

duplicate from above.

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())
Copy link
Member

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?

Copy link
Contributor Author

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.

// 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")
}
15 changes: 15 additions & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func queryCmd(a *appState) *cobra.Command {
lineBreakCommand(),
queryIBCDenoms(a),
queryBaseDenomFromIBCDenom(a),
feegrantQueryCmd(a),
)

return cmd
}

// feegrantQueryCmd returns the fee grant query commands for this module
func feegrantQueryCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "feegrant",
Short: "Querying commands for the feegrant module [currently BasicAllowance only]",
}

cmd.AddCommand(
feegrantBasicGrantsCmd(a),
)

return cmd
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@ require (
pgregory.net/rapid v0.5.5 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/cosmos/cosmos-sdk => github.com/KyleMoser/cosmos-sdk v0.47.0-cachefix
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQ
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/KyleMoser/cosmos-sdk v0.47.0-cachefix h1:bGjftzXaTdhmJA1/cUrd1myq3zmIui3+bNWsjB+2KoY=
github.com/KyleMoser/cosmos-sdk v0.47.0-cachefix/go.mod h1:FTtZbqiHCZ2vun9WrPq6qLQafNKkAuIhLAxzLjr2TiI=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
Expand Down Expand Up @@ -336,8 +338,6 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8=
github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0=
github.com/cosmos/cosmos-sdk v0.47.0 h1:GKYtBpvjwuDEVix1vdnQpq7PuEOnItuEK0vdAL2cZ5g=
github.com/cosmos/cosmos-sdk v0.47.0/go.mod h1:FTtZbqiHCZ2vun9WrPq6qLQafNKkAuIhLAxzLjr2TiI=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.19

use (
.
./interchaintest
)
Loading