fix: Fix bug in update_replaced_transactions query (#10634)

* fix: Fix bug in update_replaced_transactions query

* Fix condition for error
vb-dockerfile-nonroot-only
Victor Baranov 3 months ago committed by GitHub
parent e7f14c3dcd
commit 8a65bb0470
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      apps/explorer/lib/explorer/chain.ex

@ -2738,19 +2738,23 @@ defmodule Explorer.Chain do
|> select_repo(options).all() |> select_repo(options).all()
end end
@doc """
Query to return all pending transactions
"""
@spec pending_transactions_query(Ecto.Queryable.t()) :: Ecto.Queryable.t()
def pending_transactions_query(query) do def pending_transactions_query(query) do
from(transaction in query, from(transaction in query,
where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced")
) )
end end
@doc """
Returns pending transactions list from the DB
"""
@spec pending_transactions_list() :: Ecto.Schema.t() | term()
def pending_transactions_list do def pending_transactions_list do
query = Transaction
from(transaction in Transaction, |> pending_transactions_query()
where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced")
)
query
|> Repo.all(timeout: :infinity) |> Repo.all(timeout: :infinity)
end end
@ -3877,13 +3881,17 @@ defmodule Explorer.Chain do
|> Enum.uniq() |> Enum.uniq()
if Enum.empty?(filters) do if Enum.empty?(filters) do
{:ok, []} {0, []}
else else
query = query =
filters filters
|> Enum.reduce(Transaction, fn {nonce, from_address}, query -> |> Enum.reduce(Transaction, fn {nonce, from_address}, query ->
from(t in query, from(t in query,
or_where: t.nonce == ^nonce and t.from_address_hash == ^from_address and is_nil(t.block_hash) or_where:
t.nonce == ^nonce and
t.from_address_hash == ^from_address and
is_nil(t.block_hash) and
(is_nil(t.error) or t.error != "dropped/replaced")
) )
end) end)
# Enforce Transaction ShareLocks order (see docs: sharelocks.md) # Enforce Transaction ShareLocks order (see docs: sharelocks.md)

Loading…
Cancel
Save