diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index ae0b0eada..3c7ff47fc 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -226,20 +226,11 @@ func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk. } func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) { - var unbondingTime time.Duration - res, err := cc.QueryStakingParams(ctx) + + 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 diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index eccba377b..a328d7044 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -366,13 +366,22 @@ func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Durati } //Attempt Staking query. - unbondingPeriod, err := cc.queryStakingUnbondingPeriod(ctx) - if err != nil { - return 0, - fmt.Errorf("failed to query unbonding period as both consumer and standard chain: %w: %s", consumerErr, err.Error()) + unbondingPeriod, stakingParamsErr := cc.queryStakingUnbondingPeriod(ctx) + if stakingParamsErr == nil { + return unbondingPeriod, nil + } + + // Fallback + req := stakingtypes.QueryParamsRequest{} + queryClient := stakingtypes.NewQueryClient(cc) + res, err := queryClient.Params(ctx, &req) + if err == nil { + return res.Params.UnbondingTime, nil + } - return unbondingPeriod, 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