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), rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", do: :http, else: :ipc),
ipc_path: System.get_env("IPC_PATH") ipc_path: System.get_env("IPC_PATH")
# Add this configuration to add global RPC request throttling. # Add this configuration to add global RPC request throttling.
# throttle_rate_limit: 250, # throttle_rate_limit: 250,
# throttle_rolling_window_opts: [ # 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), :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) Supervisor.child_spec({RollingWindow, [rolling_window_opts]}, id: RollingWindow.ErrorThrottle)
] ]
|> add_ipc_client()
|> add_throttle_rolling_window(config) |> add_throttle_rolling_window(config)
|> add_ipc_client()
|> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor) |> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor)
end end
@ -41,7 +41,7 @@ defmodule EthereumJSONRPC.Application do
defp add_ipc_client(children) do defp add_ipc_client(children) do
case Application.get_env(:ethereum_jsonrpc, :rpc_transport) 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 _ -> children
end end
end end

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

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

Loading…
Cancel
Save