Merge pull request #3398 from poanetwork/vb-gas-usage-per-day

Collect and display gas usage per day at the main page
pull/3399/head
Victor Baranov 4 years ago committed by GitHub
commit 84625a710a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 13
      apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex
  3. 4
      apps/block_scout_web/lib/block_scout_web/views/layout_view.ex
  4. 22
      apps/block_scout_web/priv/gettext/default.pot
  5. 22
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 24
      apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs
  7. 4
      apps/explorer/lib/explorer/chain/transaction/history/historian.ex
  8. 5
      apps/explorer/lib/explorer/chain/transaction/history/transaction_stats.ex
  9. 9
      apps/explorer/priv/repo/migrations/20201026093652_transactions_stat_add_gas_usage_column.exs
  10. 14
      apps/explorer/test/explorer/chain/transaction/history/historian_test.exs

@ -1,6 +1,7 @@
## Current ## Current
### Features ### Features
- [#3398](https://github.com/poanetwork/blockscout/pull/3398) - Collect and display gas usage per day at the main page
- [#3385](https://github.com/poanetwork/blockscout/pull/3385), [#3397](https://github.com/poanetwork/blockscout/pull/3397) - Total gas usage at the main page - [#3385](https://github.com/poanetwork/blockscout/pull/3385), [#3397](https://github.com/poanetwork/blockscout/pull/3397) - Total gas usage at the main page
- [#3384](https://github.com/poanetwork/blockscout/pull/3384), [#3386](https://github.com/poanetwork/blockscout/pull/3386) - Address total gas usage - [#3384](https://github.com/poanetwork/blockscout/pull/3384), [#3386](https://github.com/poanetwork/blockscout/pull/3386) - Address total gas usage
- [#3377](https://github.com/poanetwork/blockscout/pull/3377) - Add links to contract libraries - [#3377](https://github.com/poanetwork/blockscout/pull/3377) - Add links to contract libraries

@ -91,7 +91,18 @@
<%= gettext "Tx/day" %> <%= gettext "Tx/day" %>
</span> </span>
<span class="dashboard-banner-chart-legend-value" data-selector="tx_per_day"> <span class="dashboard-banner-chart-legend-value" data-selector="tx_per_day">
<%= BlockScoutWeb.Cldr.Number.to_string!(Enum.at(@transaction_stats, 0).number_of_transactions, format: "#,###") %> <% num_of_transactions = BlockScoutWeb.Cldr.Number.to_string!(Enum.at(@transaction_stats, 0).number_of_transactions, format: "#,###") %>
<%= num_of_transactions %>
<%= if Enum.at(@transaction_stats, 0).gas_used do %>
<span
data-toggle="tooltip"
data-placement="top"
data-html="true"
data-template="<div class='tooltip tooltip-inversed-color tooltip-gas-usage' role='tooltip'><div class='arrow'></div><div class='tooltip-inner'></div></div>"
title="<div class='custom-tooltip-header'>Gas used</div><div class='custom-tooltip-description'><b><%= BlockScoutWeb.Cldr.Number.to_string!(Enum.at(@transaction_stats, 0).gas_used, format: "#,###") %><b></div>">
<i style="color: #ffffff;" class="fa fa-info-circle ml-1"></i>
</span>
<% end %>
</span> </span>
</div> </div>
<% end %> <% end %>

@ -11,7 +11,7 @@ defmodule BlockScoutWeb.LayoutView do
url: "https://blockscout.com/poa/core" url: "https://blockscout.com/poa/core"
}, },
%{ %{
title: "POA Sokol", title: "Sokol",
url: "https://blockscout.com/poa/sokol", url: "https://blockscout.com/poa/sokol",
test_net?: true test_net?: true
}, },
@ -47,7 +47,7 @@ defmodule BlockScoutWeb.LayoutView do
end end
def subnetwork_title do def subnetwork_title do
Keyword.get(application_config(), :subnetwork) || "POA Sokol" Keyword.get(application_config(), :subnetwork) || "Sokol"
end end
def network_title do def network_title do

@ -151,7 +151,7 @@ msgid "Anything not in this list is not supported. Click on the method to be tak
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:110 #: lib/block_scout_web/templates/chain/show.html.eex:121
msgid "Average block time" msgid "Average block time"
msgstr "" msgstr ""
@ -236,7 +236,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:165 #: lib/block_scout_web/templates/chain/show.html.eex:176
#: lib/block_scout_web/templates/layout/_topnav.html.eex:34 #: lib/block_scout_web/templates/layout/_topnav.html.eex:34
#: lib/block_scout_web/templates/layout/_topnav.html.eex:38 #: lib/block_scout_web/templates/layout/_topnav.html.eex:38
msgid "Blocks" msgid "Blocks"
@ -1065,7 +1065,7 @@ msgid "More internal transactions have come in"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:226 #: lib/block_scout_web/templates/chain/show.html.eex:237
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:12 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:12
#: lib/block_scout_web/templates/transaction/index.html.eex:18 #: lib/block_scout_web/templates/transaction/index.html.eex:18
msgid "More transactions have come in" msgid "More transactions have come in"
@ -1309,7 +1309,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_transaction/index.html.eex:48 #: lib/block_scout_web/templates/address_transaction/index.html.eex:48
#: lib/block_scout_web/templates/address_validation/index.html.eex:22 #: lib/block_scout_web/templates/address_validation/index.html.eex:22
#: lib/block_scout_web/templates/block_transaction/index.html.eex:23 #: lib/block_scout_web/templates/block_transaction/index.html.eex:23
#: lib/block_scout_web/templates/chain/show.html.eex:169 #: lib/block_scout_web/templates/chain/show.html.eex:180
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:21 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:21
#: lib/block_scout_web/templates/stakes/_table.html.eex:44 #: lib/block_scout_web/templates/stakes/_table.html.eex:44
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:22 #: lib/block_scout_web/templates/tokens/holder/index.html.eex:22
@ -1324,7 +1324,7 @@ msgid "Something went wrong, click to reload."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:232 #: lib/block_scout_web/templates/chain/show.html.eex:243
msgid "Something went wrong, click to retry." msgid "Something went wrong, click to retry."
msgstr "" msgstr ""
@ -1453,7 +1453,7 @@ msgid "Total Supply"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:140 #: lib/block_scout_web/templates/chain/show.html.eex:151
msgid "Total blocks" msgid "Total blocks"
msgstr "" msgstr ""
@ -1593,12 +1593,12 @@ msgid "Version"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:164 #: lib/block_scout_web/templates/chain/show.html.eex:175
msgid "View All Blocks" msgid "View All Blocks"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:222 #: lib/block_scout_web/templates/chain/show.html.eex:233
msgid "View All Transactions" msgid "View All Transactions"
msgstr "" msgstr ""
@ -1640,7 +1640,7 @@ msgid "WEI"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:148 #: lib/block_scout_web/templates/chain/show.html.eex:159
msgid "Wallet addresses" msgid "Wallet addresses"
msgstr "" msgstr ""
@ -1780,7 +1780,7 @@ msgid "Module"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:119 #: lib/block_scout_web/templates/chain/show.html.eex:130
msgid "Total transactions" msgid "Total transactions"
msgstr "" msgstr ""
@ -1867,7 +1867,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_transaction/index.html.eex:15 #: lib/block_scout_web/templates/address_transaction/index.html.eex:15
#: lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/block_transaction/index.html.eex:10
#: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/block_transaction/index.html.eex:18
#: lib/block_scout_web/templates/chain/show.html.eex:223 #: lib/block_scout_web/templates/chain/show.html.eex:234
#: lib/block_scout_web/templates/layout/_topnav.html.eex:53 #: lib/block_scout_web/templates/layout/_topnav.html.eex:53
#: lib/block_scout_web/views/address_view.ex:349 #: lib/block_scout_web/views/address_view.ex:349
msgid "Transactions" msgid "Transactions"

@ -151,7 +151,7 @@ msgid "Anything not in this list is not supported. Click on the method to be tak
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:110 #: lib/block_scout_web/templates/chain/show.html.eex:121
msgid "Average block time" msgid "Average block time"
msgstr "" msgstr ""
@ -236,7 +236,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:165 #: lib/block_scout_web/templates/chain/show.html.eex:176
#: lib/block_scout_web/templates/layout/_topnav.html.eex:34 #: lib/block_scout_web/templates/layout/_topnav.html.eex:34
#: lib/block_scout_web/templates/layout/_topnav.html.eex:38 #: lib/block_scout_web/templates/layout/_topnav.html.eex:38
msgid "Blocks" msgid "Blocks"
@ -1065,7 +1065,7 @@ msgid "More internal transactions have come in"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:226 #: lib/block_scout_web/templates/chain/show.html.eex:237
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:12 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:12
#: lib/block_scout_web/templates/transaction/index.html.eex:18 #: lib/block_scout_web/templates/transaction/index.html.eex:18
msgid "More transactions have come in" msgid "More transactions have come in"
@ -1309,7 +1309,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_transaction/index.html.eex:48 #: lib/block_scout_web/templates/address_transaction/index.html.eex:48
#: lib/block_scout_web/templates/address_validation/index.html.eex:22 #: lib/block_scout_web/templates/address_validation/index.html.eex:22
#: lib/block_scout_web/templates/block_transaction/index.html.eex:23 #: lib/block_scout_web/templates/block_transaction/index.html.eex:23
#: lib/block_scout_web/templates/chain/show.html.eex:169 #: lib/block_scout_web/templates/chain/show.html.eex:180
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:21 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:21
#: lib/block_scout_web/templates/stakes/_table.html.eex:44 #: lib/block_scout_web/templates/stakes/_table.html.eex:44
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:22 #: lib/block_scout_web/templates/tokens/holder/index.html.eex:22
@ -1324,7 +1324,7 @@ msgid "Something went wrong, click to reload."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:232 #: lib/block_scout_web/templates/chain/show.html.eex:243
msgid "Something went wrong, click to retry." msgid "Something went wrong, click to retry."
msgstr "" msgstr ""
@ -1453,7 +1453,7 @@ msgid "Total Supply"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:140 #: lib/block_scout_web/templates/chain/show.html.eex:151
msgid "Total blocks" msgid "Total blocks"
msgstr "" msgstr ""
@ -1593,12 +1593,12 @@ msgid "Version"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:164 #: lib/block_scout_web/templates/chain/show.html.eex:175
msgid "View All Blocks" msgid "View All Blocks"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:222 #: lib/block_scout_web/templates/chain/show.html.eex:233
msgid "View All Transactions" msgid "View All Transactions"
msgstr "" msgstr ""
@ -1640,7 +1640,7 @@ msgid "WEI"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:148 #: lib/block_scout_web/templates/chain/show.html.eex:159
msgid "Wallet addresses" msgid "Wallet addresses"
msgstr "" msgstr ""
@ -1780,7 +1780,7 @@ msgid "Module"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:119 #: lib/block_scout_web/templates/chain/show.html.eex:130
msgid "Total transactions" msgid "Total transactions"
msgstr "" msgstr ""
@ -1867,7 +1867,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_transaction/index.html.eex:15 #: lib/block_scout_web/templates/address_transaction/index.html.eex:15
#: lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/block_transaction/index.html.eex:10
#: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/block_transaction/index.html.eex:18
#: lib/block_scout_web/templates/chain/show.html.eex:223 #: lib/block_scout_web/templates/chain/show.html.eex:234
#: lib/block_scout_web/templates/layout/_topnav.html.eex:53 #: lib/block_scout_web/templates/layout/_topnav.html.eex:53
#: lib/block_scout_web/views/address_view.ex:349 #: lib/block_scout_web/views/address_view.ex:349
msgid "Transactions" msgid "Transactions"

@ -33,7 +33,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
end end
test "use the default subnetwork title when there is no env configured for it" do test "use the default subnetwork title when there is no env configured for it" do
assert LayoutView.subnetwork_title() == "POA Sokol" assert LayoutView.subnetwork_title() == "Sokol"
end end
end end
@ -91,7 +91,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
end end
end end
@supported_chains_pattern ~s([ { "title": "RSK Mainnet", "url": "https://blockscout.com/rsk/mainnet", "other?": true }, { "title": "POA Sokol", "url": "https://blockscout.com/poa/sokol", "test_net?": true }, { "title": "POA Core", "url": "https://blockscout.com/poa/core" }, { "title": "LUKSO L14 testnet", "url": "https://blockscout.com/lukso/l14", "test_net?": true, "hide_in_dropdown?": true } ]) @supported_chains_pattern ~s([ { "title": "RSK", "url": "https://blockscout.com/rsk/mainnet", "other?": true }, { "title": "Sokol", "url": "https://blockscout.com/poa/sokol", "test_net?": true }, { "title": "POA", "url": "https://blockscout.com/poa/core" }, { "title": "LUKSO L14", "url": "https://blockscout.com/lukso/l14", "test_net?": true, "hide_in_dropdown?": true } ])
describe "other_networks/0" do describe "other_networks/0" do
test "get networks list based on env variables" do test "get networks list based on env variables" do
@ -99,16 +99,16 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.other_networks() == [ assert LayoutView.other_networks() == [
%{ %{
title: "POA Core", title: "POA",
url: "https://blockscout.com/poa/core" url: "https://blockscout.com/poa/core"
}, },
%{ %{
title: "RSK Mainnet", title: "RSK",
url: "https://blockscout.com/rsk/mainnet", url: "https://blockscout.com/rsk/mainnet",
other?: true other?: true
}, },
%{ %{
title: "LUKSO L14 testnet", title: "LUKSO L14",
url: "https://blockscout.com/lukso/l14", url: "https://blockscout.com/lukso/l14",
test_net?: true, test_net?: true,
hide_in_dropdown?: true hide_in_dropdown?: true
@ -129,11 +129,11 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.main_nets(LayoutView.other_networks()) == [ assert LayoutView.main_nets(LayoutView.other_networks()) == [
%{ %{
title: "POA Core", title: "POA",
url: "https://blockscout.com/poa/core" url: "https://blockscout.com/poa/core"
}, },
%{ %{
title: "RSK Mainnet", title: "RSK",
url: "https://blockscout.com/rsk/mainnet", url: "https://blockscout.com/rsk/mainnet",
other?: true other?: true
} }
@ -147,7 +147,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.test_nets(LayoutView.other_networks()) == [ assert LayoutView.test_nets(LayoutView.other_networks()) == [
%{ %{
title: "LUKSO L14 testnet", title: "LUKSO L14",
url: "https://blockscout.com/lukso/l14", url: "https://blockscout.com/lukso/l14",
test_net?: true, test_net?: true,
hide_in_dropdown?: true hide_in_dropdown?: true
@ -162,11 +162,11 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.dropdown_nets() == [ assert LayoutView.dropdown_nets() == [
%{ %{
title: "POA Core", title: "POA",
url: "https://blockscout.com/poa/core" url: "https://blockscout.com/poa/core"
}, },
%{ %{
title: "RSK Mainnet", title: "RSK",
url: "https://blockscout.com/rsk/mainnet", url: "https://blockscout.com/rsk/mainnet",
other?: true other?: true
} }
@ -180,7 +180,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.dropdown_head_main_nets() == [ assert LayoutView.dropdown_head_main_nets() == [
%{ %{
title: "POA Core", title: "POA",
url: "https://blockscout.com/poa/core" url: "https://blockscout.com/poa/core"
} }
] ]
@ -193,7 +193,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.dropdown_other_nets() == [ assert LayoutView.dropdown_other_nets() == [
%{ %{
title: "RSK Mainnet", title: "RSK",
url: "https://blockscout.com/rsk/mainnet", url: "https://blockscout.com/rsk/mainnet",
other?: true other?: true
} }

@ -63,7 +63,9 @@ defmodule Explorer.Chain.Transaction.History.Historian do
) )
num_transactions = Repo.aggregate(query, :count, :hash, timeout: :infinity) num_transactions = Repo.aggregate(query, :count, :hash, timeout: :infinity)
records = [%{date: day_to_fetch, number_of_transactions: num_transactions} | records] gas_used = Repo.aggregate(query, :sum, :gas_used, timeout: :infinity)
records = [%{date: day_to_fetch, number_of_transactions: num_transactions, gas_used: gas_used} | records]
compile_records(num_days - 1, records) compile_records(num_days - 1, records)
else else
records = [%{date: day_to_fetch, number_of_transactions: 0} | records] records = [%{date: day_to_fetch, number_of_transactions: 0} | records]

@ -17,16 +17,19 @@ defmodule Explorer.Chain.Transaction.History.TransactionStats do
schema "transaction_stats" do schema "transaction_stats" do
field(:date, :date) field(:date, :date)
field(:number_of_transactions, :integer) field(:number_of_transactions, :integer)
field(:gas_used, :decimal)
end end
@typedoc """ @typedoc """
The recorded values of the number of transactions for a single day. The recorded values of the number of transactions for a single day.
* `:date` - The date in UTC. * `:date` - The date in UTC.
* `:number_of_transactions` - Number of transactions processed by the vm for a given date. * `:number_of_transactions` - Number of transactions processed by the vm for a given date.
* `:gas_used` - Gas used in transactions per single day
""" """
@type t :: %__MODULE__{ @type t :: %__MODULE__{
date: Date.t(), date: Date.t(),
number_of_transactions: integer() number_of_transactions: integer(),
gas_used: non_neg_integer()
} }
@spec by_date_range(Date.t(), Date.t()) :: [__MODULE__] @spec by_date_range(Date.t(), Date.t()) :: [__MODULE__]

@ -0,0 +1,9 @@
defmodule Explorer.Repo.Migrations.TransactionsStatAddGasUsageColumn do
use Ecto.Migration
def change do
alter table(:transaction_stats) do
add(:gas_used, :numeric, precision: 100, null: true)
end
end
end

@ -28,9 +28,9 @@ defmodule Explorer.Chain.Transaction.History.HistorianTest do
insert(:block, timestamp: DateTime.from_unix!(days_to_secs(1))) insert(:block, timestamp: DateTime.from_unix!(days_to_secs(1)))
] ]
insert(:transaction) |> with_block(Enum.at(blocks, 0)) transaction_1 = insert(:transaction) |> with_block(Enum.at(blocks, 0))
insert(:transaction) |> with_block(Enum.at(blocks, 1)) transaction_2 = insert(:transaction) |> with_block(Enum.at(blocks, 1))
insert(:transaction) |> with_block(Enum.at(blocks, 2)) transaction_3 = insert(:transaction) |> with_block(Enum.at(blocks, 2))
expected = [ expected = [
%{date: ~D[1970-01-04], number_of_transactions: 0} %{date: ~D[1970-01-04], number_of_transactions: 0}
@ -38,17 +38,19 @@ defmodule Explorer.Chain.Transaction.History.HistorianTest do
assert {:ok, ^expected} = Historian.compile_records(1) assert {:ok, ^expected} = Historian.compile_records(1)
total_gas_used_1 = Decimal.add(transaction_1.gas_used, transaction_2.gas_used)
expected = [ expected = [
%{date: ~D[1970-01-04], number_of_transactions: 0}, %{date: ~D[1970-01-04], number_of_transactions: 0},
%{date: ~D[1970-01-03], number_of_transactions: 2} %{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2}
] ]
assert {:ok, ^expected} = Historian.compile_records(2) assert {:ok, ^expected} = Historian.compile_records(2)
expected = [ expected = [
%{date: ~D[1970-01-04], number_of_transactions: 0}, %{date: ~D[1970-01-04], number_of_transactions: 0},
%{date: ~D[1970-01-03], number_of_transactions: 2}, %{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2},
%{date: ~D[1970-01-02], number_of_transactions: 1} %{date: ~D[1970-01-02], gas_used: transaction_3.gas_used, number_of_transactions: 1}
] ]
assert {:ok, ^expected} = Historian.compile_records(3) assert {:ok, ^expected} = Historian.compile_records(3)

Loading…
Cancel
Save