diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex index bc48544d1abd..85c5317aedbf 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex @@ -84,6 +84,7 @@ defmodule BlockScoutWeb.API.V2.BlockController do full_options |> Keyword.merge(paging_options(params)) |> Keyword.merge(@api_true) + |> Keyword.merge([with_transactions: true]) |> Chain.list_blocks() {blocks, next_page} = split_list_by_page(blocks_plus_one) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex index b047880b6de1..b3f6c61163c7 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex @@ -26,7 +26,6 @@ defmodule EthereumJSONRPC.Geth do @impl EthereumJSONRPC.Variant def fetch_internal_transactions(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do id_to_params = id_to_params(transactions_params) - json_rpc_named_arguments_corrected_timeout = correct_timeouts(json_rpc_named_arguments) with {:ok, responses} <- @@ -149,11 +148,27 @@ defmodule EthereumJSONRPC.Geth do debug_trace_transaction_timeout = Application.get_env(:ethereum_jsonrpc, __MODULE__)[:debug_trace_transaction_timeout] - request(%{ + request_params = %{ id: id, method: "debug_traceTransaction", params: [hash_data, %{timeout: debug_trace_transaction_timeout} |> Map.merge(tracer_params())] - }) + } + + try do + request(request_params) + catch + kind, reason -> + IO.inspect(request_params) + + # Optionally, re-raise the error if you want the caller to handle it + {:error, reason} + end + + # request(%{ + # id: id, + # method: "debug_traceTransaction", + # params: [hash_data, %{timeout: debug_trace_transaction_timeout} |> Map.merge(tracer_params())] + # }) end defp debug_trace_block_by_number_request({id, block_number}) do @@ -197,7 +212,7 @@ defmodule EthereumJSONRPC.Geth do with {:ok, receipts} <- id_to_params |> Enum.map(fn {id, %{hash_data: hash_data}} -> - request(%{id: id, method: "eth_getTransactionReceipt", params: [hash_data]}) + request(%{id: id, method: "hmy_getTransactionReceipt", params: [hash_data]}) end) |> json_rpc(json_rpc_named_arguments), {:ok, txs} <- diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index c544646085b0..1ca1e8700612 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1691,26 +1691,29 @@ defmodule Explorer.Chain do """ @spec list_blocks([paging_options | necessity_by_association_option | api?]) :: [Block.t()] def list_blocks(options \\ []) when is_list(options) do - necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) + necessity_by_association = + Keyword.get(options, :necessity_by_association) || %{} + paging_options = Keyword.get(options, :paging_options) || @default_paging_options block_type = Keyword.get(options, :block_type, "Block") + with_transactions = Keyword.get(options, :with_transactions) || false cond do block_type == "Block" && !paging_options.key -> - block_from_cache(block_type, paging_options, necessity_by_association, options) + block_from_cache(block_type, paging_options, necessity_by_association, options, with_transactions) block_type == "Uncle" && !paging_options.key -> uncles_from_cache(block_type, paging_options, necessity_by_association, options) true -> - fetch_blocks(block_type, paging_options, necessity_by_association, options) + fetch_blocks(block_type, paging_options, necessity_by_association, options, with_transactions) end end - defp block_from_cache(block_type, paging_options, necessity_by_association, options) do + defp block_from_cache(block_type, paging_options, necessity_by_association, options, with_transactions) do case Blocks.take_enough(paging_options.page_size) do nil -> - elements = fetch_blocks(block_type, paging_options, necessity_by_association, options) + elements = fetch_blocks(block_type, paging_options, necessity_by_association, options, with_transactions) Blocks.update(elements) @@ -1724,7 +1727,7 @@ defmodule Explorer.Chain do def uncles_from_cache(block_type, paging_options, necessity_by_association, options) do case Uncles.take_enough(paging_options.page_size) do nil -> - elements = fetch_blocks(block_type, paging_options, necessity_by_association, options) + elements = fetch_blocks(block_type, paging_options, necessity_by_association, options, false) Uncles.update(elements) @@ -1735,16 +1738,26 @@ defmodule Explorer.Chain do end end - defp fetch_blocks(block_type, paging_options, necessity_by_association, options) do + defp fetch_blocks(block_type, paging_options, necessity_by_association, options, with_transactions) do Block |> Block.block_type_filter(block_type) |> page_blocks(paging_options) |> limit(^paging_options.page_size) |> order_by(desc: :number) |> join_associations(necessity_by_association) + |> with_transactions(with_transactions) |> select_repo(options).all() end + defp with_transactions(query, true) do + from(b in query, + inner_join: t in assoc(b, :transactions), + group_by: b.hash, + having: count(t.hash) > 0) + end + + defp with_transactions(query, false), do: query + @doc """ Map `block_number`s to their `t:Explorer.Chain.Block.t/0` `hash` `t:Explorer.Chain.Hash.Full.t/0`. @@ -1939,7 +1952,8 @@ defmodule Explorer.Chain do from( po in PendingBlockOperation, where: not is_nil(po.block_number), - select: po.block_number + select: po.block_number, + order_by: [desc: po.block_number] ) query @@ -2886,7 +2900,9 @@ defmodule Explorer.Chain do |> select_repo(options).all() end - @spec staking_transaction_to_logs(Hash.Full.t(), [paging_options | necessity_by_association_option | api?]) :: [StakingLog.t()] + @spec staking_transaction_to_logs(Hash.Full.t(), [paging_options | necessity_by_association_option | api?]) :: [ + StakingLog.t() + ] def staking_transaction_to_logs(transaction_hash, options \\ []) when is_list(options) do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) paging_options = Keyword.get(options, :paging_options, @default_paging_options) diff --git a/apps/indexer/lib/indexer/block/fetcher/receipts.ex b/apps/indexer/lib/indexer/block/fetcher/receipts.ex index c5b1b21f9e59..4adbe1aea279 100644 --- a/apps/indexer/lib/indexer/block/fetcher/receipts.ex +++ b/apps/indexer/lib/indexer/block/fetcher/receipts.ex @@ -59,9 +59,11 @@ defmodule Indexer.Block.Fetcher.Receipts do if is_nil(block_number) do transaction = find_transaction_by_hash(transaction_params, transaction_hash) - %{log_params | block_number: transaction[:block_number]} + %{log_params | block_number: transaction[:block_number], transaction_hash: transaction[:hash] } else - log_params + transaction = find_transaction_by_hash(transaction_params, transaction_hash) + + %{log_params | transaction_hash: transaction[:hash] } end end) @@ -70,7 +72,7 @@ defmodule Indexer.Block.Fetcher.Receipts do defp find_transaction_by_hash(transaction_params, transaction_hash) do Enum.find(transaction_params, fn transaction -> - transaction[:hash] == transaction_hash + transaction[:hash] == transaction_hash or transaction[:eth_hash] == transaction_hash end) end end diff --git a/apps/indexer/lib/indexer/fetcher/internal_transaction.ex b/apps/indexer/lib/indexer/fetcher/internal_transaction.ex index d5d1af69436a..68445f9311a6 100644 --- a/apps/indexer/lib/indexer/fetcher/internal_transaction.ex +++ b/apps/indexer/lib/indexer/fetcher/internal_transaction.ex @@ -123,7 +123,7 @@ defmodule Indexer.Fetcher.InternalTransaction do end, error_count: filtered_unique_numbers_count ) - + IO.inspect(filtered_unique_numbers) handle_not_found_transaction(reason) # re-queue the de-duped entries