Skip to content

Commit

Permalink
Merge pull request blockscout#5016 from blockscout/np-fix-transaction…
Browse files Browse the repository at this point in the history
…-error-status

Add view for internal transactions error
  • Loading branch information
vbaranov authored and jagdeep sidhu committed Feb 18, 2022
1 parent cd852c0 commit 4e3d019
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features
- [#5200](https://github.com/blockscout/blockscout/pull/5200) - Docker-compose configuration
- [#5105](https://github.com/blockscout/blockscout/pull/5105) - Redesign token page
- [#5016](https://github.com/blockscout/blockscout/pull/5016) - Add view for internal transactions error
- [#4690](https://github.com/blockscout/blockscout/pull/4690) - Improve pagination: introduce pagination with random access to pages; Integrate it to the Transactions List page

### Fixes
Expand Down
4 changes: 4 additions & 0 deletions apps/block_scout_web/assets/css/components/_i_tooltip_2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
&:hover {
color: $i-tooltip-background-active;
}
}

.color-inherit {
color: inherit;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<div class="tile tile-type-internal-transaction fade-in" data-test="internal_transaction" data-key="<%= @internal_transaction.transaction_hash %>_<%= @internal_transaction.index %>" data-internal-transaction-transaction-hash="<%= @internal_transaction.transaction_hash %>" data-internal-transaction-index="<%= @internal_transaction.index %>">
<% error = @internal_transaction.error %>
<div class="tile tile-type-internal-transaction fade-in <%= if error, do: "tile-status--error--reason"%>" data-test="internal_transaction" data-key="<%= @internal_transaction.transaction_hash %>_<%= @internal_transaction.index %>" data-internal-transaction-transaction-hash="<%= @internal_transaction.transaction_hash %>" data-internal-transaction-index="<%= @internal_transaction.index %>">
<div class="row tile-body">
<!-- Color Block -->
<div class="tile-transaction-type-block col-md-2 d-flex flex-row flex-md-column">
<span class="tile-label">
<%= gettext("Internal Transaction") %>
</span>
<span class="tile-status-label ml-2 ml-md-0" data-internal-transaction-type="<%= type(@internal_transaction) %>"><%= type(@internal_transaction) %></span>
<%= if error do %>
<span class="tile-status-label ml-2 ml-md-0"><%= gettext "Error" %>: <%= error %></span>
<% end %>
</div>
<!-- Content -->
<div class="col-md-7 col-lg-8 d-flex flex-column pr-2 pr-sm-2 pr-md-0">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<% status = transaction_status(@transaction) %>
<% error_in_internal_tx = @transaction.has_error_in_internal_txs %>
<div class="tile tile-type-<%= type_suffix(@transaction) %> fade-in <%= status_class(@transaction) %>" data-test="<%= type_suffix(@transaction) %>" data-identifier-hash="<%= @transaction.hash %>">
<div class="row tile-body" data-selector="token-transfers-toggle" data-test="chain_transaction">
<!-- Color Block -->
<div class="tile-transaction-type-block col-md-2 d-flex flex-row flex-md-column">
<span class="tile-label" data-test="transaction_type">
<%= transaction_display_type(@transaction) %>
</span>
<div>
<%= if error_in_internal_tx do %>
<%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html", text: gettext("Error in internal transactions"), additional_classes: ["color-inherit"] %>
<% end %>
<span class="tile-label" data-test="transaction_type">
<%= transaction_display_type(@transaction) %>
</span>
</div>
<span class="tile-status-label ml-2 ml-md-0" data-test="transaction_status">
<%= if status_class(@transaction) == "tile-status--pending" do %>
<div class="loading-spinner-small">
Expand Down
28 changes: 17 additions & 11 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_link.html.eex:2
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:28 lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:32 lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43
msgid "Block #%{number}"
msgstr ""

Expand Down Expand Up @@ -1080,6 +1080,7 @@ msgid "Epochs range(s) or enum, e.g.: 5-9,23-27,47,50"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:11
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:10
msgid "Error"
msgstr ""
Expand Down Expand Up @@ -1118,10 +1119,10 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_balance_card.html.eex:18
#: lib/block_scout_web/templates/address/index.html.eex:5 lib/block_scout_web/templates/address/overview.html.eex:180
#: lib/block_scout_web/templates/block/overview.html.eex:215 lib/block_scout_web/templates/internal_transaction/_tile.html.eex:20
#: lib/block_scout_web/templates/block/overview.html.eex:215 lib/block_scout_web/templates/internal_transaction/_tile.html.eex:24
#: lib/block_scout_web/templates/layout/_topnav.html.eex:89 lib/block_scout_web/templates/layout/_topnav.html.eex:110
#: lib/block_scout_web/templates/layout/app.html.eex:51 lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:37 lib/block_scout_web/templates/transaction/overview.html.eex:411
#: lib/block_scout_web/templates/transaction/_tile.html.eex:43 lib/block_scout_web/templates/transaction/overview.html.eex:411
#: lib/block_scout_web/views/wei_helpers.ex:78
msgid "Ether"
msgstr ""
Expand Down Expand Up @@ -1315,8 +1316,8 @@ msgid "IMPORTANT: This information is a best guess based on similar functions fr
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:38
#: lib/block_scout_web/templates/transaction/_tile.html.eex:80
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:42
#: lib/block_scout_web/templates/transaction/_tile.html.eex:86
msgid "IN"
msgstr ""

Expand Down Expand Up @@ -1376,7 +1377,7 @@ msgid "Interacted With (To)"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:6
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:7
msgid "Internal Transaction"
msgstr ""

Expand Down Expand Up @@ -1751,8 +1752,8 @@ msgid "Number of transfers to/from this address."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:36
#: lib/block_scout_web/templates/transaction/_tile.html.eex:76
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:40
#: lib/block_scout_web/templates/transaction/_tile.html.eex:82
msgid "OUT"
msgstr ""

Expand Down Expand Up @@ -2276,7 +2277,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:21
#: lib/block_scout_web/templates/transaction/_tile.html.eex:40
#: lib/block_scout_web/templates/transaction/_tile.html.eex:46
msgid "TX Fee"
msgstr ""

Expand Down Expand Up @@ -3052,12 +3053,12 @@ msgid "View Contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:61
#: lib/block_scout_web/templates/transaction/_tile.html.eex:67
msgid "View Less Transfers"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:60
#: lib/block_scout_web/templates/transaction/_tile.html.eex:66
msgid "View More Transfers"
msgstr ""

Expand Down Expand Up @@ -3359,3 +3360,8 @@ msgstr ""
#: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:18
msgid "validator"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:9
msgid "Error in internal transactions"
msgstr ""
28 changes: 17 additions & 11 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_link.html.eex:2
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:28 lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:32 lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43
msgid "Block #%{number}"
msgstr ""

Expand Down Expand Up @@ -1080,6 +1080,7 @@ msgid "Epochs range(s) or enum, e.g.: 5-9,23-27,47,50"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:11
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:10
msgid "Error"
msgstr ""
Expand Down Expand Up @@ -1118,10 +1119,10 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_balance_card.html.eex:18
#: lib/block_scout_web/templates/address/index.html.eex:5 lib/block_scout_web/templates/address/overview.html.eex:180
#: lib/block_scout_web/templates/block/overview.html.eex:215 lib/block_scout_web/templates/internal_transaction/_tile.html.eex:20
#: lib/block_scout_web/templates/block/overview.html.eex:215 lib/block_scout_web/templates/internal_transaction/_tile.html.eex:24
#: lib/block_scout_web/templates/layout/_topnav.html.eex:89 lib/block_scout_web/templates/layout/_topnav.html.eex:110
#: lib/block_scout_web/templates/layout/app.html.eex:51 lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:37 lib/block_scout_web/templates/transaction/overview.html.eex:411
#: lib/block_scout_web/templates/transaction/_tile.html.eex:43 lib/block_scout_web/templates/transaction/overview.html.eex:411
#: lib/block_scout_web/views/wei_helpers.ex:78
msgid "Ether"
msgstr ""
Expand Down Expand Up @@ -1315,8 +1316,8 @@ msgid "IMPORTANT: This information is a best guess based on similar functions fr
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:38
#: lib/block_scout_web/templates/transaction/_tile.html.eex:80
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:42
#: lib/block_scout_web/templates/transaction/_tile.html.eex:86
msgid "IN"
msgstr ""

Expand Down Expand Up @@ -1376,7 +1377,7 @@ msgid "Interacted With (To)"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:6
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:7
msgid "Internal Transaction"
msgstr ""

Expand Down Expand Up @@ -1751,8 +1752,8 @@ msgid "Number of transfers to/from this address."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:36
#: lib/block_scout_web/templates/transaction/_tile.html.eex:76
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:40
#: lib/block_scout_web/templates/transaction/_tile.html.eex:82
msgid "OUT"
msgstr ""

Expand Down Expand Up @@ -2276,7 +2277,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:21
#: lib/block_scout_web/templates/transaction/_tile.html.eex:40
#: lib/block_scout_web/templates/transaction/_tile.html.eex:46
msgid "TX Fee"
msgstr ""

Expand Down Expand Up @@ -3052,12 +3053,12 @@ msgid "View Contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:61
#: lib/block_scout_web/templates/transaction/_tile.html.eex:67
msgid "View Less Transfers"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:60
#: lib/block_scout_web/templates/transaction/_tile.html.eex:66
msgid "View More Transfers"
msgstr ""

Expand Down Expand Up @@ -3359,3 +3360,8 @@ msgstr ""
#: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:18
msgid "validator"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:9
msgid "Error in internal transactions"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do

update_transactions_inner(
repo,
valid_internal_transactions_count,
valid_internal_transactions,
transaction_hashes,
transaction_hashes_iterator,
timeout,
Expand All @@ -454,7 +454,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
transaction_from_db && Map.get(transaction_from_db, :cumulative_gas_used) ->
update_transactions_inner(
repo,
valid_internal_transactions_count,
valid_internal_transactions,
transaction_hashes,
transaction_hashes_iterator,
timeout,
Expand All @@ -468,7 +468,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do

update_transactions_inner(
repo,
valid_internal_transactions_count,
valid_internal_transactions,
transaction_hashes,
transaction_hashes_iterator,
timeout,
Expand All @@ -489,6 +489,13 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
end
end

defp get_trivial_tx_hashes_with_error_in_internal_tx(internal_transactions) do
internal_transactions
|> Enum.filter(fn internal_tx -> internal_tx[:index] != 0 && !is_nil(internal_tx[:error]) end)
|> Enum.map(fn internal_tx -> internal_tx[:transaction_hash] end)
|> MapSet.new()
end

defp fetch_transaction_receipt_from_node(transaction_hash, json_rpc_named_arguments) do
receipt_response =
EthereumJSONRPC.fetch_transaction_receipts(
Expand Down Expand Up @@ -517,15 +524,24 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do

defp update_transactions_inner(
repo,
valid_internal_transactions_count,
valid_internal_transactions,
transaction_hashes,
transaction_hashes_iterator,
timeout,
timestamps,
first_trace,
transaction_receipt_from_node \\ nil
) do
set = generate_transaction_set_to_update(first_trace, transaction_receipt_from_node, timestamps)
valid_internal_transactions_count = Enum.count(valid_internal_transactions)
txs_with_error_in_internal_txs = get_trivial_tx_hashes_with_error_in_internal_tx(valid_internal_transactions)

set =
generate_transaction_set_to_update(
first_trace,
transaction_receipt_from_node,
timestamps,
txs_with_error_in_internal_txs
)

update_query =
from(
Expand Down Expand Up @@ -553,7 +569,12 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
end
end

def generate_transaction_set_to_update(first_trace, transaction_receipt_from_node, timestamps) do
def generate_transaction_set_to_update(
first_trace,
transaction_receipt_from_node,
timestamps,
txs_with_error_in_internal_txs
) do
default_set = [
created_contract_address_hash: first_trace.created_contract_address_hash,
error: first_trace.error,
Expand All @@ -570,6 +591,10 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
:cumulative_gas_used,
transaction_receipt_from_node && transaction_receipt_from_node.cumulative_gas_used
)
|> Keyword.put_new(
:has_error_in_internal_txs,
if(Enum.member?(txs_with_error_in_internal_txs, first_trace.transaction_hash), do: true, else: false)
)

set_with_gas_used =
if first_trace.gas_used do
Expand Down
8 changes: 5 additions & 3 deletions apps/explorer/lib/explorer/chain/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ defmodule Explorer.Chain.Transaction do
alias Explorer.Chain.Transaction.{Fork, Status}

@optional_attrs ~w(max_priority_fee_per_gas max_fee_per_gas block_hash block_number created_contract_address_hash cumulative_gas_used earliest_processing_start
error gas_used index created_contract_code_indexed_at status
to_address_hash revert_reason type)a
error gas_used index created_contract_code_indexed_at status to_address_hash revert_reason type has_error_in_internal_txs)a

@required_attrs ~w(from_address_hash gas gas_price hash input nonce r s v value)a

Expand Down Expand Up @@ -135,6 +134,7 @@ defmodule Explorer.Chain.Transaction do
* `max_priority_fee_per_gas` - User defined maximum fee (tip) per unit of gas paid to validator for transaction prioritization.
* `max_fee_per_gas` - Maximum total amount per unit of gas a user is willing to pay for a transaction, including base fee and priority fee.
* `type` - New transaction type identifier introduced in EIP 2718 (Berlin HF)
* `has_error_in_internal_txs` - shows if the internal transactions related to transaction have errors
"""
@type t :: %__MODULE__{
block: %Ecto.Association.NotLoaded{} | Block.t() | nil,
Expand Down Expand Up @@ -169,7 +169,8 @@ defmodule Explorer.Chain.Transaction do
revert_reason: String.t() | nil,
max_priority_fee_per_gas: wei_per_gas | nil,
max_fee_per_gas: wei_per_gas | nil,
type: non_neg_integer() | nil
type: non_neg_integer() | nil,
has_error_in_internal_txs: boolean()
}

@derive {Poison.Encoder,
Expand Down Expand Up @@ -234,6 +235,7 @@ defmodule Explorer.Chain.Transaction do
field(:max_priority_fee_per_gas, Wei)
field(:max_fee_per_gas, Wei)
field(:type, :integer)
field(:has_error_in_internal_txs, :boolean)

# A transient field for deriving old block hash during transaction upserts.
# Used to force refetch of a block in case a transaction is re-collated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Explorer.Repo.Migrations.AddHasErrorInInternalTxsFieldToTransaction do
use Ecto.Migration

def change do
alter table(:transactions) do
add(:has_error_in_internal_txs, :boolean, null: true)
end
end
end
Loading

0 comments on commit 4e3d019

Please sign in to comment.