|
|
|
@ -1275,8 +1275,8 @@ defmodule Explorer.Chain do |
|
|
|
|
Checks to see if the chain is down indexing based on the transaction from the |
|
|
|
|
oldest block and the pending operation |
|
|
|
|
""" |
|
|
|
|
@spec finished_internal_transactions_indexing?([api?]) :: boolean() |
|
|
|
|
def finished_internal_transactions_indexing?(options \\ []) do |
|
|
|
|
@spec finished_indexing_internal_transactions?([api?]) :: boolean() |
|
|
|
|
def finished_indexing_internal_transactions?(options \\ []) do |
|
|
|
|
internal_transactions_disabled? = System.get_env("INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER", "false") == "true" |
|
|
|
|
|
|
|
|
|
if internal_transactions_disabled? do |
|
|
|
@ -1312,19 +1312,21 @@ defmodule Explorer.Chain do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def finished_blocks_indexing?(indexed_ratio_blocks) do |
|
|
|
|
Decimal.compare(indexed_ratio_blocks, 1) !== :lt |
|
|
|
|
def finished_indexing_from_ratio?(ratio) do |
|
|
|
|
Decimal.compare(ratio, 1) !== :lt |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Checks if indexing of blocks and internal transactions finished aka full indexing |
|
|
|
|
""" |
|
|
|
|
@spec finished_indexing?(Decimal.t(), [api?]) :: boolean() |
|
|
|
|
def finished_indexing?(indexed_ratio_blocks, options \\ []) do |
|
|
|
|
@spec finished_indexing?([api?]) :: boolean() |
|
|
|
|
def finished_indexing?(options \\ []) do |
|
|
|
|
if Application.get_env(:indexer, Indexer.Supervisor)[:enabled] do |
|
|
|
|
case finished_blocks_indexing?(indexed_ratio_blocks) do |
|
|
|
|
indexed_ratio = indexed_ratio_blocks() |
|
|
|
|
|
|
|
|
|
case finished_indexing_from_ratio?(indexed_ratio) do |
|
|
|
|
false -> false |
|
|
|
|
_ -> finished_internal_transactions_indexing?(options) |
|
|
|
|
_ -> finished_indexing_internal_transactions?(options) |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
true |
|
|
|
@ -2185,58 +2187,66 @@ defmodule Explorer.Chain do |
|
|
|
|
""" |
|
|
|
|
@spec indexed_ratio_blocks() :: Decimal.t() |
|
|
|
|
def indexed_ratio_blocks do |
|
|
|
|
%{min: min, max: max} = BlockNumber.get_all() |
|
|
|
|
if Application.get_env(:indexer, Indexer.Supervisor)[:enabled] do |
|
|
|
|
%{min: min, max: max} = BlockNumber.get_all() |
|
|
|
|
|
|
|
|
|
min_blockchain_block_number = |
|
|
|
|
case Integer.parse(Application.get_env(:indexer, :first_block)) do |
|
|
|
|
{block_number, _} -> block_number |
|
|
|
|
_ -> 0 |
|
|
|
|
end |
|
|
|
|
min_blockchain_block_number = |
|
|
|
|
case Integer.parse(Application.get_env(:indexer, :first_block)) do |
|
|
|
|
{block_number, _} -> block_number |
|
|
|
|
_ -> 0 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
case {min, max} do |
|
|
|
|
{0, 0} -> |
|
|
|
|
Decimal.new(0) |
|
|
|
|
case {min, max} do |
|
|
|
|
{0, 0} -> |
|
|
|
|
Decimal.new(0) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
result = |
|
|
|
|
BlockCache.estimated_count() |
|
|
|
|
|> Decimal.div(max - min_blockchain_block_number + 1) |
|
|
|
|
|> (&if( |
|
|
|
|
(Decimal.compare(&1, Decimal.from_float(0.99)) == :gt || |
|
|
|
|
Decimal.compare(&1, Decimal.from_float(0.99)) == :eq) && |
|
|
|
|
min <= min_blockchain_block_number, |
|
|
|
|
do: Decimal.new(1), |
|
|
|
|
else: &1 |
|
|
|
|
)).() |
|
|
|
|
|
|
|
|
|
result |
|
|
|
|
|> Decimal.round(2, :down) |
|
|
|
|
|> Decimal.min(Decimal.new(1)) |
|
|
|
|
_ -> |
|
|
|
|
result = |
|
|
|
|
BlockCache.estimated_count() |
|
|
|
|
|> Decimal.div(max - min_blockchain_block_number + 1) |
|
|
|
|
|> (&if( |
|
|
|
|
(Decimal.compare(&1, Decimal.from_float(0.99)) == :gt || |
|
|
|
|
Decimal.compare(&1, Decimal.from_float(0.99)) == :eq) && |
|
|
|
|
min <= min_blockchain_block_number, |
|
|
|
|
do: Decimal.new(1), |
|
|
|
|
else: &1 |
|
|
|
|
)).() |
|
|
|
|
|
|
|
|
|
result |
|
|
|
|
|> Decimal.round(2, :down) |
|
|
|
|
|> Decimal.min(Decimal.new(1)) |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
Decimal.new(1) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec indexed_ratio_internal_transactions() :: Decimal.t() |
|
|
|
|
def indexed_ratio_internal_transactions do |
|
|
|
|
%{max: max} = BlockNumber.get_all() |
|
|
|
|
count = Repo.aggregate(PendingBlockOperation, :count, timeout: :infinity) |
|
|
|
|
if Application.get_env(:indexer, Indexer.Supervisor)[:enabled] do |
|
|
|
|
%{max: max} = BlockNumber.get_all() |
|
|
|
|
count = Repo.aggregate(PendingBlockOperation, :count, timeout: :infinity) |
|
|
|
|
|
|
|
|
|
min_blockchain_trace_block_number = |
|
|
|
|
case Integer.parse(Application.get_env(:indexer, :trace_first_block)) do |
|
|
|
|
{block_number, _} -> block_number |
|
|
|
|
_ -> 0 |
|
|
|
|
end |
|
|
|
|
min_blockchain_trace_block_number = |
|
|
|
|
case Integer.parse(Application.get_env(:indexer, :trace_first_block)) do |
|
|
|
|
{block_number, _} -> block_number |
|
|
|
|
_ -> 0 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
case max do |
|
|
|
|
0 -> |
|
|
|
|
Decimal.new(0) |
|
|
|
|
case max do |
|
|
|
|
0 -> |
|
|
|
|
Decimal.new(0) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
full_blocks_range = max - min_blockchain_trace_block_number + 1 |
|
|
|
|
result = Decimal.div(full_blocks_range - count, full_blocks_range) |
|
|
|
|
_ -> |
|
|
|
|
full_blocks_range = max - min_blockchain_trace_block_number + 1 |
|
|
|
|
result = Decimal.div(full_blocks_range - count, full_blocks_range) |
|
|
|
|
|
|
|
|
|
result |
|
|
|
|
|> Decimal.round(2, :down) |
|
|
|
|
|> Decimal.min(Decimal.new(1)) |
|
|
|
|
result |
|
|
|
|
|> Decimal.round(2, :down) |
|
|
|
|
|> Decimal.min(Decimal.new(1)) |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
Decimal.new(1) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|