From a51eef84a1ae8d84a60aa8f73701e3a600f71392 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Mon, 16 Jan 2023 13:27:04 -0700 Subject: [PATCH 1/2] Fix trusting period query for ics chains --- relayer/chains/cosmos/provider.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 45bd08abe..96b676307 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -196,8 +196,18 @@ 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 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) + } + unbondingTime = consumerUnbondingPeriod + } else { + unbondingTime = res.UnbondingTime } // We want the trusting period to be 85% of the unbonding time. @@ -206,7 +216,7 @@ func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, er // by converting int64 to float64. // Use integer math the whole time, first reducing by a factor of 100 // and then re-growing by 85x. - tp := res.UnbondingTime / 100 * 85 + tp := unbondingTime / 100 * 85 // And we only want the trusting period to be whole hours. return tp.Truncate(time.Hour), nil From d333aa6341e227711b57df8d6cd98128a37f2f32 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 17 Jan 2023 10:12:52 -0700 Subject: [PATCH 2/2] avoid truncation if less than an hour --- relayer/chains/cosmos/provider.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 96b676307..b13e6537a 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -218,8 +218,13 @@ func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, er // and then re-growing by 85x. tp := unbondingTime / 100 * 85 - // And we only want the trusting period to be whole hours. - return tp.Truncate(time.Hour), nil + // We only want the trusting period to be whole hours unless it's less than an hour (for testing). + truncated := tp.Truncate(time.Hour) + if truncated.Hours() == 0 { + return tp, nil + } + + return truncated, nil } // Sprint returns the json representation of the specified proto message.