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

Query param prop directly #1264

Merged
merged 13 commits into from
Sep 13, 2023
1 change: 1 addition & 0 deletions interchaintest/tendermint_v0.37_boundary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestScenarioTendermint37Boundary(t *testing.T) {
rf := relayerinterchaintest.NewRelayerFactory(relayerinterchaintest.RelayerConfig{
InitialBlockHistory: 50,
})

r := rf.Build(t, client, network)

t.Parallel()
Expand Down
14 changes: 2 additions & 12 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,11 @@ func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk.
}

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.
// 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
62 changes: 46 additions & 16 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/query"
querytypes "github.com/cosmos/cosmos-sdk/types/query"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
Expand Down Expand Up @@ -189,7 +188,7 @@ func parseEventsFromResponseDeliverTx(resp abci.ResponseDeliverTx) []provider.Re

// QueryFeegrantsByGrantee returns all requested grants for the given grantee.
// Default behavior will return all grants.
func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *query.PageRequest) ([]*feegrant.Grant, error) {
func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *querytypes.PageRequest) ([]*feegrant.Grant, error) {
grants := []*feegrant.Grant{}
allPages := paginator == nil

Expand Down Expand Up @@ -228,7 +227,7 @@ func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *que

// Feegrant_GrantsByGranterRPC returns all requested grants for the given Granter.
// Default behavior will return all grants.
func (cc *CosmosProvider) QueryFeegrantsByGranter(address string, paginator *query.PageRequest) ([]*feegrant.Grant, error) {
func (cc *CosmosProvider) QueryFeegrantsByGranter(address string, paginator *querytypes.PageRequest) ([]*feegrant.Grant, error) {
grants := []*feegrant.Grant{}
allPages := paginator == nil

Expand Down Expand Up @@ -316,42 +315,73 @@ func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (tim

params := proposal.QueryParamsRequest{Subspace: "ccvconsumer", Key: "UnbondingPeriod"}

resICS, err := queryClient.Params(ctx, &params)
res, err := queryClient.Params(ctx, &params)

if err != nil {
return 0, fmt.Errorf("failed to make ccvconsumer params request: %w", err)
}

if resICS.Param.Value == "" {
if res.Param.Value == "" {
return 0, fmt.Errorf("ccvconsumer unbonding period is empty")
}

unbondingPeriod, err := strconv.ParseUint(strings.ReplaceAll(resICS.Param.Value, `"`, ""), 10, 64)
unbondingPeriod, err := strconv.ParseUint(strings.ReplaceAll(res.Param.Value, `"`, ""), 10, 64)
if err != nil {
return 0, fmt.Errorf("failed to parse unbonding period from ccvconsumer param: %w", err)
}

return time.Duration(unbondingPeriod), nil
}

func (cc *CosmosProvider) queryStakingUnbondingPeriod(ctx context.Context) (time.Duration, error) {
vimystic marked this conversation as resolved.
Show resolved Hide resolved
queryClient := proposal.NewQueryClient(cc)

params := proposal.QueryParamsRequest{Subspace: "staking", Key: "UnbondingTime"}

res, err := queryClient.Params(ctx, &params)

if err != nil {
return 0, fmt.Errorf("failed to make staking params request: %w", err)
}

if res.Param.Value == "" {
return 0, fmt.Errorf("staking unbonding period is empty")
}

unbondingTime, err := strconv.ParseUint(strings.ReplaceAll(res.Param.Value, `"`, ""), 10, 64)
if err != nil {
return 0, fmt.Errorf("failed to parse unbonding period from staking param: %w", err)
}

return time.Duration(unbondingTime), nil
}

// QueryUnbondingPeriod returns the unbonding period of the chain
func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Duration, error) {

// Attempt ICS query
consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx)
if consumerErr == nil {
return consumerUnbondingPeriod, nil
}

//Attempt Staking query.
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 {
// 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)
}
if err == nil {
return res.Params.UnbondingTime, nil

return consumerUnbondingPeriod, nil
}

return res.Params.UnbondingTime, 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
Loading