Merge pull request #8717 from blockscout/ap-gas-price-oracle-old-prices

Save GasPriceOracle old prices as a fallback
pull/8724/head
Victor Baranov 1 year ago committed by GitHub
commit eaf2d51aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 12
      apps/explorer/lib/explorer/chain/cache/gas_price_oracle.ex

@ -4,6 +4,7 @@
### Features
- [#8717](https://github.com/blockscout/blockscout/pull/8717) - Save GasPriceOracle old prices as a fallback
- [#8696](https://github.com/blockscout/blockscout/pull/8696) - Support tokenSymbol and tokenName in `/api/v2/import/token-info`
- [#8673](https://github.com/blockscout/blockscout/pull/8673) - Add a window for balances fetching from non-archive node
- [#8651](https://github.com/blockscout/blockscout/pull/8651) - Add `stability_fee` for CHAIN_TYPE=stability

@ -22,6 +22,7 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
use Explorer.Chain.MapCache,
name: :gas_price,
key: :gas_prices,
key: :old_gas_prices,
key: :async_task,
global_ttl: Application.get_env(:explorer, __MODULE__)[:global_ttl],
ttl_check_interval: :timer.seconds(1),
@ -171,7 +172,7 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
# See next `handle_fallback` definition
get_async_task()
{:return, nil}
{:return, get_old_gas_prices()}
end
defp handle_fallback(:async_task) do
@ -182,7 +183,7 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
try do
result = get_average_gas_price(num_of_blocks(), safelow(), average(), fast())
set_all(result)
set_gas_prices(result)
rescue
e ->
Logger.debug([
@ -197,9 +198,14 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
{:update, task}
end
defp handle_fallback(_), do: {:return, nil}
# By setting this as a `callback` an async task will be started each time the
# `gas_prices` expires (unless there is one already running)
defp async_task_on_deletion({:delete, _, :gas_prices}), do: get_async_task()
defp async_task_on_deletion({:delete, _, :gas_prices}) do
set_old_gas_prices(get_gas_prices())
get_async_task()
end
defp async_task_on_deletion(_data), do: nil
end

Loading…
Cancel
Save