From 622c2abffe048df19477f4fce10b66fc7a3fc9ec Mon Sep 17 00:00:00 2001 From: Qwerty5Uiop Date: Thu, 16 Mar 2023 19:28:07 +0400 Subject: [PATCH] ETHEREUM_JSONRPC_HTTP_TIMEOUT env variable --- CHANGELOG.md | 1 + .../lib/ethereum_jsonrpc/geth.ex | 14 +++++++++-- .../ethereum_jsonrpc/utility/common_helper.ex | 23 +++++++++++++++++++ apps/explorer/config/dev/arbitrum.exs | 3 ++- apps/explorer/config/dev/besu.exs | 3 ++- apps/explorer/config/dev/erigon.exs | 3 ++- apps/explorer/config/dev/ganache.exs | 3 ++- apps/explorer/config/dev/geth.exs | 3 ++- apps/explorer/config/dev/nethermind.exs | 3 ++- apps/explorer/config/dev/rsk.exs | 3 ++- apps/explorer/config/prod/arbitrum.exs | 3 ++- apps/explorer/config/prod/besu.exs | 3 ++- apps/explorer/config/prod/erigon.exs | 3 ++- apps/explorer/config/prod/ganache.exs | 3 ++- apps/explorer/config/prod/geth.exs | 3 ++- apps/explorer/config/prod/nethermind.exs | 3 ++- apps/explorer/config/prod/rsk.exs | 3 ++- apps/indexer/config/dev/arbitrum.exs | 3 ++- apps/indexer/config/dev/besu.exs | 3 ++- apps/indexer/config/dev/erigon.exs | 3 ++- apps/indexer/config/dev/ganache.exs | 3 ++- apps/indexer/config/dev/geth.exs | 3 ++- apps/indexer/config/dev/nethermind.exs | 3 ++- apps/indexer/config/dev/rsk.exs | 3 ++- apps/indexer/config/prod/arbitrum.exs | 3 ++- apps/indexer/config/prod/besu.exs | 3 ++- apps/indexer/config/prod/erigon.exs | 3 ++- apps/indexer/config/prod/ganache.exs | 3 ++- apps/indexer/config/prod/geth.exs | 3 ++- apps/indexer/config/prod/nethermind.exs | 3 ++- apps/indexer/config/prod/rsk.exs | 3 ++- config/config_helper.exs | 8 +++++++ deploy/testing/eth-goerli/values.yaml | 2 ++ docker-compose/envs/common-blockscout.env | 1 + docker/Makefile | 3 +++ 35 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f23298d94..fd9736a273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#7068](https://github.com/blockscout/blockscout/pull/7068) - Add authenticate endpoint - [#6990](https://github.com/blockscout/blockscout/pull/6990) - Improved http requests logging, batch transfers pagination; New API v2 endpoint `/smart-contracts/counters`; And some refactoring +- [#7089](https://github.com/blockscout/blockscout/pull/7089) - ETHEREUM_JSONRPC_HTTP_TIMEOUT env variable ### Fixes diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex index 7e3c9c6413..182bd3d5e0 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex @@ -7,7 +7,7 @@ defmodule EthereumJSONRPC.Geth do import EthereumJSONRPC, only: [id_to_params: 1, integer_to_quantity: 1, json_rpc: 2, request: 1] - alias EthereumJSONRPC.{FetchedBalance, FetchedCode, PendingTransaction} + alias EthereumJSONRPC.{FetchedBalance, FetchedCode, PendingTransaction, Utility.CommonHelper} alias EthereumJSONRPC.Geth.{Calls, Tracer} @behaviour EthereumJSONRPC.Variant @@ -27,10 +27,20 @@ defmodule EthereumJSONRPC.Geth do def fetch_internal_transactions(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do id_to_params = id_to_params(transactions_params) + debug_trace_transaction_timeout = + Application.get_env(:ethereum_jsonrpc, __MODULE__)[:debug_trace_transaction_timeout] + + parsed_timeout = CommonHelper.parse_duration(debug_trace_transaction_timeout) + + json_rpc_named_arguments_corrected_timeout = + json_rpc_named_arguments + |> put_in([:transport_options, :http_options, :timeout], parsed_timeout) + |> put_in([:transport_options, :http_options, :recv_timeout], parsed_timeout) + with {:ok, responses} <- id_to_params |> debug_trace_transaction_requests() - |> json_rpc(json_rpc_named_arguments) do + |> json_rpc(json_rpc_named_arguments_corrected_timeout) do debug_trace_transaction_responses_to_internal_transactions_params( responses, id_to_params, diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex new file mode 100644 index 0000000000..65f8a092e3 --- /dev/null +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex @@ -0,0 +1,23 @@ +defmodule EthereumJSONRPC.Utility.CommonHelper do + @moduledoc """ + Common helper functions + """ + + # converts duration like "5s", "2m" to milliseconds + @duration_regex ~r/^(\d+)([smh]{1})$/ + def parse_duration(duration) do + case Regex.run(@duration_regex, duration) do + [_, number, granularity] -> + number + |> String.to_integer() + |> convert_to_ms(granularity) + + _ -> + {:error, :invalid_format} + end + 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) +end diff --git a/apps/explorer/config/dev/arbitrum.exs b/apps/explorer/config/dev/arbitrum.exs index 344ee07f45..9eaa8a6d1c 100644 --- a/apps/explorer/config/dev/arbitrum.exs +++ b/apps/explorer/config/dev/arbitrum.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -12,7 +13,7 @@ config :explorer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Arbitrum ], diff --git a/apps/explorer/config/dev/besu.exs b/apps/explorer/config/dev/besu.exs index c2ee585259..264326700f 100644 --- a/apps/explorer/config/dev/besu.exs +++ b/apps/explorer/config/dev/besu.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Besu ], diff --git a/apps/explorer/config/dev/erigon.exs b/apps/explorer/config/dev/erigon.exs index 2403634b2e..2ee9f7519a 100644 --- a/apps/explorer/config/dev/erigon.exs +++ b/apps/explorer/config/dev/erigon.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Erigon ], diff --git a/apps/explorer/config/dev/ganache.exs b/apps/explorer/config/dev/ganache.exs index 2cd4c9f068..acb4c32d97 100644 --- a/apps/explorer/config/dev/ganache.exs +++ b/apps/explorer/config/dev/ganache.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -12,7 +13,7 @@ config :explorer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Ganache ], diff --git a/apps/explorer/config/dev/geth.exs b/apps/explorer/config/dev/geth.exs index 131607d629..629f4c2eb0 100644 --- a/apps/explorer/config/dev/geth.exs +++ b/apps/explorer/config/dev/geth.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -12,7 +13,7 @@ config :explorer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Geth ], diff --git a/apps/explorer/config/dev/nethermind.exs b/apps/explorer/config/dev/nethermind.exs index 42e1194923..2bd47827fd 100644 --- a/apps/explorer/config/dev/nethermind.exs +++ b/apps/explorer/config/dev/nethermind.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Nethermind ], diff --git a/apps/explorer/config/dev/rsk.exs b/apps/explorer/config/dev/rsk.exs index 9faf1f9000..bd29d093b3 100644 --- a/apps/explorer/config/dev/rsk.exs +++ b/apps/explorer/config/dev/rsk.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.RSK ], diff --git a/apps/explorer/config/prod/arbitrum.exs b/apps/explorer/config/prod/arbitrum.exs index 565b32ecf2..af2407090a 100644 --- a/apps/explorer/config/prod/arbitrum.exs +++ b/apps/explorer/config/prod/arbitrum.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -12,7 +13,7 @@ config :explorer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Arbitrum ], diff --git a/apps/explorer/config/prod/besu.exs b/apps/explorer/config/prod/besu.exs index 367cb86fd0..7495423c33 100644 --- a/apps/explorer/config/prod/besu.exs +++ b/apps/explorer/config/prod/besu.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Besu ], diff --git a/apps/explorer/config/prod/erigon.exs b/apps/explorer/config/prod/erigon.exs index a0684166f7..ed3e9475f1 100644 --- a/apps/explorer/config/prod/erigon.exs +++ b/apps/explorer/config/prod/erigon.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Erigon ], diff --git a/apps/explorer/config/prod/ganache.exs b/apps/explorer/config/prod/ganache.exs index da8f69e543..7b586bb43c 100644 --- a/apps/explorer/config/prod/ganache.exs +++ b/apps/explorer/config/prod/ganache.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -12,7 +13,7 @@ config :explorer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Ganache ], diff --git a/apps/explorer/config/prod/geth.exs b/apps/explorer/config/prod/geth.exs index 3e7fcc46f7..c00a7cb117 100644 --- a/apps/explorer/config/prod/geth.exs +++ b/apps/explorer/config/prod/geth.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -12,7 +13,7 @@ config :explorer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Geth ], diff --git a/apps/explorer/config/prod/nethermind.exs b/apps/explorer/config/prod/nethermind.exs index 1eec652552..ca6d557b8d 100644 --- a/apps/explorer/config/prod/nethermind.exs +++ b/apps/explorer/config/prod/nethermind.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Nethermind ], diff --git a/apps/explorer/config/prod/rsk.exs b/apps/explorer/config/prod/rsk.exs index 173a98579d..04efcc1261 100644 --- a/apps/explorer/config/prod/rsk.exs +++ b/apps/explorer/config/prod/rsk.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :explorer, json_rpc_named_arguments: [ @@ -17,7 +18,7 @@ config :explorer, eth_getBalance: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.RSK ], diff --git a/apps/indexer/config/dev/arbitrum.exs b/apps/indexer/config/dev/arbitrum.exs index dfd5f3b8cc..9292e02a8d 100644 --- a/apps/indexer/config/dev/arbitrum.exs +++ b/apps/indexer/config/dev/arbitrum.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :indexer, block_interval: :timer.seconds(5), @@ -17,7 +18,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Arbitrum ], diff --git a/apps/indexer/config/dev/besu.exs b/apps/indexer/config/dev/besu.exs index bfa64797c7..686859041d 100644 --- a/apps/indexer/config/dev/besu.exs +++ b/apps/indexer/config/dev/besu.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -23,7 +24,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Besu ], diff --git a/apps/indexer/config/dev/erigon.exs b/apps/indexer/config/dev/erigon.exs index 5f655cb4a0..9dba28795c 100644 --- a/apps/indexer/config/dev/erigon.exs +++ b/apps/indexer/config/dev/erigon.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -23,7 +24,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Erigon ], diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs index c073851411..6987dfcc0d 100644 --- a/apps/indexer/config/dev/ganache.exs +++ b/apps/indexer/config/dev/ganache.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :indexer, block_interval: :timer.seconds(5), @@ -17,7 +18,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Ganache ], diff --git a/apps/indexer/config/dev/geth.exs b/apps/indexer/config/dev/geth.exs index 9a712db5f4..8f40e8395c 100644 --- a/apps/indexer/config/dev/geth.exs +++ b/apps/indexer/config/dev/geth.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :indexer, block_interval: :timer.seconds(5), @@ -17,7 +18,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Geth ], diff --git a/apps/indexer/config/dev/nethermind.exs b/apps/indexer/config/dev/nethermind.exs index 5ab6ee9ecb..b4e8439a9a 100644 --- a/apps/indexer/config/dev/nethermind.exs +++ b/apps/indexer/config/dev/nethermind.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -23,7 +24,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Nethermind ], diff --git a/apps/indexer/config/dev/rsk.exs b/apps/indexer/config/dev/rsk.exs index 6b66565b21..da953f5479 100644 --- a/apps/indexer/config/dev/rsk.exs +++ b/apps/indexer/config/dev/rsk.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -24,7 +25,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.RSK ], diff --git a/apps/indexer/config/prod/arbitrum.exs b/apps/indexer/config/prod/arbitrum.exs index 8a4e8b860b..7435fbd11c 100644 --- a/apps/indexer/config/prod/arbitrum.exs +++ b/apps/indexer/config/prod/arbitrum.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(5) config :indexer, block_interval: :timer.seconds(5), @@ -17,7 +18,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(5), timeout: :timer.minutes(5), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Arbitrum ], diff --git a/apps/indexer/config/prod/besu.exs b/apps/indexer/config/prod/besu.exs index 1e665820b3..efa532675b 100644 --- a/apps/indexer/config/prod/besu.exs +++ b/apps/indexer/config/prod/besu.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -22,7 +23,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Besu ], diff --git a/apps/indexer/config/prod/erigon.exs b/apps/indexer/config/prod/erigon.exs index aa1c0db2c9..072d0a2294 100644 --- a/apps/indexer/config/prod/erigon.exs +++ b/apps/indexer/config/prod/erigon.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -22,7 +23,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Erigon ], diff --git a/apps/indexer/config/prod/ganache.exs b/apps/indexer/config/prod/ganache.exs index c073851411..6987dfcc0d 100644 --- a/apps/indexer/config/prod/ganache.exs +++ b/apps/indexer/config/prod/ganache.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(1) config :indexer, block_interval: :timer.seconds(5), @@ -17,7 +18,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Ganache ], diff --git a/apps/indexer/config/prod/geth.exs b/apps/indexer/config/prod/geth.exs index 00c35fde33..d603ae3bc8 100644 --- a/apps/indexer/config/prod/geth.exs +++ b/apps/indexer/config/prod/geth.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -17,7 +18,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Geth ], diff --git a/apps/indexer/config/prod/nethermind.exs b/apps/indexer/config/prod/nethermind.exs index 2f4b8f1d08..366d55a795 100644 --- a/apps/indexer/config/prod/nethermind.exs +++ b/apps/indexer/config/prod/nethermind.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout() config :indexer, block_interval: :timer.seconds(5), @@ -22,7 +23,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.Nethermind ], diff --git a/apps/indexer/config/prod/rsk.exs b/apps/indexer/config/prod/rsk.exs index 3b4bb8bee7..40a77c83cf 100644 --- a/apps/indexer/config/prod/rsk.exs +++ b/apps/indexer/config/prod/rsk.exs @@ -5,6 +5,7 @@ import Config |> Code.eval_file() hackney_opts = ConfigHelper.hackney_options() +timeout = ConfigHelper.timeout(10) config :indexer, block_interval: :timer.seconds(5), @@ -24,7 +25,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] + http_options: [recv_timeout: timeout, timeout: timeout, hackney: hackney_opts] ], variant: EthereumJSONRPC.RSK ], diff --git a/config/config_helper.exs b/config/config_helper.exs index 7a03f172df..b0213e1b60 100644 --- a/config/config_helper.exs +++ b/config/config_helper.exs @@ -10,4 +10,12 @@ defmodule ConfigHelper do else: &1 )).() end + + def timeout(default_minutes \\ 1) do + case Integer.parse(System.get_env("ETHEREUM_JSONRPC_HTTP_TIMEOUT", "#{default_minutes * 60}")) do + {seconds, ""} -> seconds + _ -> default_minutes * 60 + end + |> :timer.seconds() + end end diff --git a/deploy/testing/eth-goerli/values.yaml b/deploy/testing/eth-goerli/values.yaml index 5d0143b59d..daf8e7dd8c 100644 --- a/deploy/testing/eth-goerli/values.yaml +++ b/deploy/testing/eth-goerli/values.yaml @@ -97,6 +97,8 @@ blockscout: _default: '[{"title": "Marketplace", "url": "/apps", "embedded?": true}]' ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT: _default: '20s' + ETHEREUM_JSONRPC_HTTP_TIMEOUT: + _default: 60 INDEXER_INTERNAL_TRANSACTIONS_BATCH_SIZE: _default: 15 INDEXER_DISABLE_EMPTY_BLOCK_SANITIZER: diff --git a/docker-compose/envs/common-blockscout.env b/docker-compose/envs/common-blockscout.env index 3bfa77bd2d..bb5710a8b5 100644 --- a/docker-compose/envs/common-blockscout.env +++ b/docker-compose/envs/common-blockscout.env @@ -3,6 +3,7 @@ ETHEREUM_JSONRPC_VARIANT=geth ETHEREUM_JSONRPC_HTTP_URL=http://host.docker.internal:8545/ DATABASE_URL=postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false ETHEREUM_JSONRPC_TRACE_URL=http://host.docker.internal:8545/ +# ETHEREUM_JSONRPC_HTTP_TIMEOUT= NETWORK= SUBNETWORK=Awesome chain LOGO=/images/blockscout_logo.svg diff --git a/docker/Makefile b/docker/Makefile index 32546767b0..3e2dd9cf7b 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -376,6 +376,9 @@ endif ifdef ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT BLOCKSCOUT_CONTAINER_PARAMS += -e 'ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT=$(ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT)' endif +ifdef ETHEREUM_JSONRPC_HTTP_TIMEOUT + BLOCKSCOUT_CONTAINER_PARAMS += -e 'ETHEREUM_JSONRPC_HTTP_TIMEOUT=$(ETHEREUM_JSONRPC_HTTP_TIMEOUT)' +endif ifdef FETCH_REWARDS_WAY BLOCKSCOUT_CONTAINER_PARAMS += -e 'FETCH_REWARDS_WAY=$(FETCH_REWARDS_WAY)' endif