Merge pull request #6903 from blockscout/vb-fix-indexing-blocks-banner-value

Fix indexed blocks value in "Indexing tokens" banner
pull/6932/head
Victor Baranov 2 years ago committed by GitHub
commit 95f31b50ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 11
      apps/explorer/lib/explorer/chain.ex
  3. 14
      apps/explorer/lib/explorer/chain/cache/block.ex
  4. 14
      apps/explorer/lib/explorer/chain/cache/gas_price_oracle.ex
  5. 14
      apps/explorer/lib/explorer/chain/cache/transaction.ex
  6. 16
      apps/explorer/test/explorer/chain_test.exs
  7. 36
      config/runtime.exs

@ -12,6 +12,7 @@
- [#6912](https://github.com/blockscout/blockscout/pull/6912) - Docker compose fix exposed ports - [#6912](https://github.com/blockscout/blockscout/pull/6912) - Docker compose fix exposed ports
- [#6913](https://github.com/blockscout/blockscout/pull/6913) - Fix an error occurred when decoding base64 encoded json - [#6913](https://github.com/blockscout/blockscout/pull/6913) - Fix an error occurred when decoding base64 encoded json
- [#6911](https://github.com/blockscout/blockscout/pull/6911) - Fix bugs in verification API v2 - [#6911](https://github.com/blockscout/blockscout/pull/6911) - Fix bugs in verification API v2
- [#6903](https://github.com/blockscout/blockscout/pull/6903) - Fix indexed blocks value in "Indexing tokens" banner
- [#6891](https://github.com/blockscout/blockscout/pull/6891) - Fix read contract for geth - [#6891](https://github.com/blockscout/blockscout/pull/6891) - Fix read contract for geth
- [#6889](https://github.com/blockscout/blockscout/pull/6889) - Fix Internal Server Error on tx input decoding - [#6889](https://github.com/blockscout/blockscout/pull/6889) - Fix Internal Server Error on tx input decoding
- [#6893](https://github.com/blockscout/blockscout/pull/6893) - Fix token type definition for multiple interface tokens - [#6893](https://github.com/blockscout/blockscout/pull/6893) - Fix token type definition for multiple interface tokens

@ -77,6 +77,8 @@ defmodule Explorer.Chain do
VerifiedContractsCounter VerifiedContractsCounter
} }
alias Explorer.Chain.Cache.Block, as: BlockCache
alias Explorer.Chain.Import.Runner alias Explorer.Chain.Import.Runner
alias Explorer.Chain.InternalTransaction.{CallType, Type} alias Explorer.Chain.InternalTransaction.{CallType, Type}
@ -2209,13 +2211,6 @@ defmodule Explorer.Chain do
@doc """ @doc """
The percentage of indexed blocks on the chain. The percentage of indexed blocks on the chain.
iex> for index <- 5..9 do
...> insert(:block, number: index)
...> Process.sleep(200)
...> end
iex> Explorer.Chain.indexed_ratio_blocks()
Decimal.new(1, 50, -2)
If there are no blocks, the percentage is 0. If there are no blocks, the percentage is 0.
iex> Explorer.Chain.indexed_ratio_blocks() iex> Explorer.Chain.indexed_ratio_blocks()
@ -2237,7 +2232,7 @@ defmodule Explorer.Chain do
Decimal.new(0) Decimal.new(0)
_ -> _ ->
result = Decimal.div(max - min + 1, max - min_blockchain_block_number + 1) result = Decimal.div(BlockCache.estimated_count(), max - min_blockchain_block_number + 1)
result result
|> Decimal.round(2, :down) |> Decimal.round(2, :down)

@ -3,8 +3,6 @@ defmodule Explorer.Chain.Cache.Block do
Cache for block count. Cache for block count.
""" """
@default_cache_period :timer.hours(2)
import Ecto.Query, import Ecto.Query,
only: [ only: [
from: 2 from: 2
@ -14,7 +12,7 @@ defmodule Explorer.Chain.Cache.Block do
name: :block_count, name: :block_count,
key: :count, key: :count,
key: :async_task, key: :async_task,
global_ttl: cache_period(), global_ttl: Application.get_env(:explorer, __MODULE__)[:global_ttl],
ttl_check_interval: :timer.minutes(15), ttl_check_interval: :timer.minutes(15),
callback: &async_task_on_deletion(&1) callback: &async_task_on_deletion(&1)
@ -78,16 +76,6 @@ defmodule Explorer.Chain.Cache.Block do
defp async_task_on_deletion(_data), do: nil defp async_task_on_deletion(_data), do: nil
defp cache_period do
"CACHE_BLOCK_COUNT_PERIOD"
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, ""} -> :timer.seconds(integer)
_ -> @default_cache_period
end
end
@spec fetch_count_consensus_block() :: non_neg_integer @spec fetch_count_consensus_block() :: non_neg_integer
defp fetch_count_consensus_block do defp fetch_count_consensus_block do
query = query =

@ -17,8 +17,6 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
alias Explorer.Repo alias Explorer.Repo
@default_cache_period :timer.seconds(30)
@num_of_blocks (case Integer.parse(System.get_env("GAS_PRICE_ORACLE_NUM_OF_BLOCKS", "200")) do @num_of_blocks (case Integer.parse(System.get_env("GAS_PRICE_ORACLE_NUM_OF_BLOCKS", "200")) do
{integer, ""} -> integer {integer, ""} -> integer
_ -> 200 _ -> 200
@ -43,7 +41,7 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
name: :gas_price, name: :gas_price,
key: :gas_prices, key: :gas_prices,
key: :async_task, key: :async_task,
global_ttl: cache_period(), global_ttl: Application.get_env(:explorer, __MODULE__)[:global_ttl],
ttl_check_interval: :timer.minutes(5), ttl_check_interval: :timer.minutes(5),
callback: &async_task_on_deletion(&1) callback: &async_task_on_deletion(&1)
@ -155,14 +153,4 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
defp async_task_on_deletion({:delete, _, :gas_prices}), do: get_async_task() defp async_task_on_deletion({:delete, _, :gas_prices}), do: get_async_task()
defp async_task_on_deletion(_data), do: nil defp async_task_on_deletion(_data), do: nil
defp cache_period do
"GAS_PRICE_ORACLE_CACHE_PERIOD"
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, ""} -> :timer.seconds(integer)
_ -> @default_cache_period
end
end
end end

@ -3,13 +3,11 @@ defmodule Explorer.Chain.Cache.Transaction do
Cache for estimated transaction count. Cache for estimated transaction count.
""" """
@default_cache_period :timer.hours(2)
use Explorer.Chain.MapCache, use Explorer.Chain.MapCache,
name: :transaction_count, name: :transaction_count,
key: :count, key: :count,
key: :async_task, key: :async_task,
global_ttl: cache_period(), global_ttl: Application.get_env(:explorer, __MODULE__)[:global_ttl],
ttl_check_interval: :timer.minutes(15), ttl_check_interval: :timer.minutes(15),
callback: &async_task_on_deletion(&1) callback: &async_task_on_deletion(&1)
@ -74,14 +72,4 @@ defmodule Explorer.Chain.Cache.Transaction do
defp async_task_on_deletion({:delete, _, :count}), do: get_async_task() defp async_task_on_deletion({:delete, _, :count}), do: get_async_task()
defp async_task_on_deletion(_data), do: nil defp async_task_on_deletion(_data), do: nil
defp cache_period do
"CACHE_TXS_COUNT_PERIOD"
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, ""} -> :timer.seconds(integer)
_ -> @default_cache_period
end
end
end end

@ -28,6 +28,7 @@ defmodule Explorer.ChainTest do
} }
alias Explorer.{Chain, Etherscan} alias Explorer.{Chain, Etherscan}
alias Explorer.Chain.Cache.Block, as: BlockCache
alias Explorer.Chain.Cache.Transaction, as: TransactionCache alias Explorer.Chain.Cache.Transaction, as: TransactionCache
alias Explorer.Chain.InternalTransaction.Type alias Explorer.Chain.InternalTransaction.Type
@ -1475,6 +1476,9 @@ defmodule Explorer.ChainTest do
describe "indexed_ratio_blocks/0" do describe "indexed_ratio_blocks/0" do
setup do setup do
Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Block.child_id())
Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Block.child_id())
on_exit(fn -> on_exit(fn ->
Application.put_env(:indexer, :first_block, "") Application.put_env(:indexer, :first_block, "")
end) end)
@ -1482,9 +1486,11 @@ defmodule Explorer.ChainTest do
test "returns indexed ratio" do test "returns indexed ratio" do
for index <- 5..9 do for index <- 5..9 do
insert(:block, number: index) insert(:block, number: index, consensus: true)
end end
BlockCache.estimated_count()
assert Decimal.compare(Chain.indexed_ratio_blocks(), Decimal.from_float(0.5)) == :eq assert Decimal.compare(Chain.indexed_ratio_blocks(), Decimal.from_float(0.5)) == :eq
end end
@ -1494,10 +1500,12 @@ defmodule Explorer.ChainTest do
test "returns 1.0 if fully indexed blocks" do test "returns 1.0 if fully indexed blocks" do
for index <- 0..9 do for index <- 0..9 do
insert(:block, number: index) insert(:block, number: index, consensus: true)
Process.sleep(200) Process.sleep(200)
end end
BlockCache.estimated_count()
assert Decimal.compare(Chain.indexed_ratio_blocks(), 1) == :eq assert Decimal.compare(Chain.indexed_ratio_blocks(), 1) == :eq
end end
@ -1505,10 +1513,12 @@ defmodule Explorer.ChainTest do
Application.put_env(:indexer, :first_block, "5") Application.put_env(:indexer, :first_block, "5")
for index <- 5..9 do for index <- 5..9 do
insert(:block, number: index) insert(:block, number: index, consensus: true)
Process.sleep(200) Process.sleep(200)
end end
BlockCache.estimated_count()
assert Decimal.compare(Chain.indexed_ratio_blocks(), 1) == :eq assert Decimal.compare(Chain.indexed_ratio_blocks(), 1) == :eq
end end
end end

@ -256,6 +256,42 @@ config :explorer, Explorer.Chain.Cache.AddressSum, global_ttl: address_sum_globa
config :explorer, Explorer.Chain.Cache.AddressSumMinusBurnt, global_ttl: address_sum_global_ttl config :explorer, Explorer.Chain.Cache.AddressSumMinusBurnt, global_ttl: address_sum_global_ttl
block_count_global_ttl =
"CACHE_BLOCK_COUNT_PERIOD"
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, ""} -> integer
_ -> 7200
end
|> :timer.seconds()
config :explorer, Explorer.Chain.Cache.Block, global_ttl: block_count_global_ttl
transaction_count_global_ttl =
"CACHE_TXS_COUNT_PERIOD"
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, ""} -> integer
_ -> 7200
end
|> :timer.seconds()
config :explorer, Explorer.Chain.Cache.Transaction, global_ttl: transaction_count_global_ttl
gas_price_oracle_global_ttl =
"GAS_PRICE_ORACLE_CACHE_PERIOD"
|> System.get_env("")
|> Integer.parse()
|> case do
{integer, ""} -> integer
_ -> 30
end
|> :timer.seconds()
config :explorer, Explorer.Chain.Cache.GasPriceOracle, global_ttl: gas_price_oracle_global_ttl
config :explorer, Explorer.ExchangeRates, config :explorer, Explorer.ExchangeRates,
store: :ets, store: :ets,
enabled: System.get_env("DISABLE_EXCHANGE_RATES") != "true", enabled: System.get_env("DISABLE_EXCHANGE_RATES") != "true",

Loading…
Cancel
Save