Skip to content
Open
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
15 changes: 15 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: v2
inputs:
- git_repo: https://github.com/cosmos/platform.git
subdir: apps/relayer/proto
paths:
- relayerapi/service.proto
plugins:
- remote: buf.build/protocolbuffers/go
out: ift/relayer/pb
opt:
- paths=source_relative
- remote: buf.build/grpc/go
out: ift/relayer/pb
opt:
- paths=source_relative
9 changes: 9 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v2
modules:
- path: .
lint:
use:
- STANDARD
breaking:
use:
- FILE
6 changes: 6 additions & 0 deletions chains/cosmos/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"math"
"strings"
"time"

Expand All @@ -27,6 +28,7 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

cosmosift "github.com/skip-mev/catalyst/chains/cosmos/ift"
"github.com/skip-mev/catalyst/chains/cosmos/types"
logging "github.com/skip-mev/catalyst/chains/log"
)
Expand Down Expand Up @@ -188,6 +190,9 @@ func (c *Chain) GetGasLimit(ctx context.Context) (int64, error) {
}

maxGas := params.ConsensusParams.Block.MaxGas
if maxGas == -1 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our test chain did not have max gas configured causing catalyst to fail on the maxGas check below in lin 196

return math.MaxInt64, nil
}
if maxGas <= 0 {
return 0, fmt.Errorf("invalid max gas value: %d", maxGas)
}
Expand Down Expand Up @@ -281,6 +286,7 @@ func getInterfaceRegistry() codectypes.InterfaceRegistry {
std.RegisterInterfaces(registry)
authtypes.RegisterInterfaces(registry)
banktypes.RegisterInterfaces(registry)
cosmosift.RegisterInterfaces(registry)
return registry
}

Expand Down
141 changes: 141 additions & 0 deletions chains/cosmos/ift/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package ift

import (
"fmt"
"strings"
"sync"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
gogoproto "github.com/cosmos/gogoproto/proto"
)

const DefaultMsgIFTTransferTypeURL = "catalyst.ift.v1.MsgIFTTransfer"

var (
typeRegistrationMu sync.Mutex
registeredTypeURLs = map[string]struct{}{}
)

type MsgIFTTransfer struct {
Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"`
Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"`
ClientID string `protobuf:"bytes,3,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"`
Amount string `protobuf:"bytes,5,opt,name=amount,proto3" json:"amount,omitempty"`
TimeoutTimestamp uint64 `protobuf:"varint,6,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty"`
}

func (m *MsgIFTTransfer) Reset() { *m = MsgIFTTransfer{} }
func (m *MsgIFTTransfer) String() string { return gogoproto.CompactTextString(m) }
func (*MsgIFTTransfer) ProtoMessage() {}

// Descriptor satisfies the descriptorIface the cosmos-sdk tx decoder uses
// (codec/unknownproto/unknown_fields.go). Path index 4 corresponds to
// MsgIFTTransfer's position within wfchain/ift/tx.proto.
func (*MsgIFTTransfer) Descriptor() ([]byte, []int) {
return fileDescriptor, []int{4}
}

// fileDescriptor is the gzipped FileDescriptorProto for wfchain/ift/tx.proto,
// copied verbatim from github.com/cosmos/wfchain/x/ift/types/tx.pb.go.
var fileDescriptor = []byte{
// 721 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xc1, 0x4e, 0xdb, 0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 0x64, 0xfd, 0x17, 0x5b,
0x6a, 0xd0, 0xb5, 0xd6, 0xef, 0x0f, 0xa5, 0x44, 0x53, 0xf2, 0x1a, 0x26, 0xfb, 0x6f, 0x7d, 0xfe,
0x7a, 0x75, 0x8c, 0xa0, 0xdf, 0x1b, 0x42, 0x88, 0x9a, 0x3f, 0x87, 0x4c, 0xef, 0x5d, 0x9d, 0xef,
0xaf, 0xeb, 0x01, 0xf5, 0xff, 0x6f, 0x00, 0xa3, 0x86, 0x15, 0xf8, 0xab, 0x3b, 0xb3, 0xb3, 0x03,
0xf8, 0x3e, 0xa0, 0xe7, 0x7f, 0x01, 0x44, 0x4d, 0x0c, 0xf8, 0x3b, 0x36, 0x03, 0x0b, 0xfd, 0x05,
0xbd, 0xa8, 0x7e, 0xe7, 0x26, 0xb4, 0xdb, 0x53, 0x1f, 0x7d, 0x7f, 0x79, 0xb8, 0xac, 0x94, 0x9f,
0x1e, 0x9f, 0xe7, 0x94, 0x93, 0xf3, 0x9c, 0xf2, 0xfd, 0x3c, 0xa7, 0x1c, 0x5c, 0xe4, 0x12, 0x27,
0x17, 0xb9, 0xc4, 0x97, 0x8b, 0x5c, 0xe2, 0xd5, 0x5d, 0x17, 0x8b, 0x66, 0x67, 0xa7, 0x68, 0x51,
0x4f, 0xbe, 0x63, 0xa5, 0xee, 0x53, 0xb5, 0x17, 0xbe, 0x8c, 0xfb, 0x6d, 0xc4, 0x77, 0xd2, 0xc1,
0x7b, 0xf5, 0xf0, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x90, 0x20, 0x0a, 0x35, 0x07, 0x00,
0x00,
}

func RegisterTypeURL(typeURL string) {
if typeURL == "" {
typeURL = DefaultMsgIFTTransferTypeURL
}
typeURL = strings.TrimPrefix(typeURL, "/")

typeRegistrationMu.Lock()
defer typeRegistrationMu.Unlock()

if _, exists := registeredTypeURLs[typeURL]; exists {
return
}

gogoproto.RegisterType((*MsgIFTTransfer)(nil), typeURL)
registeredTypeURLs[typeURL] = struct{}{}
}

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgIFTTransfer{})
}

func (m *MsgIFTTransfer) GetSigners() []sdk.AccAddress {
if m.Signer == "" {
return []sdk.AccAddress{}
}

return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Signer)}
}

func (m *MsgIFTTransfer) ValidateBasic() error {
if m.Signer == "" {
return fmt.Errorf("signer must be specified")
}
if m.Denom == "" {
return fmt.Errorf("denom must be specified")
}
if m.ClientID == "" {
return fmt.Errorf("client_id must be specified")
}
if m.Receiver == "" {
return fmt.Errorf("receiver must be specified")
}
if m.Amount == "" {
return fmt.Errorf("amount must be specified")
}
if m.TimeoutTimestamp == 0 {
return fmt.Errorf("timeout_timestamp must be specified")
}
return nil
}
46 changes: 46 additions & 0 deletions chains/cosmos/ift/msg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ift

import (
"testing"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/stretchr/testify/require"
)

func TestMsgIFTTransferPacksWithConfiguredTypeURL(t *testing.T) {
const typeURL = "example.ift.v1.MsgIFTTransfer"

RegisterTypeURL(typeURL)

msg := &MsgIFTTransfer{
Signer: "cosmos1deadbeefdeadbeefdeadbeefdeadbeef00",
Denom: "stake",
ClientID: "client-0",
Receiver: "0x1234567890123456789012345678901234567890",
Amount: "100",
TimeoutTimestamp: 123,
}

anyMsg, err := codectypes.NewAnyWithValue(msg)
require.NoError(t, err)
require.Equal(t, "/"+typeURL, anyMsg.TypeUrl)
}

func TestMsgIFTTransferPacksWithConfiguredTypeURLLeadingSlash(t *testing.T) {
const typeURL = "/example.ift.v1.MsgIFTTransfer"

RegisterTypeURL(typeURL)

msg := &MsgIFTTransfer{
Signer: "cosmos1deadbeefdeadbeefdeadbeefdeadbeef00",
Denom: "stake",
ClientID: "client-0",
Receiver: "0x1234567890123456789012345678901234567890",
Amount: "100",
TimeoutTimestamp: 123,
}

anyMsg, err := codectypes.NewAnyWithValue(msg)
require.NoError(t, err)
require.Equal(t, "/example.ift.v1.MsgIFTTransfer", anyMsg.TypeUrl)
}
Loading
Loading