Skip to content

Commit

Permalink
fix consumer chain unbonding period query (#1044)
Browse files Browse the repository at this point in the history
* testing consumer chain unbonding period query

* Trim quotes

* Make queryConsumerUnbondingPeriod private
  • Loading branch information
agouin authored Nov 21, 2022
1 parent 900b5bf commit 9aa3026
Showing 1 changed file with 33 additions and 1 deletion.
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

0 comments on commit 9aa3026

Please sign in to comment.