Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/config/config_helper.exs

388 lines
12 KiB

defmodule ConfigHelper do
require Logger
import Bitwise
alias Explorer.ExchangeRates.Source
alias Explorer.Market.History.Source.{MarketCap, Price, TVL}
alias Indexer.Transform.Blocks
Deposits and Withdrawals for Polygon Edge (#8180) * Prepare tables for Polygon Supernet Withdrawals module * Prepare Indexer.Fetcher.PolygonSupernetWithdrawal * Prepare Indexer.Fetcher.PolygonSupernetWithdrawalExit * Prepare tables for Polygon Supernet Deposits module * Partially add Polygon Supernet Deposits module * Add Polygon Supernet Deposits module * Extend transaction data in API v2 for Polygon Supernet Deposits and Withdrawals * Extend API v2 for list of Polygon Supernet Deposits * Extend API v2 for list of Polygon Supernet Withdrawals * Modify collated_gas_price constraint to support Immutable test chain * Update number of retries * Fix Indexer.Fetcher.PolygonSupernetWithdrawal * Fix API v2 for Indexer.Fetcher.PolygonSupernetWithdrawal * Return page_size to 50 * Fix API v2 for Indexer.Fetcher.PolygonSupernetDeposit * Fix Explorer.Validator.MetadataRetriever to prevent sending request to nil address * Refactor PolygonSupernet* modules * Refactor PolygonSupernet* modules * Small refactoring of PolygonSupernet* modules * Update changelog * Fixes for dialyzer and cspell * Fix of Explorer tests * Add env vars for docker * Add env variable for eth_getLogs * Share event signatures between modules * Refactoring for fill_block_range function * Small refactoring of transaction actions module * Move polygon_supernet_* modules to a separate folder * Add specs for public functions * Remove redundant function * Reuse decode_data function * Move polygon_supernet_* files into a separate folder * Move polygon_supernet_* files into a separate folder * Partially disband Explorer.Chain module * Define chain type * Remove infinite waiting for safe block * max format * Rename Polygon Supernet to Polygon Edge * Set INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE to polygon_edge if CHAIN_TYPE is polygon_edge * Fix chain type definition * Fix repos list definition in releases_tasks * INDEXER_POLYGON_SUPERNET_ -> INDEXER_POLYGON_EDGE_ --------- Co-authored-by: POA <33550681+poa@users.noreply.github.com> Co-authored-by: Viktor Baranov <baranov.viktor.27@gmail.com>
1 year ago
def repos do
base_repos = [Explorer.Repo, Explorer.Repo.Account]
chain_type_repo =
%{
arbitrum: Explorer.Repo.Arbitrum,
blackfort: Explorer.Repo.Blackfort,
celo: Explorer.Repo.Celo,
ethereum: Explorer.Repo.Beacon,
filecoin: Explorer.Repo.Filecoin,
optimism: Explorer.Repo.Optimism,
polygon_edge: Explorer.Repo.PolygonEdge,
polygon_zkevm: Explorer.Repo.PolygonZkevm,
rsk: Explorer.Repo.RSK,
scroll: Explorer.Repo.Scroll,
shibarium: Explorer.Repo.Shibarium,
stability: Explorer.Repo.Stability,
suave: Explorer.Repo.Suave,
zilliqa: Explorer.Repo.Zilliqa,
zksync: Explorer.Repo.ZkSync
}
|> Map.get(chain_type())
chain_type_repos = (chain_type_repo && [chain_type_repo]) || []
ext_repos =
[
{parse_bool_env_var("BRIDGED_TOKENS_ENABLED"), Explorer.Repo.BridgedTokens},
{parse_bool_env_var("MUD_INDEXER_ENABLED"), Explorer.Repo.Mud},
{parse_bool_env_var("SHRINK_INTERNAL_TRANSACTIONS_ENABLED"), Explorer.Repo.ShrunkInternalTransactions}
]
|> Enum.filter(&elem(&1, 0))
|> Enum.map(&elem(&1, 1))
base_repos ++ chain_type_repos ++ ext_repos
Deposits and Withdrawals for Polygon Edge (#8180) * Prepare tables for Polygon Supernet Withdrawals module * Prepare Indexer.Fetcher.PolygonSupernetWithdrawal * Prepare Indexer.Fetcher.PolygonSupernetWithdrawalExit * Prepare tables for Polygon Supernet Deposits module * Partially add Polygon Supernet Deposits module * Add Polygon Supernet Deposits module * Extend transaction data in API v2 for Polygon Supernet Deposits and Withdrawals * Extend API v2 for list of Polygon Supernet Deposits * Extend API v2 for list of Polygon Supernet Withdrawals * Modify collated_gas_price constraint to support Immutable test chain * Update number of retries * Fix Indexer.Fetcher.PolygonSupernetWithdrawal * Fix API v2 for Indexer.Fetcher.PolygonSupernetWithdrawal * Return page_size to 50 * Fix API v2 for Indexer.Fetcher.PolygonSupernetDeposit * Fix Explorer.Validator.MetadataRetriever to prevent sending request to nil address * Refactor PolygonSupernet* modules * Refactor PolygonSupernet* modules * Small refactoring of PolygonSupernet* modules * Update changelog * Fixes for dialyzer and cspell * Fix of Explorer tests * Add env vars for docker * Add env variable for eth_getLogs * Share event signatures between modules * Refactoring for fill_block_range function * Small refactoring of transaction actions module * Move polygon_supernet_* modules to a separate folder * Add specs for public functions * Remove redundant function * Reuse decode_data function * Move polygon_supernet_* files into a separate folder * Move polygon_supernet_* files into a separate folder * Partially disband Explorer.Chain module * Define chain type * Remove infinite waiting for safe block * max format * Rename Polygon Supernet to Polygon Edge * Set INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE to polygon_edge if CHAIN_TYPE is polygon_edge * Fix chain type definition * Fix repos list definition in releases_tasks * INDEXER_POLYGON_SUPERNET_ -> INDEXER_POLYGON_EDGE_ --------- Co-authored-by: POA <33550681+poa@users.noreply.github.com> Co-authored-by: Viktor Baranov <baranov.viktor.27@gmail.com>
1 year ago
end
@spec hackney_options() :: any()
def hackney_options() do
basic_auth_user = System.get_env("ETHEREUM_JSONRPC_USER", "")
basic_auth_pass = System.get_env("ETHEREUM_JSONRPC_PASSWORD", nil)
[pool: :ethereum_jsonrpc]
|> (&if(System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true", do: [:insecure] ++ &1, else: &1)).()
|> (&if(basic_auth_user != "" && !is_nil(basic_auth_pass),
do: [basic_auth: {basic_auth_user, basic_auth_pass}] ++ &1,
else: &1
)).()
end
@spec timeout(non_neg_integer()) :: non_neg_integer()
def timeout(default_minutes \\ 1) do
case Integer.parse(safe_get_env("ETHEREUM_JSONRPC_HTTP_TIMEOUT", "#{default_minutes * 60}")) do
{seconds, ""} -> seconds
_ -> default_minutes * 60
end
|> :timer.seconds()
end
@spec parse_integer_env_var(String.t(), integer()) :: non_neg_integer()
def parse_integer_env_var(env_var, default_value) do
env_var
|> safe_get_env(to_string(default_value))
|> Integer.parse()
|> case do
{integer, _} -> integer
_ -> 0
end
end
@spec parse_float_env_var(String.t(), float()) :: float()
def parse_float_env_var(env_var, default_value) do
env_var
|> safe_get_env(to_string(default_value))
|> Float.parse()
|> case do
{float, _} -> float
_ -> 0
end
end
@spec parse_integer_or_nil_env_var(String.t()) :: non_neg_integer() | nil
def parse_integer_or_nil_env_var(env_var) do
env_var
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, _} -> integer
_ -> nil
end
end
@spec parse_time_env_var(String.t(), String.t() | nil) :: non_neg_integer()
def parse_time_env_var(env_var, default_value) do
case env_var |> safe_get_env(default_value) |> String.downcase() |> Integer.parse() do
{milliseconds, "ms"} -> milliseconds
{hours, "h"} -> :timer.hours(hours)
{minutes, "m"} -> :timer.minutes(minutes)
{seconds, s} when s in ["s", ""] -> :timer.seconds(seconds)
_ -> 0
end
end
@doc """
Parses value of env var through catalogued values list. If a value is not in the list, nil is returned.
Also, the application shutdown option is supported, if a value is wrong.
"""
@spec parse_catalog_value(String.t(), List.t(), bool(), String.t() | nil) :: atom() | nil
def parse_catalog_value(env_var, catalog, shutdown_on_wrong_value?, default_value \\ nil) do
value = env_var |> safe_get_env(default_value)
if value !== "" do
if value in catalog do
String.to_atom(value)
else
if shutdown_on_wrong_value? do
Logger.error(wrong_value_error(value, env_var, catalog))
exit(:shutdown)
else
Logger.warning(wrong_value_error(value, env_var, catalog))
nil
end
end
else
nil
end
end
defp wrong_value_error(value, env_var, catalog) do
"Invalid value \"#{value}\" of #{env_var} environment variable is provided. Supported values are #{inspect(catalog)}"
end
def safe_get_env(env_var, default_value) do
env_var
|> System.get_env(default_value)
|> case do
"" -> default_value
value -> value
end
|> to_string()
end
@spec parse_bool_env_var(String.t(), String.t()) :: boolean()
def parse_bool_env_var(env_var, default_value \\ "false"),
do: String.downcase(safe_get_env(env_var, default_value)) == "true"
@spec cache_ttl_check_interval(boolean()) :: non_neg_integer() | false
def cache_ttl_check_interval(disable_indexer?) do
if(disable_indexer?, do: :timer.seconds(1), else: false)
end
@spec cache_global_ttl(boolean()) :: non_neg_integer()
def cache_global_ttl(disable_indexer?) do
if(disable_indexer?, do: :timer.seconds(5))
end
@spec indexer_memory_limit() :: integer()
def indexer_memory_limit do
"INDEXER_MEMORY_LIMIT"
|> safe_get_env(nil)
|> String.downcase()
|> Integer.parse()
|> case do
{integer, g} when g in ["g", "gb", ""] -> integer <<< 30
{integer, m} when m in ["m", "mb"] -> integer <<< 20
_ -> nil
end
end
@spec exchange_rates_source() :: Source.CoinGecko | Source.CoinMarketCap | Source.Mobula
def exchange_rates_source do
case System.get_env("EXCHANGE_RATES_SOURCE") do
"coin_gecko" -> Source.CoinGecko
"coin_market_cap" -> Source.CoinMarketCap
"mobula" -> Source.Mobula
_ -> Source.CoinGecko
end
end
@spec exchange_rates_secondary_coin_source() :: Source.CoinGecko | Source.CoinMarketCap | Source.Mobula
def exchange_rates_secondary_coin_source do
case System.get_env("EXCHANGE_RATES_SECONDARY_COIN_SOURCE") do
"coin_gecko" -> Source.CoinGecko
"coin_market_cap" -> Source.CoinMarketCap
"mobula" -> Source.Mobula
"cryptorank" -> Source.Cryptorank
_ -> Source.CoinGecko
end
end
@spec exchange_rates_market_cap_source() :: MarketCap.CoinGecko | MarketCap.CoinMarketCap | MarketCap.Mobula
def exchange_rates_market_cap_source do
case System.get_env("EXCHANGE_RATES_MARKET_CAP_SOURCE") do
"coin_gecko" -> MarketCap.CoinGecko
"coin_market_cap" -> MarketCap.CoinMarketCap
"mobula" -> MarketCap.Mobula
_ -> MarketCap.CoinGecko
end
end
@spec exchange_rates_tvl_source() :: TVL.DefiLlama
def exchange_rates_tvl_source do
case System.get_env("EXCHANGE_RATES_TVL_SOURCE") do
"defillama" -> TVL.DefiLlama
_ -> TVL.DefiLlama
end
end
@spec exchange_rates_price_source() :: Price.CoinGecko | Price.CoinMarketCap | Price.CryptoCompare | Price.Mobula
def exchange_rates_price_source do
case System.get_env("EXCHANGE_RATES_PRICE_SOURCE") do
"coin_gecko" -> Price.CoinGecko
"coin_market_cap" -> Price.CoinMarketCap
"crypto_compare" -> Price.CryptoCompare
"mobula" -> Price.Mobula
"cryptorank" -> Source.Cryptorank
_ -> Price.CryptoCompare
end
end
@spec exchange_rates_secondary_coin_price_source() ::
Price.CoinGecko | Price.CoinMarketCap | Price.CryptoCompare | Price.Mobula
def exchange_rates_secondary_coin_price_source do
cmc_secondary_coin_id = System.get_env("EXCHANGE_RATES_COINMARKETCAP_SECONDARY_COIN_ID")
cg_secondary_coin_id = System.get_env("EXCHANGE_RATES_COINGECKO_SECONDARY_COIN_ID")
cc_secondary_coin_symbol = System.get_env("EXCHANGE_RATES_CRYPTOCOMPARE_SECONDARY_COIN_SYMBOL")
mobula_secondary_coin_id = System.get_env("EXCHANGE_RATES_MOBULA_SECONDARY_COIN_ID")
cryptorank_secondary_coin_id = System.get_env("EXCHANGE_RATES_CRYPTORANK_SECONDARY_COIN_ID")
cond do
cg_secondary_coin_id && cg_secondary_coin_id !== "" -> Price.CoinGecko
cmc_secondary_coin_id && cmc_secondary_coin_id !== "" -> Price.CoinMarketCap
cc_secondary_coin_symbol && cc_secondary_coin_symbol !== "" -> Price.CryptoCompare
mobula_secondary_coin_id && mobula_secondary_coin_id !== "" -> Price.Mobula
cryptorank_secondary_coin_id && cryptorank_secondary_coin_id !== "" -> Source.Cryptorank
true -> Price.CryptoCompare
end
end
def token_exchange_rates_source do
case System.get_env("TOKEN_EXCHANGE_RATES_SOURCE") do
"cryptorank" -> Source.Cryptorank
_ -> Source.CoinGecko
end
end
def block_transformer do
block_transformers = %{
"clique" => Blocks.Clique,
"base" => Blocks.Base
}
# Compile time environment variable access requires recompilation.
configured_transformer = safe_get_env("BLOCK_TRANSFORMER", "base")
case Map.get(block_transformers, configured_transformer) do
nil ->
raise """
No such block transformer: #{configured_transformer}.
Valid values are:
#{Enum.join(Map.keys(block_transformers), "\n")}
Please update environment variable BLOCK_TRANSFORMER accordingly.
"""
transformer ->
transformer
end
end
@spec parse_json_env_var(String.t(), String.t()) :: any()
feat: support for `:celo` chain type (#10564) * feat: indexing of Celo transactions (#10275) * feat(json-rpc): support celo-specific fields in transactions * chore: add new chain type to matrix builder * feat: add celo-specific fields to transactions schema * chore: add "celo" to `cspell.json` * chore: fix formatting * refactor: improve naming for celo fields and ignore `ethCompatible` field * chore: add block fetcher test for celo fields * feat: add celo core contract abis * feat: add a cache for core celo contracts * feat: treat celo native token transfers as token transfers * fix: update `cspell.json` with celo words * fix(dialyzer): pattern can never match the type * fix: update `cspell.json` with celo words * feat: move `CELO_NETWORK` env to config * feat: parse native Celo token transfers from internal transactions * feat: add token balances fetching * refactor: remove `dbg` and organize code better * fix: start TokenBalance fetcher * fix: start token balance fetcher * fix: typo in log message * fix: missing fields in celo transaction token transfer * refactor: remove `AbiHandler` in favour of hardcoded pieces of abi * refactor: native token transfers from internal transactions fether * feat: implement parsing of token transfers for traceable rpc node * feat: fetch address coin balances after erc20 celo token transfers * feat: add `gas_token` to transaction response in api v2 * feat: index tokens specified as `feeCurrency` * chore: fix credo warnings * chore: decrease log level to debug * chore: fix cspell warnings * refactor: apply suggestions * fix: handle case when `gas_token` is not loaded * dbg * chore: expect contract calls in celo fetcher test * fix: compile errors for celo view on default chain type * chore: remove unused import * refactor: move `celo_gas_tokens` to chain type imports * refactor: apply suggestions * fix: swap arguments in `put_if_present` * fix: indexer tests * refactor: always include `gas_token` to the response * feat: add `gas_token` to all transaction-related endpoints * feat: celo core contracts with historical data * fix: `uncles` field is expected but not present in RPC node response * fix: credo & format * fix: define `CELO_CORE_CONTRACTS` in tests * fix: put `gas_token` under `celo` section * refactor: move token transfers filtering from `TokenTotalSupplyUpdater` to `Transform.TokenTransfers` * feat: add workflow to publish docker image * refactor: apply suggestions by @nikitosing * chore: add docs and specs * fix: malformed import * fix: publish image for celo * fix: ci build for celo * feat: index celo epoch transactions (#9944) * feat(json-rpc): support celo-specific fields in transactions * chore: add new chain type to matrix builder * feat: add celo-specific fields to transactions schema * chore: add "celo" to `cspell.json` * chore: fix formatting * refactor: improve naming for celo fields and ignore `ethCompatible` field * chore: add block fetcher test for celo fields * feat: add celo core contract abis * feat: add a cache for core celo contracts * feat: treat celo native token transfers as token transfers * fix: update `cspell.json` with celo words * fix(dialyzer): pattern can never match the type * fix: update `cspell.json` with celo words * feat: move `CELO_NETWORK` env to config * feat: parse native Celo token transfers from internal transactions * feat: add token balances fetching * refactor: remove `dbg` and organize code better * fix: start TokenBalance fetcher * fix: start token balance fetcher * fix: typo in log message * fix: missing fields in celo transaction token transfer * refactor: remove `AbiHandler` in favour of hardcoded pieces of abi * refactor: native token transfers from internal transactions fether * feat: implement parsing of token transfers for traceable rpc node * feat: fetch address coin balances after erc20 celo token transfers * feat: add `gas_token` to transaction response in api v2 * feat: index tokens specified as `feeCurrency` * chore: fix credo warnings * chore: decrease log level to debug * chore: fix cspell warnings * refactor: apply suggestions * fix: handle case when `gas_token` is not loaded * dbg * chore: expect contract calls in celo fetcher test * fix: compile errors for celo view on default chain type * chore: remove unused import * refactor: move `celo_gas_tokens` to chain type imports * refactor: apply suggestions * fix: swap arguments in `put_if_present` * fix: indexer tests * refactor: always include `gas_token` to the response * feat: add `gas_token` to all transaction-related endpoints * feat: celo core contracts with historical data * fix: `uncles` field is expected but not present in RPC node response * fix: credo & format * fix: define `CELO_CORE_CONTRACTS` in tests * fix: put `gas_token` under `celo` section * refactor: move token transfers filtering from `TokenTotalSupplyUpdater` to `Transform.TokenTransfers` * feat: add workflow to publish docker image * refactor: apply suggestions by @nikitosing * chore: add docs and specs * fix: malformed import * feat: add pending epoch operations table * refactor: fix format * feat: add transformers for epoch events * feat: add query to stream pending epoch block operations * fix: call to renamed function * fix: add factory method for pending epoch block operation * feat: add utils for logs parsing * feat: add schemas for epoch rewards and election rewards * fix: rename transformer according to event name * feat: implement epoch rewards fetcher * feat: fetch and import epoch logs * feat: improve epoch rewards fetcher 1. Do not fetch logs -- use the ones stored in DB 2. Import epochs to the database 3. Configure fetcher in runtime.exs * feat: add epoch helper functions * activated_validator_group_vote.ex * feat: add task to fetch core contracts * feat: fetch core contract events in the task * fix: merge artifacts * refactor: logs requests and reduce scope of epoch logs request * chore: fix formatting, credo warning, etc. * feat: fetch epoch rewards in one sql query * feat: fetch validator group votes (historical data and on demand) * refactor: rename fields and replace all entries on conflict * feat: validator group votes fetcher * fix: put each topic in a separate request * feat: fetch voter rewards * refactor: split epoch fetcher to multiple modules * feat: send epoch blocks for async fetching from block fetcher * chore: fix credo and formatting issues * fix: dialyzer warnings * fix: add on demand fetch of group votes * fix: failed explorer and indexer tests * fix: block fetcher tests * fix: match error in epoch logs * feat: add env to manage logs batch size when fetching validator group votes * fix: Add `ssl_opts` for Celo repo * fix: add `disabled?` predicate to supervisor config * fix: return empty list when `getPaymentDelegation` is not available * fix: validate the case when there is no voter rewards for an epoch * fix: formatting * fix: import `put_if_present/3` * fix: do not treat genesis block as an epoch block * fix: some of the fetcher tests * dbg * chore: remove commented code * chore: canonical disable flag env name * fix: run test only for celo chain type * fix: add explicit `wait_ for_tasks` in token instance realtime test * fix: set missing `CELO_CORE_CONTRACTS` env * fix: rollback token instance realtime test * chore: remove debug artifact * chore: add docs for new tables * perf: remove unused fields from `celo_validator_group_votes` table * fix: add on_exit clause * refactor: use `remove/3` function for migration rollback possibility * refactor: extract celo core contracts environment variable setup into a separate function * chore: add new vars to `common-blockscout.env` file * chore: add specs and docs for new modules and functions * refactor: eliminate unused import warnings * fix: credo warning * feat: API for celo epoch rewards and fees breakdown (#10308) * feat(json-rpc): support celo-specific fields in transactions * chore: add new chain type to matrix builder * feat: add celo-specific fields to transactions schema * chore: add "celo" to `cspell.json` * chore: fix formatting * refactor: improve naming for celo fields and ignore `ethCompatible` field * chore: add block fetcher test for celo fields * feat: add celo core contract abis * feat: add a cache for core celo contracts * feat: treat celo native token transfers as token transfers * fix: update `cspell.json` with celo words * fix(dialyzer): pattern can never match the type * fix: update `cspell.json` with celo words * feat: move `CELO_NETWORK` env to config * feat: parse native Celo token transfers from internal transactions * feat: add token balances fetching * refactor: remove `dbg` and organize code better * fix: start TokenBalance fetcher * fix: start token balance fetcher * fix: typo in log message * fix: missing fields in celo transaction token transfer * refactor: remove `AbiHandler` in favour of hardcoded pieces of abi * refactor: native token transfers from internal transactions fether * feat: implement parsing of token transfers for traceable rpc node * feat: fetch address coin balances after erc20 celo token transfers * feat: add `gas_token` to transaction response in api v2 * feat: index tokens specified as `feeCurrency` * chore: fix credo warnings * chore: decrease log level to debug * chore: fix cspell warnings * refactor: apply suggestions * fix: handle case when `gas_token` is not loaded * dbg * chore: expect contract calls in celo fetcher test * fix: compile errors for celo view on default chain type * chore: remove unused import * refactor: move `celo_gas_tokens` to chain type imports * refactor: apply suggestions * fix: swap arguments in `put_if_present` * fix: indexer tests * feat: add pending epoch operations table * feat: add several celo core contracts * refactor: fix format * feat: add new core contract default addresses * feat: add transformers for epoch events * feat: add query to stream pending epoch block operations * fix: call to renamed function * fix: add factory method for pending epoch block operation * feat: add utils for logs parsing * feat: add schemas for epoch rewards and election rewards * fix: rename transformer according to event name * feat: implement epoch rewards fetcher * feat: fetch and import epoch logs * feat: improve epoch rewards fetcher 1. Do not fetch logs -- use the ones stored in DB 2. Import epochs to the database 3. Configure fetcher in runtime.exs * fix: remove duplicated module attribute * feat: add epoch helper functions * activated_validator_group_vote.ex * feat: tmp * refactor: always include `gas_token` to the response * feat: add `gas_token` to all transaction-related endpoints * feat: celo core contracts with historical data * fix: `uncles` field is expected but not present in RPC node response * fix: credo & format * fix: define `CELO_CORE_CONTRACTS` in tests * fix: put `gas_token` under `celo` section * refactor: move token transfers filtering from `TokenTotalSupplyUpdater` to `Transform.TokenTransfers` * feat: add workflow to publish docker image * refactor: apply suggestions by @nikitosing * chore: add docs and specs * fix: malformed import * feat: add pending epoch operations table * refactor: fix format * feat: add transformers for epoch events * feat: add query to stream pending epoch block operations * fix: call to renamed function * fix: add factory method for pending epoch block operation * feat: add utils for logs parsing * feat: add schemas for epoch rewards and election rewards * fix: rename transformer according to event name * feat: implement epoch rewards fetcher * feat: fetch and import epoch logs * feat: improve epoch rewards fetcher 1. Do not fetch logs -- use the ones stored in DB 2. Import epochs to the database 3. Configure fetcher in runtime.exs * feat: add epoch helper functions * activated_validator_group_vote.ex * feat: add task to fetch core contracts * feat: fetch core contract events in the task * fix: merge artifacts * refactor: logs requests and reduce scope of epoch logs request * chore: fix formatting, credo warning, etc. * feat: fetch epoch rewards in one sql query * feat: fetch validator group votes (historical data and on demand) * refactor: rename fields and replace all entries on conflict * feat: validator group votes fetcher * fix: put each topic in a separate request * feat: fetch voter rewards * fix: merge artifacts * feat: add epoch rewards in block api response * fix: merge artifacts * feat: add base fee breakdown in block api response * feat: add aggregated election rewards to block api response * perf: use replica when querying epoch rewards * feat: endpoint for paginated election rewards * feat: endpoint for paginated election rewards for address * chore: rename `rewards` to `distributions` * fix: add missing reward type to API error message * refactor: split epoch fetcher to multiple modules * feat: send epoch blocks for async fetching from block fetcher * chore: fix credo and formatting issues * fix: dialyzer warnings * fix: add on demand fetch of group votes * fix: failed explorer and indexer tests * fix: block fetcher tests * chore: remove unused module * fix: sort election rewards by block number * fix: match error in epoch logs * feat: add env to manage logs batch size when fetching validator group votes * fix: credo and formatting warnings * fix: cspell errors * fix: dialyzer errors * fix: Add `ssl_opts` for Celo repo * fix: add missing preloads and make more explicit api response for block * fix: add `disabled?` predicate to supervisor config * fix: return empty list when `getPaymentDelegation` is not available * fix: validate the case when there is no voter rewards for an epoch * fix: formatting * fix: add missing preload * refactor: more robust fees breakdown logic for the case of fee handler * fix: formatting * refactor: move epoch information to the separate endpoint * fix: import `put_if_present/3` * fix: formatting * fix: do not treat genesis block as an epoch block * fix: some of the fetcher tests * dbg * chore: remove commented code * chore: canonical disable flag env name * fix: run test only for celo chain type * fix: add explicit `wait_ for_tasks` in token instance realtime test * fix: set missing `CELO_CORE_CONTRACTS` env * fix: rollback token instance realtime test * chore: remove debug artifact * chore: add `@docs` and `@specs` * fix: missing core contracts var in tests * feat: extend `tabs-counters` endpoint with election rewards count * refactor: move dead address to `Explorer.Chain.SmartContract` * perf: clause with simplified queries in the case of `amount == 0` and/or `block_number == 0` * fix: it comes that `NotLoaded` clause is not redundant actually... * fix: add missing preload in `BlockScoutWeb.AddressChannel` * chore: unset `CELO_CORE_CONTRACTS` in tests * chore: add missing specs * fix: `paginate` clause when `amount == 0` * refactor: move `paging_options/2` to `Explorer.Chain.Celo.ElectionReward` * refactor: avoid using virtual field for block number. * fix: remove redundant condition in the query * chore: clarify `@spec` * chore: fix credo warning * chore: remove `fi-celo` from branches that trigger ci * fix: merge artifacts * fix: remove todo comment
4 months ago
def parse_json_env_var(env_var, default_value \\ "{}") do
env_var
|> safe_get_env(default_value)
|> Jason.decode!()
rescue
err -> raise "Invalid JSON in environment variable #{env_var}: #{inspect(err)}"
end
@spec parse_list_env_var(String.t(), String.t() | nil) :: list()
def parse_list_env_var(env_var, default_value \\ nil) do
addresses_var = safe_get_env(env_var, default_value)
if addresses_var !== "" do
addresses_list = (addresses_var && String.split(addresses_var, ",")) || []
formatted_addresses_list =
addresses_list
|> Enum.map(fn addr ->
String.downcase(addr)
end)
formatted_addresses_list
else
[]
end
end
@supported_chain_types [
"default",
"arbitrum",
"blackfort",
"celo",
"ethereum",
"filecoin",
"optimism",
"polygon_edge",
"polygon_zkevm",
"rsk",
feat: Scroll rollup: L1 fee parameters in API, `queueIndex` for L2 transactions, and L1 <->L2 messages (#10484) * Add chain type for scroll and l1_fee tx field * l1_fee_scalar and l1_fee_overhead fields in api json output for tx * l2_fee field in api json output for tx * l1_gas_used field in api json output for tx * l1_fee_commit_scalar, l1_fee_blob_scalar, l1_base_fee, l1_blob_base_fee fields in api json output for tx * Partially add specs and docs * Add code specs and docs for Indexer.Fetcher.Scroll.L1FeeParam * Add code specs and docs * Small fix * Add CI matrix chain type * Fix spelling * Rename envs * Update common-blockscout.env * Small fixes * Improve scroll_view.ex * Update scroll_view.ex * Add support of queueIndex field for L1MessageTx in Scroll * Fix for mix credo * Add scroll_bridge db table * Add Scroll bridge messages indexing * Add Indexer.Transform.Scroll.Bridge * Refactoring * Add API for Scroll * Ignore credo warning about nesting level * Add specs and docs * Refactoring * Partially cover review comments * Add some specs and docs * Add GA workflows for scroll * Small refactoring * Add to_import for Explorer.Chain.Scroll.Bridge * Small refactoring * Add specs and docs * Add comments * Add Explorer.Chain.RollupReorgMonitorQueue module * Add sobelow_skip * Add INDEXER_SCROLL_ETH_GET_LOGS_RANGE_SIZE env variable * Update common-blockscout.env * Small refactoring * Add links about Curie upgrade * Small improvement * Small refactoring * Separate db query * Move chain type specific import runners from BlockReferencing to ChainTypeSpecific stage * Add draft indexer for Scroll batches * Add API for Scroll batches * Extend API for Scroll batches * Refactoring * Update common-blockscout.env * Add specs and docs * Remove misprint * Fixes * Small improvement * Refactoring * Refactoring * Refactoring * Refactoring for credo * Partially cover review comments * Add l2_block_status to transaction view for Scroll * RollupL1ReorgMonitor refactoring * Extend docs * Small refactoring of last_l2_block_number function * Extend docs * Extend docs * Fix typo * mix format * Extend docs * Extend docs * Separate eth_getLogs block range size config * Small refactoring * Add comment * Add comments * Optimization * Small optimization * Use Ecto.Multi * Extend docs * Change API response for Scroll batches * Change API response format for Scroll bridge messages * Small refactoring * Update apps/indexer/lib/indexer/transform/scroll/l1_fee_params.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/l1_fee_param.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/l1_fee_param.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/l1_fee_param.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/reader.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/reader.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/batch.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/batch_bundle.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/bridge.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/batch.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/batch.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/batch.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/fetcher/scroll/batch.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Small refactoring * Extend docs * Update apps/explorer/lib/explorer/chain/scroll/reader.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/indexer/lib/indexer/helper.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/reader.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Update apps/explorer/lib/explorer/chain/scroll/reader.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * Improve specs * Update apps/explorer/lib/explorer/chain/scroll/reader.ex Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com> * fix * mix format * Add DA container info for Scroll batches * Fallback INDEXER_SCROLL_L2_MESSENGER_START_BLOCK to FIRST_BLOCK * mix format * Remove redundant lines * Use multi update_all * rename "tx" shorthands --------- Co-authored-by: POA <33550681+poa@users.noreply.github.com> Co-authored-by: Viktor Baranov <baranov.viktor.27@gmail.com> Co-authored-by: Alexander Kolotov <alexandr.kolotov@gmail.com>
1 month ago
"scroll",
"shibarium",
"stability",
"suave",
"zetachain",
"zilliqa",
"zksync"
]
@spec chain_type() :: atom() | nil
def chain_type, do: parse_catalog_value("CHAIN_TYPE", @supported_chain_types, true, "default")
@supported_modes ["all", "indexer", "api"]
@spec mode :: atom()
def mode, do: parse_catalog_value("APPLICATION_MODE", @supported_modes, true, "all")
@spec eth_call_url(String.t() | nil) :: String.t() | nil
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
@doc """
Parses and validates a microservice URL from an environment variable, removing any trailing slash.
## Parameters
- `env_name`: The name of the environment variable containing the URL
## Returns
- The validated URL string with any trailing slash removed
- `nil` if the URL is invalid or missing required components
"""
@spec parse_microservice_url(String.t()) :: String.t() | nil
def parse_microservice_url(env_name) do
url = System.get_env(env_name)
cond do
not valid_url?(url) ->
nil
String.ends_with?(url, "/") ->
url
|> String.slice(0..(String.length(url) - 2))
true ->
url
end
end
# Validates if the given string is a valid URL by checking if it has both scheme (like http,
# https, ftp) and host components.
@spec valid_url?(String.t()) :: boolean()
defp valid_url?(string) when is_binary(string) do
uri = URI.parse(string)
!is_nil(uri.scheme) && !is_nil(uri.host)
end
defp valid_url?(_), do: false
end