Skip to content

Commit

Permalink
fix(explorer): handle empty events from batcher payment system (#888)
Browse files Browse the repository at this point in the history
Co-authored-by: Mariano A. Nicolini <mariano.nicolini.91@gmail.com>
  • Loading branch information
glpecile and entropidelic authored Aug 29, 2024
1 parent b2982a9 commit 155d5de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/batches.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions explorer/lib/explorer_web/live/pages/batch/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@
</h3>
<p><%= @current_batch.amount_of_proofs %></p>
</div>
<%= if @current_batch.fee_per_proof != nil do %>
<div class="flex flex-col sm:flex-row">
<h3>
Cost per Proof:
</h3>
<p>
<%= @current_batch.fee_per_proof |> EthConverter.wei_to_eth() %> ETH
<%= if @eth_usd_price != :empty and @eth_usd_price != "0.00000" do %>
<span class="inline-flex md:inline-block">(<%= @eth_usd_price %> USD)</span>
<% end %>
</p>
</div>
<% end %>
<div
:if={@current_batch.fee_per_proof != 0}
class="flex flex-col sm:flex-row"
>
<h3>
Fee per Proof:
</h3>
<p>
<%= @current_batch.fee_per_proof |> EthConverter.wei_to_eth() %> ETH
<%= if @eth_usd_price != :empty and @eth_usd_price != "0.00000" do %>
<span class="inline-flex md:inline-block">(<%= @eth_usd_price %> USD)</span>
<% end %>
</p>
</div>
<div>
<h3>
Proofs in this batch:
Expand Down

0 comments on commit 155d5de

Please sign in to comment.