From 6b5a353317cf406ad40c4a112e49f1d0a6c3aebc Mon Sep 17 00:00:00 2001 From: POA <33550681+poa@users.noreply.github.com> Date: Mon, 8 May 2023 15:57:10 +0300 Subject: [PATCH] Add INDEXER_ZKEVM_BATCHES_ENABLED env var --- .../lib/indexer/fetcher/zkevm_txn_batch.ex | 38 ++++++++++++------- apps/indexer/lib/indexer/supervisor.ex | 5 ++- config/runtime.exs | 3 ++ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex b/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex index d85f2bbd6f..272edc83bb 100644 --- a/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex +++ b/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex @@ -38,9 +38,6 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do Logger.metadata(fetcher: :zkevm_txn_batches) # Logger.configure(truncate: :infinity) - # todo - # enabled = Application.get_all_env(:indexer)[Indexer.Fetcher.ZkevmTxnBatch][:enabled] - Process.send(self(), :continue, []) {:ok, @@ -62,10 +59,12 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do prev_verified_batch_number: prev_verified_batch_number } = state ) do - {latest_batch_number, virtual_batch_number, verified_batch_number} = fetch_latest_batch_numbers(json_rpc_named_arguments) + {latest_batch_number, virtual_batch_number, verified_batch_number} = + fetch_latest_batch_numbers(json_rpc_named_arguments) - {new_state, handle_duration} = - if latest_batch_number > prev_latest_batch_number or virtual_batch_number > prev_virtual_batch_number or verified_batch_number > prev_verified_batch_number do + {new_state, handle_duration} = + if latest_batch_number > prev_latest_batch_number or virtual_batch_number > prev_virtual_batch_number or + verified_batch_number > prev_verified_batch_number do start_batch_number = get_last_verified_batch_number() + 1 end_batch_number = latest_batch_number @@ -78,24 +77,32 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do log_message = if virtual_batch_number > prev_virtual_batch_number do - log_message <> "Found a new virtual batch number #{virtual_batch_number}. Previous virtual batch number is #{prev_virtual_batch_number}. " + log_message <> + "Found a new virtual batch number #{virtual_batch_number}. Previous virtual batch number is #{prev_virtual_batch_number}. " else log_message end log_message = if verified_batch_number > prev_verified_batch_number do - log_message <> "Found a new verified batch number #{verified_batch_number}. Previous verified batch number is #{prev_verified_batch_number}. " + log_message <> + "Found a new verified batch number #{verified_batch_number}. Previous verified batch number is #{prev_verified_batch_number}. " else log_message end Logger.info(log_message <> "Handling the batch range #{start_batch_number}..#{end_batch_number}.") - {handle_duration, _} = :timer.tc(fn -> handle_batch_range(start_batch_number, end_batch_number, json_rpc_named_arguments) end) + {handle_duration, _} = + :timer.tc(fn -> handle_batch_range(start_batch_number, end_batch_number, json_rpc_named_arguments) end) { - %{state | prev_latest_batch_number: latest_batch_number, prev_virtual_batch_number: virtual_batch_number, prev_verified_batch_number: verified_batch_number}, + %{ + state + | prev_latest_batch_number: latest_batch_number, + prev_virtual_batch_number: virtual_batch_number, + prev_verified_batch_number: verified_batch_number + }, div(handle_duration, 1000) } else @@ -319,9 +326,14 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do {:ok, responses} = repeated_call(&json_rpc/2, [requests, json_rpc_named_arguments], error_message, 3) - latest_batch_number = Enum.find_value(responses, fn resp -> if resp.id == 0, do: quantity_to_integer(resp.result) end) - virtual_batch_number = Enum.find_value(responses, fn resp -> if resp.id == 1, do: quantity_to_integer(resp.result) end) - verified_batch_number = Enum.find_value(responses, fn resp -> if resp.id == 2, do: quantity_to_integer(resp.result) end) + latest_batch_number = + Enum.find_value(responses, fn resp -> if resp.id == 0, do: quantity_to_integer(resp.result) end) + + virtual_batch_number = + Enum.find_value(responses, fn resp -> if resp.id == 1, do: quantity_to_integer(resp.result) end) + + verified_batch_number = + Enum.find_value(responses, fn resp -> if resp.id == 2, do: quantity_to_integer(resp.result) end) {latest_batch_number, virtual_batch_number, verified_batch_number} end diff --git a/apps/indexer/lib/indexer/supervisor.ex b/apps/indexer/lib/indexer/supervisor.ex index 14ae27a23c..ea63101473 100644 --- a/apps/indexer/lib/indexer/supervisor.ex +++ b/apps/indexer/lib/indexer/supervisor.ex @@ -133,8 +133,9 @@ defmodule Indexer.Supervisor do {Indexer.Fetcher.PolygonEdge.Withdrawal.Supervisor, [[memory_monitor: memory_monitor, json_rpc_named_arguments: json_rpc_named_arguments]]}, {Indexer.Fetcher.PolygonEdge.WithdrawalExit.Supervisor, [[memory_monitor: memory_monitor]]}, - {ZkevmTxnBatch.Supervisor, - [[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]]}, + configure(ZkevmTxnBatch.Supervisor, [ + [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor] + ]), # Out-of-band fetchers {EmptyBlocksSanitizer.Supervisor, [[json_rpc_named_arguments: json_rpc_named_arguments]]}, diff --git a/config/runtime.exs b/config/runtime.exs index 8af8e6f70f..fdc5fb80d2 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -613,6 +613,9 @@ config :indexer, Indexer.Fetcher.PolygonEdge.WithdrawalExit, start_block_l1: System.get_env("INDEXER_POLYGON_EDGE_L1_WITHDRAWALS_START_BLOCK"), exit_helper: System.get_env("INDEXER_POLYGON_EDGE_L1_EXIT_HELPER_CONTRACT") +config :indexer, Indexer.Fetcher.ZkevmTxnBatch.Supervisor, + enabled: ConfigHelper.parse_bool_env_var("INDEXER_ZKEVM_BATCHES_ENABLED") + Code.require_file("#{config_env()}.exs", "config/runtime") for config <- "../apps/*/config/runtime/#{config_env()}.exs" |> Path.expand(__DIR__) |> Path.wildcard() do