From e3ad87c8d3ba6ba4eb7c1938ef449302aafd3034 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Thu, 23 May 2024 00:39:50 +0700 Subject: [PATCH] whitelist TWAP query on osmosis genesis setup --- .../interchaintest/query_osmosis_twap_test.go | 8 ++----- tests/interchaintest/setup.go | 22 +++++++++++++++++++ x/feeabs/keeper/ibc.go | 4 ++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/interchaintest/query_osmosis_twap_test.go b/tests/interchaintest/query_osmosis_twap_test.go index 012b500e..67e05cdc 100644 --- a/tests/interchaintest/query_osmosis_twap_test.go +++ b/tests/interchaintest/query_osmosis_twap_test.go @@ -7,7 +7,6 @@ import ( "os" "path" "testing" - "time" sdktypes "github.com/cosmos/cosmos-sdk/types" paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" @@ -155,7 +154,7 @@ func TestQueryOsmosisTwap(t *testing.T) { height, err := feeabs.Height(ctx) require.NoError(t, err) - _, err = cosmos.PollForProposalStatus(ctx, feeabs, height, height+10, paramTx.ProposalID, cosmos.ProposalStatusPassed) + _, err = cosmos.PollForProposalStatus(ctx, feeabs, height, height+20, paramTx.ProposalID, cosmos.ProposalStatusPassed) require.NoError(t, err, "proposal status did not change to passed in expected number of blocks") _, err = feeabsCli.AddHostZoneProposal(feeabs, ctx, feeabsUser.KeyName(), "./proposal/add_host_zone.json") @@ -173,16 +172,13 @@ func TestQueryOsmosisTwap(t *testing.T) { allHost, err := feeabsCli.QueryAllHostZoneConfig(feeabs, ctx) require.NoError(t, err) fmt.Printf("QueryAllHostZoneConfig %+v", allHost) - err = testutil.WaitForBlocks(ctx, 15, feeabs) + err = testutil.WaitForBlocks(ctx, 30, feeabs) require.NoError(t, err) - time.Sleep(180 * time.Second) twapOsmosis, err := feeabsCli.QueryOsmosisArithmeticTwap(feeabs, ctx, stakeOnOsmosis) require.NoError(t, err) fmt.Println(twapOsmosis) twap, err := feeabsCli.QueryOsmosisArithmeticTwapOsmosis(osmosis, ctx, "1", stakeOnOsmosis) - fmt.Println(err) fmt.Println(twap) - require.NoError(t, err) } diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 8d7bd80e..ad35e56e 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -123,6 +123,27 @@ func GetDockerImageInfo() (repo, version string) { return repo, branchVersion } +func modifyGenesisWhitelistTwapQueryOsmosis() func(ibc.ChainConfig, []byte) ([]byte, error) { + return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { + g := make(map[string]interface{}) + if err := json.Unmarshal(genbz, &g); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err) + } + // "interchainquery":{"host_port":"icqhost","params":{"allow_queries":[],"host_enabled":true}} + whitelist := "/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow" + // failed to start chains: failed to start chain osmosis-3: failed to set whitelist in genesis json: index out of range: 0 (path element idx: 4) + if err := dyno.Append(g, whitelist, "app_state", "interchainquery", "params", "allow_queries"); err != nil { + return nil, fmt.Errorf("failed to set whitelist in genesis json: %w", err) + } + fmt.Println("Genesis file updated", g) + out, err := json.Marshal(g) + if err != nil { + return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err) + } + return out, nil + } +} + func modifyGenesisShortProposals(votingPeriod string, maxDepositPeriod string, queryEpochTime string) func(ibc.ChainConfig, []byte) ([]byte, error) { return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { g := make(map[string]interface{}) @@ -186,6 +207,7 @@ func SetupChain(t *testing.T, ctx context.Context) ([]ibc.Chain, []ibc.Wallet, [ ChainConfig: ibc.ChainConfig{ GasPrices: "0.005uosmo", EncodingConfig: osmosisEncoding(), + ModifyGenesis: modifyGenesisWhitelistTwapQueryOsmosis(), }, NumValidators: &numVals, NumFullNodes: &numFullNodes, diff --git a/x/feeabs/keeper/ibc.go b/x/feeabs/keeper/ibc.go index ca6b211c..4460304e 100644 --- a/x/feeabs/keeper/ibc.go +++ b/x/feeabs/keeper/ibc.go @@ -114,6 +114,7 @@ func (k Keeper) SendInterchainQuery( func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, ack channeltypes.Acknowledgement, icqReqs []abci.RequestQuery) error { switch resp := ack.Response.(type) { + case *channeltypes.Acknowledgement_Result: var ackData types.InterchainQueryPacketAck if err := types.ModuleCdc.UnmarshalJSON(resp.Result, &ackData); err != nil { @@ -282,6 +283,7 @@ func (k Keeper) HandleOsmosisIbcQuery(ctx sdk.Context) (int, error) { // fee abstraction will not send query to a frozen host zone // however, it will continue to send query to other host zone if UPDATED, or OUTDATED // this logic iterate through registered host zones and collect requests before sending it + k.Logger(ctx).Info("start iterate host zone") k.IterateHostZone(ctx, func(hostZoneConfig types.HostChainFeeAbsConfig) (stop bool) { if k.IbcQueryHostZoneFilter(ctx, hostZoneConfig, queryTwapEpochInfo) { return false @@ -371,6 +373,7 @@ func (k Keeper) ExecuteAllHostChainSwap(ctx sdk.Context) { func (k Keeper) IbcQueryHostZoneFilter(ctx sdk.Context, hostZoneConfig types.HostChainFeeAbsConfig, queryTwapEpochInfo types.EpochInfo) bool { if hostZoneConfig.Status == types.HostChainFeeAbsStatus_FROZEN { + k.Logger(ctx).Info(fmt.Sprintf("Host zone %s is frozen", hostZoneConfig.IbcDenom)) return true } @@ -384,6 +387,7 @@ func (k Keeper) IbcQueryHostZoneFilter(ctx sdk.Context, hostZoneConfig types.Hos } if queryTwapEpochInfo.CurrentEpoch < exponential.FutureEpoch { + k.Logger(ctx).Info(fmt.Sprintf("Host zone %s is not ready to query", hostZoneConfig.IbcDenom)) return true }