Skip to content

Commit

Permalink
Fix BlocksTransactionsMismatch temporary fetcher
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pasqu4le committed May 25, 2019
1 parent 56f5057 commit 1bd2dcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -38,6 +38,7 @@
- [#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
- [#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

Expand Down
Expand Up @@ -51,7 +51,7 @@ defmodule Indexer.Temporary.BlocksTransactionsMismatch do
def init(initial, reducer, _) do
query =
from(block in Block,
join: transactions in assoc(block, :transactions),
left_join: transactions in assoc(block, :transactions),
where: block.consensus and block.refetch_needed,
group_by: block.hash,
select: {block, count(transactions.hash)}
Expand Down Expand Up @@ -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{transactions_params: transactions_params},
%Blocks{transactions_params: transactions_params, blocks_params: blocks_params},
blocks_data
) do
found_blocks_map =
blocks_with_transactions_map =
transactions_params
|> Enum.group_by(&Map.fetch!(&1, :block_hash))
|> 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} =
Enum.split_with(blocks_data, fn {block, _trans_num} ->
Map.has_key?(found_blocks_map, to_string(block.hash))
Expand Down

0 comments on commit 1bd2dcd

Please sign in to comment.