Remove duplicate blocks from changes_list before import

pull/2777/head
pasqu4le 5 years ago
parent 1d855ee0e1
commit d39f817bb0
No known key found for this signature in database
GPG Key ID: 8F3EE01F1DC90687
  1. 1
      CHANGELOG.md
  2. 5
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  3. 14
      apps/explorer/test/explorer/chain/import/runner/blocks_test.exs

@ -18,6 +18,7 @@
- [#2470](https://github.com/poanetwork/blockscout/pull/2470) - Allow Realtime Fetcher to wait for small skips - [#2470](https://github.com/poanetwork/blockscout/pull/2470) - Allow Realtime Fetcher to wait for small skips
### Fixes ### Fixes
- [#2777](https://github.com/poanetwork/blockscout/pull/2777) - Remove duplicate blocks from changes_list before import
- [#2755](https://github.com/poanetwork/blockscout/pull/2755) - various token instance fetcher fixes - [#2755](https://github.com/poanetwork/blockscout/pull/2755) - various token instance fetcher fixes
- [#2770](https://github.com/poanetwork/blockscout/pull/2770) - do not re-fetch token instances without uris - [#2770](https://github.com/poanetwork/blockscout/pull/2770) - do not re-fetch token instances without uris
- [#2761](https://github.com/poanetwork/blockscout/pull/2761) - add indexes for token instances fetching queries - [#2761](https://github.com/poanetwork/blockscout/pull/2761) - add indexes for token instances fetching queries

@ -224,7 +224,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0) on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
# Enforce Block ShareLocks order (see docs: sharelocks.md) # Enforce Block ShareLocks order (see docs: sharelocks.md)
ordered_changes_list = Enum.sort_by(changes_list, & &1.hash) ordered_changes_list =
changes_list
|> Enum.sort_by(& &1.hash)
|> Enum.dedup_by(& &1.hash)
Import.insert_changes_list( Import.insert_changes_list(
repo, repo,

@ -382,6 +382,20 @@ defmodule Explorer.Chain.Import.Runner.BlocksTest do
insert_transaction(transaction2, options) insert_transaction(transaction2, options)
assert Chain.missing_block_number_ranges(range) == [(block_number + 1)..(block_number + 1)] assert Chain.missing_block_number_ranges(range) == [(block_number + 1)..(block_number + 1)]
end end
test "removes duplicate blocks (by hash) before inserting",
%{consensus_block: %{number: block_number, hash: block_hash, miner_hash: miner_hash}, options: options} do
new_block = params_for(:block, miner_hash: miner_hash, consensus: true)
%Ecto.Changeset{valid?: true, changes: block_changes} = Block.changeset(%Block{}, new_block)
result =
Multi.new()
|> Blocks.run([block_changes, block_changes], options)
|> Repo.transaction()
assert {:ok, %{blocks: [%{hash: block_hash, consensus: true}]}} = result
end
end end
defp insert_block(block_params, options) do defp insert_block(block_params, options) do

Loading…
Cancel
Save