diff --git a/CHANGELOG.md b/CHANGELOG.md index e32c8d3b36..3098c21ba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#4353](https://github.com/blockscout/blockscout/pull/4353) - Added live-reload on the token holders page ### Fixes +- [#4437](https://github.com/blockscout/blockscout/pull/4437) - Fix `PendingTransactionsSanitizer` for non-consensus blocks - [#4430](https://github.com/blockscout/blockscout/pull/4430) - Fix current token balance on-demand fetcher - [#4429](https://github.com/blockscout/blockscout/pull/4429), [#4431](https://github.com/blockscout/blockscout/pull/4431) - Fix 500 response on `/tokens/{addressHash}/token-holders?type=JSON` when total supply is zero - [#4419](https://github.com/blockscout/blockscout/pull/4419) - Order contracts in the search by inserted_at in descending order @@ -21,7 +22,7 @@ - [#4398](https://github.com/blockscout/blockscout/pull/4398) - Speed up the transactions loading on the front-end - [#4384](https://github.com/blockscout/blockscout/pull/4384) - Fix Elixir version in `.tool-versions` - [#4382](https://github.com/blockscout/blockscout/pull/4382) - Replace awesomplete with autocomplete.js -- [#4371] - (https://github.com/blockscout/blockscout/pull/4371) - Place search outside of burger in mobile view +- [#4371](https://github.com/blockscout/blockscout/pull/4371) - Place search outside of burger in mobile view - [#4355](https://github.com/blockscout/blockscout/pull/4355) - Do not redirect to 404 page with empty string in the search field diff --git a/apps/indexer/lib/indexer/pending_transactions_sanitizer.ex b/apps/indexer/lib/indexer/pending_transactions_sanitizer.ex index bb3969808b..620e7c6f99 100644 --- a/apps/indexer/lib/indexer/pending_transactions_sanitizer.ex +++ b/apps/indexer/lib/indexer/pending_transactions_sanitizer.ex @@ -9,9 +9,11 @@ defmodule Indexer.PendingTransactionsSanitizer do require Logger import EthereumJSONRPC, only: [json_rpc: 2, request: 1] + import EthereumJSONRPC.Receipt, only: [to_elixir: 1] alias Ecto.Changeset alias Explorer.{Chain, Repo} + alias Explorer.Chain.Hash.Full, as: Hash alias Explorer.Chain.Import.Runner.Blocks alias Explorer.Chain.Transaction @@ -72,7 +74,7 @@ defmodule Indexer.PendingTransactionsSanitizer do pending_tx_hash_str = "0x" <> Base.encode16(pending_tx.hash.bytes, case: :lower) with {:ok, result} <- - %{id: ind, method: "eth_getTransactionByHash", params: [pending_tx_hash_str]} + %{id: ind, method: "eth_getTransactionReceipt", params: [pending_tx_hash_str]} |> request() |> json_rpc(json_rpc_named_arguments) do if result do @@ -84,7 +86,7 @@ defmodule Indexer.PendingTransactionsSanitizer do fetcher: :pending_transactions_to_refetch ) - fetch_block_and_invalidate(block_hash, pending_tx) + fetch_block_and_invalidate(block_hash, pending_tx, result) else Logger.debug( "Transaction with hash #{pending_tx_hash_str} is still pending. Do nothing.", @@ -130,7 +132,7 @@ defmodule Indexer.PendingTransactionsSanitizer do end end - defp fetch_block_and_invalidate(block_hash, pending_tx) do + defp fetch_block_and_invalidate(block_hash, pending_tx, tx) do case Chain.fetch_block_by_hash(block_hash) do %{number: number, consensus: consensus} -> Logger.debug( @@ -140,7 +142,7 @@ defmodule Indexer.PendingTransactionsSanitizer do fetcher: :pending_transactions_to_refetch ) - invalidate_block(number, block_hash, consensus, pending_tx) + invalidate_block(number, block_hash, consensus, pending_tx, tx) _ -> Logger.debug( @@ -150,7 +152,7 @@ defmodule Indexer.PendingTransactionsSanitizer do end end - defp invalidate_block(block_number, block_hash, consensus, pending_tx) do + defp invalidate_block(block_number, block_hash, consensus, pending_tx, tx) do if consensus do opts = %{ timeout: 60_000, @@ -159,15 +161,25 @@ defmodule Indexer.PendingTransactionsSanitizer do Blocks.lose_consensus(Repo, [], [block_number], [], opts) else + {:ok, hash} = Hash.cast(block_hash) + tx_info = to_elixir(tx) + changeset = pending_tx |> Transaction.changeset() + |> Changeset.put_change(:cumulative_gas_used, tx_info["cumulativeGasUsed"]) + |> Changeset.put_change(:gas_used, tx_info["gasUsed"]) + |> Changeset.put_change(:index, tx_info["transactionIndex"]) |> Changeset.put_change(:block_number, block_number) - |> Changeset.put_change(:block_hash, block_hash) + |> Changeset.put_change(:block_hash, hash) Repo.update(changeset) - Logger.debug("Pending tx with hash #{pending_tx.hash} assigned to block ##{block_number}") + Logger.debug( + "Pending tx with hash #{"0x" <> Base.encode16(pending_tx.hash.bytes, case: :lower)} assigned to block ##{ + block_number + } with hash #{block_hash}" + ) end end end