Skip to content

Commit

Permalink
Merge pull request blockscout#43 from crypto-org-chain/hotfix/limit_r…
Browse files Browse the repository at this point in the history
…esources_and_fix_nil_timestamp

Hotfix/limit resources and fix nil timestamp
  • Loading branch information
mofhusseini committed Nov 11, 2021
2 parents c84abc6 + 7944f1d commit 65bf976
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ defmodule Explorer.Chain.Import.Runner.Address.CoinBalancesDaily do
end)

if target_item do
if change.value > target_item.value do
if Map.has_key?(change, :value) && Map.has_key?(target_item, :value) && change.value > target_item.value do
acc_updated = List.delete(acc, target_item)
[change | acc_updated]
else
Expand Down
7 changes: 6 additions & 1 deletion apps/indexer/lib/indexer/block/catchup/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ defmodule Indexer.Block.Catchup.Fetcher do
false

_ ->
sequence_opts = put_memory_monitor([ranges: missing_ranges, step: -1 * blocks_batch_size], state)
step = step(first, last, blocks_batch_size)
sequence_opts = put_memory_monitor([ranges: missing_ranges, step: step], state)
gen_server_opts = [name: @sequence_name]
{:ok, sequence} = Sequence.start_link(sequence_opts, gen_server_opts)
Sequence.cap(sequence)
Expand All @@ -128,6 +129,10 @@ defmodule Indexer.Block.Catchup.Fetcher do
end
end

defp step(first, last, blocks_batch_size) do
if first < last, do: blocks_batch_size, else: -1 * blocks_batch_size
end

@async_import_remaining_block_data_options ~w(address_hash_to_fetched_balance_block_number)a

@impl Block.Fetcher
Expand Down
2 changes: 1 addition & 1 deletion apps/indexer/lib/indexer/fetcher/contract_code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Indexer.Fetcher.ContractCode do

@behaviour BufferedTask

@max_batch_size 4
@max_batch_size 2
@max_concurrency 2
@defaults [
flush_interval: :timer.seconds(3),
Expand Down
2 changes: 1 addition & 1 deletion apps/indexer/lib/indexer/fetcher/internal_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Indexer.Fetcher.InternalTransaction do

@behaviour BufferedTask

@max_batch_size 3
@max_batch_size 5
@max_concurrency 2
@defaults [
flush_interval: :timer.seconds(3),
Expand Down
2 changes: 1 addition & 1 deletion apps/indexer/lib/indexer/fetcher/token_balance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Indexer.Fetcher.TokenBalance do

@defaults [
flush_interval: 300,
max_batch_size: 40,
max_batch_size: 20,
max_concurrency: 3,
task_supervisor: Indexer.Fetcher.TokenBalance.TaskSupervisor
]
Expand Down
2 changes: 1 addition & 1 deletion apps/indexer/lib/indexer/fetcher/token_instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Indexer.Fetcher.TokenInstance do
@defaults [
flush_interval: 300,
max_batch_size: 1,
max_concurrency: 3,
max_concurrency: 5,
task_supervisor: Indexer.Fetcher.TokenInstance.TaskSupervisor
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Indexer.Transform.AddressCoinBalancesDaily do
Extracts `Explorer.Chain.Address.CoinBalanceDaily` params from other schema's params.
"""

import EthereumJSONRPC, only: [integer_to_quantity: 1, json_rpc: 2, quantity_to_integer: 1, request: 1]

def params_set(%{coin_balances_params: coin_balances_params_set, blocks: blocks}) do
coin_balances_params =
coin_balances_params_set
Expand All @@ -19,7 +21,20 @@ defmodule Indexer.Transform.AddressCoinBalancesDaily do
block.number == block_number
end)

day = DateTime.to_date(block.timestamp)
day =
if block do
DateTime.to_date(block.timestamp)
else
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments)

with {:ok, %{"timestamp" => timestamp_raw}} <-
%{id: 1, method: "eth_getBlockByNumber", params: [integer_to_quantity(block_number), false]}
|> request()
|> json_rpc(json_rpc_named_arguments) do
timestamp = quantity_to_integer(timestamp_raw)
DateTime.from_unix!(timestamp)
end
end

[%{address_hash: address_hash, day: day} | acc]
end)
Expand Down

0 comments on commit 65bf976

Please sign in to comment.