fix message handling

pull/2791/head
Ayrat Badykov 5 years ago
parent f03ead074c
commit 141ebda719
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 1
      apps/ethereum_jsonrpc/config/config.exs
  2. 4
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex
  3. 11
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex
  4. 2
      apps/indexer/config/dev/parity.exs

@ -13,7 +13,6 @@ config :ethereum_jsonrpc,
rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", do: :http, else: :ipc),
ipc_path: System.get_env("IPC_PATH")
# Add this configuration to add global RPC request throttling.
# throttle_rate_limit: 250,
# throttle_rolling_window_opts: [

@ -17,8 +17,8 @@ defmodule EthereumJSONRPC.Application do
:hackney_pool.child_spec(:ethereum_jsonrpc, recv_timeout: 60_000, timeout: 60_000, max_connections: 1000),
Supervisor.child_spec({RollingWindow, [rolling_window_opts]}, id: RollingWindow.ErrorThrottle)
]
|> add_ipc_client()
|> add_throttle_rolling_window(config)
|> add_ipc_client()
|> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor)
end
@ -41,7 +41,7 @@ defmodule EthereumJSONRPC.Application do
defp add_ipc_client(children) do
case Application.get_env(:ethereum_jsonrpc, :rpc_transport) do
:ipc -> [IPC.child_spec([path: Application.get_env(:ethereum_jsonrpc, :ipc_path)]) | children]
:ipc -> [IPC.child_spec(path: Application.get_env(:ethereum_jsonrpc, :ipc_path)) | children]
_ -> children
end
end

@ -5,7 +5,6 @@ defmodule EthereumJSONRPC.IPC do
# Server
def child_spec(opts) do
IO.inspect(opts)
default = %{
id: __MODULE__,
start: {__MODULE__, :start_link, opts},
@ -16,7 +15,7 @@ defmodule EthereumJSONRPC.IPC do
end
def start_link({:path, path}) do
GenServer.start_link(__MODULE__, [path: path, socket: nil])
GenServer.start_link(__MODULE__, [path: path, socket: nil], name: __MODULE__)
end
def init(state) do
@ -59,20 +58,20 @@ defmodule EthereumJSONRPC.IPC do
def handle_call(
{:request, request},
_from,
[socket: socket, path: _, ipc_request_timeout: timeout] = state
[socket: socket, path: _] = state
) do
response =
socket
|> :gen_tcp.send(request)
|> receive_response(socket, timeout)
|> receive_response(socket, 500_000)
{:reply, response, state}
end
# Client
def json_rpc(pid, payload, _opts) do
with {:ok, response} <- post(pid, payload),
def json_rpc(payload, _opts) do
with {:ok, response} <- post(__MODULE__, Jason.encode!(payload)),
{:ok, decoded_body} <- Jason.decode(response) do
case decoded_body do
%{"error" => error} -> {:error, error}

@ -3,7 +3,7 @@ use Mix.Config
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
transport: EthereumJSONRPC.HTTP,
transport: EthereumJSONRPC.IPC,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545",

Loading…
Cancel
Save