Add INDEXER_ZKEVM_BATCHES_ENABLED env var

pull/7584/head
POA 2 years ago
parent f3dd999aca
commit 6b5a353317
  1. 38
      apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex
  2. 5
      apps/indexer/lib/indexer/supervisor.ex
  3. 3
      config/runtime.exs

@ -38,9 +38,6 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
Logger.metadata(fetcher: :zkevm_txn_batches) Logger.metadata(fetcher: :zkevm_txn_batches)
# Logger.configure(truncate: :infinity) # Logger.configure(truncate: :infinity)
# todo
# enabled = Application.get_all_env(:indexer)[Indexer.Fetcher.ZkevmTxnBatch][:enabled]
Process.send(self(), :continue, []) Process.send(self(), :continue, [])
{:ok, {:ok,
@ -62,10 +59,12 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
prev_verified_batch_number: prev_verified_batch_number prev_verified_batch_number: prev_verified_batch_number
} = state } = state
) do ) 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} = {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 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 start_batch_number = get_last_verified_batch_number() + 1
end_batch_number = latest_batch_number end_batch_number = latest_batch_number
@ -78,24 +77,32 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
log_message = log_message =
if virtual_batch_number > prev_virtual_batch_number do 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 else
log_message log_message
end end
log_message = log_message =
if verified_batch_number > prev_verified_batch_number do 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 else
log_message log_message
end end
Logger.info(log_message <> "Handling the batch range #{start_batch_number}..#{end_batch_number}.") 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) div(handle_duration, 1000)
} }
else 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) {: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) latest_batch_number =
virtual_batch_number = Enum.find_value(responses, fn resp -> if resp.id == 1, do: quantity_to_integer(resp.result) end) Enum.find_value(responses, fn resp -> if resp.id == 0, 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)
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} {latest_batch_number, virtual_batch_number, verified_batch_number}
end end

@ -133,8 +133,9 @@ defmodule Indexer.Supervisor do
{Indexer.Fetcher.PolygonEdge.Withdrawal.Supervisor, {Indexer.Fetcher.PolygonEdge.Withdrawal.Supervisor,
[[memory_monitor: memory_monitor, json_rpc_named_arguments: json_rpc_named_arguments]]}, [[memory_monitor: memory_monitor, json_rpc_named_arguments: json_rpc_named_arguments]]},
{Indexer.Fetcher.PolygonEdge.WithdrawalExit.Supervisor, [[memory_monitor: memory_monitor]]}, {Indexer.Fetcher.PolygonEdge.WithdrawalExit.Supervisor, [[memory_monitor: memory_monitor]]},
{ZkevmTxnBatch.Supervisor, configure(ZkevmTxnBatch.Supervisor, [
[[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]]}, [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]
]),
# Out-of-band fetchers # Out-of-band fetchers
{EmptyBlocksSanitizer.Supervisor, [[json_rpc_named_arguments: json_rpc_named_arguments]]}, {EmptyBlocksSanitizer.Supervisor, [[json_rpc_named_arguments: json_rpc_named_arguments]]},

@ -613,6 +613,9 @@ config :indexer, Indexer.Fetcher.PolygonEdge.WithdrawalExit,
start_block_l1: System.get_env("INDEXER_POLYGON_EDGE_L1_WITHDRAWALS_START_BLOCK"), 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") 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") Code.require_file("#{config_env()}.exs", "config/runtime")
for config <- "../apps/*/config/runtime/#{config_env()}.exs" |> Path.expand(__DIR__) |> Path.wildcard() do for config <- "../apps/*/config/runtime/#{config_env()}.exs" |> Path.expand(__DIR__) |> Path.wildcard() do

Loading…
Cancel
Save