Get rid of all first traces

pull/3000/head
Victor Baranov 5 years ago
parent 7091cb1bf0
commit d227729db6
  1. 10
      apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex
  2. 39
      apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs
  3. 12
      apps/explorer/test/explorer/chain/import_test.exs
  4. 12
      apps/explorer/test/explorer/chain_test.exs
  5. 14
      apps/indexer/config/test.exs
  6. 8
      apps/indexer/config/test/ganache.exs
  7. 8
      apps/indexer/config/test/geth.exs
  8. 8
      apps/indexer/config/test/parity.exs
  9. 8
      apps/indexer/config/test/rsk.exs
  10. 19
      apps/indexer/test/indexer/fetcher/internal_transaction_test.exs

@ -299,13 +299,21 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
) do ) do
with {:ok, valid_internal_txs} <- with {:ok, valid_internal_txs} <-
valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do
json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments)
variant = Keyword.fetch!(json_rpc_named_arguments, :variant)
# we exclude first traces from storing in the DB only in case of Parity variant (Parity/Nethermind). todo: to the same for Geth
if variant == EthereumJSONRPC.Parity do
valid_internal_txs_without_first_trace = valid_internal_txs_without_first_trace =
valid_internal_txs valid_internal_txs
|> Enum.reject(fn trace -> |> Enum.reject(fn trace ->
trace[:index] == 0 && trace[:input] == %Explorer.Chain.Data{bytes: ""} trace[:index] == 0
end) end)
{:ok, valid_internal_txs_without_first_trace} {:ok, valid_internal_txs_without_first_trace}
else
{:ok, valid_internal_txs}
end
end end
end end

@ -102,22 +102,35 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
index = 0 index = 0
internal_transaction_changes_0 = make_internal_transaction_changes(transaction0, index, nil) internal_transaction_changes_0 = make_internal_transaction_changes(transaction0, index, nil)
internal_transaction_changes_0_1 = make_internal_transaction_changes(transaction0, 1, nil)
internal_transaction_changes_1 = internal_transaction_changes_1 =
make_internal_transaction_changes_for_simple_coin_transfers(transaction1, index, nil) make_internal_transaction_changes_for_simple_coin_transfers(transaction1, index, nil)
internal_transaction_changes_2 = make_internal_transaction_changes(transaction2, index, nil) internal_transaction_changes_2 = make_internal_transaction_changes(transaction2, index, nil)
internal_transaction_changes_2_1 = make_internal_transaction_changes(transaction2, 1, nil)
assert {:ok, _} = assert {:ok, _} =
run_internal_transactions([ run_internal_transactions([
internal_transaction_changes_0, internal_transaction_changes_0,
internal_transaction_changes_0_1,
internal_transaction_changes_1, internal_transaction_changes_1,
internal_transaction_changes_2 internal_transaction_changes_2,
internal_transaction_changes_2_1
]) ])
assert 0 == Repo.get_by!(InternalTransaction, transaction_hash: transaction0.hash).block_index assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction0.hash, where: i.index == 0)
|> Repo.one()
|> is_nil()
assert 1 == Repo.get_by!(InternalTransaction, transaction_hash: transaction0.hash, index: 1).block_index
assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction1.hash) |> Repo.one() |> is_nil() assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction1.hash) |> Repo.one() |> is_nil()
assert 2 == Repo.get_by!(InternalTransaction, transaction_hash: transaction2.hash).block_index
assert from(i in InternalTransaction, where: i.transaction_hash == ^transaction2.hash, where: i.index == 0)
|> Repo.one()
|> is_nil()
assert 4 == Repo.get_by!(InternalTransaction, transaction_hash: transaction2.hash, index: 1).block_index
end end
test "simple coin transfer has no internal transaction inserted" do test "simple coin transfer has no internal transaction inserted" do
@ -145,7 +158,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
assert :ok == transaction.status assert :ok == transaction.status
assert is_nil(pending.block_hash) assert is_nil(pending.block_hash)
index = 0 index = 1
transaction_changes = make_internal_transaction_changes(transaction, index, nil) transaction_changes = make_internal_transaction_changes(transaction, index, nil)
pending_changes = make_internal_transaction_changes(pending, index, nil) pending_changes = make_internal_transaction_changes(pending, index, nil)
@ -176,7 +189,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
assert full_block.hash == inserted.block_hash assert full_block.hash == inserted.block_hash
index = 0 index = 1
pending_transaction_changes = pending_transaction_changes =
pending pending
@ -256,17 +269,23 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
assert full_block.hash == inserted.block_hash assert full_block.hash == inserted.block_hash
index = 0 transaction_changes = make_internal_transaction_changes(inserted, 0, nil)
transaction_changes_2 = make_internal_transaction_changes(inserted, 1, nil)
transaction_changes = make_internal_transaction_changes(inserted, index, nil)
empty_changes = make_empty_block_changes(empty_block.number) empty_changes = make_empty_block_changes(empty_block.number)
assert {:ok, _} = run_internal_transactions([empty_changes, transaction_changes]) assert {:ok, _} = run_internal_transactions([empty_changes, transaction_changes, transaction_changes_2])
assert %{consensus: true} = Repo.get(Block, empty_block.hash) assert %{consensus: true} = Repo.get(Block, empty_block.hash)
assert PendingBlockOperation |> Repo.get(empty_block.hash) |> is_nil() assert PendingBlockOperation |> Repo.get(empty_block.hash) |> is_nil()
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, where: i.index == 0)
|> Repo.one()
|> is_nil() ==
true
assert from(i in InternalTransaction, where: i.transaction_hash == ^inserted.hash, where: i.index == 1)
|> Repo.one()
|> is_nil() ==
false false
assert %{consensus: true} = Repo.get(Block, full_block.hash) assert %{consensus: true} = Repo.get(Block, full_block.hash)

@ -252,15 +252,6 @@ defmodule Explorer.Chain.ImportTest do
} }
], ],
internal_transactions: [ internal_transactions: [
%{
index: 0,
transaction_hash: %Hash{
byte_count: 32,
bytes:
<<83, 189, 136, 72, 114, 222, 62, 72, 134, 146, 136, 27, 174, 236, 38, 46, 123, 149, 35, 77, 57,
101, 36, 140, 57, 254, 153, 47, 255, 212, 51, 229>>
}
},
%{ %{
index: 1, index: 1,
transaction_hash: %Hash{ transaction_hash: %Hash{
@ -485,8 +476,7 @@ defmodule Explorer.Chain.ImportTest do
Subscriber.to(:internal_transactions, :realtime) Subscriber.to(:internal_transactions, :realtime)
Import.all(@import_data) Import.all(@import_data)
assert_receive {:chain_event, :internal_transactions, :realtime, assert_receive {:chain_event, :internal_transactions, :realtime, [%{transaction_hash: _, index: _}]}
[%{transaction_hash: _, index: _}, %{transaction_hash: _, index: _}]}
end end
test "publishes transactions data to subscribers on insert" do test "publishes transactions data to subscribers on insert" do

@ -1562,17 +1562,7 @@ defmodule Explorer.ChainTest do
updated_at: %{} updated_at: %{}
} }
], ],
internal_transactions: [ internal_transactions: [],
%{
index: 0,
transaction_hash: %Hash{
byte_count: 32,
bytes:
<<83, 189, 136, 72, 114, 222, 62, 72, 134, 146, 136, 27, 174, 236, 38, 46, 123, 149, 35, 77, 57,
101, 36, 140, 57, 254, 153, 47, 255, 212, 51, 229>>
}
}
],
logs: [ logs: [
%Log{ %Log{
address_hash: %Hash{ address_hash: %Hash{

@ -20,3 +20,17 @@ config :logger, :addresses_without_code,
level: :debug, level: :debug,
path: Path.absname("logs/test/indexer/addresses_without_code.log"), path: Path.absname("logs/test/indexer/addresses_without_code.log"),
metadata_filter: [fetcher: :addresses_without_code] metadata_filter: [fetcher: :addresses_without_code]
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
# Import variant specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "test/#{variant}.exs"

@ -0,0 +1,8 @@
use Mix.Config
config :indexer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.Ganache
]

@ -0,0 +1,8 @@
use Mix.Config
config :indexer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.Geth
]

@ -0,0 +1,8 @@
use Mix.Config
config :indexer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.Parity
]

@ -0,0 +1,8 @@
use Mix.Config
config :indexer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.RSK
]

@ -210,9 +210,26 @@ defmodule Indexer.Fetcher.InternalTransactionTest do
"value" => "0x174876e800" "value" => "0x174876e800"
}, },
"result" => %{"gasUsed" => "0x7d37", "output" => "0x"}, "result" => %{"gasUsed" => "0x7d37", "output" => "0x"},
"subtraces" => 0, "subtraces" => 1,
"traceAddress" => [], "traceAddress" => [],
"type" => "call" "type" => "call"
},
%{
"action" => %{
"callType" => "call",
"from" => "0xb37b428a7ddee91f39b26d79d23dc1c89e3e12a7",
"gas" => "0x32dcf",
"input" => "0x42dad49e",
"to" => "0xee4019030fb5c2b68c42105552c6268d56c6cbfe",
"value" => "0x0"
},
"result" => %{
"gasUsed" => "0xb08",
"output" => "0x"
},
"subtraces" => 0,
"traceAddress" => [0],
"type" => "call"
} }
], ],
"transactionHash" => transaction.hash, "transactionHash" => transaction.hash,

Loading…
Cancel
Save