Explicitly set consensus == true in queries (convenient for search)

pull/7934/head
Viktor Baranov 1 year ago
parent a019b6f9fe
commit 2981a6455e
  1. 1
      CHANGELOG.md
  2. 2
      apps/explorer/lib/explorer/account/notifier/summary.ex
  3. 8
      apps/explorer/lib/explorer/chain.ex
  4. 18
      apps/explorer/lib/explorer/chain/address/coin_balance.ex
  5. 4
      apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex
  6. 2
      apps/explorer/lib/explorer/smart_contract/vyper/code_compiler.ex
  7. 2
      apps/indexer/lib/indexer/fetcher/empty_blocks_sanitizer.ex
  8. 2
      apps/indexer/lib/indexer/temporary/uncles_without_index.ex

@ -25,6 +25,7 @@
### Chore
- [#7934](https://github.com/blockscout/blockscout/pull/7934) - Explicitly set consensus == true in queries (convenient for search)
- [#7901](https://github.com/blockscout/blockscout/pull/7901) - Fix Docker image build
- [#7890](https://github.com/blockscout/blockscout/pull/7890), [#7918](https://github.com/blockscout/blockscout/pull/7918) - Resolve warning: Application.get_env/2 is discouraged in the module body, use Application.compile_env/3 instead
- [#7863](https://github.com/blockscout/blockscout/pull/7863) - Add max_age for account sessions

@ -3,8 +3,6 @@ defmodule Explorer.Account.Notifier.Summary do
Compose a summary from transactions
"""
require Logger
alias Explorer
alias Explorer.Account.Notifier.Summary
alias Explorer.{Chain, Repo}

@ -764,7 +764,7 @@ defmodule Explorer.Chain do
def block_reward(block_number) do
block_hash =
Block
|> where([block], block.number == ^block_number and block.consensus)
|> where([block], block.number == ^block_number and block.consensus == true)
|> select([block], block.hash)
|> Repo.one!()
@ -784,7 +784,7 @@ defmodule Explorer.Chain do
left_join: transaction in assoc(block, :transactions),
inner_join: emission_reward in EmissionReward,
on: fragment("? <@ ?", block.number, emission_reward.block_range),
where: block.number == ^block_number and block.consensus,
where: block.number == ^block_number and block.consensus == true,
group_by: [emission_reward.reward, block.hash],
select: %Wei{
value: coalesce(sum(transaction.gas_used * transaction.gas_price), 0) + emission_reward.reward
@ -6373,8 +6373,8 @@ defmodule Explorer.Chain do
defp find_block_timestamp(number, options) do
Block
|> where([b], b.number == ^number)
|> select([b], b.timestamp)
|> where([block], block.number == ^number)
|> select([block], block.timestamp)
|> limit(1)
|> select_repo(options).one()
end

@ -104,19 +104,19 @@ defmodule Explorer.Chain.Address.CoinBalance do
Application.get_env(:block_scout_web, BlockScoutWeb.Chain.Address.CoinBalance)[:coin_balance_history_days]
CoinBalance
|> join(:inner, [cb], b in Block, on: cb.block_number == b.number)
|> join(:inner, [cb], block in Block, on: cb.block_number == block.number)
|> where([cb], cb.address_hash == ^address_hash)
|> limit_time_interval(days_to_consider, block_timestamp)
|> group_by([cb, b], fragment("date_trunc('day', ?)", b.timestamp))
|> order_by([cb, b], fragment("date_trunc('day', ?)", b.timestamp))
|> select([cb, b], %{date: type(fragment("date_trunc('day', ?)", b.timestamp), :date), value: max(cb.value)})
|> group_by([cb, block], fragment("date_trunc('day', ?)", block.timestamp))
|> order_by([cb, block], fragment("date_trunc('day', ?)", block.timestamp))
|> select([cb, block], %{date: type(fragment("date_trunc('day', ?)", block.timestamp), :date), value: max(cb.value)})
end
def limit_time_interval(query, days_to_consider, nil) do
query
|> where(
[cb, b],
b.timestamp >=
[cb, block],
block.timestamp >=
fragment("date_trunc('day', now() - CAST(? AS INTERVAL))", ^%Postgrex.Interval{days: days_to_consider})
)
end
@ -124,8 +124,8 @@ defmodule Explorer.Chain.Address.CoinBalance do
def limit_time_interval(query, days_to_consider, %{timestamp: timestamp}) do
query
|> where(
[cb, b],
b.timestamp >=
[cb, block],
block.timestamp >=
fragment(
"(? AT TIME ZONE ?) - CAST(? AS INTERVAL)",
^timestamp,
@ -146,7 +146,7 @@ defmodule Explorer.Chain.Address.CoinBalance do
cb in subquery(coin_balance_query),
inner_join: block in Block,
on: cb.block_number == block.number,
where: block.consensus,
where: block.consensus == true,
select: %{timestamp: block.timestamp, value: cb.value}
)
end

@ -282,7 +282,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
query =
from(
block in Block,
where: block.number in ^block_numbers and block.consensus,
where: block.number in ^block_numbers and block.consensus == true,
select: block.hash,
# Enforce Block ShareLocks order (see docs: sharelocks.md)
order_by: [asc: block.hash],
@ -672,7 +672,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
update_query =
from(
block in Block,
where: block.number in ^invalid_block_numbers and block.consensus,
where: block.number in ^invalid_block_numbers and block.consensus == true,
where: block.number > ^minimal_block,
select: block.hash,
# ShareLocks order already enforced by `acquire_blocks` (see docs: sharelocks.md)

@ -5,8 +5,6 @@ defmodule Explorer.SmartContract.Vyper.CodeCompiler do
alias Explorer.SmartContract.VyperDownloader
require Logger
@spec run(Keyword.t()) :: {:ok, map} | {:error, :compilation | :name}
def run(params) do
compiler_version = Keyword.fetch!(params, :compiler_version)

@ -97,7 +97,7 @@ defmodule Indexer.Fetcher.EmptyBlocksSanitizer do
if transactions_count > 0 do
Logger.info(
"Block with number #{block_number} and hash #{to_string(block_hash)} is full of transactions. We should set consensus=false for it in order to refetch.",
"Block with number #{block_number} and hash #{to_string(block_hash)} is full of transactions. We should set consensus = false for it in order to refetch.",
fetcher: :empty_blocks_to_refetch
)

@ -52,7 +52,7 @@ defmodule Indexer.Temporary.UnclesWithoutIndex do
query =
from(bsdr in SecondDegreeRelation,
join: block in assoc(bsdr, :nephew),
where: is_nil(bsdr.index) and is_nil(bsdr.uncle_fetched_at) and block.consensus,
where: is_nil(bsdr.index) and is_nil(bsdr.uncle_fetched_at) and block.consensus == true,
select: bsdr.nephew_hash,
group_by: bsdr.nephew_hash
)

Loading…
Cancel
Save