Merge pull request #4437 from blockscout/np-fix-pending-sanitizer

Complete fix pending sanitizer
pull/4401/head
Victor Baranov 3 years ago committed by GitHub
commit 726e3ae636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 26
      apps/indexer/lib/indexer/pending_transactions_sanitizer.ex

@ -7,6 +7,7 @@
- [#4353](https://github.com/blockscout/blockscout/pull/4353) - Added live-reload on the token holders page - [#4353](https://github.com/blockscout/blockscout/pull/4353) - Added live-reload on the token holders page
### Fixes ### 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 - [#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 - [#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 - [#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 - [#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` - [#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 - [#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 - [#4355](https://github.com/blockscout/blockscout/pull/4355) - Do not redirect to 404 page with empty string in the search field

@ -9,9 +9,11 @@ defmodule Indexer.PendingTransactionsSanitizer do
require Logger require Logger
import EthereumJSONRPC, only: [json_rpc: 2, request: 1] import EthereumJSONRPC, only: [json_rpc: 2, request: 1]
import EthereumJSONRPC.Receipt, only: [to_elixir: 1]
alias Ecto.Changeset alias Ecto.Changeset
alias Explorer.{Chain, Repo} alias Explorer.{Chain, Repo}
alias Explorer.Chain.Hash.Full, as: Hash
alias Explorer.Chain.Import.Runner.Blocks alias Explorer.Chain.Import.Runner.Blocks
alias Explorer.Chain.Transaction 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) pending_tx_hash_str = "0x" <> Base.encode16(pending_tx.hash.bytes, case: :lower)
with {:ok, result} <- with {:ok, result} <-
%{id: ind, method: "eth_getTransactionByHash", params: [pending_tx_hash_str]} %{id: ind, method: "eth_getTransactionReceipt", params: [pending_tx_hash_str]}
|> request() |> request()
|> json_rpc(json_rpc_named_arguments) do |> json_rpc(json_rpc_named_arguments) do
if result do if result do
@ -84,7 +86,7 @@ defmodule Indexer.PendingTransactionsSanitizer do
fetcher: :pending_transactions_to_refetch fetcher: :pending_transactions_to_refetch
) )
fetch_block_and_invalidate(block_hash, pending_tx) fetch_block_and_invalidate(block_hash, pending_tx, result)
else else
Logger.debug( Logger.debug(
"Transaction with hash #{pending_tx_hash_str} is still pending. Do nothing.", "Transaction with hash #{pending_tx_hash_str} is still pending. Do nothing.",
@ -130,7 +132,7 @@ defmodule Indexer.PendingTransactionsSanitizer do
end end
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 case Chain.fetch_block_by_hash(block_hash) do
%{number: number, consensus: consensus} -> %{number: number, consensus: consensus} ->
Logger.debug( Logger.debug(
@ -140,7 +142,7 @@ defmodule Indexer.PendingTransactionsSanitizer do
fetcher: :pending_transactions_to_refetch fetcher: :pending_transactions_to_refetch
) )
invalidate_block(number, block_hash, consensus, pending_tx) invalidate_block(number, block_hash, consensus, pending_tx, tx)
_ -> _ ->
Logger.debug( Logger.debug(
@ -150,7 +152,7 @@ defmodule Indexer.PendingTransactionsSanitizer do
end end
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 if consensus do
opts = %{ opts = %{
timeout: 60_000, timeout: 60_000,
@ -159,15 +161,25 @@ defmodule Indexer.PendingTransactionsSanitizer do
Blocks.lose_consensus(Repo, [], [block_number], [], opts) Blocks.lose_consensus(Repo, [], [block_number], [], opts)
else else
{:ok, hash} = Hash.cast(block_hash)
tx_info = to_elixir(tx)
changeset = changeset =
pending_tx pending_tx
|> Transaction.changeset() |> 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_number, block_number)
|> Changeset.put_change(:block_hash, block_hash) |> Changeset.put_change(:block_hash, hash)
Repo.update(changeset) 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 end
end end

Loading…
Cancel
Save