Skip to content

Commit

Permalink
whitelist TWAP query on osmosis genesis setup
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed May 22, 2024
1 parent 5cb267f commit e3ad87c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 2 additions & 6 deletions tests/interchaintest/query_osmosis_twap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
22 changes: 22 additions & 0 deletions tests/interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions x/feeabs/keeper/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit e3ad87c

Please sign in to comment.