diff --git a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex index a3c12ac6eb..228b06eee3 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex @@ -66,7 +66,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do where_forked: where_forked }) end) - |> Multi.run(:lose_consenus, fn repo, _ -> + |> Multi.run(:lose_consensus, fn repo, _ -> lose_consensus(repo, ordered_consensus_block_numbers, insert_options) end) |> Multi.run(:delete_address_token_balances, fn repo, _ -> diff --git a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex index 08ff1f60a1..45bd9e3f43 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -51,10 +51,8 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do |> Multi.run(:internal_transactions, fn repo, _ -> insert(repo, changes_list, insert_options) end) - |> Multi.run(:internal_transactions_indexed_at_transactions, fn repo, - %{internal_transactions: internal_transactions} - when is_list(internal_transactions) -> - update_transactions(repo, internal_transactions, update_transactions_options) + |> Multi.run(:internal_transactions_indexed_at_transactions, fn repo, _ -> + update_transactions(repo, changes_list, update_transactions_options) end) end diff --git a/apps/explorer/test/explorer/chain/import_test.exs b/apps/explorer/test/explorer/chain/import_test.exs index 93a981648a..982f84c3c2 100644 --- a/apps/explorer/test/explorer/chain/import_test.exs +++ b/apps/explorer/test/explorer/chain/import_test.exs @@ -565,6 +565,61 @@ defmodule Explorer.Chain.ImportTest do assert address.contract_code != smart_contract_bytecode end + test "updates `error`, `status` and `internal_transaction_indexed_at` even if internal transactions were alreader inserted" do + address_hash = "0x1c494fa496f1cfd918b5ff190835af3aaf609899" + from_address = insert(:address, hash: address_hash) + + block = insert(:block, consensus: true) + + transaction = + :transaction + |> insert(error: nil, internal_transactions_indexed_at: nil, status: nil, from_address: from_address, status: 0) + |> with_block(block, status: :error) + + internal_transacton = + insert(:internal_transaction, + transaction_hash: transaction.hash, + error: "Bad Instruction", + index: 0, + gas_used: nil, + output: nil, + gas: 19, + type: "call" + ) + + options = %{ + internal_transactions: %{ + params: [ + %{ + block_number: internal_transacton.block_number, + call_type: internal_transacton.type, + gas: internal_transacton.gas, + gas_used: internal_transacton.gas_used, + index: internal_transacton.index, + output: internal_transacton.output, + transaction_hash: internal_transacton.transaction_hash, + type: internal_transacton.type, + from_address_hash: address_hash, + to_address_hash: address_hash, + trace_address: [], + value: 0, + transaction_index: 0, + error: internal_transacton.error, + input: internal_transacton.input + } + ] + } + } + + {:ok, _} = Import.all(options) + + assert result = + %Transaction{error: "Bad Instruction", status: :error} = + Repo.one!(from(t in Transaction, where: t.hash == ^transaction.hash)) + + assert result.internal_transactions_indexed_at + end + test "with internal_transactions updates Transaction internal_transactions_indexed_at" do block_hash = "0xe52d77084cab13a4e724162bcd8c6028e5ecfaa04d091ee476e96b9958ed6b47" block_number = 34