Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into build_evm_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Aug 2, 2023
2 parents ea42d5d + 2138221 commit 5d7e4ec
Show file tree
Hide file tree
Showing 64 changed files with 6,180 additions and 2,625 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/interchaintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ jobs:
- name: interchaintest
run: make interchaintest-fee-middleware

fee-grant:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v1
with:
go-version: 1.20
id: go

- name: checkout relayer
uses: actions/checkout@v2

- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: interchaintest
run: make interchaintest-fee-grant

scenarios:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ dist/

# Don't commit the vendor directory if anyone runs 'go mod vendor'.
/vendor

go.work.sum
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [\#1208](https://github.com/cosmos/relayer/pull/1208) Replace gogo/protobuf to cosmos/gogoproto.
* [\#1221](https://github.com/cosmos/relayer/pull/1221) Update cometbft to v0.37.2 and ibc-go to v7.2.0.
* [\#1226](https://github.com/cosmos/relayer/pull/1226) Avoid invalid Bech32 prefix error in parallel tests when sdk Config get overwritten by each other in single process.
* [\#1231](https://github.com/cosmos/relayer/pull/1231) Reduce get bech32 prefix when get signer.
* [\#1225](https://github.com/cosmos/relayer/pull/1225) Support build EVM messages to allow signing Ethereum transactions.

## v0.9.3
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ interchaintest-misbehaviour:
interchaintest-fee-middleware:
cd interchaintest && go test -race -v -run TestRelayerFeeMiddleware .

interchaintest-fee-grant:
cd interchaintest && go test -race -v -run TestRelayerFeeGrant .

interchaintest-scenario: ## Scenario tests are suitable for simple networks of 1 validator and no full nodes. They test specific functionality.
cd interchaintest && go test -timeout 30m -race -v -run TestScenario ./...

Expand Down
19 changes: 17 additions & 2 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 @@ -144,6 +145,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 Expand Up @@ -277,9 +291,10 @@ func chainsAddCmd(a *appState) *cobra.Command {
" the chain-registry or passing a file (-f) or url (-u)",
Args: withUsage(cobra.MinimumNArgs(0)),
Example: fmt.Sprintf(` $ %s chains add cosmoshub
$ %s chains add testnets/cosmoshubtestnet
$ %s chains add cosmoshub osmosis
$ %s chains add --file chains/ibc0.json ibc0
$ %s chains add --url https://relayer.com/ibc0.json ibc0`, appName, appName, appName, appName),
$ %s chains add --url https://relayer.com/ibc0.json ibc0`, appName, appName, appName, appName, appName),
RunE: func(cmd *cobra.Command, args []string) error {
file, url, err := getAddInputs(cmd)
if err != nil {
Expand Down Expand Up @@ -447,7 +462,7 @@ func addChainsFromRegistry(ctx context.Context, a *appState, chains []string) er
continue
}

chainConfig, err := chainInfo.GetChainConfig(ctx)
chainConfig, err := chainInfo.GetChainConfig(ctx, chain)
if err != nil {
a.log.Warn(
"Error generating chain config",
Expand Down
7 changes: 6 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -393,7 +394,11 @@ func UnmarshalJSONProviderConfig(data []byte, customTypes map[string]reflect.Typ
return nil, err
}

typeName := m["type"].(string)
typeName, ok := m["type"].(string)
if !ok {
return nil, errors.New("cannot find type");
}

var provCfg provider.ProviderConfig
if ty, found := customTypes[typeName]; found {
provCfg = reflect.New(ty).Interface().(provider.ProviderConfig)
Expand Down
197 changes: 197 additions & 0 deletions cmd/feegrant.go
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")
}
50 changes: 39 additions & 11 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 Expand Up @@ -1055,9 +1070,10 @@ $ %s query unrelayed-acks demo-path channel-0`,

func queryClientsExpiration(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "clients-expiration path",
Short: "query for light clients expiration date",
Args: withUsage(cobra.ExactArgs(1)),
Use: "clients-expiration path",
Aliases: []string{"ce"},
Short: "query for light clients expiration date",
Args: withUsage(cobra.ExactArgs(1)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s query clients-expiration demo-path`,
appName,
Expand All @@ -1080,17 +1096,29 @@ $ %s query clients-expiration demo-path`,
return err
}

srcExpiration, err := relayer.QueryClientExpiration(cmd.Context(), c[src], c[dst])
if err != nil {
return err
srcExpiration, srcClientInfo, errSrc := relayer.QueryClientExpiration(cmd.Context(), c[src], c[dst])
if errSrc != nil && !strings.Contains(errSrc.Error(), "light client not found") {
return errSrc
}
dstExpiration, err := relayer.QueryClientExpiration(cmd.Context(), c[dst], c[src])
if err != nil {
return err
dstExpiration, dstClientInfo, errDst := relayer.QueryClientExpiration(cmd.Context(), c[dst], c[src])
if errDst != nil && !strings.Contains(errDst.Error(), "light client not found") {
return errDst
}

// if only the src light client is found, just print info for source light client
if errSrc == nil && errDst != nil {
fmt.Fprintln(cmd.OutOrStdout(), relayer.SPrintClientExpiration(c[src], srcExpiration, srcClientInfo))
return nil
}

// if only the dst light client is found, just print info for destination light client
if errDst == nil && errSrc != nil {
fmt.Fprintln(cmd.OutOrStdout(), relayer.SPrintClientExpiration(c[dst], dstExpiration, dstClientInfo))
return nil
}

fmt.Fprintf(cmd.OutOrStdout(), relayer.SPrintClientExpiration(c[src], srcExpiration))
fmt.Fprintf(cmd.OutOrStdout(), relayer.SPrintClientExpiration(c[dst], dstExpiration))
fmt.Fprintln(cmd.OutOrStdout(), relayer.SPrintClientExpiration(c[src], srcExpiration, srcClientInfo))
fmt.Fprintln(cmd.OutOrStdout(), relayer.SPrintClientExpiration(c[dst], dstExpiration, dstClientInfo))

return nil
},
Expand Down
Loading

0 comments on commit 5d7e4ec

Please sign in to comment.