diff --git a/.dialyzer-ignore b/.dialyzer-ignore index bf2a526f58..0ad50fe2a7 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index efeb5176ca..6d2226bd1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex b/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex index f0ed6f0f54..fba8977fac 100644 --- a/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex +++ b/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex @@ -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. """ diff --git a/apps/explorer/lib/explorer/exchange_rates/source.ex b/apps/explorer/lib/explorer/exchange_rates/source.ex index 20422a0b33..470458a657 100644 --- a/apps/explorer/lib/explorer/exchange_rates/source.ex +++ b/apps/explorer/lib/explorer/exchange_rates/source.ex @@ -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 """ diff --git a/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs b/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs index d1bed67de1..26ae7f1e5b 100644 --- a/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs +++ b/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs @@ -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