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 @@

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")

Check warning on line 275 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L275

Added line #L275 was not covered by tests
}

return iconClientState, nil
Expand All @@ -297,13 +297,13 @@
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) {

Check warning on line 300 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L300

Added line #L300 was not covered by tests
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)

Check warning on line 306 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L306

Added line #L306 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -316,46 +316,67 @@
}

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
}

Check warning on line 323 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L319-L323

Added lines #L319 - L323 were not covered by tests
consensusState, err := ap.QueryIBCHandlerContractProcessed(ctx, consensusStateParam)
if err != nil {
return nil, err
}

cdc := codec.NewProtoCodec(ap.Cdc.InterfaceRegistry)
csState, err := clienttypes.UnmarshalConsensusState(cdc, consensusState)
if err != nil {

Check warning on line 331 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L329-L331

Added lines #L329 - L331 were not covered by tests
return nil, err
}

anyConsensusState, err := clienttypes.PackConsensusState(csState)

Check warning on line 335 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L335

Added line #L335 was not covered by tests
if err != nil {
return nil, err
}
return clienttypes.NewQueryConsensusStateResponse(anyConsensusState, nil, clienttypes.NewHeight(0, uint64(chainHeight))), nil
}

func (ap *WasmProvider) QueryIBCHandlerContract(ctx context.Context, param wasmtypes.RawContractMessage) (op *wasmtypes.QuerySmartContractStateResponse, err error) {
return op, retry.Do(func() error {
done := ap.SetSDKContext()
defer done()
op, err = ap.QueryClient.SmartContractState(ctx, &wasmtypes.QuerySmartContractStateRequest{
Address: ap.PCfg.IbcHandlerAddress,
QueryData: param,
})
return err
}, retry.Context(ctx), retry.Attempts(latestHeightQueryRetries), retry.Delay(50*time.Millisecond), retry.LastErrorOnly(true), retry.OnRetry(func(n uint, err error) {
ap.log.Error(
"Failed to query",
zap.Uint("attempt", n+1),
zap.Uint("max_attempts", latestHeightQueryRetries),
zap.Any("Param", param),
zap.Error(err),
)
}))

Check warning on line 359 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L342-L359

Added lines #L342 - L359 were not covered by tests
}

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{

Check warning on line 365 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L362-L365

Added lines #L362 - L365 were not covered by tests
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)

Check warning on line 377 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L369-L377

Added lines #L369 - L377 were not covered by tests
}

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,13 +522,16 @@

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

Check warning on line 527 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L525-L527

Added lines #L525 - L527 were not covered by tests

return conntypes.NewQueryConnectionResponse(conn, connProof, clienttypes.NewHeight(0, uint64(height))), nil
}

func (ap *WasmProvider) QueryWasmProof(ctx context.Context, storageKey []byte, height int64) ([]byte, error) {
done := ap.SetSDKContext()
defer done()

Check warning on line 534 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L533-L534

Added lines #L533 - L534 were not covered by tests
ibcAddr, err := sdk.AccAddressFromBech32(ap.PCfg.IbcHandlerAddress)
if err != nil {
return nil, err
Expand All @@ -522,7 +546,7 @@
}

req := abci.RequestQuery{
Path: fmt.Sprintf("store/wasm/key"),
Path: "store/wasm/key",

Check warning on line 549 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L549

Added line #L549 was not covered by tests
Data: key,
Prove: true,
Height: height,
Expand Down Expand Up @@ -643,6 +667,9 @@

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

Check warning on line 672 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L670-L672

Added lines #L670 - L672 were not covered by tests

return chantypes.NewQueryChannelResponse(channelS, proof, clienttypes.NewHeight(0, uint64(height))), nil
}
Expand Down Expand Up @@ -683,7 +710,7 @@
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)

Check warning on line 713 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L713

Added line #L713 was not covered by tests
if err != nil {
continue
}
Expand Down Expand Up @@ -732,10 +759,10 @@
if err != nil {
return nil, err
}
var seq uint64
if err := json.Unmarshal(nextSeqRecv.Data, &seq); err != nil {
return nil, err
}

Check warning on line 765 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L762-L765

Added lines #L762 - L765 were not covered by tests

proof, err := ap.QueryWasmProof(ctx, common.MustHexStrToBytes(STORAGEKEY__NextSequenceReceive), height)
if err != nil {
Expand All @@ -743,7 +770,7 @@
}

return &chantypes.QueryNextSequenceReceiveResponse{
NextSequenceReceive: seq,

Check warning on line 773 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L773

Added line #L773 was not covered by tests
Proof: proof,
ProofHeight: clienttypes.NewHeight(0, uint64(height)),
}, nil
Expand Down Expand Up @@ -864,22 +891,22 @@
return transfers, nil
}

func (ap *WasmProvider) QueryClientPrevConsensusStateHeight(ctx context.Context, chainHeight int64, clientId string, clientHeight int64) (exported.Height, error) {
param, err := types.NewPrevConsensusStateHeight(clientId, uint64(clientHeight)).Bytes()
res, err := ap.QueryIBCHandlerContract(ctx, param)
if err != nil {
return nil, err
}

Check warning on line 899 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L894-L899

Added lines #L894 - L899 were not covered by tests

var heights []int64
err = json.Unmarshal(res.Data.Bytes(), &heights)

if err != nil {
return nil, err
}

Check warning on line 906 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L901-L906

Added lines #L901 - L906 were not covered by tests

if len(heights) == 0 {
return nil, fmt.Errorf("consensus state of client %s before %d", clientId, clientHeight)
}
return clienttypes.Height{RevisionNumber: 0, RevisionHeight: uint64(heights[0])}, nil

Check warning on line 911 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L908-L911

Added lines #L908 - L911 were not covered by tests
}
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 @@
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 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)

Check warning on line 37 in relayer/chains/wasm/utils.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/utils.go#L33-L37

Added lines #L33 - L37 were not covered by tests
}

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