pull/9098/head
POA 11 months ago
parent 1fda56ef15
commit 0092b1a4c3
  1. 86
      apps/indexer/lib/indexer/fetcher/zkevm/bridge_l1.ex
  2. 8
      apps/indexer/lib/indexer/supervisor.ex
  3. 15
      config/runtime.exs
  4. 2
      config/runtime/prod.exs

@ -72,45 +72,26 @@ defmodule Indexer.Fetcher.Zkevm.BridgeL1 do
with {:start_block_undefined, false} <- {:start_block_undefined, is_nil(env[:start_block])}, with {:start_block_undefined, false} <- {:start_block_undefined, is_nil(env[:start_block])},
rpc = env[:rpc], rpc = env[:rpc],
{:rpc_undefined, false} <- {:rpc_undefined, is_nil(rpc)}, {:rpc_undefined, false} <- {:rpc_undefined, is_nil(rpc)},
{:deposit_manager_address_is_valid, true} <- {:bridge_contract_address_is_valid, true} <- {:bridge_contract_address_is_valid, Helper.is_address_correct?(env[:bridge_contract])},
{:deposit_manager_address_is_valid, Helper.is_address_correct?(env[:deposit_manager_proxy])},
{:ether_predicate_address_is_valid, true} <-
{:ether_predicate_address_is_valid, Helper.is_address_correct?(env[:ether_predicate_proxy])},
{:erc20_predicate_address_is_valid, true} <-
{:erc20_predicate_address_is_valid, Helper.is_address_correct?(env[:erc20_predicate_proxy])},
{:erc721_predicate_address_is_valid, true} <-
{:erc721_predicate_address_is_valid,
is_nil(env[:erc721_predicate_proxy]) or Helper.is_address_correct?(env[:erc721_predicate_proxy])},
{:erc1155_predicate_address_is_valid, true} <-
{:erc1155_predicate_address_is_valid,
is_nil(env[:erc1155_predicate_proxy]) or Helper.is_address_correct?(env[:erc1155_predicate_proxy])},
{:withdraw_manager_address_is_valid, true} <-
{:withdraw_manager_address_is_valid, Helper.is_address_correct?(env[:withdraw_manager_proxy])},
start_block = parse_integer(env[:start_block]), start_block = parse_integer(env[:start_block]),
false <- is_nil(start_block), false <- is_nil(start_block),
true <- start_block > 0, true <- start_block > 0,
{last_l1_block_number, last_l1_transaction_hash} <- get_last_l1_item(), {last_l1_block_number, last_l1_transaction_hash} <- get_last_l1_item(),
{:start_block_valid, true} <-
{:start_block_valid, start_block <= last_l1_block_number || last_l1_block_number == 0},
json_rpc_named_arguments = json_rpc_named_arguments(rpc), json_rpc_named_arguments = json_rpc_named_arguments(rpc),
{:ok, block_check_interval, safe_block, safe_block_is_latest} <- get_block_check_interval(json_rpc_named_arguments),
{:start_block_valid, true} <- {:start_block_valid, (start_block <= last_l1_block_number || last_l1_block_number == 0) && start_block <= safe_block},
{:ok, last_l1_tx} <- Helper.get_transaction_by_hash(last_l1_transaction_hash, json_rpc_named_arguments), {:ok, last_l1_tx} <- Helper.get_transaction_by_hash(last_l1_transaction_hash, json_rpc_named_arguments),
{:l1_tx_not_found, false} <- {:l1_tx_not_found, !is_nil(last_l1_transaction_hash) && is_nil(last_l1_tx)}, {:l1_tx_not_found, false} <- {:l1_tx_not_found, !is_nil(last_l1_transaction_hash) && is_nil(last_l1_tx)} do
{:ok, block_check_interval, latest_block} <- get_block_check_interval(json_rpc_named_arguments),
{:start_block_valid, true} <- {:start_block_valid, start_block <= latest_block} do
Process.send(self(), :reorg_monitor, []) Process.send(self(), :reorg_monitor, [])
Process.send(self(), :continue, []) Process.send(self(), :continue, [])
{:noreply, {:noreply,
%{ %{
deposit_manager_proxy: env[:deposit_manager_proxy], bridge_contract: env[:bridge_contract],
ether_predicate_proxy: env[:ether_predicate_proxy],
erc20_predicate_proxy: env[:erc20_predicate_proxy],
erc721_predicate_proxy: env[:erc721_predicate_proxy],
erc1155_predicate_proxy: env[:erc1155_predicate_proxy],
withdraw_manager_proxy: env[:withdraw_manager_proxy],
block_check_interval: block_check_interval, block_check_interval: block_check_interval,
start_block: max(start_block, last_l1_block_number), start_block: max(start_block, last_l1_block_number),
end_block: latest_block, safe_block: safe_block,
safe_block_is_latest: safe_block_is_latest,
json_rpc_named_arguments: json_rpc_named_arguments, json_rpc_named_arguments: json_rpc_named_arguments,
reorg_monitor_prev_latest: 0 reorg_monitor_prev_latest: 0
}} }}
@ -123,28 +104,8 @@ defmodule Indexer.Fetcher.Zkevm.BridgeL1 do
Logger.error("L1 RPC URL is not defined.") Logger.error("L1 RPC URL is not defined.")
{:stop, :normal, %{}} {:stop, :normal, %{}}
{:deposit_manager_address_is_valid, false} -> {:bridge_contract_address_is_valid, false} ->
Logger.error("DepositManagerProxy contract address is invalid or not defined.") Logger.error("PolygonZkEVMBridge contract address is invalid or not defined.")
{:stop, :normal, %{}}
{:ether_predicate_address_is_valid, false} ->
Logger.error("EtherPredicateProxy contract address is invalid or not defined.")
{:stop, :normal, %{}}
{:erc20_predicate_address_is_valid, false} ->
Logger.error("ERC20PredicateProxy contract address is invalid or not defined.")
{:stop, :normal, %{}}
{:erc721_predicate_address_is_valid, false} ->
Logger.error("ERC721PredicateProxy contract address is invalid.")
{:stop, :normal, %{}}
{:erc1155_predicate_address_is_valid, false} ->
Logger.error("ERC1155PredicateProxy contract address is invalid.")
{:stop, :normal, %{}}
{:withdraw_manager_address_is_valid, false} ->
Logger.error("WithdrawManagerProxy contract address is invalid or not defined.")
{:stop, :normal, %{}} {:stop, :normal, %{}}
{:start_block_valid, false} -> {:start_block_valid, false} ->
@ -160,7 +121,7 @@ defmodule Indexer.Fetcher.Zkevm.BridgeL1 do
{:l1_tx_not_found, true} -> {:l1_tx_not_found, true} ->
Logger.error( Logger.error(
"Cannot find last L1 transaction from RPC by its hash. Probably, there was a reorg on L1 chain. Please, check shibarium_bridge table." "Cannot find last L1 transaction from RPC by its hash. Probably, there was a reorg on L1 chain. Please, check zkevm_bridge table."
) )
{:stop, :normal, %{}} {:stop, :normal, %{}}
@ -288,16 +249,16 @@ defmodule Indexer.Fetcher.Zkevm.BridgeL1 do
end end
defp get_block_check_interval(json_rpc_named_arguments) do defp get_block_check_interval(json_rpc_named_arguments) do
with {:ok, latest_block} <- Helper.get_block_number_by_tag("latest", json_rpc_named_arguments), {last_safe_block, safe_block_is_latest} = get_safe_block(json_rpc_named_arguments)
first_block = max(latest_block - @block_check_interval_range_size, 1),
{:ok, first_block_timestamp} <- Helper.get_block_timestamp_by_number(first_block, json_rpc_named_arguments), first_block = max(latest_block - @block_check_interval_range_size, 1)
{:ok, last_safe_block_timestamp} <-
Helper.get_block_timestamp_by_number(latest_block, json_rpc_named_arguments) do with {:ok, first_block_timestamp} <- Helper.get_block_timestamp_by_number(first_block, json_rpc_named_arguments),
block_check_interval = {:ok, last_safe_block_timestamp} <- Helper.get_block_timestamp_by_number(last_safe_block, json_rpc_named_arguments) do
ceil((last_safe_block_timestamp - first_block_timestamp) / (latest_block - first_block) * 1000 / 2) block_check_interval = ceil((last_safe_block_timestamp - first_block_timestamp) / (last_safe_block - first_block) * 1000 / 2)
Logger.info("Block check interval is calculated as #{block_check_interval} ms.") Logger.info("Block check interval is calculated as #{block_check_interval} ms.")
{:ok, block_check_interval, latest_block} {:ok, block_check_interval, last_safe_block, safe_block_is_latest}
else else
{:error, error} -> {:error, error} ->
{:error, "Failed to calculate block check interval due to #{inspect(error)}"} {:error, "Failed to calculate block check interval due to #{inspect(error)}"}
@ -530,6 +491,17 @@ defmodule Indexer.Fetcher.Zkevm.BridgeL1 do
) )
end end
defp get_safe_block(json_rpc_named_arguments) do
case Helper.get_block_number_by_tag("safe", json_rpc_named_arguments) do
{:ok, safe_block} ->
{safe_block, false}
{:error, :not_found} ->
{:ok, latest_block} = Helper.get_block_number_by_tag("latest", json_rpc_named_arguments, 100_000_000)
{latest_block, true}
end
end
defp json_rpc_named_arguments(rpc_url) do defp json_rpc_named_arguments(rpc_url) do
[ [
transport: EthereumJSONRPC.HTTP, transport: EthereumJSONRPC.HTTP,

@ -44,8 +44,6 @@ defmodule Indexer.Supervisor do
Withdrawal Withdrawal
} }
alias Indexer.Fetcher.Zkevm.TransactionBatch
alias Indexer.Temporary.{ alias Indexer.Temporary.{
BlocksTransactionsMismatch, BlocksTransactionsMismatch,
UncatalogedTokenTransfers, UncatalogedTokenTransfers,
@ -147,7 +145,11 @@ defmodule Indexer.Supervisor do
[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor] [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]
]), ]),
configure(Indexer.Fetcher.Shibarium.L1.Supervisor, [[memory_monitor: memory_monitor]]), configure(Indexer.Fetcher.Shibarium.L1.Supervisor, [[memory_monitor: memory_monitor]]),
configure(TransactionBatch.Supervisor, [ configure(Indexer.Fetcher.Zkevm.BridgeL1.Supervisor, [[memory_monitor: memory_monitor]]),
configure(Indexer.Fetcher.Zkevm.BridgeL2.Supervisor, [
[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]
]),
configure(Indexer.Fetcher.Zkevm.TransactionBatch.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]
]), ]),
{Indexer.Fetcher.Beacon.Blob.Supervisor, [[memory_monitor: memory_monitor]]}, {Indexer.Fetcher.Beacon.Blob.Supervisor, [[memory_monitor: memory_monitor]]},

@ -727,6 +727,21 @@ config :indexer, Indexer.Fetcher.Shibarium.L1.Supervisor, enabled: ConfigHelper.
config :indexer, Indexer.Fetcher.Shibarium.L2.Supervisor, enabled: ConfigHelper.chain_type() == "shibarium" config :indexer, Indexer.Fetcher.Shibarium.L2.Supervisor, enabled: ConfigHelper.chain_type() == "shibarium"
config :indexer, Indexer.Fetcher.Zkevm.BridgeL1,
rpc: System.get_env("INDEXER_POLYGON_ZKEVM_L1_RPC"),
start_block: System.get_env("INDEXER_POLYGON_ZKEVM_L1_BRIDGE_START_BLOCK"),
bridge_contract: System.get_env("INDEXER_POLYGON_ZKEVM_L1_BRIDGE_CONTRACT"),
native_symbol: System.get_env("INDEXER_POLYGON_ZKEVM_L1_BRIDGE_NATIVE_SYMBOL", "ETH"),
native_decimals: ConfigHelper.parse_integer_env_var("INDEXER_POLYGON_ZKEVM_L1_BRIDGE_NATIVE_DECIMALS", 18)
config :indexer, Indexer.Fetcher.Zkevm.BridgeL1.Supervisor, enabled: ConfigHelper.chain_type() == "polygon_zkevm"
config :indexer, Indexer.Fetcher.Zkevm.BridgeL2,
start_block: System.get_env("INDEXER_POLYGON_ZKEVM_L2_BRIDGE_START_BLOCK"),
bridge_contract: System.get_env("INDEXER_POLYGON_ZKEVM_L2_BRIDGE_CONTRACT"),
config :indexer, Indexer.Fetcher.Zkevm.BridgeL2.Supervisor, enabled: ConfigHelper.chain_type() == "polygon_zkevm"
config :indexer, Indexer.Fetcher.Zkevm.TransactionBatch, config :indexer, Indexer.Fetcher.Zkevm.TransactionBatch,
chunk_size: ConfigHelper.parse_integer_env_var("INDEXER_POLYGON_ZKEVM_BATCHES_CHUNK_SIZE", 20), chunk_size: ConfigHelper.parse_integer_env_var("INDEXER_POLYGON_ZKEVM_BATCHES_CHUNK_SIZE", 20),
recheck_interval: ConfigHelper.parse_integer_env_var("INDEXER_POLYGON_ZKEVM_BATCHES_RECHECK_INTERVAL", 60) recheck_interval: ConfigHelper.parse_integer_env_var("INDEXER_POLYGON_ZKEVM_BATCHES_RECHECK_INTERVAL", 60)

@ -78,8 +78,6 @@ config :explorer, Explorer.Repo.PolygonEdge,
# Configures PolygonZkevm database # Configures PolygonZkevm database
config :explorer, Explorer.Repo.PolygonZkevm, config :explorer, Explorer.Repo.PolygonZkevm,
url: System.get_env("DATABASE_URL"), url: System.get_env("DATABASE_URL"),
# actually this repo is not started, and its pool size remains unused.
# separating repos for different CHAIN_TYPE is implemented only for the sake of keeping DB schema update relevant to the current chain type
pool_size: 1, pool_size: 1,
ssl: ExplorerConfigHelper.ssl_enabled?() ssl: ExplorerConfigHelper.ssl_enabled?()

Loading…
Cancel
Save