Skip to content

Commit

Permalink
Merge branch 'relayer_errors' into e2e_adv
Browse files Browse the repository at this point in the history
  • Loading branch information
lava17 committed Jul 12, 2022
2 parents 5073856 + 1aa581a commit e5aa740
Show file tree
Hide file tree
Showing 24 changed files with 347 additions and 405 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ relayer/cmd/relayer/__debug_bin
testutil/e2e/logs/
ptnet/
scripts/vars/
testutil/debugging/

105 changes: 105 additions & 0 deletions cmd/lavad/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package main

import (
"context"
"fmt"
"os"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
"github.com/lavanet/lava/app"
"github.com/lavanet/lava/relayer"
"github.com/spf13/cobra"
)

func main() {
Expand All @@ -18,6 +26,103 @@ func main() {
app.New,
// this line is used by starport scaffolding # root/arguments
)

var cmdServer = &cobra.Command{
Use: "server [listen-ip] [listen-port] [node-url] [node-chain-id] [api-interface]",
Short: "server",
Long: `server`,
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

//
// TODO: there has to be a better way to send txs
// (cosmosclient was a fail)
clientCtx.SkipConfirm = true
txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithChainID("lava")

port, err := strconv.Atoi(args[1])
if err != nil {
return err
}

chainID := args[3]

apiInterface := args[4]

listenAddr := fmt.Sprintf("%s:%d", args[0], port)
ctx := context.Background()
relayer.Server(ctx, clientCtx, txFactory, listenAddr, args[2], chainID, apiInterface)

return nil
},
}

var cmdPortalServer = &cobra.Command{
Use: "portal_server [listen-ip] [listen-port] [relayer-chain-id] [api-interface]",
Short: "portal server",
Long: `portal server`,
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

port, err := strconv.Atoi(args[1])
if err != nil {
return err
}

chainID := args[2]
apiInterface := args[3]

listenAddr := fmt.Sprintf("%s:%d", args[0], port)
ctx := context.Background()
relayer.PortalServer(ctx, clientCtx, listenAddr, chainID, apiInterface, cmd.Flags())

return nil
},
}

var cmdTestClient = &cobra.Command{
Use: "test_client [chain-id] [api-interface]",
Short: "test client",
Long: `test client`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

chainID := args[0]

apiInterface := args[1]

ctx := context.Background()

relayer.TestClient(ctx, clientCtx, chainID, apiInterface, cmd.Flags())

return nil
},
}

flags.AddTxFlagsToCmd(cmdServer)
cmdServer.MarkFlagRequired(flags.FlagFrom)
flags.AddTxFlagsToCmd(cmdPortalServer)
cmdPortalServer.MarkFlagRequired(flags.FlagFrom)
flags.AddTxFlagsToCmd(cmdTestClient)
cmdTestClient.MarkFlagRequired(flags.FlagFrom)
cmdTestClient.Flags().Bool("secure", false, "secure sends reliability on every message")
cmdPortalServer.Flags().Bool("secure", false, "secure sends reliability on every message")
rootCmd.AddCommand(cmdServer)
rootCmd.AddCommand(cmdPortalServer)
rootCmd.AddCommand(cmdTestClient)

if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil {
os.Exit(1)
}
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ require (

require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
)

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,6 @@ github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -808,8 +806,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3 h1:BGNSrTRW4rwfhJiFwvwF4XQ0Y72Jj9YEgxVrtovbD5o=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3/go.mod h1:VHn7KgNsRriXa4mcgtkpR00OXyQY6g67JWMvn+R27A4=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
6 changes: 5 additions & 1 deletion relayer/chainproxy/chainproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
spectypes "github.com/lavanet/lava/x/spec/types"
)

const (
DefaultTimeout = 5 * time.Second
)

type NodeMessage interface {
GetServiceApi() *spectypes.ServiceApi
Send(ctx context.Context) (*pairingtypes.RelayReply, error)
Expand Down Expand Up @@ -126,7 +130,7 @@ func SendRelay(

relaySentTime := time.Now()
clientSession.QoSInfo.TotalRelays++
connectCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
connectCtx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()

reply, err := c.Relay(connectCtx, relayRequest)
Expand Down
3 changes: 1 addition & 2 deletions relayer/chainproxy/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"log"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -289,7 +288,7 @@ func (nm *JrpcMessage) Send(ctx context.Context) (*pairingtypes.RelayReply, erro
//
// Call our node
var result json.RawMessage
connectCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
connectCtx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()
err = rpc.CallContext(connectCtx, &result, nm.msg.Method, nm.msg.Params...)

Expand Down
3 changes: 1 addition & 2 deletions relayer/chainproxy/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -222,7 +221,7 @@ func (nm *RestMessage) GetServiceApi() *spectypes.ServiceApi {

func (nm *RestMessage) Send(ctx context.Context) (*pairingtypes.RelayReply, error) {
httpClient := http.Client{
Timeout: time.Second * 5, // Timeout after 5 seconds
Timeout: DefaultTimeout, // Timeout after 5 seconds
}

//
Expand Down
3 changes: 1 addition & 2 deletions relayer/chainproxy/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -273,7 +272,7 @@ func (nm *TendemintRpcMessage) Send(ctx context.Context) (*pairingtypes.RelayRep
//
// Call our node
var result json.RawMessage
connectCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
connectCtx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()
err = rpc.CallContext(connectCtx, &result, nm.msg.Method, nm.msg.Params...)

Expand Down
142 changes: 0 additions & 142 deletions relayer/cmd/relayer/main.go

This file was deleted.

6 changes: 3 additions & 3 deletions relayer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ bash ./relayer/compile_proto.sh

```bash
# in lava folder
go run relayer/cmd/relayer/main.go server 127.0.0.1 2222 wss://mainnet.infura.io/ws/v3/<your_token> 0 --from bob
lavad server 127.0.0.1 2222 wss://mainnet.infura.io/ws/v3/<your_token> 0 --from bob
```

## Run relayer test client

```bash
# in lava folder
go run relayer/cmd/relayer/main.go test_client 0 --from alice
lavad test_client 0 --from alice
```

## Run portal server

```bash
# in lava folder
go run relayer/cmd/relayer/main.go portal_server 127.0.0.1 3333 0 --from user2
lavad portal_server 127.0.0.1 3333 0 --from user2
geth attach ws://127.0.0.1:3333/ws
```
Loading

0 comments on commit e5aa740

Please sign in to comment.