Skip to content

Commit

Permalink
feat: allow setting different configuration just for realtime fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Mar 14, 2019
1 parent 807f7c3 commit 75b558b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
17 changes: 17 additions & 0 deletions apps/indexer/config/dev/parity.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ config :indexer,
],
variant: EthereumJSONRPC.Parity
],
# Example configuration to override json_rpc_named_arguments for just the realtime block fetcher
# realtime_overrides: [
# json_rpc_named_arguments: [
# transport: EthereumJSONRPC.HTTP,
# transport_options: [
# http: EthereumJSONRPC.HTTP.HTTPoison,
# url: System.get_env("ETHEREUM_JSONRPC_REALTIME_HTTP_URL") || "http://localhost:8545",
# method_to_url: [
# eth_getBalance: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545",
# trace_block: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545",
# trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545"
# ],
# http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
# ],
# variant: EthereumJSONRPC.Parity
# ]
# ],
subscribe_named_arguments: [
transport: EthereumJSONRPC.WebSocket,
transport_options: [
Expand Down
15 changes: 12 additions & 3 deletions apps/indexer/lib/indexer/block/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@ defmodule Indexer.Block.Supervisor do
%{
block_interval: block_interval,
json_rpc_named_arguments: json_rpc_named_arguments,
subscribe_named_arguments: subscribe_named_arguments
subscribe_named_arguments: subscribe_named_arguments,
realtime_overrides: realtime_overrides
} = named_arguments
) do
block_fetcher =
named_arguments
|> Map.drop(~w(block_interval memory_monitor subscribe_named_arguments)a)
|> Map.drop(~w(block_interval memory_monitor subscribe_named_arguments realtime_overrides)a)
|> Block.Fetcher.new()

realtime_block_fetcher =
named_arguments
|> Map.drop(~w(block_interval memory_monitor subscribe_named_arguments realtime_overrides)a)
|> Map.merge(Enum.into(realtime_overrides, %{}))
|> Block.Fetcher.new()

realtime_subscribe_named_arguments = realtime_overrides[:subscribe_named_arguments] || subscribe_named_arguments

memory_monitor = Map.get(named_arguments, :memory_monitor)

Supervisor.init(
Expand All @@ -38,7 +47,7 @@ defmodule Indexer.Block.Supervisor do
{InvalidConsensus.Supervisor, [[], [name: InvalidConsensus.Supervisor]]},
{Realtime.Supervisor,
[
%{block_fetcher: block_fetcher, subscribe_named_arguments: subscribe_named_arguments},
%{block_fetcher: realtime_block_fetcher, subscribe_named_arguments: realtime_subscribe_named_arguments},
[name: Realtime.Supervisor]
]},
{Uncle.Supervisor, [[block_fetcher: block_fetcher, memory_monitor: memory_monitor], [name: Uncle.Supervisor]]},
Expand Down
3 changes: 2 additions & 1 deletion apps/indexer/lib/indexer/shrinkable/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ defmodule Indexer.Shrinkable.Supervisor do
|> Application.get_all_env()
|> Keyword.take(
~w(blocks_batch_size blocks_concurrency block_interval json_rpc_named_arguments receipts_batch_size
receipts_concurrency subscribe_named_arguments)a
receipts_concurrency subscribe_named_arguments realtime_overrides)a
)
|> Enum.into(%{})
|> Map.put(:memory_monitor, memory_monitor)
|> Map.put_new(:realtime_overrides, %{})

Supervisor.init(
[
Expand Down

0 comments on commit 75b558b

Please sign in to comment.