Skip to content

Commit

Permalink
Merge branch 'staging-harmony' into production-harmony
Browse files Browse the repository at this point in the history
  • Loading branch information
DenSmolonski committed Jun 18, 2024
2 parents ef8d123 + ec88138 commit 49c3842
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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} <-
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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} <-
Expand Down
34 changes: 25 additions & 9 deletions apps/explorer/lib/explorer/chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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`.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions apps/indexer/lib/indexer/block/fetcher/receipts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
2 changes: 1 addition & 1 deletion apps/indexer/lib/indexer/fetcher/internal_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49c3842

Please sign in to comment.