diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index a1ded512d9..6dc37f460b 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -220,19 +220,9 @@ func (cc *CosmosProvider) Address() (string, error) { } 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. diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index 19769f6384..da7ac1607c 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -178,24 +178,24 @@ 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) querySubspaceUnbondingPeriod(subspace string, ctx context.Context) (time.Duration, error) { queryClient := proposal.NewQueryClient(cc) - params := proposal.QueryParamsRequest{Subspace: "ccvconsumer", Key: "UnbondingPeriod"} + params := proposal.QueryParamsRequest{Subspace: subspace, Key: "UnbondingPeriod"} resICS, err := queryClient.Params(ctx, ¶ms) 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") + return 0, fmt.Errorf("%s unbonding period is empty", subspace) } 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 0, fmt.Errorf("failed to parse unbonding period from %s param: %w", subspace, err) } return time.Duration(unbondingPeriod), nil @@ -203,22 +203,26 @@ func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (tim // 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 { - // 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) - } + res, err := cc.QueryStakingParams(ctx) + if err == nil { + return res.UnbondingTime, nil + } + // Attempt ICS query + consumerUnbondingPeriod, consumerErr := cc.querySubspaceUnbondingPeriod("ccvconsumer", ctx) + if consumerErr == nil { return consumerUnbondingPeriod, nil } - return res.Params.UnbondingTime, nil + poaUnbondingPeriod, poaErr := cc.querySubspaceUnbondingPeriod("poa", ctx) + if poaErr == nil { + return poaUnbondingPeriod, nil + } + + return 0, fmt.Errorf( + "failed to query unbonding period as both standard, consumer, and poa chain: %s, %s, %s", + err.Error(), consumerErr.Error(), poaErr.Error(), + ) } // QueryTendermintProof performs an ABCI query with the given key and returns