Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: index celo transactions #9713

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open

feat: index celo transactions #9713

wants to merge 50 commits into from

Conversation

fedor-ivn
Copy link
Collaborator

@fedor-ivn fedor-ivn commented Mar 24, 2024

Motivation

This PR adds support for custom fields from Celo blockchain and implements a
custom way to index Celo transactions.

Changelog

Enhancements

Environment variables

  1. New value for CHAIN_TYPE env: celo
  2. New variable: CELO_CORE_CONTRACTS

Transactions

New fields specific to CELO network are now supported. Here is the outline how the fields coming from RPC node are mapped to fields in transactions table:

  • feeCurrencygas_token_contract_address_hash
  • gatewayFeeRecipientgas_fee_recipient_address_hash (this field is
    scheduled for deprecation as stated in CELO docs)
  • gatewayFeegateway_fee (this field is
    scheduled for deprecation as stated in CELO
    docs
    )

The token used for gas payment (feeCurrency) is indexed within block fetcher process.

Token-duality feature

Native chain asset transfers are treated as CELO ERC-20 token transfers. These token transfers are artificial, meaning that there is not real T

API updates

Native chain asset transfers are treated as CELO ERC-20

  • Indexing of native chain asset transfers as CELO ERC-20 token transfers from transactions and internal transactions
    • Implemented in block fetcher and internal transactions

Checklist for your Pull Request (PR)

@@ -614,6 +607,39 @@ defmodule Indexer.Block.FetcherTest do
assert fifth_address.fetched_coin_balance_block_number == block_number

EthereumJSONRPC.Nethermind ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, the tests in this file just ignore the EthereumJSONRPC variant.

In my case, this config sets the variant geth:

import Config
alias EthereumJSONRPC.Variant
config :indexer, Indexer.Fetcher.Beacon.Blob.Supervisor, disabled?: true
config :indexer, Indexer.Fetcher.Beacon.Blob, start_block: 0
variant = Variant.get()
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test")
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test")

So, it loads this config, setting EthereumJSONRPC.Geth variant:

import Config
config :indexer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.Geth
]

import Config
config :explorer,
json_rpc_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.Geth
],
subscribe_named_arguments: [
transport: EthereumJSONRPC.Mox,
transport_options: [],
variant: EthereumJSONRPC.Geth
]

However, these json_rpc_named_arguments settings are just ignored in the tests. Why it could be so?

Copy link
Collaborator Author

@fedor-ivn fedor-ivn Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this, I had nothing to do, but put my celo-changes to EthereumJSONRPC.Nethermind case branch

@fedor-ivn fedor-ivn force-pushed the fi-celo-transactions branch 2 times, most recently from 7c372ce to d16cca3 Compare March 26, 2024 19:25
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hard-coded values are fine at least for v1, because they are really not a subject to change.

For instance, on Celo mainnet, the last transaction to Registry contract was done 4 years ago. On alfajores, Registry contract was not even updated -- e.g it returns nil-address (0x000...) for the core contract names.

@fedor-ivn fedor-ivn force-pushed the fi-celo-transactions branch 4 times, most recently from 40f044d to a0e8cc3 Compare April 10, 2024 09:22
@fedor-ivn fedor-ivn requested a review from vbaranov April 10, 2024 18:41
Comment on lines 460 to 461
case tokens do
[token] ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to case token_transfers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, make sense. Please, check 222feba to verify if I implemented your suggestions correctly

Comment on lines 439 to 449
defp to_address_token_balances(token_transfers, celo_token) do
%{token_transfers: token_transfers}
|> Addresses.extract_addresses()
|> Enum.map(fn %{fetched_coin_balance_block_number: block_number, hash: hash} ->
with {:ok, address_hash} <- Hash.Address.cast(hash),
{:ok, token_contract_address_hash} <- Hash.Address.cast(celo_token.contract_address_hash) do
%{
address_hash: address_hash,
token_contract_address_hash: token_contract_address_hash,
block_number: block_number,
token_type: celo_token.type,
token_id: nil
}
else
error -> Logger.error("Failed to cast string to hash: #{inspect(error)}")
end
end)
|> MapSet.new()
end

defp async_import_celo_token_balances(%{token_transfers: token_transfers, tokens: tokens}) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to define functions in order in which they are called. I.e. firstly define async_import_celo_token_balances and then to_address_token_balances

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed in 222feba

@fedor-ivn fedor-ivn added ci:celo and removed ci:all labels May 17, 2024
@fedor-ivn fedor-ivn force-pushed the fi-celo-transactions branch 11 times, most recently from 3615ae2 to b6f833b Compare May 18, 2024 12:58
* master: (65 commits)
  fix: Add healthcheck endpoints for indexer-only setup (#10076)
  6.6.0
  fix: Rework revert_reason (#9212)
  fix: Eliminate from_address_hash == #{address_hash} clause for transactions query in case of smart-contracts (#9469)
  feat: Add optional retry of NFT metadata fetch in Indexer.Fetcher.Tok… (#10036)
  fix: Separate indexer setup (#10032)
  feat: Blueprint contracts support (#10058)
  chore: Update hackney pool size: add new fetchers accounting (#9941)
  fix: Disallow batched queries in GraphQL endpoint (#10050)
  feat: Clone with immutable arguments proxy pattern (#10039)
  fix: vyper contracts re-verificaiton (#10053)
  refactor: Refactor get_additional_sources/4 -> get_additional_sources/3 (#10046)
  chore: Bump credo from 1.7.5 to 1.7.6 (#10060)
  chore: Bump redix from 1.5.0 to 1.5.1 (#10059)
  chore: Bump ex_doc from 0.32.1 to 0.32.2 (#10061)
  fix: Fix Unknown UID bug at smart-contract verification (#9986)
  refactor: test database config (#9662)
  chore: remove `has_methods` from `/addresses` (#10051)
  feat: Improve retry NFT fetcher (#10027)
  chore: Add support of Blast-specific L1 OP withdrawal events (#10049)
  ...
@fedor-ivn fedor-ivn added ci:all and removed ci:celo labels May 18, 2024
Comment on lines 74 to 79
# In CELO network, there is a token duality feature where CELO can be used
# as both a native chain currency and as an ERC-20 token. Transactions
# that transfer CELO are also counted as token transfers, and the
# TokenInstance fetcher is called. However, for simplicity, we disable it
# in this test.
Application.put_env(:indexer, Indexer.Fetcher.TokenInstance.Realtime.Supervisor, disabled?: true)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this workaround?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* master:
  refactor: Remove hardcoded numResults from fetch_pending_transactions_besu (#10117)
  feat: Add window between balance fetch retries for missing balanceOf tokens (#10142)
  fix: Add missing preloads to tokens endpoints (#10072)
  Explicit message on token balance update error (#10129)
  fix: missing nil case for revert reason (#10136)
  fix: Hotfix for Indexer.Fetcher.Optimism.WithdrawalEvent and EthereumJSONRPC.Receipt (#10130)
  hide chain specific fields behind Map.get (#10131)
  --- (#10096)
  feat: indexer for cross level messages on Arbitrum (#9312)
  chore: Bump ecto_sql from 3.11.1 to 3.11.2
  Indexer/API separated images for Redstone
  Update CHANGELOG
  Improve response of address API to return multiple implementations for Diamond proxy (#10113)
  Fix GA pre-release && release workflows
  Update CHANGELOG
  feat: implement fetch_first_trace for Geth (#10087)
  Remove custom release CI for Immutable
  Update CHANGELOG for 6.6.0
  Fix certified flag in the search API v2 endpoint (#10094)
  fix: Update Vyper inner compilers list to support all compilers (#10091)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants