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 <jack.zampolin@gmail.com>

* 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 <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Michael FIG <mfig@agoric.com>
  • Loading branch information
3 people authored Nov 5, 2020
2 parents b8ec147 + 28c36dc commit cb47e65
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
@@ -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
@@ -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)'

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

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
@@ -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 (
@@ -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
@@ -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) {
@@ -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
6 changes: 4 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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) {
@@ -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
11 changes: 9 additions & 2 deletions cmd/dev.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package cmd

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

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

Loading

0 comments on commit cb47e65

Please sign in to comment.