From 3c6f500051208e44f8e72a0c41a3ba82dbb852b6 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 7 Feb 2020 17:31:52 +0300 Subject: [PATCH 01/18] Get rid of internal transactions for simple transactions --- CHANGELOG.md | 1 + .../import/runner/internal_transactions.ex | 156 +++++++++---- .../runner/internal_transactions_test.exs | 106 +++++++++ .../test/explorer/chain/import_test.exs | 220 +++++++++++++++++- apps/explorer/test/explorer/chain_test.exs | 2 +- 5 files changed, 433 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 047c569051..038cc1055e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers - [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash 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 69899f7584..bc14b7ba15 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -43,6 +43,16 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do |> Map.put_new(:timeout, @timeout) |> Map.put(:timestamps, timestamps) + changes_list_without_first_traces_of_trivial_transactions = + Enum.reject(changes_list, fn changes -> + changes[:index] == 0 && changes[:input] == %Explorer.Chain.Data{bytes: ""} + end) + + all_first_traces = + Enum.filter(changes_list, fn changes -> + changes[:index] == 0 + end) + transactions_timeout = options[Runner.Transactions.option_key()][:timeout] || Runner.Transactions.timeout() update_transactions_options = %{timeout: transactions_timeout, timestamps: timestamps} @@ -50,6 +60,10 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do # filter out params with just `block_number` (indicating blocks without internal transactions) internal_transactions_params = Enum.filter(changes_list, &Map.has_key?(&1, :type)) + # internal transactions for update + internal_transactions_for_update_transactions_params = + Enum.filter(changes_list_without_first_traces_of_trivial_transactions, &Map.has_key?(&1, :type)) + # Enforce ShareLocks tables order (see docs: sharelocks.md) multi |> Multi.run(:acquire_blocks, fn repo, _ -> @@ -64,22 +78,43 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do |> Multi.run(:invalid_block_numbers, fn _, %{acquire_transactions: transactions} -> invalid_block_numbers(transactions, internal_transactions_params) 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( + transactions, + internal_transactions_for_update_transactions_params, + invalid_block_numbers + ) + end) |> Multi.run(:valid_internal_transactions, fn _, %{ acquire_transactions: transactions, invalid_block_numbers: invalid_block_numbers } -> - valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) + valid_internal_transactions( + transactions, + internal_transactions_params, + invalid_block_numbers + ) end) |> Multi.run(:remove_left_over_internal_transactions, fn repo, %{valid_internal_transactions: valid_internal_transactions} -> remove_left_over_internal_transactions(repo, valid_internal_transactions) end) - |> Multi.run(:internal_transactions, fn repo, %{valid_internal_transactions: valid_internal_transactions} -> - insert(repo, valid_internal_transactions, insert_options) + |> Multi.run(:internal_transactions, fn repo, + %{ + valid_internal_transactions_without_first_traces_of_trivial_transactions: + valid_internal_transactions_without_first_traces_of_trivial_transactions + } -> + insert(repo, valid_internal_transactions_without_first_traces_of_trivial_transactions, insert_options) end) |> Multi.run(:update_transactions, fn repo, %{valid_internal_transactions: valid_internal_transactions} -> - update_transactions(repo, valid_internal_transactions, update_transactions_options) + update_transactions(repo, valid_internal_transactions, all_first_traces, update_transactions_options) end) |> Multi.run(:remove_consensus_of_invalid_blocks, fn repo, %{invalid_block_numbers: invalid_block_numbers} -> remove_consensus_of_invalid_blocks(repo, invalid_block_numbers) @@ -297,7 +332,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do or_where(acc, [it], it.block_hash == ^block_hash and it.block_index > ^max_index) end) - # removes old recoreds with the same primary key (transaction hash, transaction index) + # removes old records with the same primary key (transaction hash, transaction index) delete_query = valid_internal_transactions |> Enum.map(fn params -> {params.transaction_hash, params.index} end) @@ -315,52 +350,81 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do end end - defp update_transactions(repo, valid_internal_transactions, %{ + defp update_transactions(repo, valid_internal_transactions, first_traces, %{ timeout: timeout, timestamps: timestamps - }) - when is_list(valid_internal_transactions) do - transaction_hashes = - valid_internal_transactions - |> MapSet.new(& &1.transaction_hash) - |> MapSet.to_list() + }) do + valid_internal_transactions_count = Enum.count(valid_internal_transactions) + + if valid_internal_transactions_count == 0 do + {:ok, nil} + else + params = + Enum.map(first_traces, fn first_trace -> + %{ + transaction_hash: Map.get(first_trace, :transaction_hash), + created_contract_address_hash: Map.get(first_trace, :created_contract_address_hash), + error: Map.get(first_trace, :error), + status: if(is_nil(Map.get(first_trace, :error)), do: :ok, else: :error) + } + end) - update_query = - from( - t in Transaction, - where: t.hash in ^transaction_hashes, - # ShareLocks order already enforced by `acquire_transactions` (see docs: sharelocks.md) - update: [ - set: [ - created_contract_address_hash: - fragment( - "(SELECT it.created_contract_address_hash FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index ASC LIMIT 1)", - t.hash - ), - error: - fragment( - "(SELECT it.error FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index ASC LIMIT 1)", - t.hash - ), - status: - fragment( - "CASE WHEN (SELECT it.error FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index ASC LIMIT 1) IS NULL THEN ? ELSE ? END", - t.hash, - type(^:ok, t.status), - type(^:error, t.status) - ), - updated_at: ^timestamps.updated_at - ] - ] - ) + transaction_hashes = + valid_internal_transactions + |> Enum.map(fn valid_internal_transaction -> + Map.get(valid_internal_transaction, :transaction_hash) + end) + |> Enum.filter(fn hash -> hash != nil end) - try do - {_transaction_count, result} = repo.update_all(update_query, [], timeout: timeout) + transaction_hashes_count = Enum.count(transaction_hashes) - {:ok, result} - rescue - postgrex_error in Postgrex.Error -> - {:error, %{exception: postgrex_error, transaction_hashes: transaction_hashes}} + result = + Enum.reduce_while(transaction_hashes, 0, fn transaction_hash, transaction_hashes_iterator -> + first_trace_params = + params + |> Enum.filter(fn first_trace -> + first_trace.transaction_hash == transaction_hash + end) + |> Enum.at(0) + + update_query = + from( + t in Transaction, + where: t.hash == ^transaction_hash, + # ShareLocks order already enforced by `acquire_transactions` (see docs: sharelocks.md) + update: [ + set: [ + created_contract_address_hash: ^first_trace_params.created_contract_address_hash, + error: ^first_trace_params.error, + status: ^first_trace_params.status, + updated_at: ^timestamps.updated_at + ] + ] + ) + + transaction_hashes_iterator = transaction_hashes_iterator + 1 + + try do + {_transaction_count, result} = repo.update_all(update_query, [], timeout: timeout) + + if transaction_hashes_count == transaction_hashes_iterator do + {:halt, result} + else + {:cont, transaction_hashes_iterator} + end + rescue + postgrex_error in Postgrex.Error -> + {:halt, %{exception: postgrex_error, transaction_hashes: transaction_hashes}} + end + end) + + case result do + %{exception: _} -> + {:error, result} + + _ -> + {:ok, result} + end end end diff --git a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs index bb4ecc1ac1..ac344a20fe 100644 --- a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs @@ -22,6 +22,88 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do assert :error == Repo.get(Transaction, transaction.hash).status end + test "simple coin transfer's status becomes :error when its internal_transaction has an error" do + transaction = insert(:transaction) |> with_block(status: :ok) + insert(:pending_block_operation, block_hash: transaction.block_hash, fetch_internal_transactions: true) + + assert :ok == transaction.status + + index = 0 + error = "Out of gas" + + internal_transaction_changes = + make_internal_transaction_changes_for_simple_coin_transfers(transaction, index, error) + + assert {:ok, _} = run_internal_transactions([internal_transaction_changes]) + + assert :error == Repo.get(Transaction, transaction.hash).status + end + + test "for block with 2 simple coin transfer's statuses become :error when its both internal_transactions has an error" do + a_block = insert(:block, number: 1000) + transaction1 = insert(:transaction) |> with_block(a_block, status: :ok) + transaction2 = insert(:transaction) |> with_block(a_block, status: :ok) + + insert(:pending_block_operation, block_hash: a_block.hash, fetch_internal_transactions: true) + + assert :ok == transaction1.status + assert :ok == transaction2.status + + index = 0 + error = "Out of gas" + + internal_transaction_changes_1 = + make_internal_transaction_changes_for_simple_coin_transfers(transaction1, index, error) + + internal_transaction_changes_2 = + make_internal_transaction_changes_for_simple_coin_transfers(transaction2, index, error) + + assert {:ok, _} = run_internal_transactions([internal_transaction_changes_1, internal_transaction_changes_2]) + + assert :error == Repo.get(Transaction, transaction1.hash).status + assert :error == Repo.get(Transaction, transaction2.hash).status + end + + test "for block with 2 simple coin transfer's only status become :error for tx where internal_transactions has an error" do + a_block = insert(:block, number: 1000) + transaction1 = insert(:transaction) |> with_block(a_block, status: :ok) + transaction2 = insert(:transaction) |> with_block(a_block, status: :ok) + insert(:pending_block_operation, block_hash: a_block.hash, fetch_internal_transactions: true) + + assert :ok == transaction1.status + assert :ok == transaction2.status + + index = 0 + error = "Out of gas" + + internal_transaction_changes_1 = + make_internal_transaction_changes_for_simple_coin_transfers(transaction1, index, error) + + internal_transaction_changes_2 = + make_internal_transaction_changes_for_simple_coin_transfers(transaction2, index, nil) + + assert {:ok, _} = run_internal_transactions([internal_transaction_changes_1, internal_transaction_changes_2]) + + assert :error == Repo.get(Transaction, transaction1.hash).status + assert :ok == Repo.get(Transaction, transaction2.hash).status + end + + test "simple coin transfer has no internal transaction inserted" do + transaction = insert(:transaction) |> with_block(status: :ok) + insert(:pending_block_operation, block_hash: transaction.block_hash, fetch_internal_transactions: true) + + assert :ok == transaction.status + + index = 0 + + internal_transaction_changes = + make_internal_transaction_changes_for_simple_coin_transfers(transaction, index, nil) + + assert {:ok, _} = run_internal_transactions([internal_transaction_changes]) + + assert !Repo.exists?(from(i in InternalTransaction, where: i.transaction_hash == ^transaction.hash)) + end + test "pending transactions don't get updated not its internal_transactions inserted" do transaction = insert(:transaction) |> with_block(status: :ok) pending = insert(:transaction) @@ -199,4 +281,28 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do block_number: transaction.block_number } end + + defp make_internal_transaction_changes_for_simple_coin_transfers(transaction, index, error) do + %{ + from_address_hash: insert(:address).hash, + to_address_hash: insert(:address).hash, + call_type: :call, + gas: 0, + gas_used: nil, + input: %Data{bytes: <<>>}, + output: + if is_nil(error) do + %Data{bytes: <<0>>} + else + nil + end, + index: index, + trace_address: [], + transaction_hash: transaction.hash, + type: :call, + value: Wei.from(Decimal.new(1), :wei), + error: error, + block_number: transaction.block_number + } + end end diff --git a/apps/explorer/test/explorer/chain/import_test.exs b/apps/explorer/test/explorer/chain/import_test.exs index 7a06fa2779..30e8a08e57 100644 --- a/apps/explorer/test/explorer/chain/import_test.exs +++ b/apps/explorer/test/explorer/chain/import_test.exs @@ -61,7 +61,7 @@ defmodule Explorer.Chain.ImportTest do to_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", gas: 4_677_320, gas_used: 27770, - input: "0x", + input: "0x10855269000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef", output: "0x", value: 0 }, @@ -77,7 +77,7 @@ defmodule Explorer.Chain.ImportTest do to_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", gas: 4_677_320, gas_used: 27770, - input: "0x", + input: "0x10855269000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef", output: "0x", value: 0 } @@ -612,7 +612,8 @@ defmodule Explorer.Chain.ImportTest do gas_used: 269_607, hash: transaction_hash, index: 0, - input: "0x", + input: + "0x6060604052341561000f57600080fd5b7fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5426040518082815260200191505060405180910390a1609e806100546000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063557ed1ba146044575b600080fd5b3415604e57600080fd5b6054606a565b6040518082815260200191505060405180910390f35b6000429050905600a165627a7a7230582053883c0c39da080adc15a91094921659c200b3bb60aed9e49b79b0274da3f4010029", nonce: 0, r: 0, s: 0, @@ -639,6 +640,96 @@ defmodule Explorer.Chain.ImportTest do to_address_hash: to_address_hash, gas: 4_677_320, gas_used: 27770, + input: + "0x6060604052341561000f57600080fd5b7fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5426040518082815260200191505060405180910390a1609e806100546000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063557ed1ba146044575b600080fd5b3415604e57600080fd5b6054606a565b6040518082815260200191505060405180910390f35b6000429050905600a165627a7a7230582053883c0c39da080adc15a91094921659c200b3bb60aed9e49b79b0274da3f4010029", + output: "0x", + value: 0 + } + ], + with: :blockless_changeset + } + } + + assert {:ok, _} = Import.all(options) + + assert [block_hash] = Explorer.Repo.all(PendingBlockOperation.block_hashes(:fetch_internal_transactions)) + + assert {:ok, _} = Import.all(internal_txs_options) + + assert [] == Explorer.Repo.all(PendingBlockOperation.block_hashes(:fetch_internal_transactions)) + end + + test "blocks with simple coin transfers updates PendingBlockOperation status" do + block_hash = "0xe69314b702f403e00ec89cd63d5870182ed334d9d461bd042cdd6609fd6b7c17" + block_number = 13_255_416 + miner_hash = from_address_hash = "0xe2ac1c6843A33f81aE4935E5EF1277a392990381" + to_address_hash = "0xDC1772b72d828ea9b7D4ded22dbef0f082578B8B" + transaction_hash = "0x8f20a5b3b79199db857323af7a5077d2dae7867368fef6f4e8cd8b14b88a9c6a" + + options = %{ + addresses: %{ + params: [ + %{hash: from_address_hash}, + %{hash: to_address_hash} + ] + }, + blocks: %{ + params: [ + %{ + consensus: true, + difficulty: 340_282_366_920_938_463_463_374_607_400_000_000_000, + gas_limit: 9_999_991, + gas_used: 21_000, + hash: block_hash, + miner_hash: miner_hash, + nonce: 0, + number: block_number, + parent_hash: "0x4c4505527d99e07dbcd6274ffaac629099ae6d4e1f2bc2bd3cc48d3f5a511d6f", + size: 703, + timestamp: Timex.parse!("2020-02-12 10:48:21Z", "{ISO:Extended:Z}"), + total_difficulty: 4_510_584_331_001_678_443_607_831_185_000_000_000_000_000_000 + } + ] + }, + transactions: %{ + params: [ + %{ + block_hash: block_hash, + block_number: block_number, + cumulative_gas_used: 21_000, + from_address_hash: from_address_hash, + gas: 21_000, + gas_price: 1, + gas_used: 21_000, + hash: transaction_hash, + index: 0, + input: "0x", + nonce: 0, + r: 0, + s: 0, + status: :ok, + v: 0, + value: 0 + } + ] + } + } + + internal_txs_options = %{ + internal_transactions: %{ + params: [ + %{ + block_number: block_number, + transaction_index: 0, + transaction_hash: transaction_hash, + index: 0, + trace_address: [], + type: "call", + call_type: "call", + from_address_hash: from_address_hash, + to_address_hash: to_address_hash, + gas: 21_000, + gas_used: 21000, input: "0x", output: "0x", value: 0 @@ -1709,7 +1800,7 @@ defmodule Explorer.Chain.ImportTest do end # https://github.com/poanetwork/blockscout/issues/868 regression test - test "errored transactions can be forked" do + test "errored simple coin transfer can be forked" do block_number = 0 miner_hash_before = address_hash() @@ -1771,6 +1862,125 @@ defmodule Explorer.Chain.ImportTest do status: :error } ] + } + }) + + %Block{consensus: true, number: ^block_number} = Repo.get(Block, block_hash_before) + transaction_before = Repo.get!(Transaction, transaction_hash) + + refute transaction_before.block_hash == nil + refute transaction_before.block_number == nil + refute transaction_before.gas_used == nil + refute transaction_before.cumulative_gas_used == nil + refute transaction_before.index == nil + refute transaction_before.status == nil + + miner_hash_after = address_hash() + from_address_hash_after = address_hash() + block_hash_after = block_hash() + + assert {:ok, _} = + Import.all(%{ + addresses: %{ + params: [ + %{hash: miner_hash_after}, + %{hash: from_address_hash_after} + ] + }, + blocks: %{ + params: [ + %{ + consensus: true, + difficulty: 1, + gas_limit: 1, + gas_used: 1, + hash: block_hash_after, + miner_hash: miner_hash_after, + nonce: 1, + number: block_number, + parent_hash: block_hash(), + size: 1, + timestamp: Timex.parse!("2019-01-01T02:00:00Z", "{ISO:Extended:Z}"), + total_difficulty: 1 + } + ] + } + }) + + transaction_after = Repo.get!(Transaction, transaction_hash) + + assert transaction_after.block_hash == nil + assert transaction_after.block_number == nil + assert transaction_after.gas_used == nil + assert transaction_after.cumulative_gas_used == nil + assert transaction_after.index == nil + assert transaction_after.error == nil + assert transaction_after.status == nil + end + + # https://github.com/poanetwork/blockscout/issues/868 regression test + test "errored other transactions can be forked" do + block_number = 0 + + miner_hash_before = address_hash() + from_address_hash_before = address_hash() + to_address_hash_before = address_hash() + block_hash_before = block_hash() + index_before = 0 + error = "Reverted" + + transaction_hash = transaction_hash() + + assert {:ok, _} = + Import.all(%{ + addresses: %{ + params: [ + %{hash: miner_hash_before}, + %{hash: from_address_hash_before}, + %{hash: to_address_hash_before} + ] + }, + blocks: %{ + params: [ + %{ + consensus: true, + difficulty: 0, + gas_limit: 0, + gas_used: 0, + hash: block_hash_before, + miner_hash: miner_hash_before, + nonce: 0, + number: block_number, + parent_hash: block_hash(), + size: 0, + timestamp: Timex.parse!("2019-01-01T01:00:00Z", "{ISO:Extended:Z}"), + total_difficulty: 0 + } + ] + }, + transactions: %{ + params: [ + %{ + block_hash: block_hash_before, + block_number: block_number, + error: error, + from_address_hash: from_address_hash_before, + to_address_hash: to_address_hash_before, + gas: 666_000, + gas_price: 1, + gas_used: 555_000, + cumulative_gas_used: 555_000, + hash: transaction_hash, + index: index_before, + input: "0x0102", + nonce: 0, + r: 0, + s: 0, + v: 0, + value: 0, + status: :error + } + ] }, internal_transactions: %{ params: [ @@ -1784,7 +1994,7 @@ defmodule Explorer.Chain.ImportTest do to_address_hash: to_address_hash_before, trace_address: [], value: 0, - input: "0x", + input: "0x0102", error: error, block_number: block_number, transaction_index: 0 diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index b37edbc36e..81a7fd35d8 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -1393,7 +1393,7 @@ defmodule Explorer.ChainTest do to_address_hash: "0x8bf38d4764929064f2d4d3a56520a76ab3df415b", gas: 4_677_320, gas_used: 27770, - input: "0x", + input: "0x10855269000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef", output: "0x", value: 0 } From 9267d75ca1feefb974d95b931daec3626dfbd573 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 13 Feb 2020 15:59:39 +0300 Subject: [PATCH 02/18] Refactoring --- .../import/runner/internal_transactions.ex | 81 +++++++++---------- .../runner/internal_transactions_test.exs | 32 ++++++++ 2 files changed, 71 insertions(+), 42 deletions(-) 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 bc14b7ba15..6b6301b2f9 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -43,16 +43,6 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do |> Map.put_new(:timeout, @timeout) |> Map.put(:timestamps, timestamps) - changes_list_without_first_traces_of_trivial_transactions = - Enum.reject(changes_list, fn changes -> - changes[:index] == 0 && changes[:input] == %Explorer.Chain.Data{bytes: ""} - end) - - all_first_traces = - Enum.filter(changes_list, fn changes -> - changes[:index] == 0 - end) - transactions_timeout = options[Runner.Transactions.option_key()][:timeout] || Runner.Transactions.timeout() update_transactions_options = %{timeout: transactions_timeout, timestamps: timestamps} @@ -60,10 +50,6 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do # filter out params with just `block_number` (indicating blocks without internal transactions) internal_transactions_params = Enum.filter(changes_list, &Map.has_key?(&1, :type)) - # internal transactions for update - internal_transactions_for_update_transactions_params = - Enum.filter(changes_list_without_first_traces_of_trivial_transactions, &Map.has_key?(&1, :type)) - # Enforce ShareLocks tables order (see docs: sharelocks.md) multi |> Multi.run(:acquire_blocks, fn repo, _ -> @@ -85,9 +71,9 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do invalid_block_numbers: invalid_block_numbers } -> - valid_internal_transactions( + valid_internal_transactions_without_first_trace( transactions, - internal_transactions_for_update_transactions_params, + internal_transactions_params, invalid_block_numbers ) end) @@ -114,7 +100,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do insert(repo, valid_internal_transactions_without_first_traces_of_trivial_transactions, insert_options) end) |> Multi.run(:update_transactions, fn repo, %{valid_internal_transactions: valid_internal_transactions} -> - update_transactions(repo, valid_internal_transactions, all_first_traces, update_transactions_options) + update_transactions(repo, valid_internal_transactions, update_transactions_options) end) |> Multi.run(:remove_consensus_of_invalid_blocks, fn repo, %{invalid_block_numbers: invalid_block_numbers} -> remove_consensus_of_invalid_blocks(repo, invalid_block_numbers) @@ -306,6 +292,23 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do {:ok, valid_internal_txs} end + defp valid_internal_transactions_without_first_trace( + transactions, + internal_transactions_params, + invalid_block_numbers + ) do + with {:ok, valid_internal_txs} <- + valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do + valid_internal_txs_without_first_trace = + valid_internal_txs + |> Enum.reject(fn trace -> + trace[:index] == 0 && trace[:input] == %Explorer.Chain.Data{bytes: ""} + end) + + {:ok, valid_internal_txs_without_first_trace} + end + end + def defer_internal_transactions_primary_key(repo) do # Allows internal_transactions primary key to not be checked during the # DB transactions and instead be checked only at the end of it. @@ -350,7 +353,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do end end - defp update_transactions(repo, valid_internal_transactions, first_traces, %{ + defp update_transactions(repo, valid_internal_transactions, %{ timeout: timeout, timestamps: timestamps }) do @@ -360,43 +363,37 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do {:ok, nil} else params = - Enum.map(first_traces, fn first_trace -> + valid_internal_transactions + |> Enum.filter(fn internal_tx -> + internal_tx[:index] == 0 + end) + |> Enum.map(fn trace -> %{ - transaction_hash: Map.get(first_trace, :transaction_hash), - created_contract_address_hash: Map.get(first_trace, :created_contract_address_hash), - error: Map.get(first_trace, :error), - status: if(is_nil(Map.get(first_trace, :error)), do: :ok, else: :error) + transaction_hash: Map.get(trace, :transaction_hash), + created_contract_address_hash: Map.get(trace, :created_contract_address_hash), + error: Map.get(trace, :error), + status: if(is_nil(Map.get(trace, :error)), do: :ok, else: :error) } end) + |> Enum.filter(fn transaction_hash -> transaction_hash != nil end) transaction_hashes = valid_internal_transactions - |> Enum.map(fn valid_internal_transaction -> - Map.get(valid_internal_transaction, :transaction_hash) - end) - |> Enum.filter(fn hash -> hash != nil end) - - transaction_hashes_count = Enum.count(transaction_hashes) + |> MapSet.new(& &1.transaction_hash) + |> MapSet.to_list() result = - Enum.reduce_while(transaction_hashes, 0, fn transaction_hash, transaction_hashes_iterator -> - first_trace_params = - params - |> Enum.filter(fn first_trace -> - first_trace.transaction_hash == transaction_hash - end) - |> Enum.at(0) - + Enum.reduce_while(params, 0, fn first_trace, transaction_hashes_iterator -> update_query = from( t in Transaction, - where: t.hash == ^transaction_hash, + where: t.hash == ^first_trace.transaction_hash, # ShareLocks order already enforced by `acquire_transactions` (see docs: sharelocks.md) update: [ set: [ - created_contract_address_hash: ^first_trace_params.created_contract_address_hash, - error: ^first_trace_params.error, - status: ^first_trace_params.status, + created_contract_address_hash: ^first_trace.created_contract_address_hash, + error: ^first_trace.error, + status: ^first_trace.status, updated_at: ^timestamps.updated_at ] ] @@ -407,7 +404,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do try do {_transaction_count, result} = repo.update_all(update_query, [], timeout: timeout) - if transaction_hashes_count == transaction_hashes_iterator do + if valid_internal_transactions_count == transaction_hashes_iterator do {:halt, result} else {:cont, transaction_hashes_iterator} diff --git a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs index ac344a20fe..f2c890850d 100644 --- a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs @@ -88,6 +88,38 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do assert :ok == Repo.get(Transaction, transaction2.hash).status end + test "for block with simple coin transfer and method calls, method calls internal txs have correct block_index" do + a_block = insert(:block, number: 1000) + transaction0 = insert(:transaction) |> with_block(a_block, status: :ok) + transaction1 = insert(:transaction) |> with_block(a_block, status: :ok) + transaction2 = insert(:transaction) |> with_block(a_block, status: :ok) + insert(:pending_block_operation, block_hash: a_block.hash, fetch_internal_transactions: true) + + assert :ok == transaction0.status + assert :ok == transaction1.status + assert :ok == transaction2.status + + index = 0 + + internal_transaction_changes_0 = make_internal_transaction_changes(transaction0, index, nil) + + internal_transaction_changes_1 = + make_internal_transaction_changes_for_simple_coin_transfers(transaction1, index, nil) + + internal_transaction_changes_2 = make_internal_transaction_changes(transaction2, index, nil) + + assert {:ok, _} = + run_internal_transactions([ + internal_transaction_changes_0, + internal_transaction_changes_1, + internal_transaction_changes_2 + ]) + + assert 0 == Repo.get_by!(InternalTransaction, transaction_hash: transaction0.hash).block_index + 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 + end + test "simple coin transfer has no internal transaction inserted" do transaction = insert(:transaction) |> with_block(status: :ok) insert(:pending_block_operation, block_hash: transaction.block_hash, fetch_internal_transactions: true) From d227729db6842b4a5bf9736613a36078683c43a0 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 18 Feb 2020 19:24:45 +0300 Subject: [PATCH 03/18] Get rid of all first traces --- .../import/runner/internal_transactions.ex | 22 +++++++---- .../runner/internal_transactions_test.exs | 39 ++++++++++++++----- .../test/explorer/chain/import_test.exs | 12 +----- apps/explorer/test/explorer/chain_test.exs | 12 +----- apps/indexer/config/test.exs | 14 +++++++ apps/indexer/config/test/ganache.exs | 8 ++++ apps/indexer/config/test/geth.exs | 8 ++++ apps/indexer/config/test/parity.exs | 8 ++++ apps/indexer/config/test/rsk.exs | 8 ++++ .../fetcher/internal_transaction_test.exs | 19 ++++++++- 10 files changed, 110 insertions(+), 40 deletions(-) create mode 100644 apps/indexer/config/test/ganache.exs create mode 100644 apps/indexer/config/test/geth.exs create mode 100644 apps/indexer/config/test/parity.exs create mode 100644 apps/indexer/config/test/rsk.exs 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 6b6301b2f9..beb8dcc824 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -299,13 +299,21 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do ) do with {:ok, valid_internal_txs} <- valid_internal_transactions(transactions, internal_transactions_params, invalid_block_numbers) do - valid_internal_txs_without_first_trace = - valid_internal_txs - |> Enum.reject(fn trace -> - trace[:index] == 0 && trace[:input] == %Explorer.Chain.Data{bytes: ""} - end) - - {:ok, valid_internal_txs_without_first_trace} + 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 + |> Enum.reject(fn trace -> + trace[:index] == 0 + end) + + {:ok, valid_internal_txs_without_first_trace} + else + {:ok, valid_internal_txs} + end end end diff --git a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs index f2c890850d..c58a0cef05 100644 --- a/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/internal_transactions_test.exs @@ -102,22 +102,35 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do index = 0 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 = 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_1 = make_internal_transaction_changes(transaction2, 1, nil) assert {:ok, _} = run_internal_transactions([ internal_transaction_changes_0, + internal_transaction_changes_0_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 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 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 is_nil(pending.block_hash) - index = 0 + index = 1 transaction_changes = make_internal_transaction_changes(transaction, 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 - index = 0 + index = 1 pending_transaction_changes = pending @@ -256,17 +269,23 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do assert full_block.hash == inserted.block_hash - index = 0 - - transaction_changes = make_internal_transaction_changes(inserted, index, nil) + transaction_changes = make_internal_transaction_changes(inserted, 0, nil) + transaction_changes_2 = make_internal_transaction_changes(inserted, 1, nil) 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 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 assert %{consensus: true} = Repo.get(Block, full_block.hash) diff --git a/apps/explorer/test/explorer/chain/import_test.exs b/apps/explorer/test/explorer/chain/import_test.exs index 30e8a08e57..f96a536526 100644 --- a/apps/explorer/test/explorer/chain/import_test.exs +++ b/apps/explorer/test/explorer/chain/import_test.exs @@ -252,15 +252,6 @@ defmodule Explorer.Chain.ImportTest do } ], 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, transaction_hash: %Hash{ @@ -485,8 +476,7 @@ defmodule Explorer.Chain.ImportTest do Subscriber.to(:internal_transactions, :realtime) Import.all(@import_data) - assert_receive {:chain_event, :internal_transactions, :realtime, - [%{transaction_hash: _, index: _}, %{transaction_hash: _, index: _}]} + assert_receive {:chain_event, :internal_transactions, :realtime, [%{transaction_hash: _, index: _}]} end test "publishes transactions data to subscribers on insert" do diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 81a7fd35d8..c131bacc92 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -1562,17 +1562,7 @@ defmodule Explorer.ChainTest do updated_at: %{} } ], - 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>> - } - } - ], + internal_transactions: [], logs: [ %Log{ address_hash: %Hash{ diff --git a/apps/indexer/config/test.exs b/apps/indexer/config/test.exs index fb54d51ab2..e74b5e1abf 100644 --- a/apps/indexer/config/test.exs +++ b/apps/indexer/config/test.exs @@ -20,3 +20,17 @@ config :logger, :addresses_without_code, level: :debug, path: Path.absname("logs/test/indexer/addresses_without_code.log"), 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" diff --git a/apps/indexer/config/test/ganache.exs b/apps/indexer/config/test/ganache.exs new file mode 100644 index 0000000000..b421779152 --- /dev/null +++ b/apps/indexer/config/test/ganache.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.Ganache + ] diff --git a/apps/indexer/config/test/geth.exs b/apps/indexer/config/test/geth.exs new file mode 100644 index 0000000000..7c4b58b31a --- /dev/null +++ b/apps/indexer/config/test/geth.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.Geth + ] diff --git a/apps/indexer/config/test/parity.exs b/apps/indexer/config/test/parity.exs new file mode 100644 index 0000000000..af3c396e9a --- /dev/null +++ b/apps/indexer/config/test/parity.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.Parity + ] diff --git a/apps/indexer/config/test/rsk.exs b/apps/indexer/config/test/rsk.exs new file mode 100644 index 0000000000..15e2768fc7 --- /dev/null +++ b/apps/indexer/config/test/rsk.exs @@ -0,0 +1,8 @@ +use Mix.Config + +config :indexer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.Mox, + transport_options: [], + variant: EthereumJSONRPC.RSK + ] diff --git a/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs b/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs index 0486f7c8eb..770c208269 100644 --- a/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs +++ b/apps/indexer/test/indexer/fetcher/internal_transaction_test.exs @@ -210,9 +210,26 @@ defmodule Indexer.Fetcher.InternalTransactionTest do "value" => "0x174876e800" }, "result" => %{"gasUsed" => "0x7d37", "output" => "0x"}, - "subtraces" => 0, + "subtraces" => 1, "traceAddress" => [], "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, From a62516913a0c3a3db3b5d9a823f0b44f0a9fd185 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 25 Feb 2020 19:33:04 +0300 Subject: [PATCH 04/18] Fix splitting setup --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain.ex | 11 +++++++++++ .../lib/explorer/chain/events/listener.ex | 9 ++++++++- apps/explorer/test/explorer/chain_test.exs | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 411431fcc2..8fe447f507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash ### Fixes +- [#3025](https://github.com/poanetwork/blockscout/pull/3025) - Fix splitting of indexer/web components setup - [#3021](https://github.com/poanetwork/blockscout/pull/3021), [#3022](https://github.com/poanetwork/blockscout/pull/3022) - Refine dev/test config - [#3016](https://github.com/poanetwork/blockscout/pull/3016), [#3017](https://github.com/poanetwork/blockscout/pull/3017) - Fix token instance QR code data - [#3014](https://github.com/poanetwork/blockscout/pull/3014) - Fix checksum address feature for tokens pages diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e9b31519e7..6bd95e8811 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -4033,4 +4033,15 @@ defmodule Explorer.Chain do defp boolean_to_check_result(true), do: :ok defp boolean_to_check_result(false), do: :not_found + + def extract_db_name(db_url) do + if db_url == nil do + "" + else + db_url + |> String.split("/") + |> Enum.take(-1) + |> Enum.at(0) + end + end end diff --git a/apps/explorer/lib/explorer/chain/events/listener.ex b/apps/explorer/lib/explorer/chain/events/listener.ex index 2d93eeada0..ebb637c30e 100644 --- a/apps/explorer/lib/explorer/chain/events/listener.ex +++ b/apps/explorer/lib/explorer/chain/events/listener.ex @@ -6,15 +6,22 @@ defmodule Explorer.Chain.Events.Listener do use GenServer alias Postgrex.Notifications + import Explorer.Chain, only: [extract_db_name: 1] def start_link(_) do GenServer.start_link(__MODULE__, "chain_event", name: __MODULE__) end def init(channel) do - {:ok, pid} = + explorer_repo = :explorer |> Application.get_env(Explorer.Repo) + + db_url = explorer_repo[:url] + + {:ok, pid} = + explorer_repo + |> Keyword.put(:database, extract_db_name(db_url)) |> Notifications.start_link() ref = Notifications.listen!(pid, channel) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index b37edbc36e..85bc03245f 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -4608,4 +4608,21 @@ defmodule Explorer.ChainTest do assert third.delta == Decimal.new(1) end end + + describe "extract_db_name/1" do + test "extracts correct db name" do + db_url = "postgresql://viktor:@localhost:5432/blockscout-dev-1" + assert Chain.extract_db_name(db_url) == "blockscout-dev-1" + end + + test "returns empty db name" do + db_url = "" + assert Chain.extract_db_name(db_url) == "" + end + + test "returns nil db name" do + db_url = nil + assert Chain.extract_db_name(db_url) == "" + end + end end From d183a607af243609add4e25d6c200cff8a9a7a00 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 26 Feb 2020 16:12:57 +0300 Subject: [PATCH 05/18] Handle error at first trace request --- CHANGELOG.md | 2 +- .../transaction_raw_trace_controller.ex | 20 ++++++---- .../lib/ethereum_jsonrpc/parity.ex | 40 +++++++++++++------ apps/explorer/lib/explorer/chain.ex | 9 +++-- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6291c3310..f68b2a5ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Current ### Features -- [#3013](https://github.com/poanetwork/blockscout/pull/3013) - Raw trace of transaction on-demand +- [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026) - Raw trace of transaction on-demand - [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers - [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex index 0f0e4114e1..5aeca2184e 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex @@ -35,7 +35,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do if first_trace_exists do internal_transactions else - {:ok, first_trace_params} = + response = Chain.fetch_first_trace( [ %{ @@ -48,13 +48,19 @@ defmodule BlockScoutWeb.TransactionRawTraceController do json_rpc_named_arguments ) - InternalTransactions.run_insert_only(first_trace_params, %{ - timeout: :infinity, - timestamps: Import.timestamps(), - internal_transactions: %{params: first_trace_params} - }) + case response do + {:ok, first_trace_params} -> + InternalTransactions.run_insert_only(first_trace_params, %{ + timeout: :infinity, + timestamps: Import.timestamps(), + internal_transactions: %{params: first_trace_params} + }) - Chain.all_transaction_to_internal_transactions(hash) + Chain.all_transaction_to_internal_transactions(hash) + + {:error, _} -> + internal_transactions + end end render( diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex index 5c399887dd..84a1b94702 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex @@ -2,7 +2,7 @@ defmodule EthereumJSONRPC.Parity do @moduledoc """ Ethereum JSONRPC methods that are only supported by [Parity](https://wiki.parity.io/). """ - + require Logger import EthereumJSONRPC, only: [id_to_params: 1, integer_to_quantity: 1, json_rpc: 2, request: 1] alias EthereumJSONRPC.Parity.{FetchedBeneficiaries, Traces} @@ -53,17 +53,33 @@ defmodule EthereumJSONRPC.Parity do def fetch_first_trace(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do id_to_params = id_to_params(transactions_params) - with {:ok, responses} <- - id_to_params - |> trace_replay_transaction_requests() - |> json_rpc(json_rpc_named_arguments) do - {:ok, [first_trace]} = trace_replay_transaction_responses_to_first_trace_params(responses, id_to_params) - - %{block_hash: block_hash} = - transactions_params - |> Enum.at(0) - - {:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} + trace_replay_transaction_response = + id_to_params + |> trace_replay_transaction_requests() + |> json_rpc(json_rpc_named_arguments) + + case trace_replay_transaction_response do + {:ok, responses} -> + case trace_replay_transaction_responses_to_first_trace_params(responses, id_to_params) do + {:ok, [first_trace]} -> + %{block_hash: block_hash} = + transactions_params + |> Enum.at(0) + + {:ok, + [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} + + {:error, error} -> + Logger.error(inspect(error)) + {:error, error} + end + + {:error, :econnrefused} -> + {:error, :econnrefused} + + {:error, [error]} -> + Logger.error(inspect(error)) + {:error, error} end end diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index f0992436d5..727b50aba6 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -4070,10 +4070,13 @@ defmodule Explorer.Chain do Fetches the first trace from the Parity trace URL. """ def fetch_first_trace(transactions_params, json_rpc_named_arguments) do - {:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} = - EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) + case EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) do + {:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} -> + format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) - format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) + {:error, error} -> + {:error, error} + end end defp format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) do From 3d9afe59f58c8f0009e4573e62ede23fa04da162 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 26 Feb 2020 18:24:19 +0300 Subject: [PATCH 06/18] Rescue for SUPPORTED_CHAINS env var parsing --- .dialyzer-ignore | 2 +- CHANGELOG.md | 1 + .../lib/block_scout_web/views/layout_view.ex | 11 ++++++++--- .../test/block_scout_web/views/layout_view_test.exs | 6 ++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.dialyzer-ignore b/.dialyzer-ignore index 66cdf7ae08..1535f582c8 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -12,4 +12,4 @@ apps/explorer/lib/explorer/smart_contract/publisher_worker.ex:6: The pattern 'fa apps/explorer/lib/explorer/smart_contract/publisher_worker.ex:6: The test 5 == 'infinity' can never evaluate to 'true' lib/block_scout_web/router.ex:1 lib/phoenix/router.ex:324 -lib/block_scout_web/views/layout_view.ex:142 \ No newline at end of file +lib/block_scout_web/views/layout_view.ex:143 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f68b2a5ffd..d8bb769e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash ### Fixes +- [#3027](https://github.com/poanetwork/blockscout/pull/3027) - Rescue for SUPPORTED_CHAINS env var parsing - [#3025](https://github.com/poanetwork/blockscout/pull/3025) - Fix splitting of indexer/web components setup - [#3024](https://github.com/poanetwork/blockscout/pull/3024) - Fix pool size default value in config - [#3021](https://github.com/poanetwork/blockscout/pull/3021), [#3022](https://github.com/poanetwork/blockscout/pull/3022) - Refine dev/test config diff --git a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex index 723167547d..051ec77024 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex @@ -137,9 +137,14 @@ defmodule BlockScoutWeb.LayoutView do def other_networks do get_other_networks = if Application.get_env(:block_scout_web, :other_networks) do - :block_scout_web - |> Application.get_env(:other_networks) - |> Parser.parse!(%{keys: :atoms!}) + try do + :block_scout_web + |> Application.get_env(:other_networks) + |> Parser.parse!(%{keys: :atoms!}) + rescue + _ -> + [] + end else @default_other_networks end diff --git a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs index 6ce6507c0a..0c9fafa75a 100644 --- a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs @@ -115,6 +115,12 @@ defmodule BlockScoutWeb.LayoutViewTest do } ] end + + test "get empty networks list if SUPPORTED_CHAINS is not parsed" do + Application.put_env(:block_scout_web, :other_networks, "not a valid json") + + assert LayoutView.other_networks() == [] + end end describe "main_nets/1" do From 908f6a1fa7bea738443a57352920fa1484a5d709 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 26 Feb 2020 19:13:03 +0300 Subject: [PATCH 07/18] Change min safe polling period --- CHANGELOG.md | 1 + apps/indexer/lib/indexer/block/realtime/fetcher.ex | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8bb769e71..9e1c51fba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash ### Fixes +- [#3028](https://github.com/poanetwork/blockscout/pull/3028) - Decrease polling period value for realtime fetcher - [#3027](https://github.com/poanetwork/blockscout/pull/3027) - Rescue for SUPPORTED_CHAINS env var parsing - [#3025](https://github.com/poanetwork/blockscout/pull/3025) - Fix splitting of indexer/web components setup - [#3024](https://github.com/poanetwork/blockscout/pull/3024) - Fix pool size default value in config diff --git a/apps/indexer/lib/indexer/block/realtime/fetcher.ex b/apps/indexer/lib/indexer/block/realtime/fetcher.ex index e60dcc255b..533a79c74c 100644 --- a/apps/indexer/lib/indexer/block/realtime/fetcher.ex +++ b/apps/indexer/lib/indexer/block/realtime/fetcher.ex @@ -37,7 +37,7 @@ defmodule Indexer.Block.Realtime.Fetcher do @behaviour Block.Fetcher - @minimum_safe_polling_period :timer.seconds(10) + @minimum_safe_polling_period :timer.seconds(5) @enforce_keys ~w(block_fetcher)a defstruct ~w(block_fetcher subscription previous_number max_number_seen timer)a @@ -157,7 +157,7 @@ defmodule Indexer.Block.Realtime.Fetcher do polling_period = case AverageBlockTime.average_block_time() do {:error, :disabled} -> 2_000 - block_time -> round(Duration.to_milliseconds(block_time) * 2) + block_time -> round(Duration.to_milliseconds(block_time) / 2) end safe_polling_period = max(polling_period, @minimum_safe_polling_period) From 7d448d58fd136c0ec8834cd4180c556e21f96a65 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 26 Feb 2020 23:31:32 +0300 Subject: [PATCH 08/18] Fix transactions and blocks appearance if less blocks and txs on the page than it can contain --- CHANGELOG.md | 1 + .../assets/__tests__/pages/chain.js | 35 +++++++++++++++++-- apps/block_scout_web/assets/js/pages/chain.js | 20 +++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e1c51fba5..a9da4ca6a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash ### Fixes +- [#3029](https://github.com/poanetwork/blockscout/pull/3029) - Fix transactions and blocks appearance on the main page - [#3028](https://github.com/poanetwork/blockscout/pull/3028) - Decrease polling period value for realtime fetcher - [#3027](https://github.com/poanetwork/blockscout/pull/3027) - Rescue for SUPPORTED_CHAINS env var parsing - [#3025](https://github.com/poanetwork/blockscout/pull/3025) - Fix splitting of indexer/web components setup diff --git a/apps/block_scout_web/assets/__tests__/pages/chain.js b/apps/block_scout_web/assets/__tests__/pages/chain.js index e7f69fc861..e3a4c87e0d 100644 --- a/apps/block_scout_web/assets/__tests__/pages/chain.js +++ b/apps/block_scout_web/assets/__tests__/pages/chain.js @@ -61,6 +61,36 @@ describe('RECEIVED_NEW_BLOCK', () => { expect(output.averageBlockTime).toEqual('5 seconds') expect(output.blocks).toEqual([ { blockNumber: 2, chainBlockHtml: 'new block', averageBlockTime: '5 seconds' }, + { blockNumber: 1, chainBlockHtml: 'test 1' }, + { blockNumber: 0, chainBlockHtml: 'test 0' } + ]) + }) + + test('receives new block if >= 4 blocks', () => { + const state = Object.assign({}, initialState, { + averageBlockTime: '6 seconds', + blocks: [ + { blockNumber: 3, chainBlockHtml: 'test 3' }, + { blockNumber: 2, chainBlockHtml: 'test 2' }, + { blockNumber: 1, chainBlockHtml: 'test 1' }, + { blockNumber: 0, chainBlockHtml: 'test 0' } + ] + }) + const action = { + type: 'RECEIVED_NEW_BLOCK', + msg: { + averageBlockTime: '5 seconds', + blockNumber: 4, + chainBlockHtml: 'new block' + } + } + const output = reducer(state, action) + + expect(output.averageBlockTime).toEqual('5 seconds') + expect(output.blocks).toEqual([ + { blockNumber: 4, chainBlockHtml: 'new block', averageBlockTime: '5 seconds' }, + { blockNumber: 3, chainBlockHtml: 'test 3' }, + { blockNumber: 2, chainBlockHtml: 'test 2' }, { blockNumber: 1, chainBlockHtml: 'test 1' } ]) }) @@ -318,7 +348,8 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { }) test('single transaction after large batch of transactions', () => { const state = Object.assign({}, initialState, { - transactionsBatch: [1,2,3,4,5,6,7,8,9,10,11] + transactionsBatch: [6,7,8,9,10,11,12,13,14,15,16], + transactions: [1,2,3,4,5] }) const action = { type: 'RECEIVED_NEW_TRANSACTION_BATCH', @@ -328,7 +359,7 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { } const output = reducer(state, action) - expect(output.transactions).toEqual([]) + expect(output.transactions).toEqual([1,2,3,4,5]) expect(output.transactionsBatch.length).toEqual(12) }) test('large batch of transactions after large batch of transactions', () => { diff --git a/apps/block_scout_web/assets/js/pages/chain.js b/apps/block_scout_web/assets/js/pages/chain.js index 0421558e1c..781c4c6497 100644 --- a/apps/block_scout_web/assets/js/pages/chain.js +++ b/apps/block_scout_web/assets/js/pages/chain.js @@ -13,6 +13,7 @@ import { batchChannel, showLoader } from '../lib/utils' import listMorph from '../lib/list_morph' const BATCH_THRESHOLD = 6 +const BLOCKS_PER_PAGE = 4 export const initialState = { addressCount: null, @@ -45,11 +46,17 @@ function baseReducer (state = initialState, action) { } case 'RECEIVED_NEW_BLOCK': { if (!state.blocks.length || state.blocks[0].blockNumber < action.msg.blockNumber) { + let pastBlocks + if (state.blocks.length < BLOCKS_PER_PAGE) { + pastBlocks = state.blocks + } else { + pastBlocks = state.blocks.slice(0, -1) + } return Object.assign({}, state, { averageBlockTime: action.msg.averageBlockTime, blocks: [ action.msg, - ...state.blocks.slice(0, -1) + ...pastBlocks ], blockCount: action.msg.blockNumber + 1 }) @@ -88,7 +95,16 @@ function baseReducer (state = initialState, action) { return Object.assign({}, state, { transactionCount }) } - if (!state.transactionsBatch.length && action.msgs.length < BATCH_THRESHOLD) { + const transactionsLength = state.transactions.length + action.msgs.length + if (transactionsLength < BATCH_THRESHOLD) { + return Object.assign({}, state, { + transactions: [ + ...action.msgs.reverse(), + ...state.transactions + ], + transactionCount + }) + } else if (!state.transactionsBatch.length && action.msgs.length < BATCH_THRESHOLD) { return Object.assign({}, state, { transactions: [ ...action.msgs.reverse(), From 444ea6ac0e6aa64ef6ad799ab8fbb7388b97a99a Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 27 Feb 2020 14:12:19 +0300 Subject: [PATCH 09/18] Remove default websockets URL from config --- CHANGELOG.md | 1 + apps/explorer/config/dev/ganache.exs | 2 +- apps/explorer/config/dev/geth.exs | 2 +- apps/explorer/config/dev/parity.exs | 2 +- apps/explorer/config/dev/rsk.exs | 2 +- apps/explorer/config/prod/ganache.exs | 4 ++-- apps/explorer/config/prod/geth.exs | 4 ++-- apps/indexer/config/dev/ganache.exs | 4 ++-- apps/indexer/config/dev/geth.exs | 2 +- apps/indexer/config/dev/parity.exs | 2 +- apps/indexer/config/dev/rsk.exs | 2 +- apps/indexer/config/prod/ganache.exs | 4 ++-- apps/indexer/config/prod/geth.exs | 2 +- 13 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9da4ca6a8..bac84187a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - [#2883](https://github.com/poanetwork/blockscout/pull/2883) - Fix long contracts names ### Chore +- [#3030](https://github.com/poanetwork/blockscout/pull/3030) - Remove default websockets URL from config - [#2995](https://github.com/poanetwork/blockscout/pull/2995) - Support API_PATH env var in Docker file diff --git a/apps/explorer/config/dev/ganache.exs b/apps/explorer/config/dev/ganache.exs index fec954d325..e6c2214601 100644 --- a/apps/explorer/config/dev/ganache.exs +++ b/apps/explorer/config/dev/ganache.exs @@ -14,7 +14,7 @@ config :explorer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:7545" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ], variant: EthereumJSONRPC.Ganache ] diff --git a/apps/explorer/config/dev/geth.exs b/apps/explorer/config/dev/geth.exs index 5d57d1a3f2..00f52e54e6 100644 --- a/apps/explorer/config/dev/geth.exs +++ b/apps/explorer/config/dev/geth.exs @@ -14,7 +14,7 @@ config :explorer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "wss://mainnet.infura.io/8lTvJTKmHPCHazkneJsY/ws" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ], variant: EthereumJSONRPC.Geth ] diff --git a/apps/explorer/config/dev/parity.exs b/apps/explorer/config/dev/parity.exs index 7f92c092cc..aebe0dfac1 100644 --- a/apps/explorer/config/dev/parity.exs +++ b/apps/explorer/config/dev/parity.exs @@ -19,7 +19,7 @@ config :explorer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:8546" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ], variant: EthereumJSONRPC.Parity ] diff --git a/apps/explorer/config/dev/rsk.exs b/apps/explorer/config/dev/rsk.exs index 3928520d30..58af2ee8c0 100644 --- a/apps/explorer/config/dev/rsk.exs +++ b/apps/explorer/config/dev/rsk.exs @@ -19,7 +19,7 @@ config :explorer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:8546" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ], variant: EthereumJSONRPC.RSK ] diff --git a/apps/explorer/config/prod/ganache.exs b/apps/explorer/config/prod/ganache.exs index fec954d325..c0a4b98a02 100644 --- a/apps/explorer/config/prod/ganache.exs +++ b/apps/explorer/config/prod/ganache.exs @@ -5,7 +5,7 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", + url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] ], variant: EthereumJSONRPC.Ganache @@ -14,7 +14,7 @@ config :explorer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:7545" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ], variant: EthereumJSONRPC.Ganache ] diff --git a/apps/explorer/config/prod/geth.exs b/apps/explorer/config/prod/geth.exs index 5d57d1a3f2..026d745e9b 100644 --- a/apps/explorer/config/prod/geth.exs +++ b/apps/explorer/config/prod/geth.exs @@ -5,7 +5,7 @@ config :explorer, transport: EthereumJSONRPC.HTTP, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, - url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY", + url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] ], variant: EthereumJSONRPC.Geth @@ -14,7 +14,7 @@ config :explorer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "wss://mainnet.infura.io/8lTvJTKmHPCHazkneJsY/ws" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ], variant: EthereumJSONRPC.Geth ] diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs index e90d242470..ab90c798bd 100644 --- a/apps/indexer/config/dev/ganache.exs +++ b/apps/indexer/config/dev/ganache.exs @@ -16,9 +16,9 @@ config :indexer, variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ - transport: EthereumJSONRPC.WebSocket, + transport: System.get_env("ETHEREUM_JSONRPC_WS_URL") && EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:7545" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ] ] diff --git a/apps/indexer/config/dev/geth.exs b/apps/indexer/config/dev/geth.exs index fd59ab2eb7..e7c7bb125f 100644 --- a/apps/indexer/config/dev/geth.exs +++ b/apps/indexer/config/dev/geth.exs @@ -19,6 +19,6 @@ config :indexer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "wss://mainnet.infura.io/ws/8lTvJTKmHPCHazkneJsY" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ] ] diff --git a/apps/indexer/config/dev/parity.exs b/apps/indexer/config/dev/parity.exs index c58d70f37c..0a99ce6690 100644 --- a/apps/indexer/config/dev/parity.exs +++ b/apps/indexer/config/dev/parity.exs @@ -42,6 +42,6 @@ config :indexer, transport: System.get_env("ETHEREUM_JSONRPC_WS_URL") && EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:8546" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ] ] diff --git a/apps/indexer/config/dev/rsk.exs b/apps/indexer/config/dev/rsk.exs index 19ecac5b25..ed504f91f6 100644 --- a/apps/indexer/config/dev/rsk.exs +++ b/apps/indexer/config/dev/rsk.exs @@ -26,6 +26,6 @@ config :indexer, transport: System.get_env("ETHEREUM_JSONRPC_WS_URL") && EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:8546" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ] ] diff --git a/apps/indexer/config/prod/ganache.exs b/apps/indexer/config/prod/ganache.exs index e90d242470..ab90c798bd 100644 --- a/apps/indexer/config/prod/ganache.exs +++ b/apps/indexer/config/prod/ganache.exs @@ -16,9 +16,9 @@ config :indexer, variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ - transport: EthereumJSONRPC.WebSocket, + transport: System.get_env("ETHEREUM_JSONRPC_WS_URL") && EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:7545" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ] ] diff --git a/apps/indexer/config/prod/geth.exs b/apps/indexer/config/prod/geth.exs index 5e62557fe7..e56abe5105 100644 --- a/apps/indexer/config/prod/geth.exs +++ b/apps/indexer/config/prod/geth.exs @@ -19,6 +19,6 @@ config :indexer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "wss://mainnet.infura.io/ws/8lTvJTKmHPCHazkneJsY" + url: System.get_env("ETHEREUM_JSONRPC_WS_URL") ] ] From bb728328dfbcb08013cfb0a7c9f97f2330cbedf9 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 27 Feb 2020 14:58:14 +0300 Subject: [PATCH 10/18] Ignore case for first trace response --- CHANGELOG.md | 2 +- .../controllers/transaction_raw_trace_controller.ex | 3 +++ apps/explorer/lib/explorer/chain.ex | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bac84187a2..0edcae9e86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Current ### Features -- [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026) - Raw trace of transaction on-demand +- [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026), [#3031](https://github.com/poanetwork/blockscout/pull/3031) - Raw trace of transaction on-demand - [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers - [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex index 5aeca2184e..82f189e9b3 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex @@ -60,6 +60,9 @@ defmodule BlockScoutWeb.TransactionRawTraceController do {:error, _} -> internal_transactions + + :ignore -> + internal_transactions end end diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 727b50aba6..848e37f576 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -4076,6 +4076,9 @@ defmodule Explorer.Chain do {:error, error} -> {:error, error} + + :ignore -> + :ignore end end From 626e208cfc4553f088a28aa3f4095502efec49d5 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 27 Feb 2020 16:06:58 +0300 Subject: [PATCH 11/18] Remove insdexing status top alert from Ganache variant --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain.ex | 31 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0edcae9e86..fccf655c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - [#2883](https://github.com/poanetwork/blockscout/pull/2883) - Fix long contracts names ### Chore +- [#3032](https://github.com/poanetwork/blockscout/pull/3032) - Remove indexing status alert for Ganache variant - [#3030](https://github.com/poanetwork/blockscout/pull/3030) - Remove default websockets URL from config - [#2995](https://github.com/poanetwork/blockscout/pull/2995) - Support API_PATH env var in Docker file diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 848e37f576..fe9b15bcac 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -846,20 +846,27 @@ defmodule Explorer.Chain do """ @spec finished_indexing?() :: boolean() def finished_indexing? do - 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 - 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 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 + 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 From 569cd12e163374d7d7227b782bbc17ca6708965b Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 27 Feb 2020 17:15:13 +0300 Subject: [PATCH 12/18] Fix checksum in query paramater of address_counters endpoint --- CHANGELOG.md | 4 +--- .../controllers/address_coin_balance_controller.ex | 3 ++- .../controllers/address_read_contract_controller.ex | 3 ++- .../block_scout_web/controllers/address_token_controller.ex | 3 ++- .../controllers/address_token_transfer_controller.ex | 5 +++-- apps/explorer/lib/explorer/chain/address.ex | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0edcae9e86..83669cf338 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026), [#3031](https://github.com/poanetwork/blockscout/pull/3031) - Raw trace of transaction on-demand - [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers - [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file -- [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash +- [#2834](https://github.com/poanetwork/blockscout/pull/2834), [#3009](https://github.com/poanetwork/blockscout/pull/3009), [#3014](https://github.com/poanetwork/blockscout/pull/3014), [#3033](https://github.com/poanetwork/blockscout/pull/3033) - always redirect to checksummed hash ### Fixes - [#3029](https://github.com/poanetwork/blockscout/pull/3029) - Fix transactions and blocks appearance on the main page @@ -14,10 +14,8 @@ - [#3024](https://github.com/poanetwork/blockscout/pull/3024) - Fix pool size default value in config - [#3021](https://github.com/poanetwork/blockscout/pull/3021), [#3022](https://github.com/poanetwork/blockscout/pull/3022) - Refine dev/test config - [#3016](https://github.com/poanetwork/blockscout/pull/3016), [#3017](https://github.com/poanetwork/blockscout/pull/3017) - Fix token instance QR code data -- [#3014](https://github.com/poanetwork/blockscout/pull/3014) - Fix checksum address feature for tokens pages - [#3012](https://github.com/poanetwork/blockscout/pull/3012) - Speedup token transfers list query - [#3011](https://github.com/poanetwork/blockscout/pull/3011) - Revert realtime fetcher small skips feature -- [#3009](https://github.com/poanetwork/blockscout/pull/3009) - Fix broken export to CSV - [#3007](https://github.com/poanetwork/blockscout/pull/3007) - Fix copy UTF8 tx input action - [#2996](https://github.com/poanetwork/blockscout/pull/2996) - Fix awesomplete lib loading in Firefox - [#2993](https://github.com/poanetwork/blockscout/pull/2993) - Fix path definition for contract verification endpoint diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex index e92b7b356c..538f8fd7f4 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex @@ -9,6 +9,7 @@ defmodule BlockScoutWeb.AddressCoinBalanceController do alias BlockScoutWeb.AddressCoinBalanceView alias Explorer.{Chain, Market} + alias Explorer.Chain.Address alias Explorer.ExchangeRates.Token alias Indexer.Fetcher.CoinBalanceOnDemand alias Phoenix.View @@ -64,7 +65,7 @@ defmodule BlockScoutWeb.AddressCoinBalanceController do coin_balance_status: CoinBalanceOnDemand.trigger_fetch(address), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), current_path: current_path(conn), - counters_path: address_path(conn, :address_counters, %{"id" => to_string(address_hash)}) + counters_path: address_path(conn, :address_counters, %{"id" => Address.checksum(address_hash)}) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex index baa4193f61..130debf038 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex @@ -9,6 +9,7 @@ defmodule BlockScoutWeb.AddressReadContractController do use BlockScoutWeb, :controller alias Explorer.{Chain, Market} + alias Explorer.Chain.Address alias Explorer.ExchangeRates.Token alias Indexer.Fetcher.CoinBalanceOnDemand @@ -32,7 +33,7 @@ defmodule BlockScoutWeb.AddressReadContractController do address: address, coin_balance_status: CoinBalanceOnDemand.trigger_fetch(address), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), - counters_path: address_path(conn, :address_counters, %{"id" => to_string(address_hash)}) + counters_path: address_path(conn, :address_counters, %{"id" => Address.checksum(address_hash)}) ) else _ -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex index 157d338313..b7a445f67b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex @@ -5,6 +5,7 @@ defmodule BlockScoutWeb.AddressTokenController do alias BlockScoutWeb.AddressTokenView alias Explorer.{Chain, Market} + alias Explorer.Chain.Address alias Explorer.ExchangeRates.Token alias Indexer.Fetcher.CoinBalanceOnDemand alias Phoenix.View @@ -63,7 +64,7 @@ defmodule BlockScoutWeb.AddressTokenController do current_path: current_path(conn), coin_balance_status: CoinBalanceOnDemand.trigger_fetch(address), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), - counters_path: address_path(conn, :address_counters, %{"id" => to_string(address_hash)}) + counters_path: address_path(conn, :address_counters, %{"id" => Address.checksum(address_hash)}) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex index af7a4c93f4..23b393f5a3 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex @@ -4,6 +4,7 @@ defmodule BlockScoutWeb.AddressTokenTransferController do alias BlockScoutWeb.TransactionView alias Explorer.ExchangeRates.Token alias Explorer.{Chain, Market} + alias Explorer.Chain.Address alias Indexer.Fetcher.CoinBalanceOnDemand alias Phoenix.View @@ -96,7 +97,7 @@ defmodule BlockScoutWeb.AddressTokenTransferController do exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), current_path: current_path(conn), token: token, - counters_path: address_path(conn, :address_counters, %{"id" => to_string(address_hash)}) + counters_path: address_path(conn, :address_counters, %{"id" => Address.checksum(address_hash)}) ) else :error -> @@ -178,7 +179,7 @@ defmodule BlockScoutWeb.AddressTokenTransferController do exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), filter: params["filter"], current_path: current_path(conn), - counters_path: address_path(conn, :address_counters, %{"id" => to_string(address_hash)}) + counters_path: address_path(conn, :address_counters, %{"id" => Address.checksum(address_hash)}) ) else :error -> diff --git a/apps/explorer/lib/explorer/chain/address.ex b/apps/explorer/lib/explorer/chain/address.ex index 76ea5e85dd..1b167fbc78 100644 --- a/apps/explorer/lib/explorer/chain/address.ex +++ b/apps/explorer/lib/explorer/chain/address.ex @@ -145,7 +145,6 @@ defmodule Explorer.Chain.Address do end end - # https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP60.md def eth_checksum(hash) do string_hash = hash @@ -169,6 +168,7 @@ defmodule Explorer.Chain.Address do end) end + # https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP60.md def rsk_checksum(hash) do chain_id = NetVersion.get_version() From b6674224c988da531651661d5d2f94e9b3ee3deb Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 27 Feb 2020 19:42:28 +0300 Subject: [PATCH 13/18] Support stateMutability=view to define reading functions in smart-contracts --- CHANGELOG.md | 1 + apps/block_scout_web/lib/block_scout_web/views/address_view.ex | 2 +- .../lib/block_scout_web/views/tokens/instance/overview_view.ex | 2 +- .../lib/block_scout_web/views/tokens/overview_view.ex | 2 +- apps/explorer/lib/explorer/smart_contract/reader.ex | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fccf655c08..988c6b1cb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash ### Fixes +- [#3034](https://github.com/poanetwork/blockscout/pull/3034) - Support stateMutability=view to define reading functions in smart-contracts - [#3029](https://github.com/poanetwork/blockscout/pull/3029) - Fix transactions and blocks appearance on the main page - [#3028](https://github.com/poanetwork/blockscout/pull/3028) - Decrease polling period value for realtime fetcher - [#3027](https://github.com/poanetwork/blockscout/pull/3027) - Rescue for SUPPORTED_CHAINS env var parsing diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex index 387714024a..8a0ece35fa 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex @@ -206,7 +206,7 @@ defmodule BlockScoutWeb.AddressView do def smart_contract_verified?(%Address{smart_contract: nil}), do: false def smart_contract_with_read_only_functions?(%Address{smart_contract: %SmartContract{}} = address) do - Enum.any?(address.smart_contract.abi, & &1["constant"]) + Enum.any?(address.smart_contract.abi, &(&1["constant"] || &1["stateMutability"] == "view")) end def smart_contract_with_read_only_functions?(%Address{smart_contract: nil}), do: false diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex index 9821ba93c1..02937fec9f 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex @@ -47,7 +47,7 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do def smart_contract_with_read_only_functions?( %Token{contract_address: %Address{smart_contract: %SmartContract{}}} = token ) do - Enum.any?(token.contract_address.smart_contract.abi, & &1["constant"]) + Enum.any?(token.contract_address.smart_contract.abi, &(&1["constant"] || &1["stateMutability"] == "view")) end def smart_contract_with_read_only_functions?(%Token{contract_address: %Address{smart_contract: nil}}), do: false diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex index 014ee4a563..eb82b2cc6f 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex @@ -43,7 +43,7 @@ defmodule BlockScoutWeb.Tokens.OverviewView do def smart_contract_with_read_only_functions?( %Token{contract_address: %Address{smart_contract: %SmartContract{}}} = token ) do - Enum.any?(token.contract_address.smart_contract.abi, & &1["constant"]) + Enum.any?(token.contract_address.smart_contract.abi, &(&1["constant"] || &1["stateMutability"] == "view")) end def smart_contract_with_read_only_functions?(%Token{contract_address: %Address{smart_contract: nil}}), do: false diff --git a/apps/explorer/lib/explorer/smart_contract/reader.ex b/apps/explorer/lib/explorer/smart_contract/reader.ex index cc3aae5e83..047843b317 100644 --- a/apps/explorer/lib/explorer/smart_contract/reader.ex +++ b/apps/explorer/lib/explorer/smart_contract/reader.ex @@ -175,7 +175,7 @@ defmodule Explorer.SmartContract.Reader do _ -> abi - |> Enum.filter(& &1["constant"]) + |> Enum.filter(&(&1["constant"] || &1["stateMutability"] == "view")) |> Enum.map(&fetch_current_value_from_blockchain(&1, abi, contract_address_hash)) end end From e2a43e57dff7d3f1d071b61fa5ae4b9d13324ecf Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 28 Feb 2020 09:01:37 +0300 Subject: [PATCH 14/18] Mak buttonns color at verification page consistent --- CHANGELOG.md | 1 + .../block_scout_web/templates/address_contract/index.html.eex | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8128bbb397..5492773672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2834](https://github.com/poanetwork/blockscout/pull/2834), [#3009](https://github.com/poanetwork/blockscout/pull/3009), [#3014](https://github.com/poanetwork/blockscout/pull/3014), [#3033](https://github.com/poanetwork/blockscout/pull/3033) - always redirect to checksummed hash ### Fixes +- [#3037](https://github.com/poanetwork/blockscout/pull/3037) - Make buttons color at verification page consistent - [#3034](https://github.com/poanetwork/blockscout/pull/3034) - Support stateMutability=view to define reading functions in smart-contracts - [#3029](https://github.com/poanetwork/blockscout/pull/3029) - Fix transactions and blocks appearance on the main page - [#3028](https://github.com/poanetwork/blockscout/pull/3028) - Decrease polling period value for realtime fetcher diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index f246349de6..8f7699f84e 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -61,7 +61,7 @@

<%= gettext "Contract source code" %>

-
From 508d049983d40c1d6c6e03b7cbbb0d8cad9a2c3a Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 28 Feb 2020 12:54:48 +0300 Subject: [PATCH 15/18] Remove unused index_internal_transactions_for_token_transfers --- apps/explorer/config/config.exs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index b2c3d9c189..05efdc48ea 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -20,9 +20,7 @@ config :explorer, if(System.get_env("DISABLE_WEBAPP") != "true", do: Explorer.Chain.Events.SimpleSender, else: Explorer.Chain.Events.DBSender - ), - index_internal_transactions_for_token_transfers: - if(System.get_env("INTERNAL_TRANSACTIONOS_FOR_TOKEN_TRANSFERS") == "true", do: true, else: false) + ) average_block_period = case Integer.parse(System.get_env("AVERAGE_BLOCK_CACHE_PERIOD", "")) do From 613f6bb9f124a4209e4736dac7be8e53edfe2709 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 28 Feb 2020 17:18:06 +0300 Subject: [PATCH 16/18] Return default hostname and database --- apps/explorer/config/dev.exs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/explorer/config/dev.exs b/apps/explorer/config/dev.exs index 62e5db3cb8..67745c85af 100644 --- a/apps/explorer/config/dev.exs +++ b/apps/explorer/config/dev.exs @@ -1,7 +1,12 @@ use Mix.Config +database = if System.get_env("DATABASE_URL"), do: nil, else: "explorer_dev" +hostname = if System.get_env("DATABASE_URL"), do: nil, else: "localhost" + # Configure your database config :explorer, Explorer.Repo, + database: database, + hostname: hostname, url: System.get_env("DATABASE_URL"), pool_size: String.to_integer(System.get_env("POOL_SIZE", "50")), timeout: :timer.seconds(80) From da9f0dbccb9579829625102615ba0d21e27a7106 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 28 Feb 2020 19:21:01 +0300 Subject: [PATCH 17/18] 3.1.0 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5492773672..92463a578d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ ## Current +### Features + +### Fixes + +### Chore + + +## 3.1.0-beta + ### Features - [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026), [#3031](https://github.com/poanetwork/blockscout/pull/3031) - Raw trace of transaction on-demand - [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers From aec6774c14e1524b4381ffef7134c15d2d3f9e70 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 28 Feb 2020 19:30:29 +0300 Subject: [PATCH 18/18] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92463a578d..7515a047d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ ### Features - [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026), [#3031](https://github.com/poanetwork/blockscout/pull/3031) - Raw trace of transaction on-demand -- [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers +- [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of first trace for all types of transactions for Parity variant - [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file - [#2834](https://github.com/poanetwork/blockscout/pull/2834), [#3009](https://github.com/poanetwork/blockscout/pull/3009), [#3014](https://github.com/poanetwork/blockscout/pull/3014), [#3033](https://github.com/poanetwork/blockscout/pull/3033) - always redirect to checksummed hash