Merge pull request #3457 from poanetwork/vb-mismatched-txs

Internal transactions fetcher update
pull/3480/head
Victor Baranov 4 years ago committed by GitHub
commit a35c8e65ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 2
      apps/block_scout_web/config/test.exs
  3. 11
      apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex
  4. 2
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex
  5. 12
      apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex
  6. 2
      apps/block_scout_web/mix.exs
  7. 38
      apps/block_scout_web/priv/gettext/default.pot
  8. 38
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  9. 3
      apps/block_scout_web/test/block_scout_web/features/viewing_blocks_test.exs
  10. 171
      apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex
  11. 3
      apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs
  12. 6
      mix.lock

@ -11,6 +11,10 @@
- [#3467](https://github.com/poanetwork/blockscout/pull/3467) - Fix Firefox styles - [#3467](https://github.com/poanetwork/blockscout/pull/3467) - Fix Firefox styles
- [#3464](https://github.com/poanetwork/blockscout/pull/3464) - Fix display of token transfers list at token page (fix unique identifier of a tile) - [#3464](https://github.com/poanetwork/blockscout/pull/3464) - Fix display of token transfers list at token page (fix unique identifier of a tile)
- [#3457](https://github.com/poanetwork/blockscout/pull/3457) - Fix endless block invalidation issue
- [#3457](https://github.com/poanetwork/blockscout/pull/3457) - Fix doubled total transferred/minted/burnt tokens on transaction's page if block has reorg
- [#3457](https://github.com/poanetwork/blockscout/pull/3457) - Fix doubled token transfer on block's page if block has reorg
### Chore ### Chore
- [#3468](https://github.com/poanetwork/blockscout/pull/3468) - Do not check supported networks on application loading page - [#3468](https://github.com/poanetwork/blockscout/pull/3468) - Do not check supported networks on application loading page
- [#3467](https://github.com/poanetwork/blockscout/pull/3467) - NodeJS engine upgrade up to 14 - [#3467](https://github.com/poanetwork/blockscout/pull/3467) - NodeJS engine upgrade up to 14

@ -18,7 +18,7 @@ config :logger, :block_scout_web,
path: Path.absname("logs/test/block_scout_web.log") path: Path.absname("logs/test/block_scout_web.log")
# Configure wallaby # Configure wallaby
config :wallaby, screenshot_on_failure: true, driver: Wallaby.Experimental.Chrome config :wallaby, screenshot_on_failure: true, driver: Wallaby.Chrome
config :explorer, Explorer.ExchangeRates, enabled: false, store: :none config :explorer, Explorer.ExchangeRates, enabled: false, store: :none

@ -50,10 +50,19 @@ defmodule BlockScoutWeb.BlockTransactionController do
items = items =
transactions transactions
|> Enum.map(fn transaction -> |> Enum.map(fn transaction ->
token_transfers_filtered_by_block_hash =
transaction.token_transfers
|> Enum.filter(fn token_transfer ->
token_transfer.block_hash == transaction.block_hash
end)
transaction_with_transfers_filtered =
Map.put(transaction, :token_transfers, token_transfers_filtered_by_block_hash)
View.render_to_string( View.render_to_string(
TransactionView, TransactionView,
"_tile.html", "_tile.html",
transaction: transaction, transaction: transaction_with_transfers_filtered,
burn_address_hash: @burn_address_hash, burn_address_hash: @burn_address_hash,
conn: conn conn: conn
) )

@ -34,7 +34,7 @@
</span> </span>
<!-- Transfer --> <!-- Transfer -->
<%= if involves_token_transfers?(@transaction) do %> <%= if involves_token_transfers?(@transaction) do %>
<div class="d-flex flex-column mt-2"> <div class="d-flex flex-column mt-2">
<% [first_token_transfer | remaining_token_transfers] = @transaction.token_transfers %> <% [first_token_transfer | remaining_token_transfers] = @transaction.token_transfers %>

@ -48,8 +48,18 @@ defmodule BlockScoutWeb.TransactionView do
def token_transfer_type(transaction) do def token_transfer_type(transaction) do
transaction_with_transfers = Repo.preload(transaction, token_transfers: :token) transaction_with_transfers = Repo.preload(transaction, token_transfers: :token)
token_transfers_filtered_by_block_hash =
transaction_with_transfers
|> Map.get(:token_transfers, [])
|> Enum.filter(fn token_transfer ->
token_transfer.block_hash == transaction.block_hash
end)
transaction_with_transfers_filtered =
Map.put(transaction_with_transfers, :token_transfers, token_transfers_filtered_by_block_hash)
type = Chain.transaction_token_transfer_type(transaction) type = Chain.transaction_token_transfer_type(transaction)
if type, do: {type, transaction_with_transfers}, else: {nil, transaction_with_transfers} if type, do: {type, transaction_with_transfers_filtered}, else: {nil, transaction_with_transfers_filtered}
end end
def aggregate_token_transfers(token_transfers) do def aggregate_token_transfers(token_transfers) do

@ -128,7 +128,7 @@ defmodule BlockScoutWeb.Mixfile do
# `:spandex` tracing of `:phoenix` # `:spandex` tracing of `:phoenix`
{:spandex_phoenix, "~> 0.3.1"}, {:spandex_phoenix, "~> 0.3.1"},
{:timex, "~> 3.6"}, {:timex, "~> 3.6"},
{:wallaby, "~> 0.22", only: [:test], runtime: false}, {:wallaby, "~> 0.26", only: :test, runtime: false},
# `:cowboy` `~> 2.0` and Phoenix 1.4 compatibility # `:cowboy` `~> 2.0` and Phoenix 1.4 compatibility
{:wobserver, "~> 0.2.0", github: "poanetwork/wobserver", branch: "support-https"}, {:wobserver, "~> 0.2.0", github: "poanetwork/wobserver", branch: "support-https"},
{:phoenix_form_awesomplete, "~> 0.1.4"}, {:phoenix_form_awesomplete, "~> 0.1.4"},

@ -59,7 +59,7 @@ msgid "%{subnetwork} Explorer - BlockScout"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:252 #: lib/block_scout_web/views/transaction_view.ex:262
msgid "(Awaiting internal transactions for status)" msgid "(Awaiting internal transactions for status)"
msgstr "" msgstr ""
@ -359,12 +359,12 @@ msgid "Contract Byte Code"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:341 #: lib/block_scout_web/views/transaction_view.ex:351
msgid "Contract Call" msgid "Contract Call"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:338 #: lib/block_scout_web/views/transaction_view.ex:348
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
@ -551,12 +551,12 @@ msgid "During times when the network is busy (i.e during ICOs) it can take a whi
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:138 #: lib/block_scout_web/views/transaction_view.ex:148
msgid "ERC-20 " msgid "ERC-20 "
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:139 #: lib/block_scout_web/views/transaction_view.ex:149
msgid "ERC-721 " msgid "ERC-721 "
msgstr "" msgstr ""
@ -615,12 +615,12 @@ msgid "Error trying to fetch balances."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:256 #: lib/block_scout_web/views/transaction_view.ex:266
msgid "Error: %{reason}" msgid "Error: %{reason}"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:254 #: lib/block_scout_web/views/transaction_view.ex:264
msgid "Error: (Awaiting internal transactions for reason)" msgid "Error: (Awaiting internal transactions for reason)"
msgstr "" msgstr ""
@ -771,7 +771,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:253 #: lib/block_scout_web/views/transaction_view.ex:263
msgid "Success" msgid "Success"
msgstr "" msgstr ""
@ -886,7 +886,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:12 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:12
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:10 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:10
#: lib/block_scout_web/views/transaction_view.ex:334 #: lib/block_scout_web/views/transaction_view.ex:344
msgid "Token Transfer" msgid "Token Transfer"
msgstr "" msgstr ""
@ -902,7 +902,7 @@ msgstr ""
#: lib/block_scout_web/views/address_view.ex:346 #: lib/block_scout_web/views/address_view.ex:346
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:119 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:119
#: lib/block_scout_web/views/tokens/overview_view.ex:40 #: lib/block_scout_web/views/tokens/overview_view.ex:40
#: lib/block_scout_web/views/transaction_view.ex:395 #: lib/block_scout_web/views/transaction_view.ex:405
msgid "Token Transfers" msgid "Token Transfers"
msgstr "" msgstr ""
@ -918,7 +918,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:18 #: lib/block_scout_web/templates/address_logs/_logs.html.eex:18
#: lib/block_scout_web/views/transaction_view.ex:344 #: lib/block_scout_web/views/transaction_view.ex:354
msgid "Transaction" msgid "Transaction"
msgstr "" msgstr ""
@ -1039,7 +1039,7 @@ msgid "Market Cap"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:233 #: lib/block_scout_web/views/transaction_view.ex:243
msgid "Max of" msgid "Max of"
msgstr "" msgstr ""
@ -1150,8 +1150,8 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:65 #: lib/block_scout_web/templates/layout/_topnav.html.eex:65
#: lib/block_scout_web/views/transaction_view.ex:251 #: lib/block_scout_web/views/transaction_view.ex:261
#: lib/block_scout_web/views/transaction_view.ex:285 #: lib/block_scout_web/views/transaction_view.ex:295
msgid "Pending" msgid "Pending"
msgstr "" msgstr ""
@ -1199,7 +1199,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:24 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:24
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 #: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7
#: lib/block_scout_web/views/transaction_view.ex:398 #: lib/block_scout_web/views/transaction_view.ex:408
msgid "Raw Trace" msgid "Raw Trace"
msgstr "" msgstr ""
@ -1829,7 +1829,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: 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/templates/transaction_internal_transaction/index.html.eex:6
#: lib/block_scout_web/views/address_view.ex:344 #: lib/block_scout_web/views/address_view.ex:344
#: lib/block_scout_web/views/transaction_view.ex:396 #: lib/block_scout_web/views/transaction_view.ex:406
msgid "Internal Transactions" msgid "Internal Transactions"
msgstr "" msgstr ""
@ -1839,7 +1839,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: 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/templates/transaction_log/index.html.eex:8
#: lib/block_scout_web/views/address_view.ex:355 #: lib/block_scout_web/views/address_view.ex:355
#: lib/block_scout_web/views/transaction_view.ex:397 #: lib/block_scout_web/views/transaction_view.ex:407
msgid "Logs" msgid "Logs"
msgstr "" msgstr ""
@ -1881,7 +1881,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:8 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:8
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:6 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:6
#: lib/block_scout_web/views/transaction_view.ex:333 #: lib/block_scout_web/views/transaction_view.ex:343
msgid "Token Burning" msgid "Token Burning"
msgstr "" msgstr ""
@ -1893,7 +1893,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:10 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:10
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:8 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:332 #: lib/block_scout_web/views/transaction_view.ex:342
msgid "Token Minting" msgid "Token Minting"
msgstr "" msgstr ""

@ -59,7 +59,7 @@ msgid "%{subnetwork} Explorer - BlockScout"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:252 #: lib/block_scout_web/views/transaction_view.ex:262
msgid "(Awaiting internal transactions for status)" msgid "(Awaiting internal transactions for status)"
msgstr "" msgstr ""
@ -359,12 +359,12 @@ msgid "Contract Byte Code"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:341 #: lib/block_scout_web/views/transaction_view.ex:351
msgid "Contract Call" msgid "Contract Call"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:338 #: lib/block_scout_web/views/transaction_view.ex:348
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
@ -551,12 +551,12 @@ msgid "During times when the network is busy (i.e during ICOs) it can take a whi
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:138 #: lib/block_scout_web/views/transaction_view.ex:148
msgid "ERC-20 " msgid "ERC-20 "
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:139 #: lib/block_scout_web/views/transaction_view.ex:149
msgid "ERC-721 " msgid "ERC-721 "
msgstr "" msgstr ""
@ -615,12 +615,12 @@ msgid "Error trying to fetch balances."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:256 #: lib/block_scout_web/views/transaction_view.ex:266
msgid "Error: %{reason}" msgid "Error: %{reason}"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:254 #: lib/block_scout_web/views/transaction_view.ex:264
msgid "Error: (Awaiting internal transactions for reason)" msgid "Error: (Awaiting internal transactions for reason)"
msgstr "" msgstr ""
@ -771,7 +771,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:253 #: lib/block_scout_web/views/transaction_view.ex:263
msgid "Success" msgid "Success"
msgstr "" msgstr ""
@ -886,7 +886,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:12 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:12
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:10 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:10
#: lib/block_scout_web/views/transaction_view.ex:334 #: lib/block_scout_web/views/transaction_view.ex:344
msgid "Token Transfer" msgid "Token Transfer"
msgstr "" msgstr ""
@ -902,7 +902,7 @@ msgstr ""
#: lib/block_scout_web/views/address_view.ex:346 #: lib/block_scout_web/views/address_view.ex:346
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:119 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:119
#: lib/block_scout_web/views/tokens/overview_view.ex:40 #: lib/block_scout_web/views/tokens/overview_view.ex:40
#: lib/block_scout_web/views/transaction_view.ex:395 #: lib/block_scout_web/views/transaction_view.ex:405
msgid "Token Transfers" msgid "Token Transfers"
msgstr "" msgstr ""
@ -918,7 +918,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:18 #: lib/block_scout_web/templates/address_logs/_logs.html.eex:18
#: lib/block_scout_web/views/transaction_view.ex:344 #: lib/block_scout_web/views/transaction_view.ex:354
msgid "Transaction" msgid "Transaction"
msgstr "" msgstr ""
@ -1039,7 +1039,7 @@ msgid "Market Cap"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:233 #: lib/block_scout_web/views/transaction_view.ex:243
msgid "Max of" msgid "Max of"
msgstr "" msgstr ""
@ -1150,8 +1150,8 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:65 #: lib/block_scout_web/templates/layout/_topnav.html.eex:65
#: lib/block_scout_web/views/transaction_view.ex:251 #: lib/block_scout_web/views/transaction_view.ex:261
#: lib/block_scout_web/views/transaction_view.ex:285 #: lib/block_scout_web/views/transaction_view.ex:295
msgid "Pending" msgid "Pending"
msgstr "" msgstr ""
@ -1199,7 +1199,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:24 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:24
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 #: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7
#: lib/block_scout_web/views/transaction_view.ex:398 #: lib/block_scout_web/views/transaction_view.ex:408
msgid "Raw Trace" msgid "Raw Trace"
msgstr "" msgstr ""
@ -1829,7 +1829,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: 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/templates/transaction_internal_transaction/index.html.eex:6
#: lib/block_scout_web/views/address_view.ex:344 #: lib/block_scout_web/views/address_view.ex:344
#: lib/block_scout_web/views/transaction_view.ex:396 #: lib/block_scout_web/views/transaction_view.ex:406
msgid "Internal Transactions" msgid "Internal Transactions"
msgstr "" msgstr ""
@ -1839,7 +1839,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: 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/templates/transaction_log/index.html.eex:8
#: lib/block_scout_web/views/address_view.ex:355 #: lib/block_scout_web/views/address_view.ex:355
#: lib/block_scout_web/views/transaction_view.ex:397 #: lib/block_scout_web/views/transaction_view.ex:407
msgid "Logs" msgid "Logs"
msgstr "" msgstr ""
@ -1881,7 +1881,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:8 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:8
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:6 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:6
#: lib/block_scout_web/views/transaction_view.ex:333 #: lib/block_scout_web/views/transaction_view.ex:343
msgid "Token Burning" msgid "Token Burning"
msgstr "" msgstr ""
@ -1893,7 +1893,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:10 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:10
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:8 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:332 #: lib/block_scout_web/views/transaction_view.ex:342
msgid "Token Minting" msgid "Token Minting"
msgstr "" msgstr ""

@ -88,7 +88,8 @@ defmodule BlockScoutWeb.ViewingBlocksTest do
3, 3,
:token_transfer, :token_transfer,
transaction: transaction, transaction: transaction,
token_contract_address: contract_token_address token_contract_address: contract_token_address,
block: block
) )
session session

@ -65,19 +65,6 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
|> Multi.run(:invalid_block_numbers, fn _, %{acquire_transactions: transactions} -> |> Multi.run(:invalid_block_numbers, fn _, %{acquire_transactions: transactions} ->
invalid_block_numbers(transactions, internal_transactions_params) invalid_block_numbers(transactions, internal_transactions_params)
end) end)
|> Multi.run(:valid_internal_transactions_without_first_traces_of_trivial_transactions, fn _,
%{
acquire_transactions:
transactions,
invalid_block_numbers:
invalid_block_numbers
} ->
valid_internal_transactions_without_first_trace(
transactions,
internal_transactions_params,
invalid_block_numbers
)
end)
|> Multi.run(:valid_internal_transactions, fn _, |> Multi.run(:valid_internal_transactions, fn _,
%{ %{
acquire_transactions: transactions, acquire_transactions: transactions,
@ -89,6 +76,13 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
invalid_block_numbers invalid_block_numbers
) )
end) end)
|> Multi.run(:valid_internal_transactions_without_first_traces_of_trivial_transactions, fn _,
%{
valid_internal_transactions:
valid_internal_transactions
} ->
valid_internal_transactions_without_first_trace(valid_internal_transactions)
end)
|> Multi.run(:remove_left_over_internal_transactions, fn repo, |> Multi.run(:remove_left_over_internal_transactions, fn repo,
%{valid_internal_transactions: valid_internal_transactions} -> %{valid_internal_transactions: valid_internal_transactions} ->
remove_left_over_internal_transactions(repo, valid_internal_transactions) remove_left_over_internal_transactions(repo, valid_internal_transactions)
@ -268,72 +262,81 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
# Finds all mistmatches between transactions and internal transactions # Finds all mistmatches between transactions and internal transactions
# for a block number: # for a block number:
# - there are no internal txs for some transactions # - there are no internal txs for some transactions
# - there are no transactions for some internal transactions
# - there are internal txs with a different block number than their transactions # - there are internal txs with a different block number than their transactions
# Returns block numbers where any of these issues is found # Returns block numbers where any of these issues is found
required_tuples = MapSet.new(transactions, &{&1.hash, &1.block_number}) # Note: the case "# - there are no transactions for some internal transactions" was removed because it caused the issue https://github.com/poanetwork/blockscout/issues/3367
# when the last block with transactions loses consensus in endless loop. In order to return this case:
# common_tuples = MapSet.intersection(required_tuples, candidate_tuples) #should be added
# |> MapSet.difference(internal_transactions_tuples) should be replaced with |> MapSet.difference(common_tuples)
candidate_tuples = MapSet.new(internal_transactions_params, &{&1.transaction_hash, &1.block_number}) transactions_tuples = MapSet.new(transactions, &{&1.hash, &1.block_number})
all_tuples = MapSet.union(required_tuples, candidate_tuples) internal_transactions_tuples = MapSet.new(internal_transactions_params, &{&1.transaction_hash, &1.block_number})
common_tuples = MapSet.intersection(required_tuples, candidate_tuples) all_tuples = MapSet.union(transactions_tuples, internal_transactions_tuples)
invalid_numbers = invalid_block_numbers =
all_tuples all_tuples
|> MapSet.difference(common_tuples) |> MapSet.difference(internal_transactions_tuples)
|> MapSet.new(fn {_hash, block_number} -> block_number end) |> MapSet.new(fn {_hash, block_number} -> block_number end)
|> MapSet.to_list() |> MapSet.to_list()
{:ok, invalid_numbers} {:ok, invalid_block_numbers}
end end
defp valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do defp valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do
blocks_map = Map.new(transactions, &{&1.block_number, &1.block_hash}) if Enum.count(transactions) > 0 do
blocks_map = Map.new(transactions, &{&1.block_number, &1.block_hash})
valid_internal_txs =
internal_transactions_params valid_internal_txs =
|> Enum.group_by(& &1.block_number) internal_transactions_params
|> Map.drop(invalid_block_numbers) |> Enum.group_by(& &1.block_number)
|> Enum.flat_map(fn {block_number, entries} -> |> Map.drop(invalid_block_numbers)
block_hash = Map.fetch!(blocks_map, block_number) |> Enum.flat_map(fn item ->
case item do
entries {block_number, entries} ->
|> Enum.sort_by(&{&1.transaction_hash, &1.index}) if Map.has_key?(blocks_map, block_number) do
|> Enum.with_index() block_hash = Map.fetch!(blocks_map, block_number)
|> Enum.map(fn {entry, index} ->
entry entries
|> Map.put(:block_hash, block_hash) |> Enum.sort_by(&{&1.transaction_hash, &1.index})
|> Map.put(:block_index, index) |> Enum.with_index()
|> Enum.map(fn {entry, index} ->
entry
|> Map.put(:block_hash, block_hash)
|> Map.put(:block_index, index)
end)
else
[]
end
_ ->
[]
end
end) end)
end)
{:ok, valid_internal_txs} {:ok, valid_internal_txs}
else
{:ok, []}
end
end end
defp valid_internal_transactions_without_first_trace( defp valid_internal_transactions_without_first_trace(valid_internal_transactions) do
transactions, json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments)
internal_transactions_params, variant = Keyword.fetch!(json_rpc_named_arguments, :variant)
invalid_block_numbers
) do # we exclude first traces from storing in the DB only in case of Parity variant (Parity/Nethermind). Todo: implement the same for Geth
with {:ok, valid_internal_txs} <- if variant == EthereumJSONRPC.Parity do
valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do valid_internal_transactions_without_first_trace =
json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments) valid_internal_transactions
variant = Keyword.fetch!(json_rpc_named_arguments, :variant) |> Enum.reject(fn trace ->
trace[:index] == 0
# we exclude first traces from storing in the DB only in case of Parity variant (Parity/Nethermind). todo: to the same for Geth end)
if variant == EthereumJSONRPC.Parity do
valid_internal_txs_without_first_trace = {:ok, valid_internal_transactions_without_first_trace}
valid_internal_txs else
|> Enum.reject(fn trace -> {:ok, valid_internal_transactions}
trace[:index] == 0
end)
{:ok, valid_internal_txs_without_first_trace}
else
{:ok, valid_internal_txs}
end
end end
end end
@ -454,30 +457,34 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
end end
defp remove_consensus_of_invalid_blocks(repo, invalid_block_numbers) do defp remove_consensus_of_invalid_blocks(repo, invalid_block_numbers) do
update_query = if Enum.count(invalid_block_numbers) > 0 do
from( update_query =
b in Block, from(
where: b.number in ^invalid_block_numbers and b.consensus, b in Block,
select: b.hash, where: b.number in ^invalid_block_numbers and b.consensus,
# ShareLocks order already enforced by `acquire_blocks` (see docs: sharelocks.md) select: b.hash,
update: [set: [consensus: false]] # ShareLocks order already enforced by `acquire_blocks` (see docs: sharelocks.md)
) update: [set: [consensus: false]]
)
try do try do
{_num, result} = repo.update_all(update_query, []) {_num, result} = repo.update_all(update_query, [])
Logger.debug(fn -> Logger.debug(fn ->
[ [
"consensus removed from blocks with numbers: ", "consensus removed from blocks with numbers: ",
inspect(invalid_block_numbers), inspect(invalid_block_numbers),
" because of mismatching transactions" " because of mismatching transactions"
] ]
end) end)
{:ok, result} {:ok, result}
rescue rescue
postgrex_error in Postgrex.Error -> postgrex_error in Postgrex.Error ->
{:error, %{exception: postgrex_error, invalid_block_numbers: invalid_block_numbers}} {:error, %{exception: postgrex_error, invalid_block_numbers: invalid_block_numbers}}
end
else
{:ok, []}
end end
end end

@ -202,9 +202,6 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
assert from(i in InternalTransaction, where: i.transaction_hash == ^pending.hash) |> Repo.one() |> is_nil() assert from(i in InternalTransaction, where: i.transaction_hash == ^pending.hash) |> Repo.one() |> is_nil()
assert %{consensus: false} = Repo.get(Block, empty_block.hash)
assert not is_nil(Repo.get(PendingBlockOperation, empty_block.hash))
assert from(i in InternalTransaction, where: i.transaction_hash == ^inserted.hash) |> Repo.one() |> is_nil() == assert from(i in InternalTransaction, where: i.transaction_hash == ^inserted.hash) |> Repo.one() |> is_nil() ==
false false

@ -56,7 +56,7 @@
"gettext": {:hex, :gettext, "0.16.1", "e2130b25eebcbe02bb343b119a07ae2c7e28bd4b146c4a154da2ffb2b3507af2", [:mix], [], "hexpm", "dd3a7ea5e3e87ee9df29452dd9560709b4c7cc8141537d0b070155038d92bdf1"}, "gettext": {:hex, :gettext, "0.16.1", "e2130b25eebcbe02bb343b119a07ae2c7e28bd4b146c4a154da2ffb2b3507af2", [:mix], [], "hexpm", "dd3a7ea5e3e87ee9df29452dd9560709b4c7cc8141537d0b070155038d92bdf1"},
"hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"}, "hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"},
"html_entities": {:hex, :html_entities, "0.4.0", "f2fee876858cf6aaa9db608820a3209e45a087c5177332799592142b50e89a6b", [:mix], [], "hexpm", "3e3d7156a272950373ce5a4018b1490bea26676f8d6a7d409f6fac8568b8cb9a"}, "html_entities": {:hex, :html_entities, "0.4.0", "f2fee876858cf6aaa9db608820a3209e45a087c5177332799592142b50e89a6b", [:mix], [], "hexpm", "3e3d7156a272950373ce5a4018b1490bea26676f8d6a7d409f6fac8568b8cb9a"},
"httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"}, "httpoison": {:hex, :httpoison, "1.7.0", "abba7d086233c2d8574726227b6c2c4f6e53c4deae7fe5f6de531162ce9929a0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "975cc87c845a103d3d1ea1ccfd68a2700c211a434d8428b10c323dc95dc5b980"},
"idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"}, "idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm", "fc3499fed7a726995aa659143a248534adc754ebd16ccd437cd93b649a95091f"}, "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm", "fc3499fed7a726995aa659143a248534adc754ebd16ccd437cd93b649a95091f"},
@ -111,10 +111,12 @@
"spandex_phoenix": {:hex, :spandex_phoenix, "0.3.2", "e81889d80852a895cf62ce2e25181b15766d21e8647962e0a4458414b935feb3", [:mix], [{:plug, "~> 1.3", [hex: :plug, repo: "hexpm", optional: false]}, {:spandex, "~> 2.2", [hex: :spandex, repo: "hexpm", optional: false]}], "hexpm", "6e882bb64093889a73b7b77c426c1fd5651d072cd97e8f3e8d89d502d7b44b48"}, "spandex_phoenix": {:hex, :spandex_phoenix, "0.3.2", "e81889d80852a895cf62ce2e25181b15766d21e8647962e0a4458414b935feb3", [:mix], [{:plug, "~> 1.3", [hex: :plug, repo: "hexpm", optional: false]}, {:spandex, "~> 2.2", [hex: :spandex, repo: "hexpm", optional: false]}], "hexpm", "6e882bb64093889a73b7b77c426c1fd5651d072cd97e8f3e8d89d502d7b44b48"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
"tesla": {:hex, :tesla, "1.3.3", "26ae98627af5c406584aa6755ab5fc96315d70d69a24dd7f8369cfcb75094a45", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2648f1c276102f9250299e0b7b57f3071c67827349d9173f34c281756a1b124c"},
"timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "f354efb2400dd7a80fd9eb6c8419068c4f632da4ac47f3d8822d6e33f08bc852"}, "timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "f354efb2400dd7a80fd9eb6c8419068c4f632da4ac47f3d8822d6e33f08bc852"},
"tzdata": {:hex, :tzdata, "1.0.1", "f6027a331af7d837471248e62733c6ebee86a72e57c613aa071ebb1f750fc71a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "cf1345dfbce6acdfd4e23cbb36e96e53d1981bc89181cd0b936f4f398f4c0b78"}, "tzdata": {:hex, :tzdata, "1.0.1", "f6027a331af7d837471248e62733c6ebee86a72e57c613aa071ebb1f750fc71a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "cf1345dfbce6acdfd4e23cbb36e96e53d1981bc89181cd0b936f4f398f4c0b78"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"},
"wallaby": {:hex, :wallaby, "0.22.0", "e5d16bfa7ab23562c8a6e3b0a31445a2fd470ca622082a910114807ba823780d", [:mix], [{:httpoison, "~> 0.12 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "b5ec4fdb22f79bc1656cf8766718d0ab77e961839a5946a3ecf212448e30bf15"}, "wallaby": {:hex, :wallaby, "0.26.2", "32f43de121ba3a65ecff060b46c92a255ac5f092b0e296e738ec9f1ad5aa1215", [:mix], [{:ecto_sql, ">= 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:httpoison, "~> 0.12 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_ecto, ">= 3.0.0", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:web_driver_client, "~> 0.1.0", [hex: :web_driver_client, repo: "hexpm", optional: false]}], "hexpm", "f40ef31caf08e3f0947e31be4b99eeb79560259430518457fa6faed89f650f38"},
"web_driver_client": {:hex, :web_driver_client, "0.1.0", "19466a989c76b7ec803c796cec0fec4611a64f445fd5120ce50c9e3817e09c2c", [:mix], [{:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:tesla, "~> 1.3.0", [hex: :tesla, repo: "hexpm", optional: false]}], "hexpm", "c9c031ca915e8fc75b5e24ac93503244f3cc406dd7f53047087a45aa62d60e9e"},
"websocket_client": {:hex, :websocket_client, "1.3.0", "2275d7daaa1cdacebf2068891c9844b15f4fdc3de3ec2602420c2fb486db59b6", [:rebar3], [], "hexpm", "b864fa076f059b615da4ab99240e515b26132ce4d2d0f9df5d7f22f01fa04b65"}, "websocket_client": {:hex, :websocket_client, "1.3.0", "2275d7daaa1cdacebf2068891c9844b15f4fdc3de3ec2602420c2fb486db59b6", [:rebar3], [], "hexpm", "b864fa076f059b615da4ab99240e515b26132ce4d2d0f9df5d7f22f01fa04b65"},
"wobserver": {:git, "https://github.com/poanetwork/wobserver.git", "13bcda30a87f4f0be1878920a79433ad831eefbe", [branch: "support-https"]}, "wobserver": {:git, "https://github.com/poanetwork/wobserver.git", "13bcda30a87f4f0be1878920a79433ad831eefbe", [branch: "support-https"]},
} }

Loading…
Cancel
Save