Skip to content

Commit

Permalink
Merge pull request #6192 from blockscout/vb-hide-indexing-msg-if-fetc…
Browse files Browse the repository at this point in the history
…her-disabled

Hide Indexing Internal Transactions message, if INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=true
  • Loading branch information
vbaranov committed Sep 30, 2022
2 parents a98c6f3 + aa4d78c commit 0827e21
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Chore

- [#6192](https://github.com/blockscout/blockscout/pull/6192) - Hide Indexing Internal Transactions message, if INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=true
- [#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
- [#6125](https://github.com/blockscout/blockscout/pull/6125) - Rename obsolete "parity" EthereumJSONRPC.Variant to "nethermind"
Expand Down
2 changes: 1 addition & 1 deletion apps/block_scout_web/assets/js/lib/indexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function tryUpdateIndexedStatus (el, indexedRatio = el.dataset.indexedRatio, ind
const blocksPercentComplete = numeral(indexedRatio).format('0%')
let indexedText
if (blocksPercentComplete === '100%') {
indexedText = window.localized['Indexing Tokens']
indexedText = window.localized['Indexing Internal Transactions']
} else {
indexedText = `${blocksPercentComplete} ${window.localized['Blocks Indexed']}`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule BlockScoutWeb.Counters.BlocksIndexedCounter do
finished? =
case Decimal.compare(ratio, 1) do
:lt -> false
_ -> Chain.finished_indexing?()
_ -> Chain.finished_internal_transactions_indexing?()
end

Notifier.broadcast_blocks_indexed_ratio(ratio, finished?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
window.localized = {
'Blocks Indexed': '<%= gettext("Blocks Indexed") %>',
'Block Processing': '<%= gettext("Block Mined, awaiting import...") %>',
'Indexing Tokens': '<%= gettext("Indexing Tokens") %>',
'Indexing Internal Transactions': '<%= gettext("Indexing Internal Transactions") %>',
'Less than': '<%= gettext("Less than") %>',
'Market Cap': '<%= gettext("Market Cap") %>',
'Price': '<%= gettext("Price") %>',
Expand Down Expand Up @@ -216,7 +216,7 @@
<%= raw(System.get_env("MAINTENANCE_ALERT_MESSAGE")) %>
</div>
<% end %>
<%= if not Explorer.Chain.finished_indexing?() do %>
<%= if not Explorer.Chain.finished_internal_transactions_indexing?() do %>
<div class="alert alert-warning text-center mb-0 p-3" data-selector="indexed-status">
<%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html" %>
<span data-indexed-ratio="<%=Explorer.Chain.indexed_ratio() %>"></span>
Expand Down
10 changes: 5 additions & 5 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1414,11 +1414,6 @@ msgstr ""
msgid "Indexed?"
msgstr ""

#: lib/block_scout_web/templates/layout/app.html.eex:44
#, elixir-autogen, elixir-format
msgid "Indexing Tokens"
msgstr ""

#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:3
#, elixir-autogen, elixir-format
msgid "Input"
Expand Down Expand Up @@ -3261,3 +3256,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "truffle flattener"
msgstr ""

#: lib/block_scout_web/templates/layout/app.html.eex:44
#, elixir-autogen, elixir-format
msgid "Indexing Internal Transactions"
msgstr ""
10 changes: 5 additions & 5 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -1414,11 +1414,6 @@ msgstr ""
msgid "Indexed?"
msgstr ""

#: lib/block_scout_web/templates/layout/app.html.eex:44
#, elixir-autogen, elixir-format
msgid "Indexing Tokens"
msgstr ""

#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:3
#, elixir-autogen, elixir-format
msgid "Input"
Expand Down Expand Up @@ -3261,3 +3256,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "truffle flattener"
msgstr ""

#: lib/block_scout_web/templates/layout/app.html.eex:44
#, elixir-autogen, elixir-format, fuzzy
msgid "Indexing Internal Transactions"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule BlockScoutWeb.ViewingAppTest do

# session
# |> AppPage.visit_page()
# |> assert_has(AppPage.indexed_status("Indexing Tokens"))
# |> assert_has(AppPage.indexed_status("Indexing Internal Transactions"))
# end

# test "updates blocks indexed percentage", %{session: session} do
Expand Down Expand Up @@ -106,7 +106,7 @@ defmodule BlockScoutWeb.ViewingAppTest do

# BlocksIndexedCounter.calculate_blocks_indexed()

# assert_has(session, AppPage.indexed_status("Indexing Tokens"))
# assert_has(session, AppPage.indexed_status("Indexing Internal Transactions"))
# end

# test "removes message when chain is indexed", %{session: session} do
Expand All @@ -129,7 +129,7 @@ defmodule BlockScoutWeb.ViewingAppTest do

# session
# |> AppPage.visit_page()
# |> assert_has(AppPage.indexed_status("Indexing Tokens"))
# |> assert_has(AppPage.indexed_status("Indexing Internal Transactions"))

# Repo.update_all(
# from(p in PendingBlockOperation, where: p.block_hash == ^block_hash),
Expand Down
50 changes: 28 additions & 22 deletions apps/explorer/lib/explorer/chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1162,33 +1162,39 @@ defmodule Explorer.Chain do
Checks to see if the chain is down indexing based on the transaction from the
oldest block and the `fetch_internal_transactions` pending operation
"""
@spec finished_indexing?() :: boolean()
def finished_indexing? do
json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments)
variant = Keyword.fetch!(json_rpc_named_arguments, :variant)
@spec finished_internal_transactions_indexing?() :: boolean()
def finished_internal_transactions_indexing? do
internal_transactions_disabled? = System.get_env("INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER", "false") == "true"

if variant == EthereumJSONRPC.Ganache || variant == EthereumJSONRPC.Arbitrum do
if internal_transactions_disabled? do
true
else
with {:transactions_exist, true} <- {:transactions_exist, Repo.exists?(Transaction)},
min_block_number when not is_nil(min_block_number) <- Repo.aggregate(Transaction, :min, :block_number) do
min_block_number =
min_block_number
|> Decimal.max(EthereumJSONRPC.first_block_to_fetch(:trace_first_block))
|> Decimal.to_integer()

query =
from(
b in Block,
join: pending_ops in assoc(b, :pending_operations),
where: pending_ops.fetch_internal_transactions,
where: b.consensus and b.number == ^min_block_number
)
json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments)
variant = Keyword.fetch!(json_rpc_named_arguments, :variant)

!Repo.exists?(query)
if variant == EthereumJSONRPC.Ganache || variant == EthereumJSONRPC.Arbitrum do
true
else
{:transactions_exist, false} -> true
nil -> false
with {:transactions_exist, true} <- {:transactions_exist, Repo.exists?(Transaction)},
min_block_number when not is_nil(min_block_number) <- Repo.aggregate(Transaction, :min, :block_number) do
min_block_number =
min_block_number
|> Decimal.max(EthereumJSONRPC.first_block_to_fetch(:trace_first_block))
|> Decimal.to_integer()

query =
from(
b in Block,
join: pending_ops in assoc(b, :pending_operations),
where: pending_ops.fetch_internal_transactions,
where: b.consensus and b.number == ^min_block_number
)

!Repo.exists?(query)
else
{:transactions_exist, false} -> true
nil -> false
end
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions apps/explorer/test/explorer/chain_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,19 +1185,19 @@ defmodule Explorer.ChainTest do
end
end

describe "finished_indexing?/0" do
describe "finished_internal_transactions_indexing?/0" do
test "finished indexing" do
block = insert(:block, number: 1)

:transaction
|> insert()
|> with_block(block)

assert Chain.finished_indexing?()
assert Chain.finished_internal_transactions_indexing?()
end

test "finished indexing (no txs)" do
assert Chain.finished_indexing?()
assert Chain.finished_internal_transactions_indexing?()
end

test "not finished indexing" do
Expand All @@ -1209,7 +1209,7 @@ defmodule Explorer.ChainTest do

insert(:pending_block_operation, block: block, fetch_internal_transactions: true)

refute Chain.finished_indexing?()
refute Chain.finished_internal_transactions_indexing?()
end
end

Expand Down

0 comments on commit 0827e21

Please sign in to comment.