From c38aea875c42b4c8e9661084beef1c8d89ddb0a7 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Thu, 11 Jul 2019 13:21:33 +0200 Subject: [PATCH] Avoid fetching internal transactions of blocks that still need refetching Problem: blocks that need refetching may have the wrong transactions, so if internal transactions for this block are fetched they can (in some cases) fail to be inserted because their transaction does not exist. As a consequence this causes their insertion to fail multiple time before the block gets refetched. Solution: exclude blocks that need refetching from internal transactions indexing. --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain.ex | 7 ++++++- apps/explorer/test/support/factory.ex | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e54bedb98..1bc72d7d50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#2294](https://github.com/poanetwork/blockscout/pull/2294) - add healthy block period checking endpoint ### Fixes +- [#2346](https://github.com/poanetwork/blockscout/pull/2346) - Avoid fetching internal transactions of blocks that still need refetching - [#2345](https://github.com/poanetwork/blockscout/pull/2345) - do not override existing market records - [#2337](https://github.com/poanetwork/blockscout/pull/2337) - set url params for prod explicitly - [#2341](https://github.com/poanetwork/blockscout/pull/2341) - fix transaction input json encoding diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 1287fbe16c..05d6407dfb 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1444,6 +1444,7 @@ defmodule Explorer.Chain do iex> non_consensus = insert(:block, consensus: false) iex> unfetched = insert(:block) iex> fetched = insert(:block, internal_transactions_indexed_at: DateTime.utc_now()) + iex> to_be_refetched = insert(:block, refetch_needed: true) iex> {:ok, number_set} = Explorer.Chain.stream_blocks_with_unfetched_internal_transactions( ...> [:number], ...> MapSet.new(), @@ -1457,6 +1458,8 @@ defmodule Explorer.Chain do true iex> fetched.hash in number_set false + iex> to_be_refetched.number in number_set + false """ @spec stream_blocks_with_unfetched_internal_transactions( @@ -1485,7 +1488,9 @@ defmodule Explorer.Chain do query = from( b in Block, - where: b.consensus and is_nil(b.internal_transactions_indexed_at), + where: b.consensus, + where: is_nil(b.internal_transactions_indexed_at), + where: not b.refetch_needed, select: ^fields ) diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 2189b8f601..a6e07683a5 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -147,7 +147,8 @@ defmodule Explorer.Factory do size: Enum.random(1..100_000), gas_limit: Enum.random(1..100_000), gas_used: Enum.random(1..100_000), - timestamp: DateTime.utc_now() + timestamp: DateTime.utc_now(), + refetch_needed: false } end