From 8a65bb047090aabab14f5f8351554d169108c982 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 22 Aug 2024 12:13:25 +0300 Subject: [PATCH] fix: Fix bug in update_replaced_transactions query (#10634) * fix: Fix bug in update_replaced_transactions query * Fix condition for error --- apps/explorer/lib/explorer/chain.ex | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 899bc290a3..473c2e0e76 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2738,19 +2738,23 @@ defmodule Explorer.Chain do |> select_repo(options).all() end + @doc """ + Query to return all pending transactions + """ + @spec pending_transactions_query(Ecto.Queryable.t()) :: Ecto.Queryable.t() def pending_transactions_query(query) do from(transaction in query, where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") ) end + @doc """ + Returns pending transactions list from the DB + """ + @spec pending_transactions_list() :: Ecto.Schema.t() | term() def pending_transactions_list do - query = - from(transaction in Transaction, - where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") - ) - - query + Transaction + |> pending_transactions_query() |> Repo.all(timeout: :infinity) end @@ -3877,13 +3881,17 @@ defmodule Explorer.Chain do |> Enum.uniq() if Enum.empty?(filters) do - {:ok, []} + {0, []} else query = filters |> Enum.reduce(Transaction, fn {nonce, from_address}, 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) # Enforce Transaction ShareLocks order (see docs: sharelocks.md)