From d15cc1d175f3680d7bfcf1282aaf53deea8e2ac7 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 8 May 2023 15:21:21 -0600 Subject: [PATCH 1/3] ethclient uses interface instead of rpc.Client --- ethclient/ethclient.go | 4 ++-- rpc/client.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 460035f36a6d..f7b08ab37756 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -33,7 +33,7 @@ import ( // Client defines typed wrappers for the Ethereum RPC API. type Client struct { - c *rpc.Client + c rpc.ClientInterface } // Dial connects a client to the given URL. @@ -50,7 +50,7 @@ func DialContext(ctx context.Context, rawurl string) (*Client, error) { } // NewClient creates a client that uses the given RPC client. -func NewClient(c *rpc.Client) *Client { +func NewClient(c rpc.ClientInterface) *Client { return &Client{c} } diff --git a/rpc/client.go b/rpc/client.go index cfd9c6694abd..d2fe01b88b98 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -60,6 +60,13 @@ const ( maxClientSubscriptionBuffer = 20000 ) +type ClientInterface interface { + CallContext(ctx_in context.Context, result interface{}, method string, args ...interface{}) error + EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*ClientSubscription, error) + BatchCallContext(ctx context.Context, b []BatchElem) error + Close() +} + // BatchElem is an element in a batch request. type BatchElem struct { Method string From 15076f63b7231bf45660448eeab7a4ed547a022e Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 8 May 2023 15:22:21 -0600 Subject: [PATCH 2/3] remove request_hook from rpc.Client --- rpc/client.go | 21 +-------------------- rpc/client_arbitrum.go | 34 ---------------------------------- 2 files changed, 1 insertion(+), 54 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index d2fe01b88b98..0c7a09296e4c 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -82,8 +82,6 @@ type BatchElem struct { // Client represents a connection to an RPC server. type Client struct { - requestHook RequestHook - idgen func() ID // for subscriptions isHTTP bool // connection type: http, ws or ipc services *serviceRegistry @@ -336,34 +334,28 @@ func (c *Client) CallContext(ctx context.Context, result interface{}, method str } op := &requestOp{ids: []json.RawMessage{msg.ID}, resp: make(chan *jsonrpcMessage, 1)} - resultHook := c.onRequest(msg) if c.isHTTP { err = c.sendHTTP(ctx, op, msg) } else { err = c.send(ctx, op, msg) } if err != nil { - resultHook.OnResult(nil, err) return err } // dispatch has accepted the request and will close the channel when it quits. switch resp, err := op.wait(ctx, c); { case err != nil: - resultHook.OnResult(resp, err) return err case resp.Error != nil: - resultHook.OnResult(resp, resp.Error) return resp.Error case len(resp.Result) == 0: - resultHook.OnResult(resp, ErrNoResult) return ErrNoResult default: if result == nil { return nil } err := json.Unmarshal(resp.Result, result) - resultHook.OnResult(resp, err) return err } } @@ -408,12 +400,6 @@ func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error { byID[string(msg.ID)] = i } - resultHooks := make([]ResultHook, len(msgs)) - responsesForHooks := make([]interface{}, len(msgs)) - for i, msg := range msgs { - resultHooks[i] = c.onRequest(msg) - } - var err error if c.isHTTP { err = c.sendBatchHTTP(ctx, op, msgs) @@ -431,9 +417,7 @@ func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error { // Find the element corresponding to this response. // The element is guaranteed to be present because dispatch // only sends valid IDs to our channel. - idx := byID[string(resp.ID)] - responsesForHooks[idx] = resp - elem := &b[idx] + elem := &b[byID[string(resp.ID)]] if resp.Error != nil { elem.Error = resp.Error continue @@ -444,9 +428,6 @@ func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error { } elem.Error = json.Unmarshal(resp.Result, elem.Result) } - for i, hook := range resultHooks { - hook.OnResult(responsesForHooks[i], err) - } return err } diff --git a/rpc/client_arbitrum.go b/rpc/client_arbitrum.go index e029013301e4..f3502e5c0b18 100644 --- a/rpc/client_arbitrum.go +++ b/rpc/client_arbitrum.go @@ -50,37 +50,3 @@ func DialTransport(ctx context.Context, rawUrl string, transport *http.Transport } return rpcClient, nil } - -func DialContextWithRequestHook(ctx context.Context, url string, hook RequestHook) (*Client, error) { - client, err := DialContext(ctx, url) - if err != nil { - return nil, err - } - client.requestHook = hook - return client, nil -} - -type RequestHook interface { - OnRequest(request interface{}) ResultHook -} - -type ResultHook interface { - OnResult(response interface{}, err error) -} - -type noopResultHook struct{} - -func (h noopResultHook) OnResult(interface{}, error) { -} - -func (c *Client) onRequest(request interface{}) ResultHook { - hooks := c.requestHook - var respHooks ResultHook - if hooks != nil { - respHooks = hooks.OnRequest(request) - } - if respHooks == nil { - respHooks = noopResultHook{} - } - return respHooks -} From ce290d3d41d05e362c6c357adfccda78f812ad09 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 8 May 2023 15:23:06 -0600 Subject: [PATCH 3/3] add JWTPath to node --- node/node.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node/node.go b/node/node.go index 59ab006851f9..a61929e46882 100644 --- a/node/node.go +++ b/node/node.go @@ -704,6 +704,14 @@ func (n *Node) WSAuthEndpoint() string { return "ws://" + n.wsAuth.listenAddr() + n.wsAuth.wsConfig.prefix } +// JWTPath returns the path for JWT secret +func (n *Node) JWTPath() string { + if n.config.JWTSecret == "" { + return n.ResolvePath(datadirJWTKey) + } + return n.config.JWTSecret +} + // EventMux retrieves the event multiplexer used by all the network services in // the current protocol stack. func (n *Node) EventMux() *event.TypeMux {