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#274: feat: allow building a shared library
- Loading branch information
1 parent
650bb76
commit 3a30839
Showing
71 changed files
with
492 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM golang:alpine as BUILD | ||
|
||
WORKDIR /relayer | ||
|
||
# Copy the files from host | ||
COPY . . | ||
|
||
# Update and install needed deps prioir to installing the binary. | ||
RUN apk update && \ | ||
apk --no-cache add make=4.2.1-r2 git=2.24.3-r0 && \ | ||
make install | ||
|
||
FROM alpine:edge | ||
|
||
ENV RELAYER /relayer | ||
|
||
RUN addgroup rlyuser && \ | ||
adduser -S -G rlyuser rlyuser -h "$RELAYER" | ||
|
||
USER rlyuser | ||
|
||
# Define working directory | ||
WORKDIR $RELAYER | ||
|
||
# Copy binary from BUILD | ||
COPY --from=BUILD /go/bin/rly /usr/bin/rly | ||
|
||
ENTRYPOINT ["/usr/bin/rly"] | ||
|
||
# Make config available ofr mutaitons | ||
VOLUME [ $RELAYER ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc0","client-id":"ibconeclient","connection-id":"ibconeconnection","channel-id":"ibconexfer","port-id":"transfer"},"dst":{"chain-id":"ibc1","client-id":"ibczeroclient","connection-id":"ibczeroconnection","channel-id":"ibczeroxfer","port-id":"transfer"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-0","client-id":"ibconeclient","connection-id":"ibconeconnection","channel-id":"ibconexfer","port-id":"transfer","version":"ics20-1"},"dst":{"chain-id":"ibc-1","client-id":"ibczeroclient","connection-id":"ibczeroconnection","channel-id":"ibczeroxfer","port-id":"transfer","version":"ics20-1"},"strategy":{"type":"naive"}} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-0","rpc-addr":"http://localhost:26657","account-prefix":"agoric","gas":200000,"gas-adjustment":1.0,"gas-prices":"","default-denom":"uagstake","trusting-period":"336h"} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-1","rpc-addr":"http://localhost:26557","account-prefix":"agoric","gas":200000,"gas-adjustment":1.0,"gas-prices":"","default-denom":"uagstake","trusting-period":"336h"} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc0","client-id":"ibconeclient","connection-id":"ibconeconnection","channel-id":"ibconexfer","port-id":"transfer","order":"unordered"},"dst":{"chain-id":"ibc1","client-id":"ibczeroclient","connection-id":"ibczeroconnection","channel-id":"ibczeroxfer","port-id":"transfer","order":"unordered"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-0","client-id":"ibconeclient","connection-id":"ibconeconnection","channel-id":"ibconexfer","port-id":"transfer","order":"unordered","version":"ics20-1"},"dst":{"chain-id":"ibc-1","client-id":"ibczeroclient","connection-id":"ibczeroconnection","channel-id":"ibczeroxfer","port-id":"transfer","order":"unordered","version":"ics20-1"},"strategy":{"type":"naive"}} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-0","rpc-addr":"http://localhost:26657","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-1","rpc-addr":"http://localhost:26557","account-prefix":"akash","gas-adjustment":1.5,"gas-prices":"0.025stake", "trusting-period":"336h"} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc0","client-id":"ibconeclient","connection-id":"ibconeconnection","channel-id":"ibconexfer","port-id":"transfer","order":"unordered"},"dst":{"chain-id":"ibc1","client-id":"ibczeroclient","connection-id":"ibczeroconnection","channel-id":"ibczeroxfer","port-id":"transfer","order":"unordered"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-0","client-id":"ibconeclient","connection-id":"ibconeconnection","channel-id":"ibconexfer","port-id":"transfer","order":"unordered","version":"ics20-1"},"dst":{"chain-id":"ibc-1","client-id":"ibczeroclient","connection-id":"ibczeroconnection","channel-id":"ibczeroxfer","port-id":"transfer","order":"unordered","version":"ics20-1"},"strategy":{"type":"naive"}} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-0","rpc-addr":"http://localhost:26657","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-1","rpc-addr":"http://localhost:26557","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake", "trusting-period":"336h"} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
{"key":"testkey","chain-id":"ibc-0","rpc-addr":"http://localhost:46657","account-prefix":"cosmos","gas-adjustment":1.0,"trusting-period":"336h"} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-1","rpc-addr":"http://localhost:46658","account-prefix":"cosmos","gas-adjustment":1.0,"trusting-period":"336h"} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-2","rpc-addr":"http://localhost:46659","account-prefix":"cosmos","gas-adjustment":1.0,"trusting-period":"336h"} |
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 @@ | ||
{"key":"testkey","chain-id":"ibc-3","rpc-addr":"http://localhost:46660","account-prefix":"cosmos","gas-adjustment":1.0,"trusting-period":"336h"} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc1","client-id":"acvfuvmoyy","connection-id":"pvsadpxocj","channel-id":"gxigiquvdc","port-id":"transfer"},"dst":{"chain-id":"ibc2","client-id":"vnsqzxwsfs","connection-id":"ikmrjehlzn","channel-id":"kzeiryubgz","port-id":"transfer"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-1","client-id":"acvfuvmoyy","connection-id":"pvsadpxocj","channel-id":"gxigiquvdc","port-id":"transfer","version":"ics20-1"},"dst":{"chain-id":"ibc-2","client-id":"vnsqzxwsfs","connection-id":"ikmrjehlzn","channel-id":"kzeiryubgz","port-id":"transfer","version":"ics20-1"},"strategy":{"type":"naive"}} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc3","client-id":"zjyshingti","connection-id":"kygrljuplq","channel-id":"hdiooxmgry","port-id":"transfer"},"dst":{"chain-id":"ibc0","client-id":"vddpwioaua","connection-id":"wmvxarvtdj","channel-id":"mytxyocvdk","port-id":"transfer"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-3","client-id":"zjyshingti","connection-id":"kygrljuplq","channel-id":"hdiooxmgry","port-id":"transfer","version":"ics20-1"},"dst":{"chain-id":"ibc-0","client-id":"vddpwioaua","connection-id":"wmvxarvtdj","channel-id":"mytxyocvdk","port-id":"transfer","version":"ics20-1"},"strategy":{"type":"naive"}} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc2","client-id":"jluiqkandb","connection-id":"mfyxyvmogc","channel-id":"ckcplvbklp","port-id":"transfer"},"dst":{"chain-id":"ibc3","client-id":"kvhumysqxf","connection-id":"kejwjeluuz","channel-id":"pcqmpcbqgi","port-id":"transfer"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-2","client-id":"jluiqkandb","connection-id":"mfyxyvmogc","channel-id":"ckcplvbklp","port-id":"transfer","version":"ics20-1"},"dst":{"chain-id":"ibc-3","client-id":"kvhumysqxf","connection-id":"kejwjeluuz","channel-id":"pcqmpcbqgi","port-id":"transfer","version":"ics20-1"},"strategy":{"type":"naive"}} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"src":{"chain-id":"ibc0","client-id":"ytwwxbikra","connection-id":"znruvklbwm","channel-id":"spqkreyyhp","port-id":"transfer"},"dst":{"chain-id":"ibc1","client-id":"unfkygnnyq","connection-id":"jighhjlxjf","channel-id":"dkqbmdcyuk","port-id":"transfer"},"strategy":{"type":"naive"}} | ||
{"src":{"chain-id":"ibc-0","client-id":"ytwwxbikra","connection-id":"znruvklbwm","channel-id":"spqkreyyhp","port-id":"transfer","version":"ics20-1"},"dst":{"chain-id":"ibc-1","client-id":"unfkygnnyq","connection-id":"jighhjlxjf","channel-id":"dkqbmdcyuk","port-id":"transfer","version":"ics20-1"},"strategy":{"type":"naive"}} |
Oops, something went wrong.