From 4cbcbe1a312d723e903a877c4e315d6f25a6dc32 Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Fri, 18 Aug 2023 18:52:30 -0600 Subject: [PATCH 1/7] Query param prop directly --- relayer/chains/cosmos/provider.go | 13 ++----- relayer/chains/cosmos/query.go | 58 +++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index c33743faf..250d3e5b5 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -226,19 +226,10 @@ 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. diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index dfc040214..978df9a2a 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -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" @@ -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 @@ -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 @@ -316,17 +315,17 @@ func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (tim params := proposal.QueryParamsRequest{Subspace: "ccvconsumer", Key: "UnbondingPeriod"} - resICS, err := queryClient.Params(ctx, ¶ms) + res, err := queryClient.Params(ctx, ¶ms) 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) } @@ -334,24 +333,45 @@ func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (tim return time.Duration(unbondingPeriod), nil } -// QueryUnbondingPeriod returns the unbonding period of the chain -func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Duration, error) { - req := stakingtypes.QueryParamsRequest{} - queryClient := stakingtypes.NewQueryClient(cc) +func (cc *CosmosProvider) queryStakingUnbondingPeriod(ctx context.Context) (time.Duration, error) { + queryClient := proposal.NewQueryClient(cc) + + params := proposal.QueryParamsRequest{Subspace: "staking", Key: "UnbondingTime"} + + res, err := queryClient.Params(ctx, ¶ms) - 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) - } + 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 Staking query. + unbondingPeriod, err := cc.queryStakingUnbondingPeriod(ctx) + if err == nil { + return unbondingPeriod, nil + } - return consumerUnbondingPeriod, 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) } - return res.Params.UnbondingTime, nil + return consumerUnbondingPeriod, nil } // QueryTendermintProof performs an ABCI query with the given key and returns From 5bb21aec0cbb53cf4fd1d26ef4468de2076741b7 Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:00:40 -0600 Subject: [PATCH 2/7] Update tendermint_v0.37_boundary_test.go To include the latest versions of Gaia v12.0.0-rc0 ibc-go-simd v7.2.0 relayer v2.4.1 --- .../tendermint_v0.37_boundary_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/interchaintest/tendermint_v0.37_boundary_test.go b/interchaintest/tendermint_v0.37_boundary_test.go index 04a7a8c47..442cb345d 100644 --- a/interchaintest/tendermint_v0.37_boundary_test.go +++ b/interchaintest/tendermint_v0.37_boundary_test.go @@ -4,10 +4,12 @@ import ( "context" "testing" - relayerinterchaintest "github.com/cosmos/relayer/v2/interchaintest" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/conformance" + "github.com/strangelove-ventures/interchaintest/v7/ibc" + "github.com/strangelove-ventures/interchaintest/v7/relayer" + "github.com/strangelove-ventures/interchaintest/v7/relayer/rly" "github.com/strangelove-ventures/interchaintest/v7/testreporter" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" @@ -25,7 +27,7 @@ func TestScenarioTendermint37Boundary(t *testing.T) { { Name: "gaia", ChainName: "gaia", - Version: "v7.0.3", + Version: "v12.0.0-rc0", NumValidators: &nv, NumFullNodes: &nf, }, @@ -33,7 +35,7 @@ func TestScenarioTendermint37Boundary(t *testing.T) { // TODO update with mainnet SDK v0.47+ chain version once available Name: "ibc-go-simd", ChainName: "ibc-go-simd", - Version: "andrew-47-rc1", + Version: "v7.2.0", NumValidators: &nv, NumFullNodes: &nf, }, @@ -51,9 +53,12 @@ func TestScenarioTendermint37Boundary(t *testing.T) { relayerName = "relayer" ) - rf := relayerinterchaintest.NewRelayerFactory(relayerinterchaintest.RelayerConfig{ - InitialBlockHistory: 50, - }) + rf := interchaintest.NewBuiltinRelayerFactory( + ibc.CosmosRly, + zaptest.NewLogger(t), + relayer.CustomDockerImage("ghcr.io/cosmos/relayer", "v2.4.1", rly.RlyDefaultUidGid), + ) + r := rf.Build(t, client, network) t.Parallel() From 5493c83f319cb26c6b78050e64a1b3f38eec133b Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Mon, 11 Sep 2023 10:56:35 -0600 Subject: [PATCH 3/7] Flip order of queries for QueryUnbondingPeriod --- relayer/chains/cosmos/query.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index 978df9a2a..eccba377b 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -358,20 +358,21 @@ func (cc *CosmosProvider) queryStakingUnbondingPeriod(ctx context.Context) (time // QueryUnbondingPeriod returns the unbonding period of the chain func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Duration, error) { - //Attempt Staking query. - unbondingPeriod, err := cc.queryStakingUnbondingPeriod(ctx) - if err == nil { - return unbondingPeriod, nil - } // Attempt ICS query consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx) - if consumerErr != nil { + if consumerErr == nil { + return consumerUnbondingPeriod, nil + } + + //Attempt Staking query. + unbondingPeriod, err := cc.queryStakingUnbondingPeriod(ctx) + if err != nil { return 0, - fmt.Errorf("failed to query unbonding period as both standard and consumer chain: %s: %w", err.Error(), consumerErr) + fmt.Errorf("failed to query unbonding period as both consumer and standard chain: %w: %s", consumerErr, err.Error()) } - return consumerUnbondingPeriod, nil + return unbondingPeriod, nil } // QueryTendermintProof performs an ABCI query with the given key and returns From 33e797f03c114bebd9b1bda2c06d66ea527e5f40 Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 12 Sep 2023 09:39:01 -0600 Subject: [PATCH 4/7] Add fallback for chains using cosmos-sdk 47+ --- .../tendermint_v0.37_boundary_test.go | 16 ++++++---------- relayer/chains/cosmos/provider.go | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/interchaintest/tendermint_v0.37_boundary_test.go b/interchaintest/tendermint_v0.37_boundary_test.go index 442cb345d..e25790176 100644 --- a/interchaintest/tendermint_v0.37_boundary_test.go +++ b/interchaintest/tendermint_v0.37_boundary_test.go @@ -4,12 +4,10 @@ import ( "context" "testing" + relayerinterchaintest "github.com/cosmos/relayer/v2/interchaintest" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/conformance" - "github.com/strangelove-ventures/interchaintest/v7/ibc" - "github.com/strangelove-ventures/interchaintest/v7/relayer" - "github.com/strangelove-ventures/interchaintest/v7/relayer/rly" "github.com/strangelove-ventures/interchaintest/v7/testreporter" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" @@ -27,7 +25,7 @@ func TestScenarioTendermint37Boundary(t *testing.T) { { Name: "gaia", ChainName: "gaia", - Version: "v12.0.0-rc0", + Version: "v7.0.3", NumValidators: &nv, NumFullNodes: &nf, }, @@ -35,7 +33,7 @@ func TestScenarioTendermint37Boundary(t *testing.T) { // TODO update with mainnet SDK v0.47+ chain version once available Name: "ibc-go-simd", ChainName: "ibc-go-simd", - Version: "v7.2.0", + Version: "andrew-47-rc1", NumValidators: &nv, NumFullNodes: &nf, }, @@ -53,11 +51,9 @@ func TestScenarioTendermint37Boundary(t *testing.T) { relayerName = "relayer" ) - rf := interchaintest.NewBuiltinRelayerFactory( - ibc.CosmosRly, - zaptest.NewLogger(t), - relayer.CustomDockerImage("ghcr.io/cosmos/relayer", "v2.4.1", rly.RlyDefaultUidGid), - ) + rf := relayerinterchaintest.NewRelayerFactory(relayerinterchaintest.RelayerConfig{ + InitialBlockHistory: 50, + }) r := rf.Build(t, client, network) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 250d3e5b5..4a8412d09 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -226,10 +226,26 @@ func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk. } func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) { + var unbondingTime time.Duration unbondingTime, err := cc.QueryUnbondingPeriod(ctx) + if err == nil { + return unbondingTime, nil + } else { + fmt.Println("%w", err) + } + + res, err := cc.QueryStakingParams(ctx) 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. From 0df7b5581b2a47a267621fcd082d54474e4f7e8d Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:44:12 -0600 Subject: [PATCH 5/7] Trusting period logic remains same --- relayer/chains/cosmos/provider.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 4a8412d09..ae0b0eada 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -227,14 +227,6 @@ func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk. func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) { var unbondingTime time.Duration - - unbondingTime, err := cc.QueryUnbondingPeriod(ctx) - if err == nil { - return unbondingTime, nil - } else { - fmt.Println("%w", err) - } - res, err := cc.QueryStakingParams(ctx) if err != nil { // Attempt ICS query From 433c916e159f333ea365525f83dc7128e85e9614 Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:00:16 -0600 Subject: [PATCH 6/7] Add Fallback --- relayer/chains/cosmos/provider.go | 15 +++------------ relayer/chains/cosmos/query.go | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 17 deletions(-) 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 From cf4f5285343363c098d6cea64c6f03a5dd7dfd33 Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:37:14 -0600 Subject: [PATCH 7/7] Consolidate functions into a single queryParamsSubspaceTime --- relayer/chains/cosmos/query.go | 41 ++++++++-------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index a328d7044..d41f25bdc 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -310,63 +310,40 @@ func (cc *CosmosProvider) QueryBalanceWithAddress(ctx context.Context, address s return coins, nil } -func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (time.Duration, error) { +func (cc *CosmosProvider) queryParamsSubspaceTime(ctx context.Context, subspace string, key string) (time.Duration, error) { queryClient := proposal.NewQueryClient(cc) - params := proposal.QueryParamsRequest{Subspace: "ccvconsumer", Key: "UnbondingPeriod"} + params := proposal.QueryParamsRequest{Subspace: subspace, Key: key} res, err := queryClient.Params(ctx, ¶ms) if err != nil { - return 0, fmt.Errorf("failed to make ccvconsumer params request: %w", err) + return 0, fmt.Errorf("failed to make %s params request: %w", subspace, err) } if res.Param.Value == "" { - return 0, fmt.Errorf("ccvconsumer unbonding period is empty") + return 0, fmt.Errorf("%s %s is empty", subspace, key) } - unbondingPeriod, err := strconv.ParseUint(strings.ReplaceAll(res.Param.Value, `"`, ""), 10, 64) + unbondingValue, 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 0, fmt.Errorf("failed to parse %s from %s param: %w", key, subspace, err) } - return time.Duration(unbondingPeriod), nil -} - -func (cc *CosmosProvider) queryStakingUnbondingPeriod(ctx context.Context) (time.Duration, error) { - queryClient := proposal.NewQueryClient(cc) - - params := proposal.QueryParamsRequest{Subspace: "staking", Key: "UnbondingTime"} - - res, err := queryClient.Params(ctx, ¶ms) - - 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 + return time.Duration(unbondingValue), 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) + consumerUnbondingPeriod, consumerErr := cc.queryParamsSubspaceTime(ctx, "ccvconsumer", "UnbondingPeriod") if consumerErr == nil { return consumerUnbondingPeriod, nil } //Attempt Staking query. - unbondingPeriod, stakingParamsErr := cc.queryStakingUnbondingPeriod(ctx) + unbondingPeriod, stakingParamsErr := cc.queryParamsSubspaceTime(ctx, "staking", "UnbondingTime") if stakingParamsErr == nil { return unbondingPeriod, nil }