Merge pull request #2027 from poanetwork/fix-block-transaction-mismatch-fetcher

Fix BlocksTransactionsMismatch temporary fetcher
pull/2062/head
Victor Baranov 6 years ago committed by GitHub
commit 8296446b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/explorer/priv/repo/migrations/20190513134025_add_refetch_needed_to_block.exs
  3. 11
      apps/indexer/lib/indexer/temporary/blocks_transactions_mismatch.ex

@ -45,6 +45,7 @@
- [#2017](https://github.com/poanetwork/blockscout/pull/2017) - fix: fix to/from filters on tx list pages
- [#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

@ -6,6 +6,6 @@ defmodule Explorer.Repo.Migrations.AddRefetchNeededToBlock do
add(:refetch_needed, :boolean, default: false)
end
execute("UPDATE blocks SET refetch_needed = TRUE;", "")
execute("UPDATE blocks SET refetch_needed = TRUE WHERE consensus", "")
end
end

@ -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)}
@ -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))

Loading…
Cancel
Save