Merge pull request #3396 from poanetwork/vb-exchange-rates-req-throttled-fix

Handle exchange rates request throttled
pull/3399/head
Victor Baranov 4 years ago committed by GitHub
commit 1b63e3caa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .dialyzer-ignore
  2. 1
      CHANGELOG.md
  3. 10
      apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex
  4. 8
      apps/explorer/lib/explorer/exchange_rates/source.ex
  5. 5
      apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs

@ -23,7 +23,7 @@ lib/block_scout_web/controllers/api/rpc/transaction_controller.ex:21
lib/block_scout_web/controllers/api/rpc/transaction_controller.ex:22
lib/explorer/smart_contract/reader.ex:330
lib/indexer/fetcher/token_total_supply_on_demand.ex:16
lib/explorer/exchange_rates/source.ex:41
lib/explorer/exchange_rates/source.ex:45
lib/explorer/exchange_rates/source/coin_gecko.ex:148
lib/explorer/exchange_rates/source/coin_gecko.ex:169
lib/explorer/smart_contract/verifier.ex:89

@ -11,6 +11,7 @@
### Fixes
- [#3396](https://github.com/poanetwork/blockscout/pull/3396) - Handle exchange rates request throttled
- [#3382](https://github.com/poanetwork/blockscout/pull/3382) - Check ets table exists for know tokens
- [#3376](https://github.com/poanetwork/blockscout/pull/3376) - Fix contract nested inputs
- [#3375](https://github.com/poanetwork/blockscout/pull/3375) - Prevent terminating of tokens/contracts process

@ -2,7 +2,7 @@ defmodule Explorer.ExchangeRates do
@moduledoc """
Local cache for token exchange rates.
Exchange rate data is updated every 5 minutes.
Exchange rate data is updated every 10 minutes.
"""
use GenServer
@ -12,7 +12,7 @@ defmodule Explorer.ExchangeRates do
alias Explorer.Chain.Events.Publisher
alias Explorer.ExchangeRates.{Source, Token}
@interval :timer.minutes(5)
@interval :timer.minutes(10)
@table_name :exchange_rates
@impl GenServer
@ -42,7 +42,7 @@ defmodule Explorer.ExchangeRates do
def handle_info({_ref, {:error, reason}}, state) do
Logger.warn(fn -> "Failed to get exchange rates with reason '#{reason}'." end)
fetch_rates()
schedule_next_consolidation()
{:noreply, state}
end
@ -77,6 +77,10 @@ defmodule Explorer.ExchangeRates do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
defp schedule_next_consolidation do
Process.send_after(self(), :update, :timer.minutes(1))
end
@doc """
Lists exchange rates for the tracked tickers.
"""

@ -33,7 +33,11 @@ defmodule Explorer.ExchangeRates.Source do
{:ok, result}
{:ok, %Response{body: body, status_code: status_code}} when status_code in 400..499 ->
{:error, decode_json(body)["error"]}
if is_map(decode_json(body)) do
{:error, decode_json(body)["error"]}
else
{:error, body}
end
{:error, %Error{reason: reason}} ->
{:error, reason}
@ -41,8 +45,6 @@ defmodule Explorer.ExchangeRates.Source do
{:error, :nxdomain} ->
{:error, "CoinGecko is not responsive"}
end
after
{:error, ""}
end
@doc """

@ -106,7 +106,10 @@ defmodule Explorer.ExchangeRatesTest do
assert {:noreply, ^state} = ExchangeRates.handle_info({nil, {:error, "some error"}}, state)
assert_receive {_, {:ok, _}}
assert_receive :update
assert {:noreply, ^state} = ExchangeRates.handle_info(:update, state)
assert_receive {_, {:ok, [%Token{}]}}
end
end

Loading…
Cancel
Save