fix: Omit pbo for blocks lower than trace first block for indexing status (#11053)

Claire
Qwerty5Uiop 2 weeks ago committed by GitHub
parent b87b06bf86
commit 3d627c5b76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      apps/explorer/lib/explorer/chain.ex
  2. 14
      apps/explorer/lib/explorer/chain/pending_block_operation.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)

@ -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

Loading…
Cancel
Save