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

fix consumer chain unbonding period query #1044

Merged
merged 4 commits into from
Nov 21, 2022
Merged
Changes from all commits
Commits
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
34 changes: 33 additions & 1 deletion relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"strconv"
"strings"
"time"

Expand All @@ -14,6 +15,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
querytypes "github.com/cosmos/cosmos-sdk/types/query"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
Expand Down Expand Up @@ -160,14 +162,44 @@ func (cc *CosmosProvider) QueryBalanceWithAddress(ctx context.Context, address s
return res.Balances, nil
}

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

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

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

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

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

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

return time.Duration(unbondingPeriod), nil
}

// QueryUnbondingPeriod returns the unbonding period of the chain
func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Duration, error) {
req := stakingtypes.QueryParamsRequest{}
queryClient := stakingtypes.NewQueryClient(cc)

res, err := queryClient.Params(ctx, &req)
if err != nil {
return 0, err
// 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)
}

return consumerUnbondingPeriod, nil
}

return res.Params.UnbondingTime, nil
Expand Down