diff --git a/CHANGELOG.md b/CHANGELOG.md index 826abf3786..b2d76424c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - [#5239](https://github.com/blockscout/blockscout/pull/5239) - Add accounting for block rewards in `getblockreward` api method ### Chore +- [#5506](https://github.com/blockscout/blockscout/pull/5506) - Refactor config files - [#5480](https://github.com/blockscout/blockscout/pull/5480) - Remove duplicate of balances_params_to_address_params function - [#5473](https://github.com/blockscout/blockscout/pull/5473) - Refactor daily coin balances fetcher - [#5458](https://github.com/blockscout/blockscout/pull/5458) - Decrease min safe polling period for realtime fetcher diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index 8392cfdda8..9fc2c0ef2f 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -55,31 +55,34 @@ config :block_scout_web, re_captcha_client_key: System.get_env("RE_CAPTCHA_CLIENT_KEY", nil), admin_panel_enabled: System.get_env("ADMIN_PANEL_ENABLED", "") == "true" +default_api_rate_limit = 50 +default_api_rate_limit_str = Integer.to_string(default_api_rate_limit) + global_api_rate_limit_value = "API_RATE_LIMIT" - |> System.get_env("50") + |> System.get_env(default_api_rate_limit_str) |> Integer.parse() |> case do {integer, ""} -> integer - _ -> 50 + _ -> default_api_rate_limit end api_rate_limit_by_key_value = "API_RATE_LIMIT_BY_KEY" - |> System.get_env("50") + |> System.get_env(default_api_rate_limit_str) |> Integer.parse() |> case do {integer, ""} -> integer - _ -> 50 + _ -> default_api_rate_limit end api_rate_limit_by_ip_value = "API_RATE_LIMIT_BY_IP" - |> System.get_env("50") + |> System.get_env(default_api_rate_limit_str) |> Integer.parse() |> case do {integer, ""} -> integer - _ -> 50 + _ -> default_api_rate_limit end config :block_scout_web, :api_rate_limit, diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index c8986bfab6..2ce8c0c4ea 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -5,6 +5,9 @@ # is restricted to this project. import Config +disable_indexer = System.get_env("DISABLE_INDEXER") +disable_webapp = System.get_env("DISABLE_WEBAPP") + # General application configuration config :explorer, ecto_repos: [Explorer.Repo], @@ -18,7 +21,7 @@ config :explorer, if(System.get_env("UNCLES_IN_AVERAGE_BLOCK_TIME") == "true", do: true, else: false), healthy_blocks_period: System.get_env("HEALTHY_BLOCKS_PERIOD") || :timer.minutes(5), realtime_events_sender: - if(System.get_env("DISABLE_WEBAPP") != "true", + if(disable_webapp != "true", do: Explorer.Chain.Events.SimpleSender, else: Explorer.Chain.Events.DBSender ) @@ -29,7 +32,7 @@ config :explorer, Explorer.Counters.AverageBlockTime, config :explorer, Explorer.Chain.Events.Listener, enabled: - if(System.get_env("DISABLE_WEBAPP") == "true" && System.get_env("DISABLE_INDEXER") == "true", + if(disable_webapp == "true" && disable_indexer == "true", do: false, else: true ) @@ -42,8 +45,8 @@ config :explorer, Explorer.ChainSpec.GenesisData, config :explorer, Explorer.Chain.Cache.BlockNumber, enabled: 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)) + ttl_check_interval: if(disable_indexer == "true", do: :timer.seconds(1), else: false), + global_ttl: if(disable_indexer == "true", do: :timer.seconds(5)) address_sum_global_ttl = "CACHE_ADDRESS_SUM_PERIOD" @@ -64,9 +67,11 @@ config :explorer, Explorer.Chain.Cache.AddressSumMinusBurnt, ttl_check_interval: :timer.seconds(1), global_ttl: address_sum_global_ttl +cache_address_with_balances_update_interval = System.get_env("CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL") + balances_update_interval = - if System.get_env("CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL") do - case Integer.parse(System.get_env("CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL")) do + if cache_address_with_balances_update_interval do + case Integer.parse(cache_address_with_balances_update_interval) do {integer, ""} -> integer _ -> nil end @@ -121,9 +126,11 @@ config :explorer, Explorer.Counters.BlockPriorityFeeCounter, config :explorer, Explorer.Chain.Cache.GasUsage, enabled: System.get_env("CACHE_ENABLE_TOTAL_GAS_USAGE_COUNTER") == "true" +cache_bridge_market_cap_update_interval = System.get_env("CACHE_BRIDGE_MARKET_CAP_UPDATE_INTERVAL") + bridge_market_cap_update_interval = - if System.get_env("CACHE_BRIDGE_MARKET_CAP_UPDATE_INTERVAL") do - case Integer.parse(System.get_env("CACHE_BRIDGE_MARKET_CAP_UPDATE_INTERVAL")) do + if cache_bridge_market_cap_update_interval do + case Integer.parse(cache_bridge_market_cap_update_interval) do {integer, ""} -> integer _ -> nil end @@ -141,7 +148,7 @@ config :explorer, Explorer.KnownTokens, enabled: System.get_env("DISABLE_KNOWN_T config :explorer, Explorer.Integrations.EctoLogger, query_time_ms_threshold: :timer.seconds(2) -config :explorer, Explorer.Market.History.Cataloger, enabled: System.get_env("DISABLE_INDEXER") != "true" +config :explorer, Explorer.Market.History.Cataloger, enabled: disable_indexer != "true" config :explorer, Explorer.Chain.Cache.MinMissingBlockNumber, enabled: System.get_env("DISABLE_WRITE_API") != "true" @@ -182,7 +189,7 @@ if System.get_env("METADATA_CONTRACT") && System.get_env("VALIDATORS_CONTRACT") metadata_contract_address: System.get_env("METADATA_CONTRACT"), validators_contract_address: System.get_env("VALIDATORS_CONTRACT") - config :explorer, Explorer.Validator.MetadataProcessor, enabled: System.get_env("DISABLE_INDEXER") != "true" + config :explorer, Explorer.Validator.MetadataProcessor, enabled: disable_indexer != "true" else config :explorer, Explorer.Validator.MetadataProcessor, enabled: false end @@ -191,10 +198,12 @@ config :explorer, Explorer.Chain.Block.Reward, validators_contract_address: System.get_env("VALIDATORS_CONTRACT"), keys_manager_contract_address: System.get_env("KEYS_MANAGER_CONTRACT") -if System.get_env("POS_STAKING_CONTRACT") do +pos_staking_contract = System.get_env("POS_STAKING_CONTRACT") + +if pos_staking_contract do config :explorer, Explorer.Staking.ContractState, enabled: true, - staking_contract_address: System.get_env("POS_STAKING_CONTRACT"), + staking_contract_address: pos_staking_contract, eth_subscribe_max_delay: System.get_env("POS_ETH_SUBSCRIBE_MAX_DELAY", "60"), eth_blocknumber_pull_interval: System.get_env("POS_ETH_BLOCKNUMBER_PULL_INTERVAL", "500") else @@ -234,20 +243,20 @@ config :spandex_ecto, SpandexEcto.EctoLogger, otp_app: :explorer config :explorer, Explorer.Chain.Cache.Blocks, - 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)) + ttl_check_interval: if(disable_indexer == "true", do: :timer.seconds(1), else: false), + global_ttl: if(disable_indexer == "true", do: :timer.seconds(5)) config :explorer, Explorer.Chain.Cache.Transactions, - 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)) + ttl_check_interval: if(disable_indexer == "true", do: :timer.seconds(1), else: false), + global_ttl: if(disable_indexer == "true", do: :timer.seconds(5)) config :explorer, Explorer.Chain.Cache.Accounts, - 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)) + ttl_check_interval: if(disable_indexer == "true", do: :timer.seconds(1), else: false), + global_ttl: if(disable_indexer == "true", do: :timer.seconds(5)) config :explorer, Explorer.Chain.Cache.Uncles, - 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)) + ttl_check_interval: if(disable_indexer == "true", do: :timer.seconds(1), else: false), + global_ttl: if(disable_indexer == "true", do: :timer.seconds(5)) config :explorer, Explorer.ThirdPartyIntegrations.Sourcify, server_url: System.get_env("SOURCIFY_SERVER_URL") || "https://sourcify.dev/server", diff --git a/apps/indexer/config/config.exs b/apps/indexer/config/config.exs index d543da2225..80330b9022 100644 --- a/apps/indexer/config/config.exs +++ b/apps/indexer/config/config.exs @@ -41,26 +41,24 @@ config :indexer, Indexer.Fetcher.PendingTransaction.Supervisor, System.get_env("ETHEREUM_JSONRPC_VARIANT") == "besu" || System.get_env("INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER", "false") == "true" +token_balance_on_demand_fetcher_threshold_minutes = System.get_env("TOKEN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD_MINUTES") + token_balance_on_demand_fetcher_threshold = - if System.get_env("TOKEN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD_MINUTES") do - case Integer.parse(System.get_env("TOKEN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD_MINUTES")) do - {integer, ""} -> integer - _ -> 60 - end - else - 60 + case token_balance_on_demand_fetcher_threshold_minutes && + Integer.parse(token_balance_on_demand_fetcher_threshold_minutes) do + {integer, ""} -> integer + _ -> 60 end config :indexer, Indexer.Fetcher.TokenBalanceOnDemand, threshold: token_balance_on_demand_fetcher_threshold +coin_balance_on_demand_fetcher_threshold_minutes = System.get_env("COIN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD_MINUTES") + coin_balance_on_demand_fetcher_threshold = - if System.get_env("COIN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD_MINUTES") do - case Integer.parse(System.get_env("COIN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD_MINUTES")) do - {integer, ""} -> integer - _ -> 60 - end - else - 60 + case coin_balance_on_demand_fetcher_threshold_minutes && + Integer.parse(coin_balance_on_demand_fetcher_threshold_minutes) do + {integer, ""} -> integer + _ -> 60 end config :indexer, Indexer.Fetcher.CoinBalanceOnDemand, threshold: coin_balance_on_demand_fetcher_threshold diff --git a/apps/indexer/lib/indexer/fetcher/coin_balance_on_demand.ex b/apps/indexer/lib/indexer/fetcher/coin_balance_on_demand.ex index e7989a027e..ac02a8f2d2 100644 --- a/apps/indexer/lib/indexer/fetcher/coin_balance_on_demand.ex +++ b/apps/indexer/lib/indexer/fetcher/coin_balance_on_demand.ex @@ -230,7 +230,8 @@ defmodule Indexer.Fetcher.CoinBalanceOnDemand do if average_block_time == 0 do {:error, :empty_database} else - block_number - div(:timer.minutes(Application.get_env(:indexer, __MODULE__)[:threshold]), average_block_time) + threshold = Application.get_env(:indexer, __MODULE__)[:threshold] + block_number - div(:timer.minutes(threshold), average_block_time) end end end diff --git a/apps/indexer/lib/indexer/fetcher/token_balance_on_demand.ex b/apps/indexer/lib/indexer/fetcher/token_balance_on_demand.ex index 620586c0ad..c63397736d 100644 --- a/apps/indexer/lib/indexer/fetcher/token_balance_on_demand.ex +++ b/apps/indexer/lib/indexer/fetcher/token_balance_on_demand.ex @@ -104,7 +104,8 @@ defmodule Indexer.Fetcher.TokenBalanceOnDemand do if average_block_time == 0 do {:error, :empty_database} else - block_number - div(:timer.minutes(Application.get_env(:indexer, __MODULE__)[:threshold]), average_block_time) + threshold = Application.get_env(:indexer, __MODULE__)[:threshold] + block_number - div(:timer.minutes(threshold), average_block_time) end end end