feat: Add feature toggle for WETH filtering (#10208)

* feat: Add feature toggle for WETH filtering

* Add new envs to docker-compose/envs/common-blockscout.env

* Fix tests
pull/10216/head
nikitosing 6 months ago committed by GitHub
parent a8e2e127b5
commit eddaeadc05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .github/workflows/config.yml
  2. 15
      apps/explorer/lib/explorer/chain/token_transfer.ex
  3. 24
      apps/explorer/lib/explorer/migrator/sanitize_incorrect_weth_token_transfers.ex
  4. 3
      config/runtime.exs
  5. 4
      docker-compose/envs/common-blockscout.env

@ -581,6 +581,7 @@ jobs:
ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Nethermind.Mox" ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Nethermind.Mox"
ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox" ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox"
CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }} CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }}
WETH_TOKEN_TRANSFERS_FILTERING_ENABLED: "true"
test_nethermind_mox_indexer: test_nethermind_mox_indexer:
strategy: strategy:
fail-fast: false fail-fast: false
@ -647,6 +648,7 @@ jobs:
ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Nethermind.Mox" ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Nethermind.Mox"
ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox" ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox"
CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }} CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }}
WETH_TOKEN_TRANSFERS_FILTERING_ENABLED: "true"
test_nethermind_mox_block_scout_web: test_nethermind_mox_block_scout_web:
strategy: strategy:
fail-fast: false fail-fast: false
@ -747,3 +749,4 @@ jobs:
ACCOUNT_REDIS_URL: "redis://localhost:6379" ACCOUNT_REDIS_URL: "redis://localhost:6379"
SOURCIFY_INTEGRATION_ENABLED: "true" SOURCIFY_INTEGRATION_ENABLED: "true"
CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }} CHAIN_TYPE: ${{ matrix.chain-type != 'default' && matrix.chain-type || '' }}
WETH_TOKEN_TRANSFERS_FILTERING_ENABLED: "true"

@ -534,10 +534,13 @@ defmodule Explorer.Chain.TokenTransfer do
WHITELISTED_WETH_CONTRACTS env is the list of whitelisted WETH contracts addresses. WHITELISTED_WETH_CONTRACTS env is the list of whitelisted WETH contracts addresses.
""" """
@spec whitelisted_weth_contract?(any()) :: boolean() @spec whitelisted_weth_contract?(any()) :: boolean()
def whitelisted_weth_contract?(contract_address_hash), def whitelisted_weth_contract?(contract_address_hash) do
do: env = Application.get_env(:explorer, Explorer.Chain.TokenTransfer)
(contract_address_hash |> to_string() |> String.downcase()) in Application.get_env(
:explorer, if env[:weth_token_transfers_filtering_enabled] do
Explorer.Chain.TokenTransfer (contract_address_hash |> to_string() |> String.downcase()) in env[:whitelisted_weth_contracts]
)[:whitelisted_weth_contracts] else
true
end
end
end end

@ -31,25 +31,37 @@ defmodule Explorer.Migrator.SanitizeIncorrectWETHTokenTransfers do
_ -> _ ->
MigrationStatus.set_status(@migration_name, "started") MigrationStatus.set_status(@migration_name, "started")
schedule_batch_migration() schedule_batch_migration()
{:ok, %{step: :delete_not_whitelisted_weth_transfers}} {:ok, %{step: :delete_duplicates}}
end end
end end
@impl true @impl true
def handle_info(:migrate_batch, %{step: step} = state) do 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 last_unprocessed_identifiers(step) do
[] -> [] ->
case step do case step do
:delete_not_whitelisted_weth_transfers -> :delete_duplicates ->
Logger.info( 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() 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") MigrationStatus.set_status(@migration_name, "completed")
{:stop, :normal, state} {:stop, :normal, state}
end end

@ -584,7 +584,8 @@ config :explorer, Explorer.Utility.MissingBalanceOfToken,
window_size: ConfigHelper.parse_integer_env_var("MISSING_BALANCE_OF_TOKENS_WINDOW_SIZE", 100) window_size: ConfigHelper.parse_integer_env_var("MISSING_BALANCE_OF_TOKENS_WINDOW_SIZE", 100)
config :explorer, Explorer.Chain.TokenTransfer, 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 ### ### Indexer ###

@ -379,3 +379,7 @@ TENDERLY_CHAIN_PATH=
# MUD_INDEXER_ENABLED= # MUD_INDEXER_ENABLED=
# MUD_DATABASE_URL= # MUD_DATABASE_URL=
# MUD_POOL_SIZE=50 # MUD_POOL_SIZE=50
# WETH_TOKEN_TRANSFERS_FILTERING_ENABLED=false
# WHITELISTED_WETH_CONTRACTS=
# SANITIZE_INCORRECT_WETH_BATCH_SIZE=100
# SANITIZE_INCORRECT_WETH_CONCURRENCY=1
Loading…
Cancel
Save