Skip to content

Commit

Permalink
Add Fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
vimystic committed Sep 12, 2023
1 parent 0df7b55 commit 433c916
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
15 changes: 3 additions & 12 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 433c916

Please sign in to comment.