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 trusting period query for ics chains #1072

Merged
merged 3 commits into from
Jan 30, 2023
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
23 changes: 19 additions & 4 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -206,10 +216,15 @@ 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

// 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
}

// And we only want the trusting period to be whole hours.
return tp.Truncate(time.Hour), nil
return truncated, nil
}

// Sprint returns the json representation of the specified proto message.
Expand Down