Merge pull request #2777 from poanetwork/pp-remove-duplicate-blocks-before-insertion

Remove duplicate blocks from changes_list before import
pull/2878/head
Victor Baranov 5 years ago committed by GitHub
commit 824cc332bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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

@ -65,6 +65,7 @@
- [#2799](https://github.com/poanetwork/blockscout/pull/2799) - fix catchup fetcher for empty node and db
- [#2783](https://github.com/poanetwork/blockscout/pull/2783) - Fix stuck value and ticker on the token page
- [#2781](https://github.com/poanetwork/blockscout/pull/2781) - optimize txlist json rpc
- [#2777](https://github.com/poanetwork/blockscout/pull/2777) - Remove duplicate blocks from changes_list before import
- [#2770](https://github.com/poanetwork/blockscout/pull/2770) - do not re-fetch token instances without uris
- [#2769](https://github.com/poanetwork/blockscout/pull/2769) - optimize token token transfers query
- [#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)
# 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(
repo,

@ -382,6 +382,20 @@ defmodule Explorer.Chain.Import.Runner.BlocksTest do
insert_transaction(transaction2, options)
assert Chain.missing_block_number_ranges(range) == [(block_number + 1)..(block_number + 1)]
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
defp insert_block(block_params, options) do

Loading…
Cancel
Save