Fix BlocksTransactionsMismatch temporary fetcher

This solves a problem that was found with this fetcher:
block with no transactions were not taken into account, so they were not checked and never had their `refetch_needed` field set to false.
pull/2027/head
pasqu4le 6 years ago
parent 56f505741f
commit 1bd2dcdda2
No known key found for this signature in database
GPG Key ID: 8F3EE01F1DC90687
  1. 1
      CHANGELOG.md
  2. 11
      apps/indexer/lib/indexer/temporary/blocks_transactions_mismatch.ex

@ -38,6 +38,7 @@
- [#1966](https://github.com/poanetwork/blockscout/pull/1966) - fix: add fields for contract filter performance - [#1966](https://github.com/poanetwork/blockscout/pull/1966) - fix: add fields for contract filter performance
- [#2008](https://github.com/poanetwork/blockscout/pull/2008) - add new function clause for xDai network beneficiaries - [#2008](https://github.com/poanetwork/blockscout/pull/2008) - add new function clause for xDai network beneficiaries
- [#2009](https://github.com/poanetwork/blockscout/pull/2009) - addresses page improvements - [#2009](https://github.com/poanetwork/blockscout/pull/2009) - addresses page improvements
- [#2027](https://github.com/poanetwork/blockscout/pull/2027) - fix: `BlocksTransactionsMismatch` ignoring blocks without transactions
### Chore ### Chore

@ -51,7 +51,7 @@ defmodule Indexer.Temporary.BlocksTransactionsMismatch do
def init(initial, reducer, _) do def init(initial, reducer, _) do
query = query =
from(block in Block, from(block in Block,
join: transactions in assoc(block, :transactions), left_join: transactions in assoc(block, :transactions),
where: block.consensus and block.refetch_needed, where: block.consensus and block.refetch_needed,
group_by: block.hash, group_by: block.hash,
select: {block, count(transactions.hash)} select: {block, count(transactions.hash)}
@ -81,14 +81,19 @@ defmodule Indexer.Temporary.BlocksTransactionsMismatch do
defp run_blocks(%Blocks{blocks_params: []}, blocks_data), do: {:retry, blocks_data} defp run_blocks(%Blocks{blocks_params: []}, blocks_data), do: {:retry, blocks_data}
defp run_blocks( defp run_blocks(
%Blocks{transactions_params: transactions_params}, %Blocks{transactions_params: transactions_params, blocks_params: blocks_params},
blocks_data blocks_data
) do ) do
found_blocks_map = blocks_with_transactions_map =
transactions_params transactions_params
|> Enum.group_by(&Map.fetch!(&1, :block_hash)) |> Enum.group_by(&Map.fetch!(&1, :block_hash))
|> Map.new(fn {block_hash, trans_lst} -> {block_hash, Enum.count(trans_lst)} end) |> Map.new(fn {block_hash, trans_lst} -> {block_hash, Enum.count(trans_lst)} end)
found_blocks_map =
blocks_params
|> Map.new(&{Map.fetch!(&1, :hash), 0})
|> Map.merge(blocks_with_transactions_map)
{found_blocks_data, missing_blocks_data} = {found_blocks_data, missing_blocks_data} =
Enum.split_with(blocks_data, fn {block, _trans_num} -> Enum.split_with(blocks_data, fn {block, _trans_num} ->
Map.has_key?(found_blocks_map, to_string(block.hash)) Map.has_key?(found_blocks_map, to_string(block.hash))

Loading…
Cancel
Save