From 3d627c5b763dfbc51286185f97279d1032b44a8f Mon Sep 17 00:00:00 2001 From: Qwerty5Uiop <105209995+Qwerty5Uiop@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:25:33 +0400 Subject: [PATCH] fix: Omit pbo for blocks lower than trace first block for indexing status (#11053) --- apps/explorer/lib/explorer/chain.ex | 3 ++- .../lib/explorer/chain/pending_block_operation.ex | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 3065e3ada2..24c19b1d39 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1473,7 +1473,6 @@ defmodule Explorer.Chain do def indexed_ratio_internal_transactions do if indexer_running?() and internal_transactions_fetcher_running?() do %{max: max_saved_block_number} = BlockNumber.get_all() - pbo_count = PendingBlockOperationCache.estimated_count() min_blockchain_trace_block_number = Application.get_env(:indexer, :trace_first_block) @@ -1485,6 +1484,8 @@ defmodule Explorer.Chain do full_blocks_range = max_saved_block_number - min_blockchain_trace_block_number - BlockNumberHelper.null_rounds_count() + 1 + pbo_count = PendingBlockOperation.count_in_range(min_blockchain_trace_block_number, max_saved_block_number) + processed_int_transactions_for_blocks_count = max(0, full_blocks_range - pbo_count) ratio = get_ratio(processed_int_transactions_for_blocks_count, full_blocks_range) diff --git a/apps/explorer/lib/explorer/chain/pending_block_operation.ex b/apps/explorer/lib/explorer/chain/pending_block_operation.ex index 9a1b5b4894..918b213c02 100644 --- a/apps/explorer/lib/explorer/chain/pending_block_operation.ex +++ b/apps/explorer/lib/explorer/chain/pending_block_operation.ex @@ -6,6 +6,7 @@ defmodule Explorer.Chain.PendingBlockOperation do use Explorer.Schema alias Explorer.Chain.{Block, Hash} + alias Explorer.Repo @required_attrs ~w(block_hash block_number)a @@ -41,4 +42,17 @@ defmodule Explorer.Chain.PendingBlockOperation do select: pending_ops.block_hash ) end + + @doc """ + Returns the count of pending block operations in provided blocks range + (between `from_block_number` and `to_block_number`). + """ + @spec count_in_range(integer(), integer()) :: integer() + def count_in_range(from_block_number, to_block_number) when from_block_number <= to_block_number do + __MODULE__ + |> where([pbo], pbo.block_number >= ^from_block_number) + |> where([pbo], pbo.block_number <= ^to_block_number) + |> select([pbo], count(pbo.block_number)) + |> Repo.one() + end end