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

chore: remove retry on getChannels for initializeChannelCache #166

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions relayer/chains/wasm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (ap *WasmProvider) QueryClientStateContract(ctx context.Context, clientId s

iconClientState, ok := clientS.(*icon.ClientState)
if !ok {
return nil, fmt.Errorf("Error casting to icon.ClientState")
return nil, fmt.Errorf("error casting to icon.ClientState")
}

return iconClientState, nil
Expand All @@ -297,13 +297,13 @@ func (ap *WasmProvider) QueryConnectionContract(ctx context.Context, connId stri
return &connS, nil
}

func (ap *WasmProvider) QueryChannelContract(ctx context.Context, portId, channelId string) (*chantypes.Channel, error) {
func (ap *WasmProvider) QueryChannelContractNoRetry(ctx context.Context, portId, channelId string) (*chantypes.Channel, error) {
channelStateParam, err := types.NewChannel(portId, channelId).Bytes()
if err != nil {
return nil, err
}

channelState, err := ap.QueryIBCHandlerContractProcessed(ctx, channelStateParam)
channelState, err := ap.QueryIBCHandlerContractNoRetry(ctx, channelStateParam)
if err != nil {
return nil, err
}
Expand All @@ -318,6 +318,9 @@ func (ap *WasmProvider) QueryChannelContract(ctx context.Context, portId, channe
func (ap *WasmProvider) QueryClientConsensusState(ctx context.Context, chainHeight int64, clientid string, clientHeight ibcexported.Height) (*clienttypes.QueryConsensusStateResponse, error) {

consensusStateParam, err := types.NewConsensusStateByHeight(clientid, uint64(clientHeight.GetRevisionHeight())).Bytes()
if err != nil {
return nil, err
}
consensusState, err := ap.QueryIBCHandlerContractProcessed(ctx, consensusStateParam)
if err != nil {
return nil, err
Expand Down Expand Up @@ -356,6 +359,24 @@ func (ap *WasmProvider) QueryIBCHandlerContract(ctx context.Context, param wasmt
}))
}

func (ap *WasmProvider) QueryIBCHandlerContractNoRetry(ctx context.Context, param wasmtypes.RawContractMessage) ([]byte, error) {
done := ap.SetSDKContext()
defer done()
resp, err := ap.QueryClient.SmartContractState(ctx, &wasmtypes.QuerySmartContractStateRequest{
Address: ap.PCfg.IbcHandlerAddress,
QueryData: param,
})
if err != nil {
ap.log.Error(
"Failed to query",
zap.Any("Param", param),
zap.Error(err),
)
return nil, err
}
return ProcessContractResponse(resp)
}

func (ap *WasmProvider) QueryIBCHandlerContractProcessed(ctx context.Context, param wasmtypes.RawContractMessage) ([]byte, error) {
res, err := ap.QueryIBCHandlerContract(ctx, param)
if err != nil {
Expand Down Expand Up @@ -501,6 +522,9 @@ func (ap *WasmProvider) QueryConnection(ctx context.Context, height int64, conne

storageKey := getStorageKeyFromPath(common.GetConnectionCommitmentKey(connectionid))
connProof, err := ap.QueryWasmProof(ctx, storageKey, height)
if err != nil {
return nil, err
}

return conntypes.NewQueryConnectionResponse(conn, connProof, clienttypes.NewHeight(0, uint64(height))), nil
}
Expand All @@ -522,7 +546,7 @@ func (ap *WasmProvider) QueryWasmProof(ctx context.Context, storageKey []byte, h
}

req := abci.RequestQuery{
Path: fmt.Sprintf("store/wasm/key"),
Path: "store/wasm/key",
Data: key,
Prove: true,
Height: height,
Expand Down Expand Up @@ -643,6 +667,9 @@ func (ap *WasmProvider) QueryChannel(ctx context.Context, height int64, channeli

storageKey := getStorageKeyFromPath(common.GetChannelCommitmentKey(portid, channelid))
proof, err := ap.QueryWasmProof(ctx, storageKey, height)
if err != nil {
return nil, err
}

return chantypes.NewQueryChannelResponse(channelS, proof, clienttypes.NewHeight(0, uint64(height))), nil
}
Expand Down Expand Up @@ -683,7 +710,7 @@ func (ap *WasmProvider) QueryChannels(ctx context.Context) ([]*chantypes.Identif
for i := 0; i <= int(nextSeq)-1; i++ {
for _, portId := range allPorts {
channelId := common.GetIdentifier(common.ChannelKey, i)
channel, err := ap.QueryChannelContract(ctx, portId, channelId)
channel, err := ap.QueryChannelContractNoRetry(ctx, portId, channelId)
if err != nil {
continue
}
Expand Down
10 changes: 6 additions & 4 deletions relayer/chains/wasm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package wasm
import (
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"strings"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/relayer/v2/relayer/common"
Expand All @@ -30,9 +30,11 @@ func byteToInt(b []byte) (int, error) {
}

func ProcessContractResponse(p *wasmtypes.QuerySmartContractStateResponse) ([]byte, error) {
data := string(p.Data.Bytes())
trimmedData := strings.ReplaceAll(data, `"`, "")
return hex.DecodeString(trimmedData)
var output string
if err := json.Unmarshal(p.Data.Bytes(), &output); err != nil {
return nil, err
}
return hex.DecodeString(output)
}

func getStorageKeyFromPath(path []byte) []byte {
Expand Down