Rename burnt_fee_counter to total_gas_used

pull/8846/head
Viktor Baranov 11 months ago
parent 9ed2e7958c
commit 21e2f46aa6
  1. 2
      .dialyzer-ignore
  2. 1
      CHANGELOG.md
  3. 4
      apps/block_scout_web/lib/block_scout_web/templates/block/_tile.html.eex
  4. 8
      apps/block_scout_web/lib/block_scout_web/templates/block/overview.html.eex
  5. 14
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  6. 2
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  7. 4
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex
  8. 16
      apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex
  9. 6
      apps/block_scout_web/lib/block_scout_web/views/api/v2/transaction_view.ex
  10. 6
      apps/block_scout_web/lib/block_scout_web/views/wei_helper.ex
  11. 30
      apps/block_scout_web/priv/gettext/default.pot
  12. 30
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  13. 63
      apps/explorer/lib/explorer/chain.ex
  14. 84
      apps/explorer/lib/explorer/chain/block.ex
  15. 9
      apps/explorer/lib/explorer/chain/wei.ex
  16. 2
      apps/explorer/lib/explorer/counters/block_burned_fee_counter.ex
  17. 44
      apps/explorer/test/explorer/chain/block_test.exs
  18. 42
      apps/explorer/test/explorer/chain_test.exs
  19. 6
      apps/indexer/lib/indexer/block/fetcher.ex

@ -24,5 +24,3 @@ lib/indexer/fetcher/zkevm/transaction_batch.ex:252
lib/block_scout_web/views/api/v2/transaction_view.ex:431
lib/block_scout_web/views/api/v2/transaction_view.ex:472
lib/explorer/chain/transaction.ex:167
lib/explorer/chain/transaction.ex:1452
lib/explorer/chain/transaction.ex:1453

@ -9,6 +9,7 @@
### Fixes
- [#8955](https://github.com/blockscout/blockscout/pull/8955) - Remove daily balances updating from BlockReward fetcher
- [#8846](https://github.com/blockscout/blockscout/pull/8846) - Handle nil gas_price at address view
### Chore

@ -1,4 +1,4 @@
<% burned_fee = if !is_nil(@block.base_fee_per_gas), do: Wei.mult(@block.base_fee_per_gas, BlockBurnedFeeCounter.fetch(@block.hash)), else: nil %>
<% burnt_fees = if !is_nil(@block.base_fee_per_gas), do: Wei.mult(@block.base_fee_per_gas, BlockBurnedFeeCounter.fetch(@block.hash)), else: nil %>
<% priority_fee = if !is_nil(@block.base_fee_per_gas), do: BlockPriorityFeeCounter.fetch(@block.hash), else: nil %>
<div class="tile tile-type-<%= String.downcase(@block_type) %> fade-up" data-selector="block-tile" data-block-number="<%= to_string(@block.number) %>" data-block-hash="<%= @block.hash %>">
<div class="row">
@ -61,7 +61,7 @@
<!-- Priority Fee -->
<span> <%= format_wei_value(%Wei{value: priority_fee}, :ether) %> <%= gettext "Priority Fees" %> </span>
<!-- Burnt Fees -->
<span> <%= format_wei_value(burned_fee, :ether) %> <%= gettext "Burnt Fees" %> </span>
<span> <%= format_wei_value(burnt_fees, :ether) %> <%= gettext "Burnt Fees" %> </span>
<% end %>
<!-- Gas Limit -->
<span> <%= formatted_gas(@block.gas_limit) %> <%= gettext "Gas Limit" %> </span>

@ -1,4 +1,4 @@
<% burned_fee = if !is_nil(@block.base_fee_per_gas), do: Wei.mult(@block.base_fee_per_gas, BlockBurnedFeeCounter.fetch(@block.hash)), else: nil %>
<% burnt_fees = if !is_nil(@block.base_fee_per_gas), do: Wei.mult(@block.base_fee_per_gas, BlockBurnedFeeCounter.fetch(@block.hash)), else: nil %>
<% priority_fee = if !is_nil(@block.base_fee_per_gas), do: BlockPriorityFeeCounter.fetch(@block.hash), else: nil %>
<section>
<%= render BlockScoutWeb.Advertisement.TextAdView, "index.html", conn: @conn %>
@ -215,7 +215,7 @@
text: Explorer.coin_name() <> " " <> gettext("burned from transactions included in the block (Base fee (per unit of gas) * Gas Used).") %>
<%= gettext("Burnt Fees") %>
</dt>
<dd class="col-sm-9 col-lg-10"><i class="fa-solid fa-fire i-tooltip-2"></i> <%= format_wei_value(burned_fee, :ether) %></dd>
<dd class="col-sm-9 col-lg-10"><i class="fa-solid fa-fire i-tooltip-2"></i> <%= format_wei_value(burnt_fees, :ether) %></dd>
</dl>
<!-- Priority Fee / Tip -->
<dl class="row">
@ -226,7 +226,7 @@
</dt>
<dd class="col-sm-9 col-lg-10"><%= format_wei_value(%Wei{value: priority_fee}, :ether) %></dd>
</dl>
<% end %>
<% end %>
<%= if show_reward?(@block.rewards) do %>
<hr>
<%= for block_reward <- @block.rewards do %>
@ -268,4 +268,4 @@
</div>
</section>
<%= render BlockScoutWeb.Advertisement.BannersAdView, "_banner_728.html", conn: @conn %>
<%= render BlockScoutWeb.Advertisement.BannersAdView, "_banner_728.html", conn: @conn %>

@ -7,7 +7,7 @@
<% base_fee_per_gas = if block, do: block.base_fee_per_gas, else: nil %>
<% max_priority_fee_per_gas = @transaction.max_priority_fee_per_gas %>
<% max_fee_per_gas = @transaction.max_fee_per_gas %>
<% burned_fee =
<% burnt_fees =
if !is_nil(max_fee_per_gas) and !is_nil(@transaction.gas_used) and !is_nil(base_fee_per_gas) do
if Decimal.compare(max_fee_per_gas.value, 0) == :eq do
%Wei{value: Decimal.new(0)}
@ -17,7 +17,7 @@
else
nil
end %>
<% %Wei{value: burned_fee_decimal} = if is_nil(burned_fee), do: %Wei{value: Decimal.new(0)}, else: burned_fee %>
<% %Wei{value: burnt_fee_decimal} = if is_nil(burnt_fees), do: %Wei{value: Decimal.new(0)}, else: burnt_fees %>
<% priority_fee_per_gas = if is_nil(max_priority_fee_per_gas) or is_nil(base_fee_per_gas), do: nil, else: Enum.min_by([max_priority_fee_per_gas, Wei.sub(max_fee_per_gas, base_fee_per_gas)], fn x -> Wei.to(x, :wei) end) %>
<% priority_fee = if is_nil(priority_fee_per_gas), do: nil, else: Wei.mult(priority_fee_per_gas, @transaction.gas_used) %>
<% decoded_input_data = decoded_input_data(@transaction) %>
@ -122,7 +122,7 @@
<% true -> %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: formatted_status, additional_classes: ["success", "large"] %></span>
<% end %>
<%= if confirmations > 0 do %>
<span class="bs-label large ml-2 confirmations-label"><%= gettext "Confirmed by " %><span data-selector="block-confirmations"><%= confirmations %></span><%= " " <> confirmations_ds_name(confirmations) %></span>
<% end %>
@ -429,17 +429,17 @@
</dt>
<dd class="col-sm-9 col-lg-10"> <%= format_wei_value(priority_fee, :ether) %> </dd>
</dl>
<% end %>
<%= if !is_nil(burned_fee) do %>
<% end %>
<%= if !is_nil(burnt_fees) do %>
<dl class="row">
<dt class="col-sm-3 col-lg-2 text-muted">
<%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
text: gettext("Amount of") <> " " <> Explorer.coin_name() <> " " <> gettext("burned for this transaction. Equals Block Base Fee per Gas * Gas Used.") %>
<%= gettext "Transaction Burnt Fee" %>
</dt>
<dd class="col-sm-9 col-lg-10"><i class="fa-solid fa-fire i-tooltip-2"></i> <%= format_wei_value(burned_fee, :ether) %>
<dd class="col-sm-9 col-lg-10"><i class="fa-solid fa-fire i-tooltip-2"></i> <%= format_wei_value(burnt_fees, :ether) %>
<%= unless empty_exchange_rate?(@exchange_rate) do %>
(<span data-wei-value=<%= burned_fee_decimal %> data-usd-exchange-rate=<%= @exchange_rate.usd_value %>></span>)
(<span data-wei-value=<%= burnt_fee_decimal %> data-usd-exchange-rate=<%= @exchange_rate.usd_value %>></span>)
<% end %>
</dd>
</dl>

@ -334,6 +334,8 @@ defmodule BlockScoutWeb.AddressView do
end
end
defp matching_address_check(nil, nil, _contract?, _truncate), do: nil
defp matching_address_check(%Address{hash: hash} = current_address, %Address{hash: hash}, contract?, truncate) do
[
view_module: __MODULE__,

@ -113,7 +113,7 @@ defmodule BlockScoutWeb.API.RPC.AddressView do
"to" => "#{transaction.to_address_hash}",
"value" => "#{transaction.value.value}",
"gas" => "#{transaction.gas}",
"gasPrice" => "#{transaction.gas_price.value}",
"gasPrice" => "#{transaction.gas_price && transaction.gas_price.value}",
"isError" => if(transaction.status == :ok, do: "0", else: "1"),
"txreceipt_status" => if(transaction.status == :ok, do: "1", else: "0"),
"input" => "#{transaction.input}",
@ -160,7 +160,7 @@ defmodule BlockScoutWeb.API.RPC.AddressView do
"tokenDecimal" => to_string(token_transfer.token_decimals),
"transactionIndex" => to_string(token_transfer.transaction_index),
"gas" => to_string(token_transfer.transaction_gas),
"gasPrice" => to_string(token_transfer.transaction_gas_price.value),
"gasPrice" => to_string(token_transfer.transaction_gas_price && token_transfer.transaction_gas_price.value),
"gasUsed" => to_string(token_transfer.transaction_gas_used),
"cumulativeGasUsed" => to_string(token_transfer.transaction_cumulative_gas_used),
"input" => to_string(token_transfer.transaction_input),

@ -3,7 +3,6 @@ defmodule BlockScoutWeb.API.V2.BlockView do
alias BlockScoutWeb.BlockView
alias BlockScoutWeb.API.V2.{ApiView, Helper}
alias Explorer.Chain
alias Explorer.Chain.Block
alias Explorer.Counters.BlockPriorityFeeCounter
@ -29,10 +28,10 @@ defmodule BlockScoutWeb.API.V2.BlockView do
end
def prepare_block(block, _conn, single_block? \\ false) do
burned_fee = Chain.burned_fees(block.transactions, block.base_fee_per_gas)
burnt_fees = Block.burnt_fees(block.transactions, block.base_fee_per_gas)
priority_fee = block.base_fee_per_gas && BlockPriorityFeeCounter.fetch(block.hash)
tx_fees = Chain.txn_fees(block.transactions)
transaction_fees = Block.transaction_fees(block.transactions)
%{
"height" => block.number,
@ -48,7 +47,7 @@ defmodule BlockScoutWeb.API.V2.BlockView do
"gas_limit" => block.gas_limit,
"nonce" => block.nonce,
"base_fee_per_gas" => block.base_fee_per_gas,
"burnt_fees" => burned_fee,
"burnt_fees" => burnt_fees,
"priority_fee" => priority_fee,
# "extra_data" => "TODO",
"uncles_hashes" => prepare_uncles(block.uncle_relations),
@ -56,9 +55,9 @@ defmodule BlockScoutWeb.API.V2.BlockView do
"rewards" => prepare_rewards(block.rewards, block, single_block?),
"gas_target_percentage" => gas_target(block),
"gas_used_percentage" => gas_used_percentage(block),
"burnt_fees_percentage" => burnt_fees_percentage(burned_fee, tx_fees),
"burnt_fees_percentage" => burnt_fees_percentage(burnt_fees, transaction_fees),
"type" => block |> BlockView.block_type() |> String.downcase(),
"tx_fees" => tx_fees,
"tx_fees" => transaction_fees,
"withdrawals_count" => count_withdrawals(block)
}
|> chain_type_fields(block, single_block?)
@ -105,8 +104,9 @@ defmodule BlockScoutWeb.API.V2.BlockView do
def burnt_fees_percentage(_, %Decimal{coef: 0}), do: nil
def burnt_fees_percentage(burnt_fees, tx_fees) when not is_nil(tx_fees) and not is_nil(burnt_fees) do
burnt_fees.value |> Decimal.div(tx_fees) |> Decimal.mult(100) |> Decimal.to_float()
def burnt_fees_percentage(burnt_fees, transaction_fees)
when not is_nil(transaction_fees) and not is_nil(burnt_fees) do
burnt_fees.value |> Decimal.div(transaction_fees) |> Decimal.mult(100) |> Decimal.to_float()
end
def burnt_fees_percentage(_, _), do: nil

@ -359,7 +359,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
priority_fee_per_gas = priority_fee_per_gas(max_priority_fee_per_gas, base_fee_per_gas, max_fee_per_gas)
burned_fee = burned_fee(transaction, max_fee_per_gas, base_fee_per_gas)
burnt_fees = burnt_fees(transaction, max_fee_per_gas, base_fee_per_gas)
status = transaction |> Chain.transaction_to_status() |> format_status()
@ -409,7 +409,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
"max_priority_fee_per_gas" => transaction.max_priority_fee_per_gas,
"base_fee_per_gas" => base_fee_per_gas,
"priority_fee" => priority_fee_per_gas && Wei.mult(priority_fee_per_gas, transaction.gas_used),
"tx_burnt_fee" => burned_fee,
"tx_burnt_fee" => burnt_fees,
"nonce" => transaction.nonce,
"position" => transaction.index,
"revert_reason" => revert_reason,
@ -595,7 +595,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
end)
end
defp burned_fee(transaction, max_fee_per_gas, base_fee_per_gas) do
defp burnt_fees(transaction, max_fee_per_gas, base_fee_per_gas) do
if !is_nil(max_fee_per_gas) and !is_nil(transaction.gas_used) and !is_nil(base_fee_per_gas) do
if Decimal.compare(max_fee_per_gas.value, 0) == :eq do
%Wei{value: Decimal.new(0)}

@ -53,7 +53,11 @@ defmodule BlockScoutWeb.WeiHelper do
"10"
"""
@spec format_wei_value(Wei.t(), Wei.unit(), format_options()) :: String.t()
def format_wei_value(%Wei{} = wei, unit, options \\ []) when unit in @valid_units do
def format_wei_value(_wei, _unit, _options \\ [])
def format_wei_value(nil, _unit, _options), do: nil
def format_wei_value(%Wei{} = wei, unit, options) when unit in @valid_units do
converted_value =
wei
|> Wei.to(unit)

@ -556,7 +556,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:56
#: lib/block_scout_web/templates/address/overview.html.eex:275
#: lib/block_scout_web/templates/address_validation/index.html.eex:11
#: lib/block_scout_web/views/address_view.ex:386
#: lib/block_scout_web/views/address_view.ex:388
#, elixir-autogen, elixir-format
msgid "Blocks Validated"
msgstr ""
@ -656,13 +656,13 @@ msgstr ""
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187
#: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126
#: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149
#: lib/block_scout_web/views/address_view.ex:379
#: lib/block_scout_web/views/address_view.ex:381
#, elixir-autogen, elixir-format
msgid "Code"
msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:42
#: lib/block_scout_web/views/address_view.ex:385
#: lib/block_scout_web/views/address_view.ex:387
#, elixir-autogen, elixir-format
msgid "Coin Balance History"
msgstr ""
@ -1084,7 +1084,7 @@ msgstr ""
msgid "Decoded"
msgstr ""
#: lib/block_scout_web/views/address_view.ex:380
#: lib/block_scout_web/views/address_view.ex:382
#, elixir-autogen, elixir-format
msgid "Decompiled Code"
msgstr ""
@ -1485,7 +1485,7 @@ msgstr ""
#: lib/block_scout_web/templates/chain/gas_price_oracle_legend_item.html.eex:22
#: lib/block_scout_web/templates/chain/gas_price_oracle_legend_item.html.eex:38
#: lib/block_scout_web/views/block_view.ex:22
#: lib/block_scout_web/views/wei_helper.ex:77
#: lib/block_scout_web/views/wei_helper.ex:81
#, elixir-autogen, elixir-format
msgid "Gwei"
msgstr ""
@ -1601,7 +1601,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:17
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:11
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6
#: lib/block_scout_web/views/address_view.ex:376
#: lib/block_scout_web/views/address_view.ex:378
#: lib/block_scout_web/views/transaction_view.ex:533
#, elixir-autogen, elixir-format
msgid "Internal Transactions"
@ -1718,7 +1718,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/index.html.eex:10
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:17
#: lib/block_scout_web/templates/transaction_log/index.html.eex:8
#: lib/block_scout_web/views/address_view.ex:387
#: lib/block_scout_web/views/address_view.ex:389
#: lib/block_scout_web/views/transaction_view.ex:534
#, elixir-autogen, elixir-format
msgid "Logs"
@ -2208,7 +2208,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:89
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27
#: lib/block_scout_web/views/address_view.ex:381
#: lib/block_scout_web/views/address_view.ex:383
#: lib/block_scout_web/views/tokens/overview_view.ex:42
#, elixir-autogen, elixir-format
msgid "Read Contract"
@ -2216,7 +2216,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:96
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41
#: lib/block_scout_web/views/address_view.ex:382
#: lib/block_scout_web/views/address_view.ex:384
#, elixir-autogen, elixir-format
msgid "Read Proxy"
msgstr ""
@ -2903,7 +2903,7 @@ msgstr ""
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:15
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:378
#: lib/block_scout_web/views/address_view.ex:380
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:114
#: lib/block_scout_web/views/tokens/overview_view.ex:40
#: lib/block_scout_web/views/transaction_view.ex:532
@ -2927,7 +2927,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:13
#: lib/block_scout_web/templates/layout/_topnav.html.eex:84
#: lib/block_scout_web/templates/tokens/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:375
#: lib/block_scout_web/views/address_view.ex:377
#, elixir-autogen, elixir-format
msgid "Tokens"
msgstr ""
@ -3100,7 +3100,7 @@ msgstr ""
#: lib/block_scout_web/templates/block/overview.html.eex:80
#: lib/block_scout_web/templates/chain/show.html.eex:214
#: lib/block_scout_web/templates/layout/_topnav.html.eex:49
#: lib/block_scout_web/views/address_view.ex:377
#: lib/block_scout_web/views/address_view.ex:379
#, elixir-autogen, elixir-format
msgid "Transactions"
msgstr ""
@ -3444,7 +3444,7 @@ msgstr ""
msgid "We recommend using flattened code. This is necessary if your code utilizes a library or inherits dependencies. Use the"
msgstr ""
#: lib/block_scout_web/views/wei_helper.ex:76
#: lib/block_scout_web/views/wei_helper.ex:80
#, elixir-autogen, elixir-format
msgid "Wei"
msgstr ""
@ -3465,14 +3465,14 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:103
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34
#: lib/block_scout_web/views/address_view.ex:383
#: lib/block_scout_web/views/address_view.ex:385
#, elixir-autogen, elixir-format
msgid "Write Contract"
msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:110
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48
#: lib/block_scout_web/views/address_view.ex:384
#: lib/block_scout_web/views/address_view.ex:386
#, elixir-autogen, elixir-format
msgid "Write Proxy"
msgstr ""

@ -556,7 +556,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:56
#: lib/block_scout_web/templates/address/overview.html.eex:275
#: lib/block_scout_web/templates/address_validation/index.html.eex:11
#: lib/block_scout_web/views/address_view.ex:386
#: lib/block_scout_web/views/address_view.ex:388
#, elixir-autogen, elixir-format
msgid "Blocks Validated"
msgstr ""
@ -656,13 +656,13 @@ msgstr ""
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187
#: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126
#: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149
#: lib/block_scout_web/views/address_view.ex:379
#: lib/block_scout_web/views/address_view.ex:381
#, elixir-autogen, elixir-format
msgid "Code"
msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:42
#: lib/block_scout_web/views/address_view.ex:385
#: lib/block_scout_web/views/address_view.ex:387
#, elixir-autogen, elixir-format
msgid "Coin Balance History"
msgstr ""
@ -1084,7 +1084,7 @@ msgstr ""
msgid "Decoded"
msgstr ""
#: lib/block_scout_web/views/address_view.ex:380
#: lib/block_scout_web/views/address_view.ex:382
#, elixir-autogen, elixir-format
msgid "Decompiled Code"
msgstr ""
@ -1485,7 +1485,7 @@ msgstr ""
#: lib/block_scout_web/templates/chain/gas_price_oracle_legend_item.html.eex:22
#: lib/block_scout_web/templates/chain/gas_price_oracle_legend_item.html.eex:38
#: lib/block_scout_web/views/block_view.ex:22
#: lib/block_scout_web/views/wei_helper.ex:77
#: lib/block_scout_web/views/wei_helper.ex:81
#, elixir-autogen, elixir-format
msgid "Gwei"
msgstr ""
@ -1601,7 +1601,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:17
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:11
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6
#: lib/block_scout_web/views/address_view.ex:376
#: lib/block_scout_web/views/address_view.ex:378
#: lib/block_scout_web/views/transaction_view.ex:533
#, elixir-autogen, elixir-format
msgid "Internal Transactions"
@ -1718,7 +1718,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/index.html.eex:10
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:17
#: lib/block_scout_web/templates/transaction_log/index.html.eex:8
#: lib/block_scout_web/views/address_view.ex:387
#: lib/block_scout_web/views/address_view.ex:389
#: lib/block_scout_web/views/transaction_view.ex:534
#, elixir-autogen, elixir-format
msgid "Logs"
@ -2208,7 +2208,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:89
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27
#: lib/block_scout_web/views/address_view.ex:381
#: lib/block_scout_web/views/address_view.ex:383
#: lib/block_scout_web/views/tokens/overview_view.ex:42
#, elixir-autogen, elixir-format
msgid "Read Contract"
@ -2216,7 +2216,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:96
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41
#: lib/block_scout_web/views/address_view.ex:382
#: lib/block_scout_web/views/address_view.ex:384
#, elixir-autogen, elixir-format
msgid "Read Proxy"
msgstr ""
@ -2903,7 +2903,7 @@ msgstr ""
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:15
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:378
#: lib/block_scout_web/views/address_view.ex:380
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:114
#: lib/block_scout_web/views/tokens/overview_view.ex:40
#: lib/block_scout_web/views/transaction_view.ex:532
@ -2927,7 +2927,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:13
#: lib/block_scout_web/templates/layout/_topnav.html.eex:84
#: lib/block_scout_web/templates/tokens/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:375
#: lib/block_scout_web/views/address_view.ex:377
#, elixir-autogen, elixir-format
msgid "Tokens"
msgstr ""
@ -3100,7 +3100,7 @@ msgstr ""
#: lib/block_scout_web/templates/block/overview.html.eex:80
#: lib/block_scout_web/templates/chain/show.html.eex:214
#: lib/block_scout_web/templates/layout/_topnav.html.eex:49
#: lib/block_scout_web/views/address_view.ex:377
#: lib/block_scout_web/views/address_view.ex:379
#, elixir-autogen, elixir-format
msgid "Transactions"
msgstr ""
@ -3444,7 +3444,7 @@ msgstr ""
msgid "We recommend using flattened code. This is necessary if your code utilizes a library or inherits dependencies. Use the"
msgstr ""
#: lib/block_scout_web/views/wei_helper.ex:76
#: lib/block_scout_web/views/wei_helper.ex:80
#, elixir-autogen, elixir-format
msgid "Wei"
msgstr ""
@ -3465,14 +3465,14 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:103
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34
#: lib/block_scout_web/views/address_view.ex:383
#: lib/block_scout_web/views/address_view.ex:385
#, elixir-autogen, elixir-format
msgid "Write Contract"
msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:110
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48
#: lib/block_scout_web/views/address_view.ex:384
#: lib/block_scout_web/views/address_view.ex:386
#, elixir-autogen, elixir-format
msgid "Write Proxy"
msgstr ""

@ -512,65 +512,6 @@ defmodule Explorer.Chain do
end
end
def txn_fees(transactions) do
Enum.reduce(transactions, Decimal.new(0), fn %{gas_used: gas_used, gas_price: gas_price}, acc ->
gas_used
|> Decimal.new()
|> Decimal.mult(gas_price_to_decimal(gas_price))
|> Decimal.add(acc)
end)
end
defp gas_price_to_decimal(%Wei{} = wei), do: wei.value
defp gas_price_to_decimal(gas_price), do: Decimal.new(gas_price)
def burned_fees(transactions, base_fee_per_gas) do
burned_fee_counter =
transactions
|> Enum.reduce(Decimal.new(0), fn %{gas_used: gas_used}, acc ->
gas_used
|> Decimal.new()
|> Decimal.add(acc)
end)
base_fee_per_gas && Wei.mult(base_fee_per_gas_to_wei(base_fee_per_gas), burned_fee_counter)
end
defp base_fee_per_gas_to_wei(%Wei{} = wei), do: wei
defp base_fee_per_gas_to_wei(base_fee_per_gas), do: %Wei{value: Decimal.new(base_fee_per_gas)}
@uncle_reward_coef 1 / 32
def block_reward_by_parts(block, transactions) do
%{hash: block_hash, number: block_number} = block
base_fee_per_gas = Map.get(block, :base_fee_per_gas)
txn_fees = txn_fees(transactions)
static_reward =
Repo.one(
from(
er in EmissionReward,
where: fragment("int8range(?, ?) <@ ?", ^block_number, ^(block_number + 1), er.block_range),
select: er.reward
)
) || %Wei{value: Decimal.new(0)}
has_uncles? = is_list(block.uncles) and not Enum.empty?(block.uncles)
burned_fees = burned_fees(transactions, base_fee_per_gas)
uncle_reward = (has_uncles? && Wei.mult(static_reward, Decimal.from_float(@uncle_reward_coef))) || nil
%{
block_number: block_number,
block_hash: block_hash,
miner_hash: block.miner_hash,
static_reward: static_reward,
txn_fees: %Wei{value: txn_fees},
burned_fees: burned_fees || %Wei{value: Decimal.new(0)},
uncle_reward: uncle_reward || %Wei{value: Decimal.new(0)}
}
end
@doc """
The `t:Explorer.Chain.Wei.t/0` paid to the miners of the `t:Explorer.Chain.Block.t/0`s with `hash`
`Explorer.Chain.Hash.Full.t/0` by the signers of the transactions in those blocks to cover the gas fee
@ -937,6 +878,8 @@ defmodule Explorer.Chain do
"""
@spec fee(Transaction.t(), :ether | :gwei | :wei) :: {:maximum, Decimal.t()} | {:actual, Decimal.t()}
def fee(%Transaction{gas: _gas, gas_price: nil, gas_used: nil}, _unit), do: {:maximum, nil}
def fee(%Transaction{gas: gas, gas_price: gas_price, gas_used: nil}, unit) do
fee =
gas_price
@ -946,6 +889,8 @@ defmodule Explorer.Chain do
{:maximum, fee}
end
def fee(%Transaction{gas_price: nil, gas_used: _gas_used}, _unit), do: {:actual, nil}
def fee(%Transaction{gas_price: gas_price, gas_used: gas_used}, unit) do
fee =
gas_price

@ -8,7 +8,8 @@ defmodule Explorer.Chain.Block do
use Explorer.Schema
alias Explorer.Chain.{Address, Block, Gas, Hash, PendingBlockOperation, Transaction, Wei, Withdrawal}
alias Explorer.Chain.Block.{Reward, SecondDegreeRelation}
alias Explorer.Chain.Block.{EmissionReward, Reward, SecondDegreeRelation}
alias Explorer.Repo
@optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas)a
|> (&(case Application.compile_env(:explorer, :chain_type) do
@ -219,4 +220,85 @@ defmodule Explorer.Chain.Block do
order_by: [desc: block.number]
)
end
@doc """
Calculates transaction fees (gas price * gas used) for the list of transactions (from a single block)
"""
@spec transaction_fees(list()) :: Decimal.t()
def transaction_fees(transactions) do
Enum.reduce(transactions, Decimal.new(0), fn %{gas_used: gas_used, gas_price: gas_price}, acc ->
if gas_price do
gas_used
|> Decimal.new()
|> Decimal.mult(gas_price_to_decimal(gas_price))
|> Decimal.add(acc)
else
acc
end
end)
end
defp gas_price_to_decimal(nil), do: nil
defp gas_price_to_decimal(%Wei{} = wei), do: wei.value
defp gas_price_to_decimal(gas_price), do: Decimal.new(gas_price)
@doc """
Calculates burnt fees for the list of transactions (from a single block)
"""
@spec burnt_fees(list(), Wei.t()) :: Wei.t() | nil
def burnt_fees(transactions, base_fee_per_gas) do
total_gas_used =
transactions
|> Enum.reduce(Decimal.new(0), fn %{gas_used: gas_used}, acc ->
gas_used
|> Decimal.new()
|> Decimal.add(acc)
end)
base_fee_per_gas && Wei.mult(base_fee_per_gas_to_wei(base_fee_per_gas), total_gas_used)
end
defp base_fee_per_gas_to_wei(%Wei{} = wei), do: wei
defp base_fee_per_gas_to_wei(base_fee_per_gas), do: %Wei{value: Decimal.new(base_fee_per_gas)}
@uncle_reward_coef 1 / 32
@spec block_reward_by_parts(Block.t(), list()) :: %{
block_number: block_number(),
block_hash: Hash.Full.t(),
miner_hash: Hash.Address.t(),
static_reward: any(),
transaction_fees: any(),
burnt_fees: Wei.t() | nil,
uncle_reward: Wei.t() | nil | false
}
def block_reward_by_parts(block, transactions) do
%{hash: block_hash, number: block_number} = block
base_fee_per_gas = Map.get(block, :base_fee_per_gas)
transaction_fees = transaction_fees(transactions)
static_reward =
Repo.one(
from(
er in EmissionReward,
where: fragment("int8range(?, ?) <@ ?", ^block_number, ^(block_number + 1), er.block_range),
select: er.reward
)
) || %Wei{value: Decimal.new(0)}
has_uncles? = is_list(block.uncles) and not Enum.empty?(block.uncles)
burnt_fees = burnt_fees(transactions, base_fee_per_gas)
uncle_reward = (has_uncles? && Wei.mult(static_reward, Decimal.from_float(@uncle_reward_coef))) || nil
%{
block_number: block_number,
block_hash: block_hash,
miner_hash: block.miner_hash,
static_reward: static_reward,
transaction_fees: %Wei{value: transaction_fees},
burnt_fees: burnt_fees || %Wei{value: Decimal.new(0)},
uncle_reward: uncle_reward || %Wei{value: Decimal.new(0)}
}
end
end

@ -139,6 +139,11 @@ defmodule Explorer.Chain.Wei do
%Explorer.Chain.Wei{value: Decimal.new(1_123)}
"""
@spec sum(Wei.t(), Wei.t()) :: Wei.t()
def sum(%Wei{value: wei_1}, %Wei{value: nil}) do
wei_1
|> from(:wei)
end
def sum(%Wei{value: wei_1}, %Wei{value: wei_2}) do
wei_1
|> Decimal.add(wei_2)
@ -207,6 +212,10 @@ defmodule Explorer.Chain.Wei do
"""
@spec from(ether(), :ether) :: t()
def from(nil, :ether), do: nil
def from(nil, :wei), do: nil
def from(nil, :gwei), do: nil
def from(%Decimal{} = ether, :ether) do
%__MODULE__{value: Decimal.mult(ether, @wei_per_ether)}
end

@ -7,7 +7,7 @@ defmodule Explorer.Counters.BlockBurnedFeeCounter do
alias Explorer.Chain
alias Explorer.Counters.Helper
@cache_name :block_burned_fee_counter
@cache_name :block_burnt_fee_counter
config = Application.compile_env(:explorer, Explorer.Counters.BlockBurnedFeeCounter)
@enable_consolidation Keyword.get(config, :enable_consolidation)

@ -2,7 +2,7 @@ defmodule Explorer.Chain.BlockTest do
use Explorer.DataCase
alias Ecto.Changeset
alias Explorer.Chain.Block
alias Explorer.Chain.{Block, Wei}
describe "changeset/2" do
test "with valid attributes" do
@ -58,4 +58,46 @@ defmodule Explorer.Chain.BlockTest do
assert Enum.member?(results, unrewarded_block.hash)
end
end
describe "block_reward_by_parts/1" do
setup do
{:ok, emission_reward: insert(:emission_reward)}
end
test "without uncles", %{emission_reward: %{reward: reward, block_range: range}} do
block = build(:block, number: range.from, base_fee_per_gas: 5, uncles: [])
tx1 = build(:transaction, gas_price: 1, gas_used: 1, block_number: block.number, block_hash: block.hash)
tx2 = build(:transaction, gas_price: 1, gas_used: 2, block_number: block.number, block_hash: block.hash)
tx3 =
build(:transaction,
gas_price: 1,
gas_used: 3,
block_number: block.number,
block_hash: block.hash,
max_priority_fee_per_gas: 1
)
expected_transaction_fees = %Wei{value: Decimal.new(6)}
expected_burnt_fees = %Wei{value: Decimal.new(30)}
expected_uncle_reward = %Wei{value: Decimal.new(0)}
assert %{
static_reward: ^reward,
transaction_fees: ^expected_transaction_fees,
burnt_fees: ^expected_burnt_fees,
uncle_reward: ^expected_uncle_reward
} = Block.block_reward_by_parts(block, [tx1, tx2, tx3])
end
test "with uncles", %{emission_reward: %{reward: reward, block_range: range}} do
block =
build(:block, number: range.from, uncles: ["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273311"])
expected_uncle_reward = Wei.mult(reward, Decimal.from_float(1 / 32))
assert %{uncle_reward: ^expected_uncle_reward} = Block.block_reward_by_parts(block, [])
end
end
end

@ -3133,48 +3133,6 @@ defmodule Explorer.ChainTest do
end
end
describe "block_reward_by_parts/1" do
setup do
{:ok, emission_reward: insert(:emission_reward)}
end
test "without uncles", %{emission_reward: %{reward: reward, block_range: range}} do
block = build(:block, number: range.from, base_fee_per_gas: 5, uncles: [])
tx1 = build(:transaction, gas_price: 1, gas_used: 1, block_number: block.number, block_hash: block.hash)
tx2 = build(:transaction, gas_price: 1, gas_used: 2, block_number: block.number, block_hash: block.hash)
tx3 =
build(:transaction,
gas_price: 1,
gas_used: 3,
block_number: block.number,
block_hash: block.hash,
max_priority_fee_per_gas: 1
)
expected_txn_fees = %Wei{value: Decimal.new(6)}
expected_burned_fees = %Wei{value: Decimal.new(30)}
expected_uncle_reward = %Wei{value: Decimal.new(0)}
assert %{
static_reward: ^reward,
txn_fees: ^expected_txn_fees,
burned_fees: ^expected_burned_fees,
uncle_reward: ^expected_uncle_reward
} = Chain.block_reward_by_parts(block, [tx1, tx2, tx3])
end
test "with uncles", %{emission_reward: %{reward: reward, block_range: range}} do
block =
build(:block, number: range.from, uncles: ["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273311"])
expected_uncle_reward = Wei.mult(reward, Decimal.from_float(1 / 32))
assert %{uncle_reward: ^expected_uncle_reward} = Chain.block_reward_by_parts(block, [])
end
end
describe "gas_payment_by_block_hash/1" do
setup do
number = 1

@ -407,15 +407,15 @@ defmodule Indexer.Block.Fetcher do
def fetch_beneficiaries_manual(block, transactions) do
block
|> Chain.block_reward_by_parts(transactions)
|> Block.block_reward_by_parts(transactions)
|> reward_parts_to_beneficiaries()
end
defp reward_parts_to_beneficiaries(reward_parts) do
reward =
reward_parts.static_reward
|> Wei.sum(reward_parts.txn_fees)
|> Wei.sub(reward_parts.burned_fees)
|> Wei.sum(reward_parts.transaction_fees)
|> Wei.sub(reward_parts.burnt_fees)
|> Wei.sum(reward_parts.uncle_reward)
MapSet.new([

Loading…
Cancel
Save