Skip to content

Commit

Permalink
Merge PR cosmos#318: Update to Cosmos v0.40.0-rc2, relayer v1.0.0-rc0
Browse files Browse the repository at this point in the history
* WIP contextual codecs

* Push changes

* WIP

* Merge PR cosmos#319: Remove GetSignBytes usage

* Merge PR cosmos#314: Fix timeout determination

* fix mutex

* fix timeout bug

* fix GetSignBytes

* address other calls to GetSignBytes

Co-authored-by: Jack Zampolin <[email protected]>

* Working version

* Update retries for better errors

* Update import paths and address cosmos#292

* Address cosmos#293

* Address cosmos#295

* Address cosmos#315

* Add defensive key checks per cosmos#297

* Add flags for timeout offsets

* Update retries to have better and more explainatory errors

* WIP acks

* Update to remove replace

* update to sdk master

* Update sdk and make changes

* WIP timeouts and acks, strategy refactor

* WIP cleanup

* update to v0.40.0-rc2

* Refactor path generation and status

* Merge PR cosmos#274: feat: allow building a shared library

Co-authored-by: colin axnér <[email protected]>
Co-authored-by: Michael FIG <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2020
2 parents b8ec147 + 28c36dc commit cb47e65
Show file tree
Hide file tree
Showing 52 changed files with 2,190 additions and 801 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ contributions under the terms of the [Apache License, Version 2.0]
* Jack Zampolin (@jackzampolin)

[Apache License, Version 2.0]: https://www.apache.org/licenses/LICENSE-2.0
[LICENSE]: https://github.com/ovrclk/relayer/blob/master/LICENSE
[LICENSE]: https://github.com/cosmos/relayer/blob/master/LICENSE
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ all: ci-lint install
# Build / Install
###############################################################################

LD_FLAGS = -X github.com/ovrclk/relayer/cmd.Version=$(VERSION) \
-X github.com/ovrclk/relayer/cmd.Commit=$(COMMIT) \
-X github.com/ovrclk/relayer/cmd.SDKCommit=$(SDKCOMMIT) \
-X github.com/ovrclk/relayer/cmd.GaiaCommit=$(GAIACOMMIT)
LD_FLAGS = -X github.com/cosmos/relayer/cmd.Version=$(VERSION) \
-X github.com/cosmos/relayer/cmd.Commit=$(COMMIT) \
-X github.com/cosmos/relayer/cmd.SDKCommit=$(SDKCOMMIT) \
-X github.com/cosmos/relayer/cmd.GaiaCommit=$(GAIACOMMIT)

BUILD_FLAGS := -ldflags '$(LD_FLAGS)'

Expand All @@ -31,6 +31,10 @@ build-zip: go.sum
@GOOS=windows GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o build/windows-amd64-rly.exe main.go
@tar -czvf release.tar.gz ./build

# Compile the relayer as a shared library to be linked into another program
compile-clib:
go build -v -mod=readonly -buildmode=c-shared -o librelayer.so ./clib

install: go.sum
@echo "installing rly binary..."
@go build -mod=readonly $(BUILD_FLAGS) -o $${GOBIN-$${GOPATH-$$HOME/go}/bin}/rly main.go
Expand All @@ -55,5 +59,4 @@ lint:

.PHONY: install build lint coverage clean

# TODO: Port reproducable build scripts from gaia for relayer
# TODO: Full tested and working releases
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![GOZ](./docs/images/github-repo-banner.png)

![Relayer Build](https://github.com/ovrclk/relayer/workflows/Build%20then%20run%20CI%20Chains/badge.svg)
![Relayer Build](https://github.com/cosmos/relayer/workflows/Build%20then%20run%20CI%20Chains/badge.svg)

The Cosmos IBC `relayer` package contains a basic relayer implementation that is
meant for users wishing to relay packets/data between sets of IBC enabled chains.
Expand All @@ -27,7 +27,7 @@ If you would like to join a relayer testnet, please [check out the instructions]
| chain | tests | supported ports |
|-------|--------|----------------|
| [`gaia`](https://github.com/cosmos/gaia) | ![gaia](https://github.com/ovrclk/relayer/workflows/TESTING%20-%20gaia%20to%20gaia%20integration/badge.svg) | `transfer` |
| [`gaia`](https://github.com/cosmos/gaia) | ![gaia](https://github.com/cosmos/relayer/workflows/TESTING%20-%20gaia%20to%20gaia%20integration/badge.svg) | `transfer` |

## Demoing the Relayer

Expand Down
130 changes: 130 additions & 0 deletions clib/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// This is the entry point for a shared library built around the relayer.
// It depends on cgo, unlike the rly binary.
//
// This library was used as the basis for the Agoric Smart Relay:
// https://github.com/Agoric/agoric-sdk/tree/goz-smart-relay/packages/smart-relay

package main

// /* These comments before the import "C" are included in the C output. */
// #include <stdlib.h>
// typedef const char* Body;
// typedef int (*sendFunc)(int, int, Body);
// inline int invokeSendFunc(sendFunc send, int port, int reply, Body str) {
// return send(port, reply, str);
// }
import "C"
import (
"encoding/json"
"errors"
"fmt"
"os"

"github.com/cosmos/relayer/cmd"
"github.com/cosmos/relayer/relayer"
)

type goReturn = struct {
str string
err error
}

var clibPort = 0
var replies = map[int]chan goReturn{}
var lastReply = 0

//export RunClib
func RunClib(nodePort C.int, toNode C.sendFunc, clibArgs []*C.char) C.int {
if relayer.SendToController == nil {
relayer.SendToController = func(needReply bool, str string) (string, error) {
var rPort int
if needReply {
lastReply++
rPort = lastReply
replies[rPort] = make(chan goReturn)
}
// Send the message.
C.invokeSendFunc(toNode, nodePort, C.int(rPort), C.CString(str))
if !needReply {
// Return immediately
return "<no-reply-requested>", nil
}

// Block the sending goroutine while we wait for the reply
ret := <-replies[rPort]
delete(replies, rPort)
return ret.str, ret.err
}
}

args := make([]string, len(clibArgs))
for i, s := range clibArgs {
args[i] = C.GoString(s)
}
// fmt.Println("Starting relayer with args", args)
go func() {
os.Args = args
cmd.Execute()
// fmt.Printf("exiting with nodePort %d\n", nodePort)
if nodePort == 0 {
os.Exit(0)
}
}()

clibPort++
return C.int(clibPort)
}

//export ReplyToClib
func ReplyToClib(replyPort C.int, isError C.int, str C.Body) C.int {
goStr := C.GoString(str)
returnCh := replies[int(replyPort)]
if returnCh == nil {
return C.int(0)
}
ret := goReturn{}
if int(isError) == 0 {
ret.str = goStr
} else {
ret.err = errors.New(goStr)
}
returnCh <- ret
return C.int(0)
}

//export SendToClib
func SendToClib(port C.int, str C.Body) C.Body {
goStr := C.GoString(str)
var action relayer.DeliverMsgsAction
err := json.Unmarshal([]byte(goStr), &action)
if err == nil {
switch action.Type {
case "RELAYER_SEND":
src := relayer.UnmarshalChain(action.Src)
dst := relayer.UnmarshalChain(action.Dst)
if src == nil || dst == nil {
return C.CString("false")
}
rm := relayer.RelayMsgs{
Succeeded: action.Succeeded,
Last: action.Last,
}
rm.Src = relayer.DecodeMsgs(src, action.SrcMsgs)
rm.Dst = relayer.DecodeMsgs(dst, action.DstMsgs)

rm.SendWithController(src, dst, false)
if !rm.Succeeded {
return C.CString("0")
}
return C.CString(fmt.Sprintf("%d", len(rm.Src)+len(rm.Dst)))
default:
fmt.Printf("failed action.Type %s\n", action.Type)
}
} else {
fmt.Printf("failed unmarshalling %s\n", err)
}
return C.CString("false")
}

// Do nothing in main.
func main() {}
9 changes: 5 additions & 4 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"net/http"
"net/url"
"os"
"path"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/ovrclk/relayer/relayer"
"github.com/cosmos/relayer/relayer"
)

const (
Expand Down Expand Up @@ -52,8 +53,6 @@ func chainsAddrCmd() *cobra.Command {
return err
}

unlock := relayer.SDKConfig.SetLock(chain)
defer unlock()
addr, err := chain.GetAddress()
if err != nil {
return err
Expand Down Expand Up @@ -270,6 +269,7 @@ func chainsAddDirCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-dir [dir]",
Aliases: []string{"ad"},
Args: cobra.ExactArgs(1),
Short: `Add new chains to the configuration file from a directory
full of chain configuration, useful for adding testnet configurations`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -285,14 +285,15 @@ func chainsAddDirCmd() *cobra.Command {
}

func filesAdd(dir string) (cfg *Config, err error) {
dir = path.Clean(dir)
files, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
cfg = config
for _, f := range files {
c := &relayer.Chain{}
pth := fmt.Sprintf("%s%s", dir, f.Name())
pth := fmt.Sprintf("%s/%s", dir, f.Name())
if f.IsDir() {
fmt.Printf("directory at %s, skipping...\n", pth)
continue
Expand Down
6 changes: 4 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/ovrclk/relayer/relayer"
"github.com/cosmos/relayer/relayer"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -146,6 +146,7 @@ func configAddDirCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-dir [dir]",
Aliases: []string{"ad"},
Args: cobra.ExactArgs(1),
Short: `Add new chains and paths to the configuration file from a
directory full of chain and path configuration, useful for adding testnet configurations`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -161,14 +162,15 @@ func configAddDirCmd() *cobra.Command {
}

func cfgFilesAdd(dir string) (cfg *Config, err error) {
dir = path.Clean(dir)
files, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
cfg = config
for _, f := range files {
c := &relayer.Chain{}
pth := fmt.Sprintf("%s%s", dir, f.Name())
pth := fmt.Sprintf("%s/%s", dir, f.Name())
if f.IsDir() {
fmt.Printf("directory at %s, skipping...\n", pth)
continue
Expand Down
11 changes: 9 additions & 2 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"os"

Expand Down Expand Up @@ -42,7 +43,13 @@ func genesisCmd() *cobra.Command {
return err
}

return c.Print(gen, false, false)
out, err := json.Marshal(gen)
if err != nil {
return err
}

fmt.Println(string(out))
return nil
},
}
return cmd
Expand Down Expand Up @@ -188,7 +195,7 @@ func rlyService() *cobra.Command {
if _, err = chains[src].GetAddress(); err != nil {
return err
}
if _, err = chains[src].GetAddress(); err != nil {
if _, err = chains[dst].GetAddress(); err != nil {
return err
}

Expand Down
Loading

0 comments on commit cb47e65

Please sign in to comment.