From 155d5ded8c9ede09384160ce2c92d742e8bea4fd Mon Sep 17 00:00:00 2001 From: Gian <58370608+glpecile@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:17:17 -0300 Subject: [PATCH] fix(explorer): handle empty events from batcher payment system (#888) Co-authored-by: Mariano A. Nicolini --- .../batcher_payment_service_manager.ex | 14 ++++++---- explorer/lib/explorer/models/batches.ex | 2 +- .../live/pages/batch/index.html.heex | 27 ++++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex b/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex index e91496214..883d08694 100644 --- a/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex +++ b/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex @@ -48,20 +48,24 @@ defmodule BatcherPaymentServiceManager do ) |> Ethers.get_logs(fromBlock: @first_block) |> case do + {:ok, []} -> + Logger.warning("No fee per proof events found for merkle root: #{merkle_root}.") + 0 + {:ok, events} -> event = events |> hd() fee_per_proof = event.data |> hd() - Logger.debug("Fee per proof of #{merkle_root}: #{fee_per_proof} wei") + Logger.debug("Fee per proof of #{merkle_root}: #{fee_per_proof} WEI.") fee_per_proof {:error, reason} -> - Logger.error("Error getting gas per proof: #{inspect(reason)}") - raise("Error getting gas per proof") + Logger.error("Error getting fee per proof: #{inspect(reason)}.") + raise("Error getting fee per proof events.") other -> - Logger.error("Unexpected response: #{inspect(other)}") - raise("Unexpected response") + Logger.error("Unexpected response on fee per proof events: #{inspect(other)}") + raise("Unexpected response on fee per proof events.") end end end diff --git a/explorer/lib/explorer/models/batches.ex b/explorer/lib/explorer/models/batches.ex index 3f4699078..b3093b30f 100644 --- a/explorer/lib/explorer/models/batches.ex +++ b/explorer/lib/explorer/models/batches.ex @@ -34,7 +34,7 @@ defmodule Batches do |> validate_format(:submission_transaction_hash, ~r/0x[a-fA-F0-9]{64}/) |> validate_number(:response_block_number, greater_than: 0) |> validate_format(:response_transaction_hash, ~r/0x[a-fA-F0-9]{64}/) - |> validate_number(:fee_per_proof, greater_than: 0) + |> validate_number(:fee_per_proof, greater_than_or_equal_to: 0) end def cast_to_batches(%BatchDB{} = batch_db) do diff --git a/explorer/lib/explorer_web/live/pages/batch/index.html.heex b/explorer/lib/explorer_web/live/pages/batch/index.html.heex index f6b728b6e..67b5626f3 100644 --- a/explorer/lib/explorer_web/live/pages/batch/index.html.heex +++ b/explorer/lib/explorer_web/live/pages/batch/index.html.heex @@ -39,19 +39,20 @@

<%= @current_batch.amount_of_proofs %>

- <%= if @current_batch.fee_per_proof != nil do %> -
-

- Cost per Proof: -

-

- <%= @current_batch.fee_per_proof |> EthConverter.wei_to_eth() %> ETH - <%= if @eth_usd_price != :empty and @eth_usd_price != "0.00000" do %> - (<%= @eth_usd_price %> USD) - <% end %> -

-
- <% end %> +
+

+ Fee per Proof: +

+

+ <%= @current_batch.fee_per_proof |> EthConverter.wei_to_eth() %> ETH + <%= if @eth_usd_price != :empty and @eth_usd_price != "0.00000" do %> + (<%= @eth_usd_price %> USD) + <% end %> +

+

Proofs in this batch: