From f833f56c7337166db514ed492c6b2535864bc68a Mon Sep 17 00:00:00 2001
From: Marcos Nicolau <76252340+MarcosNicolau@users.noreply.github.com>
Date: Fri, 3 Jan 2025 11:41:03 -0300
Subject: [PATCH 1/5] hotfix: explorer new version (#1707)
---
.../explorer_web/live/pages/batches/index.html.heex | 2 +-
explorer/lib/explorer_web/live/pages/home/index.ex | 12 ++++++++++--
.../lib/explorer_web/live/pages/home/index.html.heex | 2 +-
explorer/lib/explorer_web/live/utils.ex | 5 +++++
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/explorer/lib/explorer_web/live/pages/batches/index.html.heex b/explorer/lib/explorer_web/live/pages/batches/index.html.heex
index 8172a29613..18023a88c2 100644
--- a/explorer/lib/explorer_web/live/pages/batches/index.html.heex
+++ b/explorer/lib/explorer_web/live/pages/batches/index.html.heex
@@ -34,7 +34,7 @@
type="number"
class={
classes([
- "border border-foreground/20 text-muted-foreground w-20 focus:ring-primary",
+ "text-center border border-foreground/20 text-muted-foreground w-20 focus:ring-primary",
"phx-submit-loading:opacity-75 rounded-lg bg-card hover:bg-muted py-2 px-3",
"text-sm font-semibold leading-6 text-foregound active:text-foregound/80",
"[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
diff --git a/explorer/lib/explorer_web/live/pages/home/index.ex b/explorer/lib/explorer_web/live/pages/home/index.ex
index 2638a5c287..7e5b52baf7 100644
--- a/explorer/lib/explorer_web/live/pages/home/index.ex
+++ b/explorer/lib/explorer_web/live/pages/home/index.ex
@@ -42,13 +42,21 @@ defmodule ExplorerWeb.Home.Index do
%{
title: "Proofs verified",
value: Helpers.convert_number_to_shorthand(verified_proofs),
- tooltip_text: "= #{Helpers.format_number(verified_proofs)} proofs",
+ tooltip_text:
+ case verified_proofs >= 1000 do
+ true -> "= #{Helpers.format_number(verified_proofs)} proofs"
+ _ -> nil
+ end,
link: nil
},
%{
title: "Total batches",
value: Helpers.convert_number_to_shorthand(verified_batches),
- tooltip_text: "= #{Helpers.format_number(verified_batches)} batches",
+ tooltip_text:
+ case verified_batches >= 1000 do
+ true -> "= #{Helpers.format_number(verified_batches)} batches"
+ _ -> nil
+ end,
link: nil
},
%{
diff --git a/explorer/lib/explorer_web/live/pages/home/index.html.heex b/explorer/lib/explorer_web/live/pages/home/index.html.heex
index 18bb7687bd..fde41db9c6 100644
--- a/explorer/lib/explorer_web/live/pages/home/index.html.heex
+++ b/explorer/lib/explorer_web/live/pages/home/index.html.heex
@@ -34,7 +34,7 @@
<.card
title="Cost per proof"
- subtitle="Cost of proving over time"
+ subtitle="Verification cost over time"
class="p-0 flex-1"
header_container_class="px-10 pt-8"
>
diff --git a/explorer/lib/explorer_web/live/utils.ex b/explorer/lib/explorer_web/live/utils.ex
index 79bbb40621..dc06bd2b68 100644
--- a/explorer/lib/explorer_web/live/utils.ex
+++ b/explorer/lib/explorer_web/live/utils.ex
@@ -7,6 +7,11 @@ defmodule ExplorerWeb.Helpers do
end
end
+ def convert_number_to_shorthand(number) when number >= 1_000_000_000 do
+ formatted_number = Float.round(number / 1_000_000_000, 2)
+ "#{remove_trailing_zeros(formatted_number)}B"
+ end
+
def convert_number_to_shorthand(number) when number >= 1_000_000 do
formatted_number = Float.round(number / 1_000_000, 2)
"#{remove_trailing_zeros(formatted_number)}M"
From b6aa3bfc52753e05196a2bf2262cfbbce22822f5 Mon Sep 17 00:00:00 2001
From: Marcos Nicolau <76252340+MarcosNicolau@users.noreply.github.com>
Date: Mon, 6 Jan 2025 12:06:31 -0300
Subject: [PATCH 2/5] fix: balance alerts description and correct function call
(#1699)
Co-authored-by: Julian Arce <52429267+JuArce@users.noreply.github.com>
---
alerts/.env.example | 2 ++
alerts/balance_alerts.sh | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/alerts/.env.example b/alerts/.env.example
index b18f93c3d5..2c0fe8a843 100644
--- a/alerts/.env.example
+++ b/alerts/.env.example
@@ -19,7 +19,9 @@ EXPRESSION=
RPC_URL=
PAYMENT_CONTRACT_ADDRESS=
BALANCE_THRESHOLD=
+WALLET_NAME= # Example: "Task sender"
WALLET_ADDRESS=
+NETWORK=
# Variables for sender_with_alert.sh
REPETITIONS=
diff --git a/alerts/balance_alerts.sh b/alerts/balance_alerts.sh
index efd9ff21fa..9f8229a79e 100755
--- a/alerts/balance_alerts.sh
+++ b/alerts/balance_alerts.sh
@@ -25,12 +25,12 @@ balance_alert=false
while :
do
- balance_wei=$(cast call --rpc-url $RPC_URL $PAYMENT_CONTRACT_ADDRESS "UserBalances(address)(uint256)" $WALLET_ADDRESS | cut -d' ' -f1)
+ balance_wei=$(cast call --rpc-url $RPC_URL $PAYMENT_CONTRACT_ADDRESS "user_balances(address)(uint256)" $WALLET_ADDRESS | cut -d' ' -f1)
balance_eth=$(cast from-wei $balance_wei)
if [ 1 -eq "$(echo "$balance_eth < $BALANCE_THRESHOLD" | bc)" ]; then
- message="⚠️ WARNING: Wallet $WALLET_ADDRESS balance ($balance_eth ETH) is below $BALANCE_THRESHOLD ETH"
+ message="⚠️ WARNING: $WALLET_NAME ($NETWORK) Wallet ($WALLET_ADDRESS) balance ($balance_eth ETH) is below $BALANCE_THRESHOLD ETH"
printf "$message\n"
if [ "$balance_alert" = false ]; then
send_slack_message "$message"
From de2f3d5eca4f58aed34d85e133ec4f541ab847a2 Mon Sep 17 00:00:00 2001
From: Uriel Mihura <43704209+uri-99@users.noreply.github.com>
Date: Mon, 6 Jan 2025 16:04:33 -0300
Subject: [PATCH 3/5] hotfix: change cost_per_proof_chart var name (#1711)
---
explorer/lib/explorer_web/live/eth_converter.ex | 2 ++
explorer/lib/explorer_web/live/pages/home/index.ex | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/explorer/lib/explorer_web/live/eth_converter.ex b/explorer/lib/explorer_web/live/eth_converter.ex
index 24009e5310..919f3620c7 100644
--- a/explorer/lib/explorer_web/live/eth_converter.ex
+++ b/explorer/lib/explorer_web/live/eth_converter.ex
@@ -58,6 +58,8 @@ defmodule EthConverter do
end
end
+ defp round_to_sf(%Decimal{coef: 0} = _value, _sf), do: Decimal.new("0")
+
defp round_to_sf(value, significant_figures) do
# Convert the value to a float and calculate the magnitude
value_float = Decimal.to_float(value)
diff --git a/explorer/lib/explorer_web/live/pages/home/index.ex b/explorer/lib/explorer_web/live/pages/home/index.ex
index 7e5b52baf7..ca215722b8 100644
--- a/explorer/lib/explorer_web/live/pages/home/index.ex
+++ b/explorer/lib/explorer_web/live/pages/home/index.ex
@@ -154,7 +154,7 @@ defmodule ExplorerWeb.Home.Index do
|> assign(
stats: [],
latest_batches: [],
- cost_per_proof_data: %{points: [], extra_data: %{}},
+ cost_per_proof_chart: %{points: [], extra_data: %{}},
batch_size_chart_data: %{points: [], extra_data: %{}}
)
end
From e6a5de4444e4ae5877714c5b22cf5ac0818f828f Mon Sep 17 00:00:00 2001
From: Julian Ventura <43799596+JulianVentura@users.noreply.github.com>
Date: Mon, 6 Jan 2025 16:32:20 -0300
Subject: [PATCH 4/5] hotfix(explorer): Add endpoint to fetch last 24 hours
number of proofs verified (#1710)
Co-authored-by: Julian Ventura
Co-authored-by: avilagaston9
Co-authored-by: Mauro Toscano <12560266+MauroToscano@users.noreply.github.com>
Co-authored-by: JuArce <52429267+JuArce@users.noreply.github.com>
---
explorer/lib/explorer/models/batches.ex | 14 ++++++++++++++
.../explorer_web/controllers/data_controller.ex | 8 ++++++++
explorer/lib/explorer_web/controllers/data_json.ex | 7 +++++++
explorer/lib/explorer_web/router.ex | 7 ++++++-
4 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 explorer/lib/explorer_web/controllers/data_controller.ex
create mode 100644 explorer/lib/explorer_web/controllers/data_json.ex
diff --git a/explorer/lib/explorer/models/batches.ex b/explorer/lib/explorer/models/batches.ex
index b22dd7b68d..f92ae4d434 100644
--- a/explorer/lib/explorer/models/batches.ex
+++ b/explorer/lib/explorer/models/batches.ex
@@ -164,6 +164,20 @@ defmodule Batches do
end
end
+ def get_verified_proofs_in_last_24_hours() do
+ minutes_in_a_day = 1440
+ threshold_datetime = DateTime.utc_now() |> DateTime.add(-1 * minutes_in_a_day, :minute) # Last 24 hours
+
+ query = from(b in Batches,
+ where: b.is_verified == true and b.submission_timestamp > ^threshold_datetime,
+ select: sum(b.amount_of_proofs))
+
+ case Explorer.Repo.one(query) do
+ nil -> 0
+ result -> result
+ end
+ end
+
def insert_or_update(batch_changeset, proofs) do
merkle_root = batch_changeset.changes.merkle_root
stored_proofs = Proofs.get_proofs_from_batch(%{merkle_root: merkle_root})
diff --git a/explorer/lib/explorer_web/controllers/data_controller.ex b/explorer/lib/explorer_web/controllers/data_controller.ex
new file mode 100644
index 0000000000..df244a1197
--- /dev/null
+++ b/explorer/lib/explorer_web/controllers/data_controller.ex
@@ -0,0 +1,8 @@
+defmodule ExplorerWeb.DataController do
+ use ExplorerWeb, :controller
+
+ def verified_proofs_in_last_24_hours(conn, _params) do
+ verified_proofs_in_last_24_hours = Batches.get_verified_proofs_in_last_24_hours()
+ render(conn, :show, count: verified_proofs_in_last_24_hours)
+ end
+end
diff --git a/explorer/lib/explorer_web/controllers/data_json.ex b/explorer/lib/explorer_web/controllers/data_json.ex
new file mode 100644
index 0000000000..8f2752db28
--- /dev/null
+++ b/explorer/lib/explorer_web/controllers/data_json.ex
@@ -0,0 +1,7 @@
+defmodule ExplorerWeb.DataJSON do
+ def show(%{count: last_verified_proofs_count}) do
+ %{
+ count: last_verified_proofs_count
+ }
+ end
+end
diff --git a/explorer/lib/explorer_web/router.ex b/explorer/lib/explorer_web/router.ex
index e85cb7491f..f8d90604e6 100644
--- a/explorer/lib/explorer_web/router.ex
+++ b/explorer/lib/explorer_web/router.ex
@@ -32,11 +32,16 @@ defmodule ExplorerWeb.Router do
plug :accepts, ["json"]
end
+ scope "/api", ExplorerWeb do
+ pipe_through :api
+ get "/proofs_verified_last_24h", DataController, :verified_proofs_in_last_24_hours
+ end
+
scope "/", ExplorerWeb do
pipe_through :browser
# https://fly.io/phoenix-files/live-session/
- live_session :default,
+ live_session :default,
on_mount: [{ExplorerWeb.Hooks, :add_host}, {ExplorerWeb.Hooks, :add_theme}] do
live "/", Home.Index
live "/batches/:merkle_root", Batch.Index
From a25f01266046ac979f8a7703b744f559c8e90134 Mon Sep 17 00:00:00 2001
From: Julian Ventura <43799596+JulianVentura@users.noreply.github.com>
Date: Mon, 6 Jan 2025 19:11:27 -0300
Subject: [PATCH 5/5] hotfix(explorer): Add `fee_per_proof` average to the data
endpoint. (#1713)
Co-authored-by: Julian Ventura
Co-authored-by: avilagaston9
---
explorer/lib/explorer/models/batches.ex | 13 +++++++++----
.../explorer_web/controllers/data_controller.ex | 17 +++++++++++++++--
.../lib/explorer_web/controllers/data_json.ex | 8 ++++++--
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/explorer/lib/explorer/models/batches.ex b/explorer/lib/explorer/models/batches.ex
index f92ae4d434..ffd8f5b40a 100644
--- a/explorer/lib/explorer/models/batches.ex
+++ b/explorer/lib/explorer/models/batches.ex
@@ -164,18 +164,23 @@ defmodule Batches do
end
end
- def get_verified_proofs_in_last_24_hours() do
+ def get_last_24h_verified_proof_stats() do
minutes_in_a_day = 1440
threshold_datetime = DateTime.utc_now() |> DateTime.add(-1 * minutes_in_a_day, :minute) # Last 24 hours
query = from(b in Batches,
where: b.is_verified == true and b.submission_timestamp > ^threshold_datetime,
- select: sum(b.amount_of_proofs))
+ select: {sum(b.amount_of_proofs), avg(b.fee_per_proof)})
- case Explorer.Repo.one(query) do
- nil -> 0
+ {amount_of_proofs, avg_fee_per_proof} = case Explorer.Repo.one(query) do
+ nil -> {0, 0.0}
result -> result
end
+
+ %{
+ amount_of_proofs: amount_of_proofs,
+ avg_fee_per_proof: avg_fee_per_proof
+ }
end
def insert_or_update(batch_changeset, proofs) do
diff --git a/explorer/lib/explorer_web/controllers/data_controller.ex b/explorer/lib/explorer_web/controllers/data_controller.ex
index df244a1197..9ed257807c 100644
--- a/explorer/lib/explorer_web/controllers/data_controller.ex
+++ b/explorer/lib/explorer_web/controllers/data_controller.ex
@@ -2,7 +2,20 @@ defmodule ExplorerWeb.DataController do
use ExplorerWeb, :controller
def verified_proofs_in_last_24_hours(conn, _params) do
- verified_proofs_in_last_24_hours = Batches.get_verified_proofs_in_last_24_hours()
- render(conn, :show, count: verified_proofs_in_last_24_hours)
+ %{
+ amount_of_proofs: amount_of_proofs,
+ avg_fee_per_proof: avg_fee_per_proof
+ } = Batches.get_last_24h_verified_proof_stats()
+
+ avg_fee_per_proof_usd =
+ case EthConverter.wei_to_usd_sf(avg_fee_per_proof, 2) do
+ {:ok, value} -> value
+ _ -> 0
+ end
+
+ render(conn, :show, %{
+ amount_of_proofs: amount_of_proofs,
+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
+ })
end
end
diff --git a/explorer/lib/explorer_web/controllers/data_json.ex b/explorer/lib/explorer_web/controllers/data_json.ex
index 8f2752db28..d6d905f1a2 100644
--- a/explorer/lib/explorer_web/controllers/data_json.ex
+++ b/explorer/lib/explorer_web/controllers/data_json.ex
@@ -1,7 +1,11 @@
defmodule ExplorerWeb.DataJSON do
- def show(%{count: last_verified_proofs_count}) do
+ def show(%{
+ amount_of_proofs: amount_of_proofs,
+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
+ }) do
%{
- count: last_verified_proofs_count
+ amount_of_proofs: amount_of_proofs,
+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
}
end
end