From cc4bbe2d4cf998617ad09d610037ebbd17edefe0 Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Tue, 9 May 2023 16:14:32 +0300 Subject: [PATCH] Define batch size for token balance fetcher via runtime env var --- CHANGELOG.md | 2 ++ .../lib/indexer/fetcher/token_balance.ex | 18 +++++++++++------- config/runtime.exs | 3 +++ docker-compose/envs/common-blockscout.env | 1 + docker/Makefile | 4 ++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eeac08074..14800b0551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- [#7439](https://github.com/blockscout/blockscout/pull/7439) - Define batch size for token balance fetcher via runtime env var - [#7298](https://github.com/blockscout/blockscout/pull/7298) - Add changes to support force email verification - [#7416](https://github.com/blockscout/blockscout/pull/7416) - Add option to disable reCAPTCHA - [#6694](https://github.com/blockscout/blockscout/pull/6694) - Add withdrawals support (EIP-4895) @@ -12,6 +13,7 @@ - [#7436](https://github.com/blockscout/blockscout/pull/7436) - TokenBalanceOnDemand ERC-1155 support ### Fixes + - [#7391](https://github.com/blockscout/blockscout/pull/7391) - Fix: cannot read properties of null (reading 'value') - [#7377](https://github.com/blockscout/blockscout/pull/7377) - API v2 improvements diff --git a/apps/indexer/lib/indexer/fetcher/token_balance.ex b/apps/indexer/lib/indexer/fetcher/token_balance.ex index e81ab0b20f..bd0f3e1302 100644 --- a/apps/indexer/lib/indexer/fetcher/token_balance.ex +++ b/apps/indexer/lib/indexer/fetcher/token_balance.ex @@ -24,12 +24,7 @@ defmodule Indexer.Fetcher.TokenBalance do @behaviour BufferedTask - @defaults [ - flush_interval: 300, - max_batch_size: 100, - max_concurrency: 10, - task_supervisor: Indexer.Fetcher.TokenBalance.TaskSupervisor - ] + @default_max_batch_size 100 @max_retries 3 @@ -50,7 +45,7 @@ defmodule Indexer.Fetcher.TokenBalance do end merged_init_opts = - @defaults + defaults() |> Keyword.merge(mergeable_init_options) |> Keyword.put(:state, state) @@ -217,4 +212,13 @@ defmodule Indexer.Fetcher.TokenBalance do token_id: token_id } end + + defp defaults do + [ + flush_interval: 300, + max_batch_size: Application.get_env(:indexer, __MODULE__)[:batch_size] || @default_max_batch_size, + max_concurrency: 10, + task_supervisor: Indexer.Fetcher.TokenBalance.TaskSupervisor + ] + end end diff --git a/config/runtime.exs b/config/runtime.exs index b949b4b410..744a8f21d7 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -427,6 +427,9 @@ config :indexer, Indexer.Fetcher.PendingTransaction.Supervisor, System.get_env("ETHEREUM_JSONRPC_VARIANT") == "besu" || ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER") +config :indexer, Indexer.Fetcher.TokenBalance, + batch_size: ConfigHelper.parse_integer_env_var("INDEXER_TOKEN_BALANCES_BATCH_SIZE", 100) + config :indexer, Indexer.Fetcher.TokenBalanceOnDemand, threshold: ConfigHelper.parse_time_env_var("TOKEN_BALANCE_ON_DEMAND_FETCHER_THRESHOLD", "1h"), fallback_threshold_in_blocks: 500 diff --git a/docker-compose/envs/common-blockscout.env b/docker-compose/envs/common-blockscout.env index eeba9bbf77..8ae691f040 100644 --- a/docker-compose/envs/common-blockscout.env +++ b/docker-compose/envs/common-blockscout.env @@ -110,6 +110,7 @@ INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false # INDEXER_COIN_BALANCES_CONCURRENCY= # INDEXER_RECEIPTS_BATCH_SIZE= # INDEXER_RECEIPTS_CONCURRENCY= +# INDEXER_TOKEN_BALANCES_BATCH_SIZE= # INDEXER_TX_ACTIONS_ENABLE= # INDEXER_TX_ACTIONS_MAX_TOKEN_CACHE_SIZE= # INDEXER_TX_ACTIONS_REINDEX_FIRST_BLOCK= diff --git a/docker/Makefile b/docker/Makefile index 2b1826af45..b387955076 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -552,11 +552,15 @@ endif ifdef INDEXER_EMPTY_BLOCKS_SANITIZER_BATCH_SIZE BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_EMPTY_BLOCKS_SANITIZER_BATCH_SIZE=$(INDEXER_EMPTY_BLOCKS_SANITIZER_BATCH_SIZE)' endif +ifdef INDEXER_TOKEN_BALANCES_BATCH_SIZE + BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_TOKEN_BALANCES_BATCH_SIZE=$(INDEXER_TOKEN_BALANCES_BATCH_SIZE)' +endif ifdef INDEXER_REALTIME_FETCHER_MAX_GAP BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_REALTIME_FETCHER_MAX_GAP=$(INDEXER_REALTIME_FETCHER_MAX_GAP)' endif ifdef INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE=$(INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE)' +endif ifdef INDEXER_DISABLE_WITHDRAWALS_FETCHER BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_DISABLE_WITHDRAWALS_FETCHER=$(INDEXER_DISABLE_WITHDRAWALS_FETCHER)' endif