Merge pull request #6207 from blockscout/vb-fix-indexing-message-appearance

Fix Blocks Indexing message appearance
pull/6213/head
Victor Baranov 2 years ago committed by GitHub
commit 995d1cbe6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 10
      apps/block_scout_web/lib/block_scout_web/counters/blocks_indexed_counter.ex
  3. 7
      apps/block_scout_web/lib/block_scout_web/templates/layout/app.html.eex
  4. 2
      apps/block_scout_web/priv/gettext/default.pot
  5. 2
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 23
      apps/explorer/lib/explorer/chain.ex
  7. 17
      apps/explorer/test/explorer/chain_test.exs

@ -25,7 +25,7 @@
- [#6204](https://github.com/blockscout/blockscout/pull/6204) - Refactor contract libs render, CONTRACT_VERIFICATION_MAX_LIBRARIES, refactor parsing integer env vars in config - [#6204](https://github.com/blockscout/blockscout/pull/6204) - Refactor contract libs render, CONTRACT_VERIFICATION_MAX_LIBRARIES, refactor parsing integer env vars in config
- [#6195](https://github.com/blockscout/blockscout/pull/6195) - Docker compose configs improvements: Redis container name and persistent storage - [#6195](https://github.com/blockscout/blockscout/pull/6195) - Docker compose configs improvements: Redis container name and persistent storage
- [#6192](https://github.com/blockscout/blockscout/pull/6192) - Hide Indexing Internal Transactions message, if INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=true - [#6192](https://github.com/blockscout/blockscout/pull/6192), [#6207](https://github.com/blockscout/blockscout/pull/6207) - Hide Indexing Internal Transactions message, if INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=true
- [#6183](https://github.com/blockscout/blockscout/pull/6183) - Transparent coin name definition - [#6183](https://github.com/blockscout/blockscout/pull/6183) - Transparent coin name definition
- [#6155](https://github.com/blockscout/blockscout/pull/6155), [#6189](https://github.com/blockscout/blockscout/pull/6189) - Refactor Ethereum JSON RPC variants - [#6155](https://github.com/blockscout/blockscout/pull/6155), [#6189](https://github.com/blockscout/blockscout/pull/6189) - Refactor Ethereum JSON RPC variants
- [#6125](https://github.com/blockscout/blockscout/pull/6125) - Rename obsolete "parity" EthereumJSONRPC.Variant to "nethermind" - [#6125](https://github.com/blockscout/blockscout/pull/6125) - Rename obsolete "parity" EthereumJSONRPC.Variant to "nethermind"

@ -36,15 +36,11 @@ defmodule BlockScoutWeb.Counters.BlocksIndexedCounter do
end end
def calculate_blocks_indexed do def calculate_blocks_indexed do
ratio = Chain.indexed_ratio() indexed_ratio = Chain.indexed_ratio()
finished? = finished? = Chain.finished_indexing?(indexed_ratio)
case Decimal.compare(ratio, 1) do
:lt -> false
_ -> Chain.finished_internal_transactions_indexing?()
end
Notifier.broadcast_blocks_indexed_ratio(ratio, finished?) Notifier.broadcast_blocks_indexed_ratio(indexed_ratio, finished?)
end end
defp schedule_next_consolidation do defp schedule_next_consolidation do

@ -216,10 +216,11 @@
<%= raw(System.get_env("MAINTENANCE_ALERT_MESSAGE")) %> <%= raw(System.get_env("MAINTENANCE_ALERT_MESSAGE")) %>
</div> </div>
<% end %> <% end %>
<%= if not Explorer.Chain.finished_internal_transactions_indexing?() do %> <% indexed_ratio = Explorer.Chain.indexed_ratio() %>
<div class="alert alert-warning text-center mb-0 p-3" data-selector="indexed-status"> <%= if not Explorer.Chain.finished_indexing?(indexed_ratio) do %>
<div class="alert alert-warning text-center mb-0 p-3" data-seindexed_ratiolector="indexed-status">
<%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html" %> <%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html" %>
<span data-indexed-ratio="<%=Explorer.Chain.indexed_ratio() %>"></span> <span data-indexed-ratio="<%= indexed_ratio %>"></span>
<%= gettext("- We're indexing this chain right now. Some of the counts may be inaccurate.") %> <%= gettext("- We're indexing this chain right now. Some of the counts may be inaccurate.") %>
</div> </div>
<% end %> <% end %>

@ -76,7 +76,7 @@ msgstr ""
msgid "(query)" msgid "(query)"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/layout/app.html.eex:223 #: lib/block_scout_web/templates/layout/app.html.eex:224
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "- We're indexing this chain right now. Some of the counts may be inaccurate." msgid "- We're indexing this chain right now. Some of the counts may be inaccurate."
msgstr "" msgstr ""

@ -76,7 +76,7 @@ msgstr ""
msgid "(query)" msgid "(query)"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/layout/app.html.eex:223 #: lib/block_scout_web/templates/layout/app.html.eex:224
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "- We're indexing this chain right now. Some of the counts may be inaccurate." msgid "- We're indexing this chain right now. Some of the counts may be inaccurate."
msgstr "" msgstr ""

@ -1199,6 +1199,17 @@ defmodule Explorer.Chain do
end end
end end
@doc """
Checks if indexing of blocks and internal transactions finished aka full indexing
"""
@spec finished_indexing?(Decimal.t()) :: boolean()
def finished_indexing?(indexed_ratio) do
case Decimal.compare(indexed_ratio, 1) do
:lt -> false
_ -> Chain.finished_internal_transactions_indexing?()
end
end
@doc """ @doc """
The `t:Explorer.Chain.Transaction.t/0` `gas_price` of the `transaction` in `unit`. The `t:Explorer.Chain.Transaction.t/0` `gas_price` of the `transaction` in `unit`.
""" """
@ -2064,14 +2075,22 @@ defmodule Explorer.Chain do
def indexed_ratio do def indexed_ratio do
%{min: min, max: max} = BlockNumber.get_all() %{min: min, max: max} = BlockNumber.get_all()
min_blockchain_block_number =
case Integer.parse(Application.get_env(:indexer, :first_block)) do
{block_number, _} -> block_number
_ -> 0
end
case {min, max} do case {min, max} do
{0, 0} -> {0, 0} ->
Decimal.new(0) Decimal.new(0)
_ -> _ ->
result = Decimal.div(max - min + 1, max + 1) result = Decimal.div(max - min + 1, max - min_blockchain_block_number + 1)
Decimal.round(result, 2, :down) result
|> Decimal.round(2, :down)
|> Decimal.min(Decimal.new(1))
end end
end end

@ -1467,6 +1467,12 @@ defmodule Explorer.ChainTest do
end end
describe "indexed_ratio/0" do describe "indexed_ratio/0" do
setup do
on_exit(fn ->
Application.put_env(:indexer, :first_block, "")
end)
end
test "returns indexed ratio" do test "returns indexed ratio" do
for index <- 5..9 do for index <- 5..9 do
insert(:block, number: index) insert(:block, number: index)
@ -1487,6 +1493,17 @@ defmodule Explorer.ChainTest do
assert Decimal.compare(Chain.indexed_ratio(), 1) == :eq assert Decimal.compare(Chain.indexed_ratio(), 1) == :eq
end end
test "returns 1.0 if fully indexed blocks starting from given FIRST_BLOCK" do
Application.put_env(:indexer, :first_block, "5")
for index <- 5..9 do
insert(:block, number: index)
Process.sleep(200)
end
assert Decimal.compare(Chain.indexed_ratio(), 1) == :eq
end
end end
describe "fetch_min_block_number/0" do describe "fetch_min_block_number/0" do

Loading…
Cancel
Save