Skip to content

Commit

Permalink
Merge branch 'main' into vimystic/edit_rpcaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
vimystic authored Sep 13, 2023
2 parents ad689b6 + 259b127 commit c56ac98
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 59 deletions.
61 changes: 36 additions & 25 deletions .github/workflows/interchaintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: TESTING - interchaintest

on:
pull_request:
push:
branches:
- master

jobs:
events:
Expand All @@ -16,11 +13,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -37,11 +36,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -58,11 +59,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -79,11 +82,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -100,11 +105,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -121,11 +128,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand All @@ -139,7 +148,7 @@ jobs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Generate matrix
id: set-matrix
Expand All @@ -164,11 +173,13 @@ jobs:
go-version: '1.21'

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

- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
Expand Down
1 change: 1 addition & 0 deletions interchaintest/tendermint_v0.37_boundary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestScenarioTendermint37Boundary(t *testing.T) {
rf := relayerinterchaintest.NewRelayerFactory(relayerinterchaintest.RelayerConfig{
InitialBlockHistory: 50,
})

r := rf.Build(t, client, network)

t.Parallel()
Expand Down
14 changes: 2 additions & 12 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,11 @@ func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk.
}

func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) {
res, err := cc.QueryStakingParams(ctx)

var unbondingTime time.Duration
unbondingTime, err := cc.QueryUnbondingPeriod(ctx)
if err != nil {
// Attempt ICS query
consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx)
if consumerErr != nil {
return 0,
fmt.Errorf("failed to query unbonding period as both standard and consumer chain: %s: %w", err.Error(), consumerErr)
}
unbondingTime = consumerUnbondingPeriod
} else {
unbondingTime = res.UnbondingTime
return 0, err
}

// We want the trusting period to be 85% of the unbonding time.
// Go mentions that the time.Duration type can track approximately 290 years.
// We don't want to lose precision if the duration is a very long duration
Expand Down
51 changes: 29 additions & 22 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/query"
querytypes "github.com/cosmos/cosmos-sdk/types/query"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
Expand Down Expand Up @@ -189,7 +188,7 @@ func parseEventsFromResponseDeliverTx(resp abci.ResponseDeliverTx) []provider.Re

// QueryFeegrantsByGrantee returns all requested grants for the given grantee.
// Default behavior will return all grants.
func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *query.PageRequest) ([]*feegrant.Grant, error) {
func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *querytypes.PageRequest) ([]*feegrant.Grant, error) {
grants := []*feegrant.Grant{}
allPages := paginator == nil

Expand Down Expand Up @@ -228,7 +227,7 @@ func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *que

// Feegrant_GrantsByGranterRPC returns all requested grants for the given Granter.
// Default behavior will return all grants.
func (cc *CosmosProvider) QueryFeegrantsByGranter(address string, paginator *query.PageRequest) ([]*feegrant.Grant, error) {
func (cc *CosmosProvider) QueryFeegrantsByGranter(address string, paginator *querytypes.PageRequest) ([]*feegrant.Grant, error) {
grants := []*feegrant.Grant{}
allPages := paginator == nil

Expand Down Expand Up @@ -311,47 +310,55 @@ func (cc *CosmosProvider) QueryBalanceWithAddress(ctx context.Context, address s
return coins, nil
}

func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (time.Duration, error) {
func (cc *CosmosProvider) queryParamsSubspaceTime(ctx context.Context, subspace string, key string) (time.Duration, error) {
queryClient := proposal.NewQueryClient(cc)

params := proposal.QueryParamsRequest{Subspace: "ccvconsumer", Key: "UnbondingPeriod"}
params := proposal.QueryParamsRequest{Subspace: subspace, Key: key}

resICS, err := queryClient.Params(ctx, &params)
res, err := queryClient.Params(ctx, &params)

if err != nil {
return 0, fmt.Errorf("failed to make ccvconsumer params request: %w", err)
return 0, fmt.Errorf("failed to make %s params request: %w", subspace, err)
}

if resICS.Param.Value == "" {
return 0, fmt.Errorf("ccvconsumer unbonding period is empty")
if res.Param.Value == "" {
return 0, fmt.Errorf("%s %s is empty", subspace, key)
}

unbondingPeriod, err := strconv.ParseUint(strings.ReplaceAll(resICS.Param.Value, `"`, ""), 10, 64)
unbondingValue, err := strconv.ParseUint(strings.ReplaceAll(res.Param.Value, `"`, ""), 10, 64)
if err != nil {
return 0, fmt.Errorf("failed to parse unbonding period from ccvconsumer param: %w", err)
return 0, fmt.Errorf("failed to parse %s from %s param: %w", key, subspace, err)
}

return time.Duration(unbondingPeriod), nil
return time.Duration(unbondingValue), nil
}

// QueryUnbondingPeriod returns the unbonding period of the chain
func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Duration, error) {

// Attempt ICS query
consumerUnbondingPeriod, consumerErr := cc.queryParamsSubspaceTime(ctx, "ccvconsumer", "UnbondingPeriod")
if consumerErr == nil {
return consumerUnbondingPeriod, nil
}

//Attempt Staking query.
unbondingPeriod, stakingParamsErr := cc.queryParamsSubspaceTime(ctx, "staking", "UnbondingTime")
if stakingParamsErr == nil {
return unbondingPeriod, nil
}

// Fallback
req := stakingtypes.QueryParamsRequest{}
queryClient := stakingtypes.NewQueryClient(cc)

res, err := queryClient.Params(ctx, &req)
if err != nil {
// Attempt ICS query
consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx)
if consumerErr != nil {
return 0,
fmt.Errorf("failed to query unbonding period as both standard and consumer chain: %s: %w", err.Error(), consumerErr)
}
if err == nil {
return res.Params.UnbondingTime, nil

return consumerUnbondingPeriod, nil
}

return res.Params.UnbondingTime, nil
return 0,
fmt.Errorf("failed to query unbonding period from ccvconsumer, staking & fallback : %w: %s : %s", consumerErr, stakingParamsErr.Error(), err.Error())
}

// QueryTendermintProof performs an ABCI query with the given key and returns
Expand Down

0 comments on commit c56ac98

Please sign in to comment.