Merge branch 'master' into ab-timestamp-block-overview

pull/1769/head
Ayrat Badykov 6 years ago committed by GitHub
commit c4d3e32c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/indexer/config/prod/parity.exs
  3. 2
      apps/indexer/config/prod/rsk.exs
  4. 31
      apps/indexer/lib/indexer/block/realtime/fetcher.ex
  5. 10
      apps/indexer/lib/indexer/block/realtime/supervisor.ex

@ -14,6 +14,7 @@
- [#1743](https://github.com/poanetwork/blockscout/pull/1743) - sort decompiled smart contracts in lexicographical order
- [#1756](https://github.com/poanetwork/blockscout/pull/1756) - add today's token balance from the previous value
- [#1769](https://github.com/poanetwork/blockscout/pull/1769) - add timestamp to block overview
- [#1778](https://github.com/poanetwork/blockscout/pull/1778) - Make websocket optional for realtime fetcher
### Chore

@ -17,7 +17,7 @@ config :indexer,
variant: EthereumJSONRPC.Parity
],
subscribe_named_arguments: [
transport: EthereumJSONRPC.WebSocket,
transport: System.get_env("ETHEREUM_JSONRPC_WS_URL") && EthereumJSONRPC.WebSocket,
transport_options: [
web_socket: EthereumJSONRPC.WebSocket.WebSocketClient,
url: System.get_env("ETHEREUM_JSONRPC_WS_URL")

@ -19,7 +19,7 @@ config :indexer,
variant: EthereumJSONRPC.RSK
],
subscribe_named_arguments: [
transport: EthereumJSONRPC.WebSocket,
transport: System.get_env("ETHEREUM_JSONRPC_WS_URL") && EthereumJSONRPC.WebSocket,
transport_options: [
web_socket: EthereumJSONRPC.WebSocket.WebSocketClient,
url: System.get_env("ETHEREUM_JSONRPC_WS_URL")

@ -57,8 +57,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
end
@impl GenServer
def init(%{block_fetcher: %Block.Fetcher{} = block_fetcher, subscribe_named_arguments: subscribe_named_arguments})
when is_list(subscribe_named_arguments) do
def init(%{block_fetcher: %Block.Fetcher{} = block_fetcher, subscribe_named_arguments: subscribe_named_arguments}) do
Logger.metadata(fetcher: :block_realtime)
{:ok, %__MODULE__{block_fetcher: %Block.Fetcher{block_fetcher | broadcast: :realtime, callback_module: __MODULE__}},
@ -66,17 +65,9 @@ defmodule Indexer.Block.Realtime.Fetcher do
end
@impl GenServer
def handle_continue({:init, subscribe_named_arguments}, %__MODULE__{subscription: nil} = state)
when is_list(subscribe_named_arguments) do
case EthereumJSONRPC.subscribe("newHeads", subscribe_named_arguments) do
{:ok, subscription} ->
timer = schedule_polling()
{:noreply, %__MODULE__{state | subscription: subscription, timer: timer}}
{:error, reason} ->
{:stop, reason, state}
end
def handle_continue({:init, subscribe_named_arguments}, %__MODULE__{subscription: nil} = state) do
timer = schedule_polling()
{:noreply, %__MODULE__{state | timer: timer} |> subscribe_to_new_heads(subscribe_named_arguments)}
end
@impl GenServer
@ -141,6 +132,20 @@ defmodule Indexer.Block.Realtime.Fetcher do
}}
end
defp subscribe_to_new_heads(%__MODULE__{subscription: nil} = state, subscribe_named_arguments)
when is_list(subscribe_named_arguments) do
case EthereumJSONRPC.subscribe("newHeads", subscribe_named_arguments) do
{:ok, subscription} ->
%__MODULE__{state | subscription: subscription}
{:error, reason} ->
Logger.debug(fn -> ["Could not connect to websocket: ", reason, ". Continuing with polling."] end)
state
end
end
defp subscribe_to_new_heads(state, _), do: state
defp new_max_number(number, nil), do: number
defp new_max_number(number, max_number_seen), do: max(number, max_number_seen)

@ -34,6 +34,16 @@ defmodule Indexer.Block.Realtime.Supervisor do
[name: Indexer.Block.Realtime.Fetcher]
]}
]
_ ->
[
{Task.Supervisor, name: Indexer.Block.Realtime.TaskSupervisor},
{Indexer.Block.Realtime.Fetcher,
[
%{block_fetcher: block_fetcher, subscribe_named_arguments: nil},
[name: Indexer.Block.Realtime.Fetcher]
]}
]
end
Supervisor.init(children, strategy: :rest_for_one)

Loading…
Cancel
Save