diff --git a/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex index e6459593ba..86fc1795ba 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex @@ -226,11 +226,14 @@ defmodule BlockScoutWeb.SmartContractView do def cut_rpc_url(error) do transport_options = Application.get_env(:explorer, :json_rpc_named_arguments)[:transport_options] - error - |> String.replace(transport_options[:url], "rpc_url") - |> (&if(transport_options[:fallback_url], - do: String.replace(&1, transport_options[:fallback_url], "rpc_url"), - else: &1 - )).() + all_urls = + (transport_options[:urls] || []) ++ + (transport_options[:trace_urls] || []) ++ + (transport_options[:eth_call_urls] || []) ++ + (transport_options[:fallback_urls] || []) ++ + (transport_options[:fallback_trace_urls] || []) ++ + (transport_options[:fallback_eth_call_urls] || []) + + String.replace(error, Enum.reject(all_urls, &(&1 in [nil, ""])), "rpc_url") end end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex index 5c4d4a396e..69012ce9f1 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex @@ -552,7 +552,7 @@ defmodule EthereumJSONRPC do CommonHelper.put_in_keyword_nested( json_rpc_named_arguments, [:transport_options, :method_to_url, :eth_getBalance], - System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + :trace ) end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex index a411ab921b..7d3543f75e 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex @@ -3,7 +3,8 @@ defmodule EthereumJSONRPC.HTTP do JSONRPC over HTTP """ - alias EthereumJSONRPC.{DecodeError, Transport, Utility.EndpointAvailabilityObserver} + alias EthereumJSONRPC.{DecodeError, Transport} + alias EthereumJSONRPC.Utility.{CommonHelper, EndpointAvailabilityObserver} require Logger @@ -238,25 +239,36 @@ defmodule EthereumJSONRPC.HTTP do defp url(options, method) when is_list(options) and is_binary(method) do with {:ok, method_to_url} <- Keyword.fetch(options, :method_to_url), {:ok, method_atom} <- to_existing_atom(method), - {:ok, url} <- Keyword.fetch(method_to_url, method_atom) do - {url_type, fallback_url} = - case method_atom do - :eth_call -> {:eth_call, options[:fallback_eth_call_url]} - _ -> {:trace, options[:fallback_trace_url]} - end + {:ok, url_type} <- Keyword.fetch(method_to_url, method_atom) do + fallback_urls = CommonHelper.url_type_to_urls(url_type, options, :fallback) + + url = + url_type + |> CommonHelper.url_type_to_urls(options) + |> EndpointAvailabilityObserver.maybe_replace_urls(fallback_urls, url_type) + |> select_single_url() - {url_type, EndpointAvailabilityObserver.maybe_replace_url(url, fallback_url, url_type)} + {url_type, url} else _ -> + url_type = :http + url = - options - |> Keyword.fetch!(:url) - |> EndpointAvailabilityObserver.maybe_replace_url(options[:fallback_url], :http) + url_type + |> CommonHelper.url_type_to_urls(options) + |> EndpointAvailabilityObserver.maybe_replace_urls(options[:fallback_urls], url_type) + |> select_single_url() - {:http, url} + {url_type, url} end end + defp select_single_url([]), do: nil + + defp select_single_url(urls) do + Enum.random(urls) + end + defp to_existing_atom(string) do {:ok, String.to_existing_atom(string)} rescue diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex index a6d0d55f2d..615d9f1dda 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex @@ -30,6 +30,17 @@ defmodule EthereumJSONRPC.Utility.CommonHelper do Keyword.put(keyword || [], nearest_path, put_in_keyword_nested(keyword[nearest_path], rest_path, value)) end + @doc """ + Extracts urls corresponding to `url_type` from json rpc transport options + """ + @spec url_type_to_urls(atom(), Keyword.t(), atom() | String.t()) :: [String.t()] + def url_type_to_urls(url_type, json_rpc_transport_options, subtype \\ nil) do + key_prefix = (subtype && "#{subtype}_") || "" + url_prefix = (url_type == :http && "") || "#{url_type}_" + urls_key = String.to_existing_atom("#{key_prefix}#{url_prefix}urls") + json_rpc_transport_options[urls_key] + end + defp convert_to_ms(number, "s"), do: :timer.seconds(number) defp convert_to_ms(number, "m"), do: :timer.minutes(number) defp convert_to_ms(number, "h"), do: :timer.hours(number) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_checker.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_checker.ex index 2f1c1fdb3f..78242fe679 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_checker.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_checker.ex @@ -40,8 +40,7 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityChecker do {:ok, _number} -> url = json_rpc_named_arguments[:transport_options][:url] - EndpointAvailabilityObserver.enable_endpoint(url, url_type) - log_url_available(url, url_type, json_rpc_named_arguments) + EndpointAvailabilityObserver.enable_endpoint(url, url_type, json_rpc_named_arguments) acc _ -> @@ -54,17 +53,8 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityChecker do {:noreply, %{state | unavailable_endpoints_arguments: new_unavailable_endpoints}} end - defp log_url_available(url, url_type, json_rpc_named_arguments) do - message_extra = - if EndpointAvailabilityObserver.fallback_url_set?(url_type, json_rpc_named_arguments), - do: ", switching back to it", - else: "" - - Logger.info("URL #{inspect(url)} is available now#{message_extra}") - end - defp fetch_latest_block_number(json_rpc_named_arguments) do - {_, arguments_without_fallback} = pop_in(json_rpc_named_arguments, [:transport_options, :fallback_url]) + {_, arguments_without_fallback} = pop_in(json_rpc_named_arguments, [:transport_options, :fallback_urls]) %{id: 0, method: "eth_blockNumber", params: []} |> EthereumJSONRPC.request() diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_observer.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_observer.ex index fe768190b1..6d274f9016 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_observer.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/endpoint_availability_observer.ex @@ -7,12 +7,14 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do require Logger - alias EthereumJSONRPC.Utility.EndpointAvailabilityChecker + alias EthereumJSONRPC.Utility.{CommonHelper, EndpointAvailabilityChecker} @max_error_count 3 @window_duration 3 @cleaning_interval :timer.seconds(1) + @type url_type :: :ws | :trace | :http | :eth_call + def start_link(_) do GenServer.start_link(__MODULE__, :ok, name: __MODULE__) end @@ -23,14 +25,34 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do {:ok, %{error_counts: %{}, unavailable_endpoints: %{ws: [], trace: [], http: [], eth_call: []}}} end + @doc """ + Increases `url` of `url_type` type error count asynchronously. + """ + @spec inc_error_count(binary(), Keyword.t(), url_type()) :: :ok def inc_error_count(url, json_rpc_named_arguments, url_type) do GenServer.cast(__MODULE__, {:inc_error_count, url, json_rpc_named_arguments, url_type}) end + @doc """ + Checks if `url` of `url_type` type is available. + """ + @spec check_endpoint(binary(), url_type()) :: :ok | :unavailable def check_endpoint(url, url_type) do GenServer.call(__MODULE__, {:check_endpoint, url, url_type}) end + @doc """ + Filters out unavailable urls from `urls` of `url_type` type. + """ + @spec filter_unavailable_urls([binary()], url_type()) :: [binary()] + def filter_unavailable_urls(urls, url_type) do + GenServer.call(__MODULE__, {:filter_unavailable_urls, urls, url_type}) + end + + @doc """ + Checks if `url` of `url_type` type is unavailable and replaces it with `replace_url` if it's not `nil`. + """ + @spec maybe_replace_url(binary(), binary() | nil, url_type()) :: binary() def maybe_replace_url(url, replace_url, url_type) do case check_endpoint(url, url_type) do :ok -> url @@ -38,8 +60,23 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do end end - def enable_endpoint(url, url_type) do - GenServer.cast(__MODULE__, {:enable_endpoint, url, url_type}) + @doc """ + Analogue of `maybe_replace_url/3` for multiple urls. + """ + @spec maybe_replace_urls([binary()] | nil, [binary()] | nil, url_type()) :: [binary()] + def maybe_replace_urls(urls, replace_urls, url_type) do + case filter_unavailable_urls(urls, url_type) do + [] -> replace_urls || urls || [] + available_urls -> available_urls + end + end + + @doc """ + Marks `url` of `url_type` type as available. + """ + @spec enable_endpoint(binary(), url_type(), Keyword.t()) :: :ok + def enable_endpoint(url, url_type, json_rpc_named_arguments) do + GenServer.cast(__MODULE__, {:enable_endpoint, url, url_type, json_rpc_named_arguments}) end def handle_call({:check_endpoint, url, url_type}, _from, %{unavailable_endpoints: unavailable_endpoints} = state) do @@ -48,6 +85,14 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do {:reply, result, state} end + def handle_call( + {:filter_unavailable_urls, urls, url_type}, + _from, + %{unavailable_endpoints: unavailable_endpoints} = state + ) do + {:reply, do_filter_unavailable_urls(urls, unavailable_endpoints[url_type]), state} + end + def handle_cast({:inc_error_count, url, json_rpc_named_arguments, url_type}, state) do new_state = if json_rpc_named_arguments[:api?], @@ -57,7 +102,12 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do {:noreply, new_state} end - def handle_cast({:enable_endpoint, url, url_type}, %{unavailable_endpoints: unavailable_endpoints} = state) do + def handle_cast( + {:enable_endpoint, url, url_type, json_rpc_named_arguments}, + %{unavailable_endpoints: unavailable_endpoints} = state + ) do + log_url_available(url, url_type, unavailable_endpoints, json_rpc_named_arguments) + {:noreply, %{state | unavailable_endpoints: %{unavailable_endpoints | url_type => unavailable_endpoints[url_type] -- [url]}}} end @@ -81,6 +131,10 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do end end + defp do_filter_unavailable_urls(urls, unavailable_urls) do + Enum.reject(urls || [], fn url -> url in unavailable_urls end) + end + defp do_increase_error_counts(url, json_rpc_named_arguments, url_type, %{error_counts: error_counts} = state) do current_count = error_counts[url][url_type][:count] unavailable_endpoints = state.unavailable_endpoints[url_type] @@ -94,11 +148,11 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do current_count + 1 >= @max_error_count -> EndpointAvailabilityChecker.add_endpoint( - put_in(json_rpc_named_arguments[:transport_options][:url], url), + put_in(json_rpc_named_arguments[:transport_options][:urls], [url]), url_type ) - log_url_unavailable(url, url_type, json_rpc_named_arguments) + log_url_unavailable(url, url_type, unavailable_endpoints, json_rpc_named_arguments) %{ state @@ -114,20 +168,49 @@ defmodule EthereumJSONRPC.Utility.EndpointAvailabilityObserver do end end - defp log_url_unavailable(url, url_type, json_rpc_named_arguments) do + defp log_url_unavailable(url, :ws, _unavailable_endpoints, _json_rpc_named_arguments) do + Logger.warning("URL #{inspect(url)} is unavailable") + end + + defp log_url_unavailable(url, url_type, unavailable_endpoints, json_rpc_named_arguments) do + available_urls = + url_type + |> available_urls(unavailable_endpoints, json_rpc_named_arguments) + |> Kernel.--([url]) + fallback_url_message = - if fallback_url_set?(url_type, json_rpc_named_arguments), - do: "switching to fallback #{url_type} url", - else: "and no fallback is set" + case {available_urls, fallback_url_set?(url_type, json_rpc_named_arguments)} do + {[], true} -> "and there is no other #{url_type} url available, switching to fallback #{url_type} url" + {[], false} -> "there is no other #{url_type} url available, and no fallback is set" + _ -> "switching to another #{url_type} url" + end Logger.warning("URL #{inspect(url)} is unavailable, #{fallback_url_message}") end - def fallback_url_set?(url_type, json_rpc_named_arguments) do + defp log_url_available(url, url_type, unavailable_endpoints, json_rpc_named_arguments) do + available_urls = available_urls(url_type, unavailable_endpoints, json_rpc_named_arguments) + + message_extra = + case {available_urls, fallback_url_set?(url_type, json_rpc_named_arguments)} do + {[], true} -> ", switching back from fallback urls" + _ -> "" + end + + Logger.info("URL #{inspect(url)} of #{url_type} type is available now#{message_extra}") + end + + defp available_urls(url_type, unavailable_endpoints, json_rpc_named_arguments) do + url_type + |> CommonHelper.url_type_to_urls(json_rpc_named_arguments[:transport_options]) + |> do_filter_unavailable_urls(unavailable_endpoints) + end + + defp fallback_url_set?(url_type, json_rpc_named_arguments) do case url_type do - :http -> not is_nil(json_rpc_named_arguments[:transport_options][:fallback_url]) - :trace -> not is_nil(json_rpc_named_arguments[:transport_options][:fallback_trace_url]) - :eth_call -> not is_nil(json_rpc_named_arguments[:transport_options][:fallback_eth_call_url]) + :http -> not is_nil(json_rpc_named_arguments[:transport_options][:fallback_urls]) + :trace -> not is_nil(json_rpc_named_arguments[:transport_options][:fallback_trace_urls]) + :eth_call -> not is_nil(json_rpc_named_arguments[:transport_options][:fallback_eth_call_urls]) _ -> false end end diff --git a/apps/explorer/config/dev/besu.exs b/apps/explorer/config/dev/besu.exs index e19ee16351..598ce1459b 100644 --- a/apps/explorer/config/dev/besu.exs +++ b/apps/explorer/config/dev/besu.exs @@ -12,14 +12,33 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/dev/erigon.exs b/apps/explorer/config/dev/erigon.exs index 4c766d8247..ce6108e454 100644 --- a/apps/explorer/config/dev/erigon.exs +++ b/apps/explorer/config/dev/erigon.exs @@ -12,14 +12,33 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/dev/filecoin.exs b/apps/explorer/config/dev/filecoin.exs index f234e5b570..2ebd3941ec 100644 --- a/apps/explorer/config/dev/filecoin.exs +++ b/apps/explorer/config/dev/filecoin.exs @@ -12,13 +12,36 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:1234/rpc/v1", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_HTTP_URLS", + "ETHEREUM_JSONRPC_HTTP_URL", + "http://localhost:1234/rpc/v1" + ), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:1234/rpc/v1" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:1234/rpc/v1" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:1234/rpc/v1"), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:1234/rpc/v1" + eth_call: :eth_call, + trace_block: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/dev/ganache.exs b/apps/explorer/config/dev/ganache.exs index 6ca442c81e..8c3c678311 100644 --- a/apps/explorer/config/dev/ganache.exs +++ b/apps/explorer/config/dev/ganache.exs @@ -12,11 +12,23 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:7545"), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:7545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:7545") + eth_call: :eth_call ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/dev/geth.exs b/apps/explorer/config/dev/geth.exs index 41d6eb7a16..6210a08d58 100644 --- a/apps/explorer/config/dev/geth.exs +++ b/apps/explorer/config/dev/geth.exs @@ -12,14 +12,33 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - debug_traceTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - debug_traceBlockByNumber: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + debug_traceTransaction: :trace, + debug_traceBlockByNumber: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/dev/nethermind.exs b/apps/explorer/config/dev/nethermind.exs index 9e44aa811a..83bdbc3a89 100644 --- a/apps/explorer/config/dev/nethermind.exs +++ b/apps/explorer/config/dev/nethermind.exs @@ -12,14 +12,33 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/dev/rsk.exs b/apps/explorer/config/dev/rsk.exs index 0f8e4444e9..6e2d4f3912 100644 --- a/apps/explorer/config/dev/rsk.exs +++ b/apps/explorer/config/dev/rsk.exs @@ -12,14 +12,33 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/besu.exs b/apps/explorer/config/prod/besu.exs index cafb89d2b0..a7b8c6ff6e 100644 --- a/apps/explorer/config/prod/besu.exs +++ b/apps/explorer/config/prod/besu.exs @@ -12,14 +12,22 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/erigon.exs b/apps/explorer/config/prod/erigon.exs index 616a135b32..d2a8a51e18 100644 --- a/apps/explorer/config/prod/erigon.exs +++ b/apps/explorer/config/prod/erigon.exs @@ -12,14 +12,22 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/filecoin.exs b/apps/explorer/config/prod/filecoin.exs index bbad83ed26..a47c57517a 100644 --- a/apps/explorer/config/prod/filecoin.exs +++ b/apps/explorer/config/prod/filecoin.exs @@ -12,13 +12,21 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + trace_block: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/ganache.exs b/apps/explorer/config/prod/ganache.exs index 0fd0385cad..d4a0aff64a 100644 --- a/apps/explorer/config/prod/ganache.exs +++ b/apps/explorer/config/prod/ganache.exs @@ -12,11 +12,17 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url() + eth_call: :eth_call ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/geth.exs b/apps/explorer/config/prod/geth.exs index 9cf3bd32ab..2630943455 100644 --- a/apps/explorer/config/prod/geth.exs +++ b/apps/explorer/config/prod/geth.exs @@ -12,14 +12,22 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - debug_traceTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - debug_traceBlockByNumber: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + debug_traceTransaction: :trace, + debug_traceBlockByNumber: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/nethermind.exs b/apps/explorer/config/prod/nethermind.exs index d7cf3f3ecc..7232bad8c2 100644 --- a/apps/explorer/config/prod/nethermind.exs +++ b/apps/explorer/config/prod/nethermind.exs @@ -12,14 +12,22 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/config/prod/rsk.exs b/apps/explorer/config/prod/rsk.exs index 1046aafb0d..4f63fa6d4d 100644 --- a/apps/explorer/config/prod/rsk.exs +++ b/apps/explorer/config/prod/rsk.exs @@ -12,14 +12,22 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/explorer/lib/explorer/chain/cache/optimism_finalization_period.ex b/apps/explorer/lib/explorer/chain/cache/optimism_finalization_period.ex index aa09cf2148..7ce8d83436 100644 --- a/apps/explorer/lib/explorer/chain/cache/optimism_finalization_period.ex +++ b/apps/explorer/lib/explorer/chain/cache/optimism_finalization_period.ex @@ -42,7 +42,7 @@ defmodule Explorer.Chain.Cache.OptimismFinalizationPeriod do transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: optimism_l1_rpc, + urls: [optimism_l1_rpc], http_options: [ recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 1fe83e8f1e..8aef4e7aec 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -756,6 +756,13 @@ defmodule Explorer.ChainTest do insert(:pending_block_operation, block: block, block_number: block.number) + configuration = Application.get_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor) + Application.put_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor, disabled?: false) + + on_exit(fn -> + Application.put_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor, configuration) + end) + refute Chain.finished_indexing_internal_transactions?() end end @@ -1066,9 +1073,12 @@ defmodule Explorer.ChainTest do setup do Supervisor.terminate_child(Explorer.Supervisor, PendingBlockOperationCache.child_id()) Supervisor.restart_child(Explorer.Supervisor, PendingBlockOperationCache.child_id()) + configuration = Application.get_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor) + Application.put_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor, disabled?: false) on_exit(fn -> Application.put_env(:indexer, :trace_first_block, 0) + Application.put_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor, configuration) Supervisor.terminate_child(Explorer.Supervisor, PendingBlockOperationCache.child_id()) end) end diff --git a/apps/indexer/config/dev/besu.exs b/apps/indexer/config/dev/besu.exs index bcac1a5640..0efe225df1 100644 --- a/apps/indexer/config/dev/besu.exs +++ b/apps/indexer/config/dev/besu.exs @@ -18,16 +18,35 @@ config :indexer, else: EthereumJSONRPC.IPC, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/dev/erigon.exs b/apps/indexer/config/dev/erigon.exs index 8a0d81d498..a819283d3c 100644 --- a/apps/indexer/config/dev/erigon.exs +++ b/apps/indexer/config/dev/erigon.exs @@ -18,16 +18,35 @@ config :indexer, else: EthereumJSONRPC.IPC, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/dev/filecoin.exs b/apps/indexer/config/dev/filecoin.exs index 4f3c58b538..bed9eea600 100644 --- a/apps/indexer/config/dev/filecoin.exs +++ b/apps/indexer/config/dev/filecoin.exs @@ -17,13 +17,36 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:1234/rpc/v1", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_HTTP_URLS", + "ETHEREUM_JSONRPC_HTTP_URL", + "http://localhost:1234/rpc/v1" + ), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:1234/rpc/v1" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:1234/rpc/v1" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:1234/rpc/v1"), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:1234/rpc/v1" + eth_call: :eth_call, + trace_block: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs index c2c40947da..d66ded540f 100644 --- a/apps/indexer/config/dev/ganache.exs +++ b/apps/indexer/config/dev/ganache.exs @@ -17,11 +17,23 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:7545"), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:7545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:7545") + eth_call: :eth_call ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/dev/geth.exs b/apps/indexer/config/dev/geth.exs index d12f24dc1a..82fde60069 100644 --- a/apps/indexer/config/dev/geth.exs +++ b/apps/indexer/config/dev/geth.exs @@ -17,14 +17,33 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - debug_traceTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - debug_traceBlockByNumber: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + debug_traceTransaction: :trace, + debug_traceBlockByNumber: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/dev/nethermind.exs b/apps/indexer/config/dev/nethermind.exs index 0e21234529..0f59e2c965 100644 --- a/apps/indexer/config/dev/nethermind.exs +++ b/apps/indexer/config/dev/nethermind.exs @@ -18,16 +18,35 @@ config :indexer, else: EthereumJSONRPC.IPC, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/dev/rsk.exs b/apps/indexer/config/dev/rsk.exs index c31b0dfdf4..c4a0d84348 100644 --- a/apps/indexer/config/dev/rsk.exs +++ b/apps/indexer/config/dev/rsk.exs @@ -19,16 +19,35 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:8545"), + trace_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_TRACE_URLS", + "ETHEREUM_JSONRPC_TRACE_URL", + "http://localhost:8545" + ), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:8545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:8545"), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/besu.exs b/apps/indexer/config/prod/besu.exs index e87d210895..b78e3c611c 100644 --- a/apps/indexer/config/prod/besu.exs +++ b/apps/indexer/config/prod/besu.exs @@ -17,16 +17,24 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/erigon.exs b/apps/indexer/config/prod/erigon.exs index 1574567cf7..0686e62d3e 100644 --- a/apps/indexer/config/prod/erigon.exs +++ b/apps/indexer/config/prod/erigon.exs @@ -17,16 +17,24 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/filecoin.exs b/apps/indexer/config/prod/filecoin.exs index 82aff88a08..749c6a8fbb 100644 --- a/apps/indexer/config/prod/filecoin.exs +++ b/apps/indexer/config/prod/filecoin.exs @@ -17,13 +17,21 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + trace_block: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/ganache.exs b/apps/indexer/config/prod/ganache.exs index c2c40947da..d66ded540f 100644 --- a/apps/indexer/config/prod/ganache.exs +++ b/apps/indexer/config/prod/ganache.exs @@ -17,11 +17,23 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL", "http://localhost:7545"), + eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_ETH_CALL_URL", + "http://localhost:7545" + ), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url("http://localhost:7545") + eth_call: :eth_call ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/geth.exs b/apps/indexer/config/prod/geth.exs index b690a44094..22a2e84365 100644 --- a/apps/indexer/config/prod/geth.exs +++ b/apps/indexer/config/prod/geth.exs @@ -17,14 +17,22 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - debug_traceTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - debug_traceBlockByNumber: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + debug_traceTransaction: :trace, + debug_traceBlockByNumber: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/nethermind.exs b/apps/indexer/config/prod/nethermind.exs index 3b751ff56f..43f71bbae0 100644 --- a/apps/indexer/config/prod/nethermind.exs +++ b/apps/indexer/config/prod/nethermind.exs @@ -17,16 +17,24 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/config/prod/rsk.exs b/apps/indexer/config/prod/rsk.exs index 434344b397..b710d13474 100644 --- a/apps/indexer/config/prod/rsk.exs +++ b/apps/indexer/config/prod/rsk.exs @@ -19,16 +19,24 @@ config :indexer, ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - fallback_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), - fallback_trace_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), - fallback_eth_call_url: System.get_env("ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL"), + urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_HTTP_URLS", "ETHEREUM_JSONRPC_HTTP_URL"), + trace_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_TRACE_URLS", "ETHEREUM_JSONRPC_TRACE_URL"), + eth_call_urls: ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_ETH_CALL_URLS", "ETHEREUM_JSONRPC_ETH_CALL_URL"), + fallback_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_HTTP_URLS", "ETHEREUM_JSONRPC_FALLBACK_HTTP_URL"), + fallback_trace_urls: + ConfigHelper.parse_urls_list("ETHEREUM_JSONRPC_FALLBACK_TRACE_URLS", "ETHEREUM_JSONRPC_FALLBACK_TRACE_URL"), + fallback_eth_call_urls: + ConfigHelper.parse_urls_list( + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URLS", + "ETHEREUM_JSONRPC_FALLBACK_ETH_CALL_URL" + ), method_to_url: [ - eth_call: ConfigHelper.eth_call_url(), - eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), - trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") + eth_call: :eth_call, + eth_getBalance: :trace, + trace_block: :trace, + trace_replayBlockTransactions: :trace, + trace_replayTransaction: :trace ], http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], diff --git a/apps/indexer/test/indexer/block/fetcher_test.exs b/apps/indexer/test/indexer/block/fetcher_test.exs index dc337b5e28..023affce46 100644 --- a/apps/indexer/test/indexer/block/fetcher_test.exs +++ b/apps/indexer/test/indexer/block/fetcher_test.exs @@ -54,6 +54,13 @@ defmodule Indexer.Block.FetcherTest do poll: false ) + configuration = Application.get_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor) + Application.put_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor, disabled?: false) + + on_exit(fn -> + Application.put_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor, configuration) + end) + ContractCode.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) InternalTransaction.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) Token.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) diff --git a/config/config_helper.exs b/config/config_helper.exs index 850c3735d8..512291e8b0 100644 --- a/config/config_helper.exs +++ b/config/config_helper.exs @@ -337,4 +337,13 @@ defmodule ConfigHelper do def eth_call_url(default \\ nil) do System.get_env("ETHEREUM_JSONRPC_ETH_CALL_URL") || System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || default end + + def parse_urls_list(urls_var, url_var, default_url \\ nil) do + default = default_url || System.get_env("ETHEREUM_JSONRPC_HTTP_URL") + + case parse_list_env_var(urls_var) do + [] -> [safe_get_env(url_var, default)] + urls -> urls + end + end end diff --git a/config/runtime.exs b/config/runtime.exs index 2ad5409019..b440a741fc 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -176,10 +176,13 @@ config :ueberauth, Ueberauth, logout_url: "https://#{System.get_env("ACCOUNT_AUT ### Ethereum JSONRPC ### ######################## +trace_url_missing? = System.get_env("ETHEREUM_JSONRPC_TRACE_URL") in ["", nil] + config :ethereum_jsonrpc, rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_TRANSPORT", "http") == "http", do: :http, else: :ipc), ipc_path: System.get_env("IPC_PATH"), - disable_archive_balances?: ConfigHelper.parse_bool_env_var("ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES"), + disable_archive_balances?: + trace_url_missing? or ConfigHelper.parse_bool_env_var("ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES"), archive_balances_window: ConfigHelper.parse_integer_env_var("ETHEREUM_JSONRPC_ARCHIVE_BALANCES_WINDOW", 200) config :ethereum_jsonrpc, EthereumJSONRPC.HTTP, @@ -763,7 +766,7 @@ config :indexer, Indexer.Fetcher.BlockReward.Supervisor, disabled?: ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_BLOCK_REWARD_FETCHER") config :indexer, Indexer.Fetcher.InternalTransaction.Supervisor, - disabled?: ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER") + disabled?: trace_url_missing? or ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER") disable_coin_balances_fetcher? = ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_ADDRESS_COIN_BALANCE_FETCHER")