Merge pull request #1341 from poanetwork/ab-do-not-fetch-simple-token-transfers-internal-transactions

do not index internal transactions with simple token transfers
pull/1348/head
Andrew Cravenho 6 years ago committed by GitHub
commit 3e19a8afab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      apps/explorer/lib/explorer/chain/token_transfer.ex
  2. 27
      apps/indexer/lib/indexer/block/realtime/fetcher.ex

@ -65,6 +65,8 @@ defmodule Explorer.Chain.TokenTransfer do
@constant "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
@transfer_function_signature "0xa9059cbb"
@primary_key false
schema "token_transfers" do
field(:amount, :decimal)
@ -115,6 +117,11 @@ defmodule Explorer.Chain.TokenTransfer do
"""
def constant, do: @constant
@doc """
ERC 20's transfer(address,uint256) function signature
"""
def transfer_function_signature, do: @transfer_function_signature
@spec fetch_token_transfers_from_token_hash(Hash.t(), [paging_options]) :: []
def fetch_token_transfers_from_token_hash(token_address_hash, options) do
paging_options = Keyword.get(options, :paging_options, @default_paging_options)

@ -12,9 +12,11 @@ defmodule Indexer.Block.Realtime.Fetcher do
import EthereumJSONRPC, only: [integer_to_quantity: 1, quantity_to_integer: 1]
import Indexer.Block.Fetcher, only: [async_import_tokens: 1, async_import_uncles: 1, fetch_and_import_range: 2]
alias ABI.TypeDecoder
alias Ecto.Changeset
alias EthereumJSONRPC.{FetchedBalances, Subscription}
alias Explorer.Chain
alias Explorer.Chain.TokenTransfer
alias Explorer.Counters.AverageBlockTime
alias Indexer.{AddressExtraction, Block, TokenBalances, Tracer}
alias Indexer.Block.Realtime.{ConsensusEnsurer, TaskSupervisor}
@ -387,6 +389,31 @@ defmodule Indexer.Block.Realtime.Fetcher do
end
end
# 0xa9059cbb - signature of the transfer(address,uint256) function from the ERC-20 token specification.
# Although transaction input data can be faked we use this heuristics to filter simple token transfer internal transactions from indexing because they slow down realtime fetcher
defp fetch_internal_transactions?(
%{
status: :ok,
created_contract_address_hash: nil,
input: unquote(TokenTransfer.transfer_function_signature()) <> params,
value: 0
},
_
) do
types = [:address, {:uint, 256}]
try do
[_address, _value] =
params
|> Base.decode16!(case: :mixed)
|> TypeDecoder.decode_raw(types)
false
rescue
_ -> true
end
end
# Input-less transactions are value-transfers only, so their internal transactions do not need to be indexed
defp fetch_internal_transactions?(%{status: :ok, created_contract_address_hash: nil, input: "0x"}, _), do: false
# Token transfers not transferred during contract creation don't need internal transactions as the token transfers

Loading…
Cancel
Save