From 435bba786fe2ec45db2b36be0ec04b91b5fef0f2 Mon Sep 17 00:00:00 2001 From: Fedor Ivanov Date: Fri, 27 Sep 2024 14:41:10 +0300 Subject: [PATCH] fix: filecoin stucked pending address operations (#10832) * chore: log database related errors * fix: do not buffer failed operations * fix: do not hardcode Beryx API Filecoin mainnet base url --- .../explorer/chain/filecoin/pending_address_operation.ex | 4 +++- apps/indexer/lib/indexer/fetcher/filecoin/address_info.ex | 8 +++++++- apps/indexer/lib/indexer/fetcher/filecoin/beryx_api.ex | 2 +- config/runtime.exs | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/filecoin/pending_address_operation.ex b/apps/explorer/lib/explorer/chain/filecoin/pending_address_operation.ex index 0fa166e0fb..63e61ab615 100644 --- a/apps/explorer/lib/explorer/chain/filecoin/pending_address_operation.ex +++ b/apps/explorer/lib/explorer/chain/filecoin/pending_address_operation.ex @@ -19,7 +19,8 @@ defmodule Explorer.Chain.Filecoin.PendingAddressOperation do @typedoc """ * `address_hash` - the hash of the address that is pending to be fetched. * `http_status_code` - the unsuccessful (non-200) http code returned by Beryx - API if the fetcher failed to fetch the address. + API if the fetcher failed to fetch the address, set to `nil` if the fetcher + did not attempt to fetch the address yet. """ @primary_key false typed_schema "filecoin_pending_address_operations" do @@ -63,6 +64,7 @@ defmodule Explorer.Chain.Filecoin.PendingAddressOperation do from( op in __MODULE__, select: op, + where: is_nil(op.http_status_code), order_by: [desc: op.address_hash] ) diff --git a/apps/indexer/lib/indexer/fetcher/filecoin/address_info.ex b/apps/indexer/lib/indexer/fetcher/filecoin/address_info.ex index 83e5f7cdd1..1d7a9d66ba 100644 --- a/apps/indexer/lib/indexer/fetcher/filecoin/address_info.ex +++ b/apps/indexer/lib/indexer/fetcher/filecoin/address_info.ex @@ -108,7 +108,9 @@ defmodule Indexer.Fetcher.Filecoin.AddressInfo do else _ -> Logger.error("Could not fetch Filecoin address info: #{to_string(address_hash)}") - :retry + # TODO: We should consider implementing retry logic when fetching + # becomes more stable + :ok end end @@ -169,6 +171,10 @@ defmodule Indexer.Fetcher.Filecoin.AddressInfo do end ) |> Repo.transaction() + |> tap(fn + {:ok, _} -> :ok + error -> Logger.error("Error updating address and removing pending operation: #{inspect(error)}") + end) end @spec fetch_address_info_using_beryx_api(PendingAddressOperation.t()) :: diff --git a/apps/indexer/lib/indexer/fetcher/filecoin/beryx_api.ex b/apps/indexer/lib/indexer/fetcher/filecoin/beryx_api.ex index f4e7f212c9..494880c7a7 100644 --- a/apps/indexer/lib/indexer/fetcher/filecoin/beryx_api.ex +++ b/apps/indexer/lib/indexer/fetcher/filecoin/beryx_api.ex @@ -27,7 +27,7 @@ defmodule Indexer.Fetcher.Filecoin.BeryxAPI do base_url = config |> Keyword.get(:base_url) |> String.trim_trailing("/") api_token = config[:api_token] - url = "#{base_url}/mainnet/account/info/#{eth_address_hash}" + url = "#{base_url}/account/info/#{eth_address_hash}" headers = [ {"Authorization", "Bearer #{api_token}"}, diff --git a/config/runtime.exs b/config/runtime.exs index 7875f4c476..4ef037d05c 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1065,7 +1065,7 @@ config :indexer, Indexer.Fetcher.Celo.EpochBlockOperations.Supervisor, disabled?: not celo_epoch_fetchers_enabled? config :indexer, Indexer.Fetcher.Filecoin.BeryxAPI, - base_url: ConfigHelper.safe_get_env("BERYX_API_BASE_URL", "https://api.zondax.ch/fil/data/v3"), + base_url: ConfigHelper.safe_get_env("BERYX_API_BASE_URL", "https://api.zondax.ch/fil/data/v3/mainnet"), api_token: System.get_env("BERYX_API_TOKEN") filecoin_native_address_fetcher_enabled? =