forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#318: Update to Cosmos v0.40.0-rc2, relayer v1.0.0-rc0
* 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
Showing
52 changed files
with
2,190 additions
and
801 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.