Gas usage per day

pull/3398/head
Victor Baranov 4 years ago
parent 98fa8d60ea
commit bd71a822a5
  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
### 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
- [#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

@ -91,7 +91,18 @@
<%= gettext "Tx/day" %>
</span>
<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>
</div>
<% end %>

@ -11,7 +11,7 @@ defmodule BlockScoutWeb.LayoutView do
url: "https://blockscout.com/poa/core"
},
%{
title: "POA Sokol",
title: "Sokol",
url: "https://blockscout.com/poa/sokol",
test_net?: true
},
@ -47,7 +47,7 @@ defmodule BlockScoutWeb.LayoutView do
end
def subnetwork_title do
Keyword.get(application_config(), :subnetwork) || "POA Sokol"
Keyword.get(application_config(), :subnetwork) || "Sokol"
end
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 ""
#, 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"
msgstr ""
@ -236,7 +236,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the
msgstr ""
#, 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:38
msgid "Blocks"
@ -1065,7 +1065,7 @@ msgid "More internal transactions have come in"
msgstr ""
#, 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/transaction/index.html.eex:18
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_validation/index.html.eex:22
#: 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/stakes/_table.html.eex:44
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:22
@ -1324,7 +1324,7 @@ msgid "Something went wrong, click to reload."
msgstr ""
#, 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."
msgstr ""
@ -1453,7 +1453,7 @@ msgid "Total Supply"
msgstr ""
#, 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"
msgstr ""
@ -1593,12 +1593,12 @@ msgid "Version"
msgstr ""
#, 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"
msgstr ""
#, 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"
msgstr ""
@ -1640,7 +1640,7 @@ msgid "WEI"
msgstr ""
#, 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"
msgstr ""
@ -1780,7 +1780,7 @@ msgid "Module"
msgstr ""
#, 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"
msgstr ""
@ -1867,7 +1867,7 @@ msgstr ""
#: 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: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/views/address_view.ex:349
msgid "Transactions"

@ -151,7 +151,7 @@ msgid "Anything not in this list is not supported. Click on the method to be tak
msgstr ""
#, 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"
msgstr ""
@ -236,7 +236,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the
msgstr ""
#, 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:38
msgid "Blocks"
@ -1065,7 +1065,7 @@ msgid "More internal transactions have come in"
msgstr ""
#, 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/transaction/index.html.eex:18
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_validation/index.html.eex:22
#: 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/stakes/_table.html.eex:44
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:22
@ -1324,7 +1324,7 @@ msgid "Something went wrong, click to reload."
msgstr ""
#, 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."
msgstr ""
@ -1453,7 +1453,7 @@ msgid "Total Supply"
msgstr ""
#, 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"
msgstr ""
@ -1593,12 +1593,12 @@ msgid "Version"
msgstr ""
#, 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"
msgstr ""
#, 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"
msgstr ""
@ -1640,7 +1640,7 @@ msgid "WEI"
msgstr ""
#, 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"
msgstr ""
@ -1780,7 +1780,7 @@ msgid "Module"
msgstr ""
#, 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"
msgstr ""
@ -1867,7 +1867,7 @@ msgstr ""
#: 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: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/views/address_view.ex:349
msgid "Transactions"

@ -33,7 +33,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
end
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
@ -91,7 +91,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
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
test "get networks list based on env variables" do
@ -99,16 +99,16 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.other_networks() == [
%{
title: "POA Core",
title: "POA",
url: "https://blockscout.com/poa/core"
},
%{
title: "RSK Mainnet",
title: "RSK",
url: "https://blockscout.com/rsk/mainnet",
other?: true
},
%{
title: "LUKSO L14 testnet",
title: "LUKSO L14",
url: "https://blockscout.com/lukso/l14",
test_net?: true,
hide_in_dropdown?: true
@ -129,11 +129,11 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.main_nets(LayoutView.other_networks()) == [
%{
title: "POA Core",
title: "POA",
url: "https://blockscout.com/poa/core"
},
%{
title: "RSK Mainnet",
title: "RSK",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}
@ -147,7 +147,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.test_nets(LayoutView.other_networks()) == [
%{
title: "LUKSO L14 testnet",
title: "LUKSO L14",
url: "https://blockscout.com/lukso/l14",
test_net?: true,
hide_in_dropdown?: true
@ -162,11 +162,11 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.dropdown_nets() == [
%{
title: "POA Core",
title: "POA",
url: "https://blockscout.com/poa/core"
},
%{
title: "RSK Mainnet",
title: "RSK",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}
@ -180,7 +180,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.dropdown_head_main_nets() == [
%{
title: "POA Core",
title: "POA",
url: "https://blockscout.com/poa/core"
}
]
@ -193,7 +193,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
assert LayoutView.dropdown_other_nets() == [
%{
title: "RSK Mainnet",
title: "RSK",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}

@ -63,7 +63,9 @@ defmodule Explorer.Chain.Transaction.History.Historian do
)
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)
else
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
field(:date, :date)
field(:number_of_transactions, :integer)
field(:gas_used, :decimal)
end
@typedoc """
The recorded values of the number of transactions for a single day.
* `:date` - The date in UTC.
* `: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__{
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__]

@ -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(:transaction) |> with_block(Enum.at(blocks, 0))
insert(:transaction) |> with_block(Enum.at(blocks, 1))
insert(:transaction) |> with_block(Enum.at(blocks, 2))
transaction_1 = insert(:transaction) |> with_block(Enum.at(blocks, 0))
transaction_2 = insert(:transaction) |> with_block(Enum.at(blocks, 1))
transaction_3 = insert(:transaction) |> with_block(Enum.at(blocks, 2))
expected = [
%{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)
total_gas_used_1 = Decimal.add(transaction_1.gas_used, transaction_2.gas_used)
expected = [
%{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)
expected = [
%{date: ~D[1970-01-04], number_of_transactions: 0},
%{date: ~D[1970-01-03], number_of_transactions: 2},
%{date: ~D[1970-01-02], number_of_transactions: 1}
%{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2},
%{date: ~D[1970-01-02], gas_used: transaction_3.gas_used, number_of_transactions: 1}
]
assert {:ok, ^expected} = Historian.compile_records(3)

Loading…
Cancel
Save