diff --git a/CHANGELOG.md b/CHANGELOG.md index 938bfee6f1..0428bb019d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/explorer/lib/explorer/account/notifier/summary.ex b/apps/explorer/lib/explorer/account/notifier/summary.ex index 2c795ce252..6e7833c904 100644 --- a/apps/explorer/lib/explorer/account/notifier/summary.ex +++ b/apps/explorer/lib/explorer/account/notifier/summary.ex @@ -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} diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 7ad0d152b9..f2d2e5f023 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -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 diff --git a/apps/explorer/lib/explorer/chain/address/coin_balance.ex b/apps/explorer/lib/explorer/chain/address/coin_balance.ex index 97e0475958..bab4a62b62 100644 --- a/apps/explorer/lib/explorer/chain/address/coin_balance.ex +++ b/apps/explorer/lib/explorer/chain/address/coin_balance.ex @@ -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 diff --git a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex index 684e563c4a..532bf22373 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -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) diff --git a/apps/explorer/lib/explorer/smart_contract/vyper/code_compiler.ex b/apps/explorer/lib/explorer/smart_contract/vyper/code_compiler.ex index ae932cd52d..52e8248c61 100644 --- a/apps/explorer/lib/explorer/smart_contract/vyper/code_compiler.ex +++ b/apps/explorer/lib/explorer/smart_contract/vyper/code_compiler.ex @@ -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) diff --git a/apps/indexer/lib/indexer/fetcher/empty_blocks_sanitizer.ex b/apps/indexer/lib/indexer/fetcher/empty_blocks_sanitizer.ex index 3f15cdf92a..cbc3e9ec7e 100644 --- a/apps/indexer/lib/indexer/fetcher/empty_blocks_sanitizer.ex +++ b/apps/indexer/lib/indexer/fetcher/empty_blocks_sanitizer.ex @@ -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 ) diff --git a/apps/indexer/lib/indexer/temporary/uncles_without_index.ex b/apps/indexer/lib/indexer/temporary/uncles_without_index.ex index 814103e4f9..79abdc1814 100644 --- a/apps/indexer/lib/indexer/temporary/uncles_without_index.ex +++ b/apps/indexer/lib/indexer/temporary/uncles_without_index.ex @@ -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 )