From be99681177866db9f8c2e1a3fbfa75ce7195d8a5 Mon Sep 17 00:00:00 2001 From: POA <33550681+poa@users.noreply.github.com> Date: Tue, 31 Jan 2023 20:46:01 +0300 Subject: [PATCH] Add INDEXER_TX_ACTIONS_ENABLE env variable --- apps/indexer/lib/indexer/supervisor.ex | 2 +- .../indexer/transform/transaction_actions.ex | 62 ++++++++++--------- config/runtime.exs | 3 + docker-compose/envs/common-blockscout.env | 1 + docker/Makefile | 3 + 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/apps/indexer/lib/indexer/supervisor.ex b/apps/indexer/lib/indexer/supervisor.ex index 1782b0dd86..cb95128cf9 100644 --- a/apps/indexer/lib/indexer/supervisor.ex +++ b/apps/indexer/lib/indexer/supervisor.ex @@ -121,7 +121,7 @@ defmodule Indexer.Supervisor do [ [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor] ]}, - {TransactionAction.Supervisor, [[memory_monitor: memory_monitor]]}, + configure(TransactionAction.Supervisor, [[memory_monitor: memory_monitor]]), {ContractCode.Supervisor, [[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]]}, {TokenBalance.Supervisor, diff --git a/apps/indexer/lib/indexer/transform/transaction_actions.ex b/apps/indexer/lib/indexer/transform/transaction_actions.ex index b1921b9507..0fd3678d7f 100644 --- a/apps/indexer/lib/indexer/transform/transaction_actions.ex +++ b/apps/indexer/lib/indexer/transform/transaction_actions.ex @@ -99,38 +99,42 @@ defmodule Indexer.Transform.TransactionActions do Returns a list of transaction actions given a list of logs. """ def parse(logs, protocols_to_rewrite \\ []) do - actions = [] + if Application.get_env(:indexer, Indexer.Fetcher.TransactionAction.Supervisor)[:enabled] do + actions = [] + + chain_id = NetVersion.get_version() + + logs + |> logs_group_by_txs() + |> clear_actions(protocols_to_rewrite) + + # create tokens cache if not exists + if :ets.whereis(:tx_actions_tokens_data_cache) == :undefined do + :ets.new(:tx_actions_tokens_data_cache, [ + :set, + :named_table, + :public, + read_concurrency: true, + write_concurrency: true + ]) + end - chain_id = NetVersion.get_version() + # handle uniswap v3 + tx_actions = + if Enum.member?([@mainnet, @goerli, @optimism, @polygon], chain_id) and + (Enum.empty?(protocols_to_rewrite) or Enum.member?(protocols_to_rewrite, "uniswap_v3")) do + logs + |> uniswap_filter_logs() + |> logs_group_by_txs() + |> uniswap(actions, chain_id) + else + actions + end - logs - |> logs_group_by_txs() - |> clear_actions(protocols_to_rewrite) - - # create tokens cache if not exists - if :ets.whereis(:tx_actions_tokens_data_cache) == :undefined do - :ets.new(:tx_actions_tokens_data_cache, [ - :set, - :named_table, - :public, - read_concurrency: true, - write_concurrency: true - ]) + %{transaction_actions: tx_actions} + else + %{transaction_actions: []} end - - # handle uniswap v3 - tx_actions = - if Enum.member?([@mainnet, @goerli, @optimism, @polygon], chain_id) and - (Enum.empty?(protocols_to_rewrite) or Enum.member?(protocols_to_rewrite, "uniswap_v3")) do - logs - |> uniswap_filter_logs() - |> logs_group_by_txs() - |> uniswap(actions, chain_id) - else - actions - end - - %{transaction_actions: tx_actions} end defp uniswap(logs_grouped, actions, chain_id) do diff --git a/config/runtime.exs b/config/runtime.exs index 33949be707..56bad9a9cb 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -432,6 +432,9 @@ config :indexer, trace_last_block: System.get_env("TRACE_LAST_BLOCK") || "", fetch_rewards_way: System.get_env("FETCH_REWARDS_WAY", "trace_block") +config :indexer, Indexer.Fetcher.TransactionAction.Supervisor, + enabled: System.get_env("INDEXER_TX_ACTIONS_ENABLE", "false") == "true" + config :indexer, Indexer.Fetcher.TransactionAction, reindex_first_block: System.get_env("INDEXER_TX_ACTIONS_REINDEX_FIRST_BLOCK"), reindex_last_block: System.get_env("INDEXER_TX_ACTIONS_REINDEX_LAST_BLOCK"), diff --git a/docker-compose/envs/common-blockscout.env b/docker-compose/envs/common-blockscout.env index 479c3e02e6..92de16b89e 100644 --- a/docker-compose/envs/common-blockscout.env +++ b/docker-compose/envs/common-blockscout.env @@ -90,6 +90,7 @@ INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false # INDEXER_COIN_BALANCES_CONCURRENCY= # INDEXER_RECEIPTS_BATCH_SIZE= # INDEXER_RECEIPTS_CONCURRENCY= +# INDEXER_TX_ACTIONS_ENABLE= # INDEXER_TX_ACTIONS_MAX_TOKEN_CACHE_SIZE= # INDEXER_TX_ACTIONS_REINDEX_FIRST_BLOCK= # INDEXER_TX_ACTIONS_REINDEX_LAST_BLOCK= diff --git a/docker/Makefile b/docker/Makefile index 8223d8630d..2d7ef55d13 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -487,6 +487,9 @@ endif ifdef TOKEN_ID_MIGRATION_BATCH_SIZE BLOCKSCOUT_CONTAINER_PARAMS += -e 'TOKEN_ID_MIGRATION_BATCH_SIZE=$(TOKEN_ID_MIGRATION_BATCH_SIZE)' endif +ifdef INDEXER_TX_ACTIONS_ENABLE + BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_TX_ACTIONS_ENABLE=$(INDEXER_TX_ACTIONS_ENABLE)' +endif ifdef INDEXER_TX_ACTIONS_MAX_TOKEN_CACHE_SIZE BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_TX_ACTIONS_MAX_TOKEN_CACHE_SIZE=$(INDEXER_TX_ACTIONS_MAX_TOKEN_CACHE_SIZE)' endif