Reduce block_rewards in the catchup fetcher

Fixes #1584

If one address is rewarded for two different uncles in one block,
cardinality violation occured due to rewards not being reduced.
The reducing function from Block.Rewards.Fetcher is now reused in
Block.Fetcher.
pull/1595/head
Paul Tsupikoff 6 years ago
parent 4ceb8a8ed2
commit 5ed8a9590d
No known key found for this signature in database
GPG Key ID: DF5159A3A5F09D21
  1. 7
      apps/indexer/lib/indexer/block/fetcher.ex
  2. 2
      apps/indexer/lib/indexer/block/reward/fetcher.ex

@ -14,7 +14,7 @@ defmodule Indexer.Block.Fetcher do
alias Indexer.{AddressExtraction, CoinBalance, MintTransfer, ReplacedTransaction, Token, TokenTransfers, Tracer}
alias Indexer.Address.{CoinBalances, TokenBalances}
alias Indexer.Block.Fetcher.Receipts
alias Indexer.Block.Transform
alias Indexer.Block.{Reward, Transform}
@type address_hash_to_fetched_balance_block_number :: %{String.t() => Block.block_number()}
@ -127,7 +127,10 @@ defmodule Indexer.Block.Fetcher do
transactions_params: transactions_with_receipts
}
|> CoinBalances.params_set(),
beneficiaries_with_gas_payment <- add_gas_payments(beneficiary_params_set, transactions_with_receipts),
beneficiaries_with_gas_payment <-
beneficiary_params_set
|> add_gas_payments(transactions_with_receipts)
|> Reward.Fetcher.reduce_uncle_rewards(),
address_token_balances = TokenBalances.params_set(%{token_transfers_params: token_transfers}),
{:ok, inserted} <-
__MODULE__.import(

@ -204,7 +204,7 @@ defmodule Indexer.Block.Reward.Fetcher do
end)
end
defp reduce_uncle_rewards(beneficiaries_params) do
def reduce_uncle_rewards(beneficiaries_params) do
beneficiaries_params
|> Enum.reduce([], fn %{address_type: address_type} = beneficiary, acc ->
current =

Loading…
Cancel
Save