diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 420c082704..bcf5b142e0 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -581,6 +581,7 @@ jobs: ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Nethermind.Mox" ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox" CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }} + WETH_TOKEN_TRANSFERS_FILTERING_ENABLED: "true" test_nethermind_mox_indexer: strategy: fail-fast: false @@ -647,6 +648,7 @@ jobs: ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Nethermind.Mox" ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox" CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }} + WETH_TOKEN_TRANSFERS_FILTERING_ENABLED: "true" test_nethermind_mox_block_scout_web: strategy: fail-fast: false @@ -747,3 +749,4 @@ jobs: ACCOUNT_REDIS_URL: "redis://localhost:6379" SOURCIFY_INTEGRATION_ENABLED: "true" CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }} + WETH_TOKEN_TRANSFERS_FILTERING_ENABLED: "true" diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index 69f309410d..12edc67d89 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -534,10 +534,13 @@ defmodule Explorer.Chain.TokenTransfer do WHITELISTED_WETH_CONTRACTS env is the list of whitelisted WETH contracts addresses. """ @spec whitelisted_weth_contract?(any()) :: boolean() - def whitelisted_weth_contract?(contract_address_hash), - do: - (contract_address_hash |> to_string() |> String.downcase()) in Application.get_env( - :explorer, - Explorer.Chain.TokenTransfer - )[:whitelisted_weth_contracts] + def whitelisted_weth_contract?(contract_address_hash) do + env = Application.get_env(:explorer, Explorer.Chain.TokenTransfer) + + if env[:weth_token_transfers_filtering_enabled] do + (contract_address_hash |> to_string() |> String.downcase()) in env[:whitelisted_weth_contracts] + else + true + end + end end diff --git a/apps/explorer/lib/explorer/migrator/sanitize_incorrect_weth_token_transfers.ex b/apps/explorer/lib/explorer/migrator/sanitize_incorrect_weth_token_transfers.ex index 5759f91336..038ce5fd6d 100644 --- a/apps/explorer/lib/explorer/migrator/sanitize_incorrect_weth_token_transfers.ex +++ b/apps/explorer/lib/explorer/migrator/sanitize_incorrect_weth_token_transfers.ex @@ -31,25 +31,37 @@ defmodule Explorer.Migrator.SanitizeIncorrectWETHTokenTransfers do _ -> MigrationStatus.set_status(@migration_name, "started") schedule_batch_migration() - {:ok, %{step: :delete_not_whitelisted_weth_transfers}} + {:ok, %{step: :delete_duplicates}} end end @impl true def handle_info(:migrate_batch, %{step: step} = state) do + if step == :delete_not_whitelisted_weth_transfers and + !Application.get_env(:explorer, Explorer.Chain.TokenTransfer)[:weth_token_transfers_filtering_enabled] do + {:stop, :normal, state} + else + process_batch(state) + end + end + + defp process_batch(%{step: step} = state) do case last_unprocessed_identifiers(step) do [] -> case step do - :delete_not_whitelisted_weth_transfers -> + :delete_duplicates -> Logger.info( - "SanitizeIncorrectWETHTokenTransfers deletion of not whitelisted weth transfers finished, continuing with duplicates deletion" + "SanitizeIncorrectWETHTokenTransfers deletion of duplicates finished, continuing with deletion of not whitelisted weth transfers" ) schedule_batch_migration() - {:noreply, %{step: :delete_duplicates}} + {:noreply, %{step: :delete_not_whitelisted_weth_transfers}} + + :delete_not_whitelisted_weth_transfers -> + Logger.info( + "SanitizeIncorrectWETHTokenTransfers deletion of not whitelisted weth transfers finished. Sanitizing is completed." + ) - :delete_duplicates -> - Logger.info("SanitizeIncorrectWETHTokenTransfers migration finished") MigrationStatus.set_status(@migration_name, "completed") {:stop, :normal, state} end diff --git a/config/runtime.exs b/config/runtime.exs index 833ed58e4e..cd2072166e 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -584,7 +584,8 @@ config :explorer, Explorer.Utility.MissingBalanceOfToken, window_size: ConfigHelper.parse_integer_env_var("MISSING_BALANCE_OF_TOKENS_WINDOW_SIZE", 100) config :explorer, Explorer.Chain.TokenTransfer, - whitelisted_weth_contracts: ConfigHelper.parse_list_env_var("WHITELISTED_WETH_CONTRACTS", "") + whitelisted_weth_contracts: ConfigHelper.parse_list_env_var("WHITELISTED_WETH_CONTRACTS", ""), + weth_token_transfers_filtering_enabled: ConfigHelper.parse_bool_env_var("WETH_TOKEN_TRANSFERS_FILTERING_ENABLED") ############### ### Indexer ### diff --git a/docker-compose/envs/common-blockscout.env b/docker-compose/envs/common-blockscout.env index 08a2e64ba0..1cc45e89d0 100644 --- a/docker-compose/envs/common-blockscout.env +++ b/docker-compose/envs/common-blockscout.env @@ -379,3 +379,7 @@ TENDERLY_CHAIN_PATH= # MUD_INDEXER_ENABLED= # MUD_DATABASE_URL= # MUD_POOL_SIZE=50 +# WETH_TOKEN_TRANSFERS_FILTERING_ENABLED=false +# WHITELISTED_WETH_CONTRACTS= +# SANITIZE_INCORRECT_WETH_BATCH_SIZE=100 +# SANITIZE_INCORRECT_WETH_CONCURRENCY=1 \ No newline at end of file