Skip to content

Commit

Permalink
adding client rpc in lava
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Aug 17, 2022
1 parent 03f8f7e commit e379f07
Show file tree
Hide file tree
Showing 47 changed files with 6,055 additions and 13 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ require (
github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect
github.com/cosmos/ledger-go v0.9.2 // indirect
github.com/danieljoos/wincred v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
github.com/dgraph-io/ristretto v0.0.3 // indirect
Expand Down Expand Up @@ -99,7 +99,7 @@ require (
github.com/google/orderedcode v0.0.1 // indirect
github.com/gookit/color v1.5.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
Expand Down Expand Up @@ -190,7 +190,7 @@ require (
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/ini.v1 v1.66.3 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand Down
16 changes: 8 additions & 8 deletions relayer/chainproxy/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/rpc"
"github.com/lavanet/lava/relayer/chainproxy/rpcclient"
)

type Connector struct {
lock sync.Mutex
freeClients []*rpc.Client
freeClients []*rpcclient.Client
usedClients int
}

func NewConnector(ctx context.Context, nConns uint, addr string) *Connector {
connector := &Connector{
freeClients: make([]*rpc.Client, 0, nConns),
freeClients: make([]*rpcclient.Client, 0, nConns),
}

for i := uint(0); i < nConns; i++ {
var rpcClient *rpc.Client
var rpcClient *rpcclient.Client
var err error
for {
if ctx.Err() != nil {
connector.Close()
return nil
}
nctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
rpcClient, err = rpc.DialContext(nctx, addr)
rpcClient, err = rpcclient.DialContext(nctx, addr)
if err != nil {
log.Println("retrying", err)
cancel()
Expand Down Expand Up @@ -64,7 +64,7 @@ func (connector *Connector) Close() {
for i := 0; i < len(connector.freeClients); i++ {
connector.freeClients[i].Close()
}
connector.freeClients = []*rpc.Client{}
connector.freeClients = []*rpcclient.Client{}

if connector.usedClients > 0 {
log.Println("Connector closing, waiting for in use clients", connector.usedClients)
Expand All @@ -77,7 +77,7 @@ func (connector *Connector) Close() {
}
}

func (connector *Connector) GetRpc(block bool) (*rpc.Client, error) {
func (connector *Connector) GetRpc(block bool) (*rpcclient.Client, error) {
connector.lock.Lock()
defer connector.lock.Unlock()
countPrint := 0
Expand Down Expand Up @@ -107,7 +107,7 @@ func (connector *Connector) GetRpc(block bool) (*rpc.Client, error) {
return ret, nil
}

func (connector *Connector) ReturnRpc(rpc *rpc.Client) {
func (connector *Connector) ReturnRpc(rpc *rpcclient.Client) {
connector.lock.Lock()
defer connector.lock.Unlock()

Expand Down
Loading

0 comments on commit e379f07

Please sign in to comment.