Merge pull request #4819 from blockscout/vb-gas-usage-cache-add-config

Add config for GasUsage Cache
pull/4820/head
Victor Baranov 3 years ago committed by GitHub
commit 50e45972e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/block_scout_web/lib/block_scout_web/counters/blocks_indexed_counter.ex
  3. 11
      apps/explorer/config/config.exs
  4. 38
      apps/explorer/lib/explorer/chain/cache/gas_usage.ex

@ -58,6 +58,7 @@
- [#4582](https://github.com/blockscout/blockscout/pull/4582) - Fix NaN input on write contract page - [#4582](https://github.com/blockscout/blockscout/pull/4582) - Fix NaN input on write contract page
### Chore ### Chore
- [#4819](https://github.com/blockscout/blockscout/pull/4819) - Add config for GasUsage Cache
- [#4735](https://github.com/blockscout/blockscout/pull/4735) - Code clean up: Remove clauses for outdated ganache bugs - [#4735](https://github.com/blockscout/blockscout/pull/4735) - Code clean up: Remove clauses for outdated ganache bugs
- [#4726](https://github.com/blockscout/blockscout/pull/4726) - Update chart.js - [#4726](https://github.com/blockscout/blockscout/pull/4726) - Update chart.js
- [#4707](https://github.com/blockscout/blockscout/pull/4707) - Top navigation: Move Accounts tab to Tokens - [#4707](https://github.com/blockscout/blockscout/pull/4707) - Top navigation: Move Accounts tab to Tokens

@ -13,7 +13,7 @@ defmodule BlockScoutWeb.Counters.BlocksIndexedCounter do
# It is undesirable to automatically start the counter in all environments. # It is undesirable to automatically start the counter in all environments.
# Consider the test environment: if it initiates but does not finish before a # Consider the test environment: if it initiates but does not finish before a
# test ends, that test will fail. # test ends, that test will fail.
config = Application.get_env(:block_scout_web, BlockScoutWeb.Counters.BlocksIndexedCounter) config = Application.get_env(:block_scout_web, __MODULE__)
@enabled Keyword.get(config, :enabled) @enabled Keyword.get(config, :enabled)
@doc """ @doc """

@ -241,19 +241,12 @@ config :explorer, Explorer.Chain.Cache.Accounts,
ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false), ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false),
global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5)) global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5))
config :explorer, Explorer.Chain.Cache.PendingTransactions,
enabled:
if(System.get_env("ETHEREUM_JSONRPC_VARIANT") == "besu",
do: false,
else: true
),
ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false),
global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5))
config :explorer, Explorer.Chain.Cache.Uncles, config :explorer, Explorer.Chain.Cache.Uncles,
ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false), ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false),
global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5)) global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5))
config :explorer, Explorer.Chain.Cache.GasUsage, enabled: false
config :explorer, Explorer.ThirdPartyIntegrations.Sourcify, config :explorer, Explorer.ThirdPartyIntegrations.Sourcify,
server_url: System.get_env("SOURCIFY_SERVER_URL") || "https://sourcify.dev/server", server_url: System.get_env("SOURCIFY_SERVER_URL") || "https://sourcify.dev/server",
enabled: System.get_env("ENABLE_SOURCIFY_INTEGRATION") == "true", enabled: System.get_env("ENABLE_SOURCIFY_INTEGRATION") == "true",

@ -6,6 +6,8 @@ defmodule Explorer.Chain.Cache.GasUsage do
require Logger require Logger
@default_cache_period :timer.hours(2) @default_cache_period :timer.hours(2)
config = Application.get_env(:explorer, __MODULE__)
@enabled Keyword.get(config, :enabled)
use Explorer.Chain.MapCache, use Explorer.Chain.MapCache,
name: :gas_usage, name: :gas_usage,
@ -26,25 +28,29 @@ defmodule Explorer.Chain.Cache.GasUsage do
end end
defp handle_fallback(:async_task) do defp handle_fallback(:async_task) do
# If this gets called it means an async task was requested, but none exists if @enabled do
# so a new one needs to be launched # If this gets called it means an async task was requested, but none exists
{:ok, task} = # so a new one needs to be launched
Task.start(fn -> {:ok, task} =
try do Task.start(fn ->
result = Chain.fetch_sum_gas_used() try do
result = Chain.fetch_sum_gas_used()
set_sum(result) set_sum(result)
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update gas used sum test #{inspect(e)}" "Coudn't update gas used sum test #{inspect(e)}"
]) ])
end end
set_async_task(nil) set_async_task(nil)
end) end)
{:update, task} {:update, task}
else
{:update, nil}
end
end end
# By setting this as a `callback` an async task will be started each time the # By setting this as a `callback` an async task will be started each time the

Loading…
Cancel
Save