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.
pull/2346/head
pasqu4le 5 years ago
parent e0c423e9c5
commit c38aea875c
No known key found for this signature in database
GPG Key ID: 8F3EE01F1DC90687
  1. 1
      CHANGELOG.md
  2. 7
      apps/explorer/lib/explorer/chain.ex
  3. 3
      apps/explorer/test/support/factory.ex

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

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

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

Loading…
Cancel
Save