Set trace_block_ranges to first..last if not set

pull/8960/head
Qwerty5Uiop 11 months ago
parent 61eeae6e2c
commit 3ab544f500
  1. 45
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/ranges_helper.ex
  2. 6
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  3. 19
      apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex
  4. 15
      config/runtime.exs

@ -4,38 +4,37 @@ defmodule EthereumJSONRPC.Utility.RangesHelper do
Helper for ranges manipulations.
"""
@default_trace_block_ranges "0..latest"
@spec traceable_block_number?(integer() | nil) :: boolean()
def traceable_block_number?(block_number) do
case Application.get_env(:indexer, :trace_block_ranges) do
nil ->
min_block = Application.get_env(:indexer, :trace_first_block)
max_block = Application.get_env(:indexer, :trace_last_block)
!block_number || (block_number >= min_block && if(max_block, do: block_number <= max_block, else: true))
block_ranges ->
parsed_ranges = parse_block_ranges(block_ranges)
number_in_ranges?(block_number, parsed_ranges)
if trace_ranges_present?() do
number_in_ranges?(block_number, get_trace_block_ranges())
else
true
end
end
@spec filter_traceable_block_numbers([integer()]) :: [integer()]
def filter_traceable_block_numbers(block_numbers) do
case Application.get_env(:indexer, :trace_block_ranges) do
nil ->
min_block = Application.get_env(:indexer, :trace_first_block)
max_block = Application.get_env(:indexer, :trace_last_block)
Enum.filter(block_numbers, fn block_number ->
block_number >= min_block && if max_block, do: block_number <= max_block, else: true
end)
block_ranges ->
parsed_ranges = parse_block_ranges(block_ranges)
if trace_ranges_present?() do
trace_block_ranges = get_trace_block_ranges()
Enum.filter(block_numbers, &number_in_ranges?(&1, trace_block_ranges))
else
block_numbers
end
end
Enum.filter(block_numbers, &number_in_ranges?(&1, parsed_ranges))
@spec trace_ranges_present? :: boolean()
def trace_ranges_present? do
Application.get_env(:indexer, :trace_block_ranges) != @default_trace_block_ranges
end
@spec get_trace_block_ranges :: [Range.t() | integer()]
def get_trace_block_ranges do
:indexer
|> Application.get_env(:trace_block_ranges)
|> parse_block_ranges()
end
@spec parse_block_ranges(binary()) :: [Range.t() | integer()]

@ -887,11 +887,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
end
defp filter_by_height_range(blocks, filter_func) do
trace_block_ranges = Application.get_env(:indexer, :trace_block_ranges)
minimal_block_height = Application.get_env(:indexer, :trace_first_block)
maximal_block_height = Application.get_env(:indexer, :trace_last_block)
if trace_block_ranges || minimal_block_height > 0 || maximal_block_height do
if RangesHelper.trace_ranges_present?() do
Enum.filter(blocks, &filter_func.(&1))
else
blocks

@ -751,24 +751,15 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
end
defp traceable_blocks_dynamic_query do
case Application.get_env(:indexer, :trace_block_ranges) do
nil ->
min_block = Application.get_env(:indexer, :trace_first_block)
max_block = Application.get_env(:indexer, :trace_last_block)
if RangesHelper.trace_ranges_present?() do
block_ranges = RangesHelper.get_trace_block_ranges()
filter_by_min_dynamic = dynamic([block], block.number > ^min_block)
if max_block,
do: dynamic([block], ^filter_by_min_dynamic and block.number < ^max_block),
else: filter_by_min_dynamic
block_ranges ->
parsed_ranges = RangesHelper.parse_block_ranges(block_ranges)
Enum.reduce(parsed_ranges, dynamic([_], false), fn
Enum.reduce(block_ranges, dynamic([_], false), fn
_from.._to = range, acc -> dynamic([block], ^acc or block.number in ^range)
num_to_latest, acc -> dynamic([block], ^acc or block.number >= ^num_to_latest)
end)
else
dynamic([_], true)
end
end
end

@ -459,15 +459,24 @@ config :explorer, Explorer.MicroserviceInterfaces.BENS,
### Indexer ###
###############
trace_first_block = ConfigHelper.parse_integer_env_var("TRACE_FIRST_BLOCK", 0)
trace_last_block = ConfigHelper.parse_integer_or_nil_env_var("TRACE_LAST_BLOCK")
trace_block_ranges =
case ConfigHelper.safe_get_env("TRACE_BLOCK_RANGES", nil) do
"" -> "#{trace_first_block}..#{trace_last_block || "latest"}"
ranges -> ranges
end
config :indexer,
block_transformer: ConfigHelper.block_transformer(),
metadata_updater_milliseconds_interval: ConfigHelper.parse_time_env_var("TOKEN_METADATA_UPDATE_INTERVAL", "48h"),
block_ranges: System.get_env("BLOCK_RANGES"),
first_block: ConfigHelper.parse_integer_env_var("FIRST_BLOCK", 0),
last_block: ConfigHelper.parse_integer_or_nil_env_var("LAST_BLOCK"),
trace_block_ranges: System.get_env("TRACE_BLOCK_RANGES"),
trace_first_block: ConfigHelper.parse_integer_env_var("TRACE_FIRST_BLOCK", 0),
trace_last_block: ConfigHelper.parse_integer_or_nil_env_var("TRACE_LAST_BLOCK"),
trace_block_ranges: trace_block_ranges,
trace_first_block: trace_first_block,
trace_last_block: trace_last_block,
fetch_rewards_way: System.get_env("FETCH_REWARDS_WAY", "trace_block"),
memory_limit: ConfigHelper.indexer_memory_limit(),
receipts_batch_size: ConfigHelper.parse_integer_env_var("INDEXER_RECEIPTS_BATCH_SIZE", 250),

Loading…
Cancel
Save