From 1dda3e50c78e72a3056b3cfcf79f8592651b9b6a Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 30 Oct 2019 15:59:29 +0300 Subject: [PATCH 1/6] Estimated address count on the main page --- CHANGELOG.md | 1 + .../assets/js/pages/token_counters.js | 2 +- .../controllers/address_controller.ex | 2 +- .../controllers/chain_controller.ex | 3 +- .../lib/block_scout_web/notifier.ex | 2 +- .../channels/address_channel_test.exs | 11 -- .../controllers/address_controller_test.exs | 8 -- .../api/rpc/address_controller_test.exs | 3 +- .../api/rpc/eth_controller_test.exs | 3 +- .../controllers/chain_controller_test.exs | 4 - .../features/viewing_addresses_test.exs | 4 - .../features/viewing_app_test.exs | 4 - .../features/viewing_chain_test.exs | 25 ---- apps/explorer/config/config.exs | 5 - apps/explorer/config/test.exs | 2 - apps/explorer/lib/explorer/application.ex | 3 +- apps/explorer/lib/explorer/chain.ex | 29 ++-- .../lib/explorer/chain/cache/address_count.ex | 66 +++++++++ .../explorer/counters/addresses_counter.ex | 125 ------------------ .../chain/cache/address_count_test.ex | 54 ++++++++ apps/explorer/test/explorer/chain_test.exs | 17 --- .../counters/addresses_counter_test.exs | 16 --- 22 files changed, 150 insertions(+), 239 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/cache/address_count.ex delete mode 100644 apps/explorer/lib/explorer/counters/addresses_counter.ex create mode 100644 apps/explorer/test/explorer/chain/cache/address_count_test.ex delete mode 100644 apps/explorer/test/explorer/counters/addresses_counter_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b2dcb1de..8722791098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - [#2791](https://github.com/poanetwork/blockscout/pull/2791) - add ipc client - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify +- [#2822](https://github.com/poanetwork/blockscout/pull/2822) - Estimated address count on the main page, if cache is empty ### Fixes - [#2800](https://github.com/poanetwork/blockscout/pull/2800) - return not found for not verified contract for token read_contract diff --git a/apps/block_scout_web/assets/js/pages/token_counters.js b/apps/block_scout_web/assets/js/pages/token_counters.js index dfbdca4f94..42f8b38792 100644 --- a/apps/block_scout_web/assets/js/pages/token_counters.js +++ b/apps/block_scout_web/assets/js/pages/token_counters.js @@ -66,7 +66,7 @@ const elements = { function loadCounters (store) { const $element = $('[data-async-counters]') - const path = $element.data().asyncCounters + const path = $element.data() && $element.data().asyncCounters function fetchCounters () { store.dispatch({type: 'START_REQUEST'}) $.getJSON(path) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex index d91552229a..1a86669ad9 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex @@ -60,7 +60,7 @@ defmodule BlockScoutWeb.AddressController do def index(conn, _params) do render(conn, "index.html", current_path: current_path(conn), - address_count: Chain.count_addresses_from_cache() + address_count: Chain.address_estimated_count() ) end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex index 936d3ab0a0..d358ca8158 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex @@ -13,6 +13,7 @@ defmodule BlockScoutWeb.ChainController do def show(conn, _params) do transaction_estimated_count = Chain.transaction_estimated_count() block_count = Chain.block_estimated_count() + address_count = Chain.address_estimated_count() market_cap_calculation = case Application.get_env(:explorer, :supply) do @@ -28,7 +29,7 @@ defmodule BlockScoutWeb.ChainController do render( conn, "show.html", - address_count: Chain.count_addresses_from_cache(), + address_count: address_count, average_block_time: AverageBlockTime.average_block_time(), exchange_rate: exchange_rate, chart_data_path: market_history_chart_path(conn, :show), diff --git a/apps/block_scout_web/lib/block_scout_web/notifier.ex b/apps/block_scout_web/lib/block_scout_web/notifier.ex index 5955ca02d4..4bf9185d23 100644 --- a/apps/block_scout_web/lib/block_scout_web/notifier.ex +++ b/apps/block_scout_web/lib/block_scout_web/notifier.ex @@ -14,7 +14,7 @@ defmodule BlockScoutWeb.Notifier do alias Phoenix.View def handle_event({:chain_event, :addresses, type, addresses}) when type in [:realtime, :on_demand] do - Endpoint.broadcast("addresses:new_address", "count", %{count: Chain.count_addresses_from_cache()}) + Endpoint.broadcast("addresses:new_address", "count", %{count: Chain.address_estimated_count()}) addresses |> Stream.reject(fn %Address{fetched_coin_balance: fetched_coin_balance} -> is_nil(fetched_coin_balance) end) diff --git a/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs b/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs index 357a73eba8..d5bb63255c 100644 --- a/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs +++ b/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs @@ -1,11 +1,9 @@ defmodule BlockScoutWeb.AddressChannelTest do use BlockScoutWeb.ChannelCase, - # ETS tables are shared in `Explorer.Counters.AddressesCounter` async: false alias BlockScoutWeb.UserSocket alias BlockScoutWeb.Notifier - alias Explorer.Counters.AddressesCounter test "subscribed user is notified of new_address count event" do topic = "addresses:new_address" @@ -13,9 +11,6 @@ defmodule BlockScoutWeb.AddressChannelTest do address = insert(:address) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - Notifier.handle_event({:chain_event, :addresses, :realtime, [address]}) assert_receive %Phoenix.Socket.Broadcast{topic: ^topic, event: "count", payload: %{count: _}}, :timer.seconds(5) @@ -55,9 +50,6 @@ defmodule BlockScoutWeb.AddressChannelTest do test "notified of balance_update for matching address", %{address: address, topic: topic} do address_with_balance = %{address | fetched_coin_balance: 1} - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - Notifier.handle_event({:chain_event, :addresses, :realtime, [address_with_balance]}) assert_receive %Phoenix.Socket.Broadcast{topic: ^topic, event: "balance_update", payload: payload}, @@ -67,9 +59,6 @@ defmodule BlockScoutWeb.AddressChannelTest do end test "not notified of balance_update if fetched_coin_balance is nil", %{address: address} do - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - Notifier.handle_event({:chain_event, :addresses, :realtime, [address]}) refute_receive _, 100, "Message was broadcast for nil fetched_coin_balance." diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs index baae81bc1f..157435f940 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs @@ -3,8 +3,6 @@ defmodule BlockScoutWeb.AddressControllerTest do # ETS tables are shared in `Explorer.Counters.*` async: false - alias Explorer.Counters.AddressesCounter - describe "GET index/2" do test "returns top addresses", %{conn: conn} do address_hashes = @@ -12,9 +10,6 @@ defmodule BlockScoutWeb.AddressControllerTest do |> Enum.map(&insert(:address, fetched_coin_balance: &1)) |> Enum.map(& &1.hash) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - conn = get(conn, address_path(conn, :index, %{type: "JSON"})) {:ok, %{"items" => items}} = Poison.decode(conn.resp_body) @@ -25,9 +20,6 @@ defmodule BlockScoutWeb.AddressControllerTest do address = insert(:address, fetched_coin_balance: 1) insert(:address_name, address: address, primary: true, name: "POA Wallet") - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - conn = get(conn, address_path(conn, :index, %{type: "JSON"})) {:ok, %{"items" => [item]}} = Poison.decode(conn.resp_body) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs index 135fbe9948..85baf575fc 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs @@ -6,7 +6,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do alias BlockScoutWeb.API.RPC.AddressController alias Explorer.Chain alias Explorer.Chain.{Events.Subscriber, Transaction, Wei} - alias Explorer.Counters.{AddressesCounter, AverageBlockTime} + alias Explorer.Counters.AverageBlockTime alias Indexer.Fetcher.CoinBalanceOnDemand alias Explorer.Repo @@ -22,7 +22,6 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do start_supervised!({Task.Supervisor, name: Indexer.TaskSupervisor}) start_supervised!(AverageBlockTime) start_supervised!({CoinBalanceOnDemand, [mocked_json_rpc_named_arguments, [name: CoinBalanceOnDemand]]}) - start_supervised!(AddressesCounter) Application.put_env(:explorer, AverageBlockTime, enabled: true) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs index 5ab050aefc..5facef3a46 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.API.RPC.EthControllerTest do use BlockScoutWeb.ConnCase, async: false - alias Explorer.Counters.{AddressesCounter, AverageBlockTime} + alias Explorer.Counters.AverageBlockTime alias Explorer.Repo alias Indexer.Fetcher.CoinBalanceOnDemand @@ -14,7 +14,6 @@ defmodule BlockScoutWeb.API.RPC.EthControllerTest do start_supervised!({Task.Supervisor, name: Indexer.TaskSupervisor}) start_supervised!(AverageBlockTime) start_supervised!({CoinBalanceOnDemand, [mocked_json_rpc_named_arguments, [name: CoinBalanceOnDemand]]}) - start_supervised!(AddressesCounter) Application.put_env(:explorer, AverageBlockTime, enabled: true) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs index 93777e16e3..3e96ed709b 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs @@ -1,20 +1,16 @@ defmodule BlockScoutWeb.ChainControllerTest do use BlockScoutWeb.ConnCase, - # ETS table is shared in `Explorer.Counters.AddressesCounter` async: false import BlockScoutWeb.WebRouter.Helpers, only: [chain_path: 2, block_path: 3, transaction_path: 3, address_path: 3] alias Explorer.Chain.Block - alias Explorer.Counters.AddressesCounter setup do Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Blocks.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Blocks.child_id()) Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Uncles.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Uncles.child_id()) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() :ok end diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs index bb223077a2..d50faf1a60 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs @@ -3,7 +3,6 @@ defmodule BlockScoutWeb.ViewingAddressesTest do # Because ETS tables is shared for `Explorer.Counters.*` async: false - alias Explorer.Counters.AddressesCounter alias BlockScoutWeb.{AddressPage, AddressView, Notifier} setup do @@ -58,9 +57,6 @@ defmodule BlockScoutWeb.ViewingAddressesTest do [first_address | _] = addresses [last_address | _] = Enum.reverse(addresses) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> AddressPage.visit_page() |> assert_has(AddressPage.address(first_address)) diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs index ff37eed468..b38ad10062 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs @@ -5,14 +5,10 @@ defmodule BlockScoutWeb.ViewingAppTest do alias BlockScoutWeb.AppPage alias BlockScoutWeb.Counters.BlocksIndexedCounter - alias Explorer.Counters.AddressesCounter alias Explorer.{Repo} alias Explorer.Chain.{Transaction} setup do - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - :ok end diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs index 367e8b8b7c..2fffe2762e 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs @@ -7,7 +7,6 @@ defmodule BlockScoutWeb.ViewingChainTest do alias BlockScoutWeb.{AddressPage, BlockPage, ChainPage, TransactionPage} alias Explorer.Chain.Block - alias Explorer.Counters.AddressesCounter setup do Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Blocks.child_id()) @@ -35,9 +34,6 @@ defmodule BlockScoutWeb.ViewingChainTest do test "search for address", %{session: session} do address = insert(:address) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> ChainPage.search(to_string(address.hash)) @@ -49,9 +45,6 @@ defmodule BlockScoutWeb.ViewingChainTest do test "search for blocks from chain page", %{session: session} do block = insert(:block, number: 6) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> ChainPage.search(to_string(block.number)) @@ -59,9 +52,6 @@ defmodule BlockScoutWeb.ViewingChainTest do end test "blocks list", %{session: session} do - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> assert_has(ChainPage.blocks(count: 4)) @@ -70,9 +60,6 @@ defmodule BlockScoutWeb.ViewingChainTest do test "inserts place holder blocks on render for out of order blocks", %{session: session} do insert(:block, number: 409) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> assert_has(ChainPage.block(%Block{number: 408})) @@ -84,9 +71,6 @@ defmodule BlockScoutWeb.ViewingChainTest do test "search for transactions", %{session: session} do transaction = insert(:transaction) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> ChainPage.search(to_string(transaction.hash)) @@ -94,9 +78,6 @@ defmodule BlockScoutWeb.ViewingChainTest do end test "transactions list", %{session: session} do - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> assert_has(ChainPage.transactions(count: 5)) @@ -111,9 +92,6 @@ defmodule BlockScoutWeb.ViewingChainTest do |> with_contract_creation(contract_address) |> with_block(block) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> assert_has(ChainPage.contract_creation(transaction)) @@ -138,9 +116,6 @@ defmodule BlockScoutWeb.ViewingChainTest do token_contract_address: contract_token_address ) - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - session |> ChainPage.visit_page() |> assert_has(ChainPage.token_transfers(transaction, count: 1)) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 60b0afdb48..d36a09450e 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -65,11 +65,6 @@ config :explorer, Explorer.Counters.AddressesWithBalanceCounter, enable_consolidation: true, update_interval_in_seconds: balances_update_interval || 30 * 60 -config :explorer, Explorer.Counters.AddressesCounter, - enabled: true, - enable_consolidation: true, - update_interval_in_seconds: balances_update_interval || 30 * 60 - config :explorer, Explorer.ExchangeRates, enabled: true, store: :ets config :explorer, Explorer.KnownTokens, enabled: true, store: :ets diff --git a/apps/explorer/config/test.exs b/apps/explorer/config/test.exs index 58050cba2c..1133c92fdb 100644 --- a/apps/explorer/config/test.exs +++ b/apps/explorer/config/test.exs @@ -21,8 +21,6 @@ config :explorer, Explorer.Counters.AverageBlockTime, enabled: false config :explorer, Explorer.Counters.AddressesWithBalanceCounter, enabled: false, enable_consolidation: false -config :explorer, Explorer.Counters.AddressesCounter, enabled: false, enable_consolidation: false - config :explorer, Explorer.Market.History.Cataloger, enabled: false config :explorer, Explorer.Tracer, disabled?: false diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 4f3e5585f9..709ce7c5a5 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -9,6 +9,7 @@ defmodule Explorer.Application do alias Explorer.Chain.Cache.{ Accounts, + AddressCount, BlockCount, BlockNumber, Blocks, @@ -47,6 +48,7 @@ defmodule Explorer.Application do {Admin.Recovery, [[], [name: Admin.Recovery]]}, TransactionCount, BlockCount, + AddressCount, Blocks, NetVersion, BlockNumber, @@ -73,7 +75,6 @@ defmodule Explorer.Application do configure(Explorer.Market.History.Cataloger), configure(Explorer.Chain.Events.Listener), configure(Explorer.Counters.AddressesWithBalanceCounter), - configure(Explorer.Counters.AddressesCounter), configure(Explorer.Counters.AverageBlockTime), configure(Explorer.Validator.MetadataProcessor), configure(Explorer.Staking.EpochCounter) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 5b3cfc2928..dd500b7eb0 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -51,6 +51,7 @@ defmodule Explorer.Chain do alias Explorer.Chain.Cache.{ Accounts, + AddressCount, BlockCount, BlockNumber, Blocks, @@ -61,7 +62,7 @@ defmodule Explorer.Chain do } alias Explorer.Chain.Import.Runner - alias Explorer.Counters.{AddressesCounter, AddressesWithBalanceCounter} + alias Explorer.Counters.AddressesWithBalanceCounter alias Explorer.Market.MarketHistoryCache alias Explorer.{PagingOptions, Repo} @@ -121,14 +122,6 @@ defmodule Explorer.Chain do AddressesWithBalanceCounter.fetch() end - @doc """ - Gets from the cache the count of all `t:Explorer.Chain.Address.t/0`'s - """ - @spec count_addresses_from_cache :: non_neg_integer() - def count_addresses_from_cache do - AddressesCounter.fetch() - end - @doc """ Counts the number of addresses with fetched coin balance > 0. @@ -2394,6 +2387,24 @@ defmodule Explorer.Chain do end end + @doc """ + Estimated count of `t:Explorer.Chain.Address.t/0`. + + Estimated count of addresses. + """ + @spec address_estimated_count() :: non_neg_integer() + def address_estimated_count do + cached_value = AddressCount.get_count() + + if is_nil(cached_value) do + %Postgrex.Result{rows: [[count]]} = Repo.query!("SELECT reltuples FROM pg_class WHERE relname = 'addresses';") + + count + else + cached_value + end + end + @doc """ `t:Explorer.Chain.InternalTransaction/0`s in `t:Explorer.Chain.Transaction.t/0` with `hash`. diff --git a/apps/explorer/lib/explorer/chain/cache/address_count.ex b/apps/explorer/lib/explorer/chain/cache/address_count.ex new file mode 100644 index 0000000000..0b603cdbc5 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/cache/address_count.ex @@ -0,0 +1,66 @@ +defmodule Explorer.Chain.Cache.AddressCount do + @moduledoc """ + Cache for address count. + """ + + require Logger + + @default_cache_period :timer.hours(2) + + use Explorer.Chain.MapCache, + name: :address_count, + key: :count, + key: :async_task, + global_ttl: cache_period(), + ttl_check_interval: :timer.minutes(1), + callback: &async_task_on_deletion(&1) + + alias Explorer.Chain.Address + alias Explorer.Repo + + defp handle_fallback(:count) do + # This will get the task PID if one exists and launch a new task if not + # See next `handle_fallback` definition + get_async_task() + + {:return, nil} + end + + defp handle_fallback(:async_task) do + # If this gets called it means an async task was requested, but none exists + # so a new one needs to be launched + {:ok, task} = + Task.start(fn -> + try do + result = Repo.aggregate(Address, :count, :hash, timeout: :infinity) + + set_count(result) + rescue + e -> + Logger.debug([ + "Coudn't update address count test #{inspect(e)}" + ]) + end + + set_async_task(nil) + end) + + {:update, task} + end + + # By setting this as a `callback` an async task will be started each time the + # `count` expires (unless there is one already running) + defp async_task_on_deletion({:delete, _, :count}), do: get_async_task() + + defp async_task_on_deletion(_data), do: nil + + defp cache_period do + "ADDRESS_COUNT_CACHE_PERIOD" + |> System.get_env("") + |> Integer.parse() + |> case do + {integer, ""} -> :timer.seconds(integer) + _ -> @default_cache_period + end + end +end diff --git a/apps/explorer/lib/explorer/counters/addresses_counter.ex b/apps/explorer/lib/explorer/counters/addresses_counter.ex deleted file mode 100644 index 5febd8fbb9..0000000000 --- a/apps/explorer/lib/explorer/counters/addresses_counter.ex +++ /dev/null @@ -1,125 +0,0 @@ -defmodule Explorer.Counters.AddressesCounter do - @moduledoc """ - Caches the number of all addresses. - - It loads the count asynchronously and in a time interval of 30 minutes. - """ - - use GenServer - - alias Explorer.Chain - - @table :addresses_counter - - @cache_key "addresses" - - def table_name do - @table - end - - def cache_key do - @cache_key - end - - # It is undesirable to automatically start the consolidation in all environments. - # Consider the test environment: if the consolidation initiates but does not - # finish before a test ends, that test will fail. This way, hundreds of - # tests were failing before disabling the consolidation and the scheduler in - # the test env. - config = Application.get_env(:explorer, Explorer.Counters.AddressesCounter) - @enable_consolidation Keyword.get(config, :enable_consolidation) - - @update_interval_in_seconds Keyword.get(config, :update_interval_in_seconds) - - @doc """ - Starts a process to periodically update the counter of the token holders. - """ - @spec start_link(term()) :: GenServer.on_start() - def start_link(_) do - GenServer.start_link(__MODULE__, :ok, name: __MODULE__) - end - - @impl true - def init(_args) do - create_table() - - {:ok, %{consolidate?: enable_consolidation?()}, {:continue, :ok}} - end - - def create_table do - opts = [ - :set, - :named_table, - :public, - read_concurrency: true - ] - - :ets.new(table_name(), opts) - end - - defp schedule_next_consolidation do - Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) - end - - @doc """ - Inserts new items into the `:ets` table. - """ - def insert_counter({key, info}) do - :ets.insert(table_name(), {key, info}) - end - - @impl true - def handle_continue(:ok, %{consolidate?: true} = state) do - consolidate() - schedule_next_consolidation() - - {:noreply, state} - end - - @impl true - def handle_continue(:ok, state) do - {:noreply, state} - end - - @impl true - def handle_info(:consolidate, state) do - consolidate() - - schedule_next_consolidation() - - {:noreply, state} - end - - @doc """ - Fetches the info for a specific item from the `:ets` table. - """ - def fetch do - do_fetch(:ets.lookup(table_name(), cache_key())) - end - - defp do_fetch([{_, result}]), do: result - defp do_fetch([]), do: 0 - - @doc """ - Consolidates the info by populating the `:ets` table with the current database information. - """ - def consolidate do - counter = Chain.count_addresses() - - insert_counter({cache_key(), counter}) - end - - @doc """ - Returns a boolean that indicates whether consolidation is enabled - - In order to choose whether or not to enable the scheduler and the initial - consolidation, change the following Explorer config: - - `config :explorer, Explorer.Counters.AddressesCounter, enable_consolidation: true` - - to: - - `config :explorer, Explorer.Counters.AddressesCounter, enable_consolidation: false` - """ - def enable_consolidation?, do: @enable_consolidation -end diff --git a/apps/explorer/test/explorer/chain/cache/address_count_test.ex b/apps/explorer/test/explorer/chain/cache/address_count_test.ex new file mode 100644 index 0000000000..9bb10543fe --- /dev/null +++ b/apps/explorer/test/explorer/chain/cache/address_count_test.ex @@ -0,0 +1,54 @@ +defmodule Explorer.Chain.Cache.AddressCountTest do + use Explorer.DataCase + + alias Explorer.Chain.Cache.AddressCount + + setup do + Supervisor.terminate_child(Explorer.Supervisor, AddressCount.child_id()) + Supervisor.restart_child(Explorer.Supervisor, AddressCount.child_id()) + :ok + end + + test "returns default address count" do + result = AddressCount.get_count() + + assert is_nil(result) + end + + test "updates cache if initial value is zero" do + insert(:address) + insert(:address) + + _result = AddressCount.get_count() + + Process.sleep(1000) + + updated_value = AddressCount.get_count() + + assert updated_value == 2 + end + + test "does not update cache if cache period did not pass" do + insert(:address) + insert(:address) + + _result = AddressCount.get_count() + + Process.sleep(1000) + + updated_value = AddressCount.get_count() + + assert updated_value == 2 + + insert(:address) + insert(:address) + + _updated_value = AddressCount.get_count() + + Process.sleep(1000) + + updated_value = AddressCount.get_count() + + assert updated_value == 2 + end +end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 94d4c70062..abdcc8a963 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -27,7 +27,6 @@ defmodule Explorer.ChainTest do alias Explorer.Chain.Supply.ProofOfAuthority alias Explorer.Counters.AddressesWithBalanceCounter - alias Explorer.Counters.AddressesCounter doctest Explorer.Chain @@ -51,22 +50,6 @@ defmodule Explorer.ChainTest do end end - describe "count_addresses_from_cache/0" do - test "returns the number of all addresses" do - insert(:address, fetched_coin_balance: 0) - insert(:address, fetched_coin_balance: 1) - insert(:address, fetched_coin_balance: 2) - - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - - addresses_with_balance = Chain.count_addresses_from_cache() - - assert is_integer(addresses_with_balance) - assert addresses_with_balance == 3 - end - end - describe "last_db_block_status/0" do test "return no_blocks errors if db is empty" do assert {:error, :no_blocks} = Chain.last_db_block_status() diff --git a/apps/explorer/test/explorer/counters/addresses_counter_test.exs b/apps/explorer/test/explorer/counters/addresses_counter_test.exs deleted file mode 100644 index b187fd8c0e..0000000000 --- a/apps/explorer/test/explorer/counters/addresses_counter_test.exs +++ /dev/null @@ -1,16 +0,0 @@ -defmodule Explorer.Counters.AddressesCounterTest do - use Explorer.DataCase - - alias Explorer.Counters.AddressesCounter - - test "populates the cache with the number of all addresses" do - insert(:address, fetched_coin_balance: 0) - insert(:address, fetched_coin_balance: 1) - insert(:address, fetched_coin_balance: 2) - - start_supervised!(AddressesCounter) - AddressesCounter.consolidate() - - assert AddressesCounter.fetch() == 3 - end -end From 905a24c1a61bcede0ed68d3a7458574023c46227 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 1 Nov 2019 14:09:58 +0300 Subject: [PATCH 2/6] Clear assets script fix --- CHANGELOG.md | 1 + apps/explorer/package-lock.json | 477 +++++++++++--------------------- apps/explorer/package.json | 2 +- rel/commands/clear_build.sh | 3 +- 4 files changed, 159 insertions(+), 324 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3da3c2a4b2..d9b8903c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify ### Fixes +- [#2828](https://github.com/poanetwork/blockscout/pull/2828) - Fix for script that clears compilation/launching assets - [#2800](https://github.com/poanetwork/blockscout/pull/2800) - return not found for not verified contract for token read_contract - [#2806](https://github.com/poanetwork/blockscout/pull/2806) - Fix blocks fetching on the main page - [#2803](https://github.com/poanetwork/blockscout/pull/2803) - Fix block validator custom tooltip diff --git a/apps/explorer/package-lock.json b/apps/explorer/package-lock.json index 60c9460594..29cf4e81a8 100644 --- a/apps/explorer/package-lock.json +++ b/apps/explorer/package-lock.json @@ -4,9 +4,17 @@ "lockfileVersion": 1, "dependencies": { "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } }, "balanced-match": { "version": "1.0.0", @@ -30,10 +38,33 @@ "concat-map": "0.0.1" } }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" + }, + "cliui": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "requires": { + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "command-exists": { "version": "1.2.8", @@ -45,40 +76,29 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, - "cross-spawn": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", - "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", - "requires": { - "lru-cache": "^4.0.1", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - } - }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, - "execa": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", - "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", - "requires": { - "cross-spawn": "^5.0.1", - "get-stream": "^3.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" }, "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "requires": { + "locate-path": "^3.0.0" + } + }, "fs-extra": { "version": "0.30.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz", @@ -97,19 +117,14 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "get-caller-file": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz", - "integrity": "sha1-9wLmMSfn4jHBYKgMFVSstw1QR+U=" - }, - "get-stream": { - "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.1.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.5.tgz", + "integrity": "sha512-J9dlskqUXK1OeTOYBEn5s8aMukWMwWfs+rPTn/jn50Ux4MNXVhubL1wu/j2t+H4NVI+cXEcCaYellqaPVGXNqQ==", "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -120,9 +135,9 @@ } }, "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", + "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==" }, "inflight": { "version": "1.0.6", @@ -138,28 +153,15 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, - "invert-kv": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", - "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" - }, "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "requires": { - "number-is-nan": "^1.0.0" - } - }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" - }, - "isexe": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" }, "jsonfile": { "version": "2.4.0", @@ -188,45 +190,13 @@ "graceful-fs": "^4.1.9" } }, - "lcid": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", - "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", - "requires": { - "invert-kv": "^1.0.0" - } - }, "locate-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", - "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", "requires": { - "p-locate": "^2.0.0", + "p-locate": "^3.0.0", "path-exists": "^3.0.0" - }, - "dependencies": { - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" - } - } - }, - "lru-cache": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "mem": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz", - "integrity": "sha1-Xt1StIXKHZAP5kiVUFOZoN+kX3Y=", - "requires": { - "mimic-fn": "^1.0.0" } }, "memorystream": { @@ -234,11 +204,6 @@ "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz", "integrity": "sha1-htcJCzDORV1j+64S3aUaR93K+bI=" }, - "mimic-fn": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -252,19 +217,6 @@ "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" }, - "npm-run-path": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", - "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", - "requires": { - "path-key": "^2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" - }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -275,66 +227,61 @@ }, "os-tmpdir": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" }, - "p-finally": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" - }, "p-limit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", - "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz", + "integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==", "requires": { - "p-try": "^1.0.0" + "p-try": "^2.0.0" } }, "p-locate": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", - "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", "requires": { - "p-limit": "^1.1.0" + "p-limit": "^2.0.0" } }, "p-try": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", - "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, - "path-key": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" - }, - "pseudomap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" - }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" + }, "require-main-filename": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, "rimraf": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", - "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { - "glob": "^7.0.5" + "glob": "^7.1.3" } }, "safe-buffer": { @@ -343,181 +290,48 @@ "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" }, "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, - "shebang-command": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", - "requires": { - "shebang-regex": "^1.0.0" - } - }, - "shebang-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" - }, - "signal-exit": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" - }, "solc": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/solc/-/solc-0.5.1.tgz", - "integrity": "sha512-+RJfa5zRpWBm8DhEiEScIzEzPHWppwHSp/2yV9qvM/lNr0Y8cCv2mcNiXy+R6SSV0OoskhPEfe6Fwa4QQEgxlg==", + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/solc/-/solc-0.5.12.tgz", + "integrity": "sha512-OX/AGZT04tuUsagoVXSZBiBZYJReA02hdwZOfRkB03/eeYP9Dl3pr+M+au+1MhssgiuWBlFPN7sRXFiqwkAW2g==", "requires": { "command-exists": "^1.2.8", "fs-extra": "^0.30.0", - "keccak": "^1.0.2", + "js-sha3": "0.8.0", "memorystream": "^0.3.1", "require-from-string": "^2.0.0", "semver": "^5.5.0", "tmp": "0.0.33", - "yargs": "^11.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - }, - "camelcase": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", - "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=" - }, - "cliui": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", - "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", - "requires": { - "string-width": "^2.1.1", - "strip-ansi": "^4.0.0", - "wrap-ansi": "^2.0.0" - } - }, - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "requires": { - "locate-path": "^2.0.0" - } - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" - }, - "keccak": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/keccak/-/keccak-1.4.0.tgz", - "integrity": "sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw==", - "requires": { - "bindings": "^1.2.1", - "inherits": "^2.0.3", - "nan": "^2.2.1", - "safe-buffer": "^5.1.0" - } - }, - "os-locale": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz", - "integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==", - "requires": { - "execa": "^0.7.0", - "lcid": "^1.0.0", - "mem": "^1.1.0" - } - }, - "require-from-string": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "requires": { - "ansi-regex": "^3.0.0" - } - }, - "which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" - }, - "yargs": { - "version": "11.1.0", - "resolved": "http://registry.npmjs.org/yargs/-/yargs-11.1.0.tgz", - "integrity": "sha512-NwW69J42EsCSanF8kyn5upxvjp5ds+t3+udGBeTbFnERA+lF541DDpMawzo4z6W/QrzNM18D+BPMiOBibnFV5A==", - "requires": { - "cliui": "^4.0.0", - "decamelize": "^1.1.1", - "find-up": "^2.1.0", - "get-caller-file": "^1.0.1", - "os-locale": "^2.0.0", - "require-directory": "^2.1.1", - "require-main-filename": "^1.0.1", - "set-blocking": "^2.0.0", - "string-width": "^2.0.0", - "which-module": "^2.0.0", - "y18n": "^3.2.1", - "yargs-parser": "^9.0.2" - } - }, - "yargs-parser": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", - "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", - "requires": { - "camelcase": "^4.1.0" - } - } + "yargs": "^13.2.0" } }, "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" } }, "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "requires": { - "ansi-regex": "^2.0.0" + "ansi-regex": "^4.1.0" } }, - "strip-eof": { - "version": "1.0.0", - "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" - }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -526,21 +340,19 @@ "os-tmpdir": "~1.0.2" } }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "requires": { - "isexe": "^2.0.0" - } + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, "wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", "requires": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" } }, "wrappy": { @@ -549,14 +361,35 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "y18n": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", - "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" + }, + "yargs": { + "version": "13.3.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz", + "integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==", + "requires": { + "cliui": "^5.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^13.1.1" + } }, - "yallist": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" + "yargs-parser": { + "version": "13.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", + "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } } } } diff --git a/apps/explorer/package.json b/apps/explorer/package.json index 371bb361b4..9010d39c7d 100644 --- a/apps/explorer/package.json +++ b/apps/explorer/package.json @@ -14,6 +14,6 @@ "scripts": {}, "dependencies": { "keccak": "^2.0.0", - "solc": "^0.5" + "solc": "^0.5.12" } } diff --git a/rel/commands/clear_build.sh b/rel/commands/clear_build.sh index a07a11870e..5a032809ba 100755 --- a/rel/commands/clear_build.sh +++ b/rel/commands/clear_build.sh @@ -4,7 +4,8 @@ rm -rf ./_build rm -rf ./deps logs=$(find . -not -path '*/\.*' -name "logs" -type d) dev=$(find ${logs} -name "dev") -rm -rf {ls -la ${dev}} +files_and_dirs_in_logs=$(ls -d ${dev}/*) +rm -rf $files_and_dirs_in_logs find . -name "node_modules" -type d -exec rm -rf '{}' + From 626571619b2110750cd483c10cdc1e9bfac117d2 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 1 Nov 2019 16:38:31 +0300 Subject: [PATCH 3/6] Fix viewing_app_test.exs --- .../test/block_scout_web/features/viewing_app_test.exs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs index b38ad10062..5f3d027f5f 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs @@ -9,6 +9,9 @@ defmodule BlockScoutWeb.ViewingAppTest do alias Explorer.Chain.{Transaction} setup do + Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.BlockNumber.child_id()) + Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.BlockNumber.child_id()) + :ok end From 5539ad2a770c56008e33c8c7c280d815e8b0a5b5 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 1 Nov 2019 17:58:28 +0300 Subject: [PATCH 4/6] Revert refactor to generalized cache solution --- .../channels/address_channel_test.exs | 11 ++ .../controllers/address_controller_test.exs | 8 ++ .../api/rpc/address_controller_test.exs | 3 +- .../api/rpc/eth_controller_test.exs | 3 +- .../controllers/chain_controller_test.exs | 4 + .../features/viewing_addresses_test.exs | 4 + .../features/viewing_app_test.exs | 7 +- .../features/viewing_chain_test.exs | 25 ++++ apps/explorer/config/config.exs | 5 + apps/explorer/config/test.exs | 2 + apps/explorer/lib/explorer/application.ex | 3 +- apps/explorer/lib/explorer/chain.ex | 39 +++--- .../lib/explorer/chain/cache/address_count.ex | 66 --------- .../explorer/counters/addresses_counter.ex | 125 ++++++++++++++++++ .../chain/cache/address_count_test.ex | 54 -------- apps/explorer/test/explorer/chain_test.exs | 17 +++ .../counters/addresses_counter_test.exs | 16 +++ 17 files changed, 245 insertions(+), 147 deletions(-) delete mode 100644 apps/explorer/lib/explorer/chain/cache/address_count.ex create mode 100644 apps/explorer/lib/explorer/counters/addresses_counter.ex delete mode 100644 apps/explorer/test/explorer/chain/cache/address_count_test.ex create mode 100644 apps/explorer/test/explorer/counters/addresses_counter_test.exs diff --git a/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs b/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs index d5bb63255c..357a73eba8 100644 --- a/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs +++ b/apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs @@ -1,9 +1,11 @@ defmodule BlockScoutWeb.AddressChannelTest do use BlockScoutWeb.ChannelCase, + # ETS tables are shared in `Explorer.Counters.AddressesCounter` async: false alias BlockScoutWeb.UserSocket alias BlockScoutWeb.Notifier + alias Explorer.Counters.AddressesCounter test "subscribed user is notified of new_address count event" do topic = "addresses:new_address" @@ -11,6 +13,9 @@ defmodule BlockScoutWeb.AddressChannelTest do address = insert(:address) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + Notifier.handle_event({:chain_event, :addresses, :realtime, [address]}) assert_receive %Phoenix.Socket.Broadcast{topic: ^topic, event: "count", payload: %{count: _}}, :timer.seconds(5) @@ -50,6 +55,9 @@ defmodule BlockScoutWeb.AddressChannelTest do test "notified of balance_update for matching address", %{address: address, topic: topic} do address_with_balance = %{address | fetched_coin_balance: 1} + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + Notifier.handle_event({:chain_event, :addresses, :realtime, [address_with_balance]}) assert_receive %Phoenix.Socket.Broadcast{topic: ^topic, event: "balance_update", payload: payload}, @@ -59,6 +67,9 @@ defmodule BlockScoutWeb.AddressChannelTest do end test "not notified of balance_update if fetched_coin_balance is nil", %{address: address} do + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + Notifier.handle_event({:chain_event, :addresses, :realtime, [address]}) refute_receive _, 100, "Message was broadcast for nil fetched_coin_balance." diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs index f46b195471..6153aa6895 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs @@ -3,6 +3,8 @@ defmodule BlockScoutWeb.AddressControllerTest do # ETS tables are shared in `Explorer.Counters.*` async: false + alias Explorer.Counters.AddressesCounter + describe "GET index/2" do test "returns top addresses", %{conn: conn} do address_hashes = @@ -10,6 +12,9 @@ defmodule BlockScoutWeb.AddressControllerTest do |> Enum.map(&insert(:address, fetched_coin_balance: &1)) |> Enum.map(& &1.hash) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + conn = get(conn, address_path(conn, :index, %{type: "JSON"})) {:ok, %{"items" => items}} = Poison.decode(conn.resp_body) @@ -20,6 +25,9 @@ defmodule BlockScoutWeb.AddressControllerTest do address = insert(:address, fetched_coin_balance: 1) insert(:address_name, address: address, primary: true, name: "POA Wallet") + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + conn = get(conn, address_path(conn, :index, %{type: "JSON"})) {:ok, %{"items" => [item]}} = Poison.decode(conn.resp_body) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs index 85baf575fc..135fbe9948 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs @@ -6,7 +6,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do alias BlockScoutWeb.API.RPC.AddressController alias Explorer.Chain alias Explorer.Chain.{Events.Subscriber, Transaction, Wei} - alias Explorer.Counters.AverageBlockTime + alias Explorer.Counters.{AddressesCounter, AverageBlockTime} alias Indexer.Fetcher.CoinBalanceOnDemand alias Explorer.Repo @@ -22,6 +22,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do start_supervised!({Task.Supervisor, name: Indexer.TaskSupervisor}) start_supervised!(AverageBlockTime) start_supervised!({CoinBalanceOnDemand, [mocked_json_rpc_named_arguments, [name: CoinBalanceOnDemand]]}) + start_supervised!(AddressesCounter) Application.put_env(:explorer, AverageBlockTime, enabled: true) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs index 5facef3a46..5ab050aefc 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.API.RPC.EthControllerTest do use BlockScoutWeb.ConnCase, async: false - alias Explorer.Counters.AverageBlockTime + alias Explorer.Counters.{AddressesCounter, AverageBlockTime} alias Explorer.Repo alias Indexer.Fetcher.CoinBalanceOnDemand @@ -14,6 +14,7 @@ defmodule BlockScoutWeb.API.RPC.EthControllerTest do start_supervised!({Task.Supervisor, name: Indexer.TaskSupervisor}) start_supervised!(AverageBlockTime) start_supervised!({CoinBalanceOnDemand, [mocked_json_rpc_named_arguments, [name: CoinBalanceOnDemand]]}) + start_supervised!(AddressesCounter) Application.put_env(:explorer, AverageBlockTime, enabled: true) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs index 3e96ed709b..93777e16e3 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs @@ -1,16 +1,20 @@ defmodule BlockScoutWeb.ChainControllerTest do use BlockScoutWeb.ConnCase, + # ETS table is shared in `Explorer.Counters.AddressesCounter` async: false import BlockScoutWeb.WebRouter.Helpers, only: [chain_path: 2, block_path: 3, transaction_path: 3, address_path: 3] alias Explorer.Chain.Block + alias Explorer.Counters.AddressesCounter setup do Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Blocks.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Blocks.child_id()) Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Uncles.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Uncles.child_id()) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() :ok end diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs index d50faf1a60..bb223077a2 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs @@ -3,6 +3,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do # Because ETS tables is shared for `Explorer.Counters.*` async: false + alias Explorer.Counters.AddressesCounter alias BlockScoutWeb.{AddressPage, AddressView, Notifier} setup do @@ -57,6 +58,9 @@ defmodule BlockScoutWeb.ViewingAddressesTest do [first_address | _] = addresses [last_address | _] = Enum.reverse(addresses) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> AddressPage.visit_page() |> assert_has(AddressPage.address(first_address)) diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs index 5f3d027f5f..ff37eed468 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_app_test.exs @@ -5,13 +5,14 @@ defmodule BlockScoutWeb.ViewingAppTest do alias BlockScoutWeb.AppPage alias BlockScoutWeb.Counters.BlocksIndexedCounter + alias Explorer.Counters.AddressesCounter alias Explorer.{Repo} alias Explorer.Chain.{Transaction} setup do - Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.BlockNumber.child_id()) - Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.BlockNumber.child_id()) - + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + :ok end diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs index 2fffe2762e..367e8b8b7c 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_chain_test.exs @@ -7,6 +7,7 @@ defmodule BlockScoutWeb.ViewingChainTest do alias BlockScoutWeb.{AddressPage, BlockPage, ChainPage, TransactionPage} alias Explorer.Chain.Block + alias Explorer.Counters.AddressesCounter setup do Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Blocks.child_id()) @@ -34,6 +35,9 @@ defmodule BlockScoutWeb.ViewingChainTest do test "search for address", %{session: session} do address = insert(:address) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> ChainPage.search(to_string(address.hash)) @@ -45,6 +49,9 @@ defmodule BlockScoutWeb.ViewingChainTest do test "search for blocks from chain page", %{session: session} do block = insert(:block, number: 6) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> ChainPage.search(to_string(block.number)) @@ -52,6 +59,9 @@ defmodule BlockScoutWeb.ViewingChainTest do end test "blocks list", %{session: session} do + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> assert_has(ChainPage.blocks(count: 4)) @@ -60,6 +70,9 @@ defmodule BlockScoutWeb.ViewingChainTest do test "inserts place holder blocks on render for out of order blocks", %{session: session} do insert(:block, number: 409) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> assert_has(ChainPage.block(%Block{number: 408})) @@ -71,6 +84,9 @@ defmodule BlockScoutWeb.ViewingChainTest do test "search for transactions", %{session: session} do transaction = insert(:transaction) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> ChainPage.search(to_string(transaction.hash)) @@ -78,6 +94,9 @@ defmodule BlockScoutWeb.ViewingChainTest do end test "transactions list", %{session: session} do + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> assert_has(ChainPage.transactions(count: 5)) @@ -92,6 +111,9 @@ defmodule BlockScoutWeb.ViewingChainTest do |> with_contract_creation(contract_address) |> with_block(block) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> assert_has(ChainPage.contract_creation(transaction)) @@ -116,6 +138,9 @@ defmodule BlockScoutWeb.ViewingChainTest do token_contract_address: contract_token_address ) + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + session |> ChainPage.visit_page() |> assert_has(ChainPage.token_transfers(transaction, count: 1)) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index d36a09450e..60b0afdb48 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -65,6 +65,11 @@ config :explorer, Explorer.Counters.AddressesWithBalanceCounter, enable_consolidation: true, update_interval_in_seconds: balances_update_interval || 30 * 60 +config :explorer, Explorer.Counters.AddressesCounter, + enabled: true, + enable_consolidation: true, + update_interval_in_seconds: balances_update_interval || 30 * 60 + config :explorer, Explorer.ExchangeRates, enabled: true, store: :ets config :explorer, Explorer.KnownTokens, enabled: true, store: :ets diff --git a/apps/explorer/config/test.exs b/apps/explorer/config/test.exs index 1133c92fdb..58050cba2c 100644 --- a/apps/explorer/config/test.exs +++ b/apps/explorer/config/test.exs @@ -21,6 +21,8 @@ config :explorer, Explorer.Counters.AverageBlockTime, enabled: false config :explorer, Explorer.Counters.AddressesWithBalanceCounter, enabled: false, enable_consolidation: false +config :explorer, Explorer.Counters.AddressesCounter, enabled: false, enable_consolidation: false + config :explorer, Explorer.Market.History.Cataloger, enabled: false config :explorer, Explorer.Tracer, disabled?: false diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 709ce7c5a5..4f3e5585f9 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -9,7 +9,6 @@ defmodule Explorer.Application do alias Explorer.Chain.Cache.{ Accounts, - AddressCount, BlockCount, BlockNumber, Blocks, @@ -48,7 +47,6 @@ defmodule Explorer.Application do {Admin.Recovery, [[], [name: Admin.Recovery]]}, TransactionCount, BlockCount, - AddressCount, Blocks, NetVersion, BlockNumber, @@ -75,6 +73,7 @@ defmodule Explorer.Application do configure(Explorer.Market.History.Cataloger), configure(Explorer.Chain.Events.Listener), configure(Explorer.Counters.AddressesWithBalanceCounter), + configure(Explorer.Counters.AddressesCounter), configure(Explorer.Counters.AverageBlockTime), configure(Explorer.Validator.MetadataProcessor), configure(Explorer.Staking.EpochCounter) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 477c4b6da9..8f533748b0 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -51,7 +51,6 @@ defmodule Explorer.Chain do alias Explorer.Chain.Cache.{ Accounts, - AddressCount, BlockCount, BlockNumber, Blocks, @@ -62,7 +61,7 @@ defmodule Explorer.Chain do } alias Explorer.Chain.Import.Runner - alias Explorer.Counters.AddressesWithBalanceCounter + alias Explorer.Counters.{AddressesCounter, AddressesWithBalanceCounter} alias Explorer.Market.MarketHistoryCache alias Explorer.{PagingOptions, Repo} @@ -122,6 +121,24 @@ defmodule Explorer.Chain do AddressesWithBalanceCounter.fetch() end + @doc """ + Estimated count of `t:Explorer.Chain.Address.t/0`. + + Estimated count of addresses. + """ + @spec address_estimated_count() :: non_neg_integer() + def address_estimated_count do + cached_value = AddressesCounter.fetch() + + if is_nil(cached_value) do + %Postgrex.Result{rows: [[count]]} = Repo.query!("SELECT reltuples FROM pg_class WHERE relname = 'addresses';") + + count + else + cached_value + end + end + @doc """ Counts the number of addresses with fetched coin balance > 0. @@ -2387,24 +2404,6 @@ defmodule Explorer.Chain do end end - @doc """ - Estimated count of `t:Explorer.Chain.Address.t/0`. - - Estimated count of addresses. - """ - @spec address_estimated_count() :: non_neg_integer() - def address_estimated_count do - cached_value = AddressCount.get_count() - - if is_nil(cached_value) do - %Postgrex.Result{rows: [[count]]} = Repo.query!("SELECT reltuples FROM pg_class WHERE relname = 'addresses';") - - count - else - cached_value - end - end - @doc """ `t:Explorer.Chain.InternalTransaction/0`s in `t:Explorer.Chain.Transaction.t/0` with `hash`. diff --git a/apps/explorer/lib/explorer/chain/cache/address_count.ex b/apps/explorer/lib/explorer/chain/cache/address_count.ex deleted file mode 100644 index 0b603cdbc5..0000000000 --- a/apps/explorer/lib/explorer/chain/cache/address_count.ex +++ /dev/null @@ -1,66 +0,0 @@ -defmodule Explorer.Chain.Cache.AddressCount do - @moduledoc """ - Cache for address count. - """ - - require Logger - - @default_cache_period :timer.hours(2) - - use Explorer.Chain.MapCache, - name: :address_count, - key: :count, - key: :async_task, - global_ttl: cache_period(), - ttl_check_interval: :timer.minutes(1), - callback: &async_task_on_deletion(&1) - - alias Explorer.Chain.Address - alias Explorer.Repo - - defp handle_fallback(:count) do - # This will get the task PID if one exists and launch a new task if not - # See next `handle_fallback` definition - get_async_task() - - {:return, nil} - end - - defp handle_fallback(:async_task) do - # If this gets called it means an async task was requested, but none exists - # so a new one needs to be launched - {:ok, task} = - Task.start(fn -> - try do - result = Repo.aggregate(Address, :count, :hash, timeout: :infinity) - - set_count(result) - rescue - e -> - Logger.debug([ - "Coudn't update address count test #{inspect(e)}" - ]) - end - - set_async_task(nil) - end) - - {:update, task} - end - - # By setting this as a `callback` an async task will be started each time the - # `count` expires (unless there is one already running) - defp async_task_on_deletion({:delete, _, :count}), do: get_async_task() - - defp async_task_on_deletion(_data), do: nil - - defp cache_period do - "ADDRESS_COUNT_CACHE_PERIOD" - |> System.get_env("") - |> Integer.parse() - |> case do - {integer, ""} -> :timer.seconds(integer) - _ -> @default_cache_period - end - end -end diff --git a/apps/explorer/lib/explorer/counters/addresses_counter.ex b/apps/explorer/lib/explorer/counters/addresses_counter.ex new file mode 100644 index 0000000000..5febd8fbb9 --- /dev/null +++ b/apps/explorer/lib/explorer/counters/addresses_counter.ex @@ -0,0 +1,125 @@ +defmodule Explorer.Counters.AddressesCounter do + @moduledoc """ + Caches the number of all addresses. + + It loads the count asynchronously and in a time interval of 30 minutes. + """ + + use GenServer + + alias Explorer.Chain + + @table :addresses_counter + + @cache_key "addresses" + + def table_name do + @table + end + + def cache_key do + @cache_key + end + + # It is undesirable to automatically start the consolidation in all environments. + # Consider the test environment: if the consolidation initiates but does not + # finish before a test ends, that test will fail. This way, hundreds of + # tests were failing before disabling the consolidation and the scheduler in + # the test env. + config = Application.get_env(:explorer, Explorer.Counters.AddressesCounter) + @enable_consolidation Keyword.get(config, :enable_consolidation) + + @update_interval_in_seconds Keyword.get(config, :update_interval_in_seconds) + + @doc """ + Starts a process to periodically update the counter of the token holders. + """ + @spec start_link(term()) :: GenServer.on_start() + def start_link(_) do + GenServer.start_link(__MODULE__, :ok, name: __MODULE__) + end + + @impl true + def init(_args) do + create_table() + + {:ok, %{consolidate?: enable_consolidation?()}, {:continue, :ok}} + end + + def create_table do + opts = [ + :set, + :named_table, + :public, + read_concurrency: true + ] + + :ets.new(table_name(), opts) + end + + defp schedule_next_consolidation do + Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) + end + + @doc """ + Inserts new items into the `:ets` table. + """ + def insert_counter({key, info}) do + :ets.insert(table_name(), {key, info}) + end + + @impl true + def handle_continue(:ok, %{consolidate?: true} = state) do + consolidate() + schedule_next_consolidation() + + {:noreply, state} + end + + @impl true + def handle_continue(:ok, state) do + {:noreply, state} + end + + @impl true + def handle_info(:consolidate, state) do + consolidate() + + schedule_next_consolidation() + + {:noreply, state} + end + + @doc """ + Fetches the info for a specific item from the `:ets` table. + """ + def fetch do + do_fetch(:ets.lookup(table_name(), cache_key())) + end + + defp do_fetch([{_, result}]), do: result + defp do_fetch([]), do: 0 + + @doc """ + Consolidates the info by populating the `:ets` table with the current database information. + """ + def consolidate do + counter = Chain.count_addresses() + + insert_counter({cache_key(), counter}) + end + + @doc """ + Returns a boolean that indicates whether consolidation is enabled + + In order to choose whether or not to enable the scheduler and the initial + consolidation, change the following Explorer config: + + `config :explorer, Explorer.Counters.AddressesCounter, enable_consolidation: true` + + to: + + `config :explorer, Explorer.Counters.AddressesCounter, enable_consolidation: false` + """ + def enable_consolidation?, do: @enable_consolidation +end diff --git a/apps/explorer/test/explorer/chain/cache/address_count_test.ex b/apps/explorer/test/explorer/chain/cache/address_count_test.ex deleted file mode 100644 index 9bb10543fe..0000000000 --- a/apps/explorer/test/explorer/chain/cache/address_count_test.ex +++ /dev/null @@ -1,54 +0,0 @@ -defmodule Explorer.Chain.Cache.AddressCountTest do - use Explorer.DataCase - - alias Explorer.Chain.Cache.AddressCount - - setup do - Supervisor.terminate_child(Explorer.Supervisor, AddressCount.child_id()) - Supervisor.restart_child(Explorer.Supervisor, AddressCount.child_id()) - :ok - end - - test "returns default address count" do - result = AddressCount.get_count() - - assert is_nil(result) - end - - test "updates cache if initial value is zero" do - insert(:address) - insert(:address) - - _result = AddressCount.get_count() - - Process.sleep(1000) - - updated_value = AddressCount.get_count() - - assert updated_value == 2 - end - - test "does not update cache if cache period did not pass" do - insert(:address) - insert(:address) - - _result = AddressCount.get_count() - - Process.sleep(1000) - - updated_value = AddressCount.get_count() - - assert updated_value == 2 - - insert(:address) - insert(:address) - - _updated_value = AddressCount.get_count() - - Process.sleep(1000) - - updated_value = AddressCount.get_count() - - assert updated_value == 2 - end -end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index abdcc8a963..12208cc3f0 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -27,6 +27,7 @@ defmodule Explorer.ChainTest do alias Explorer.Chain.Supply.ProofOfAuthority alias Explorer.Counters.AddressesWithBalanceCounter + alias Explorer.Counters.AddressesCounter doctest Explorer.Chain @@ -50,6 +51,22 @@ defmodule Explorer.ChainTest do end end + describe "address_estimated_count/0" do + test "returns the number of all addresses" do + insert(:address, fetched_coin_balance: 0) + insert(:address, fetched_coin_balance: 1) + insert(:address, fetched_coin_balance: 2) + + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + + addresses_with_balance = Chain.address_estimated_count() + + assert is_integer(addresses_with_balance) + assert addresses_with_balance == 3 + end + end + describe "last_db_block_status/0" do test "return no_blocks errors if db is empty" do assert {:error, :no_blocks} = Chain.last_db_block_status() diff --git a/apps/explorer/test/explorer/counters/addresses_counter_test.exs b/apps/explorer/test/explorer/counters/addresses_counter_test.exs new file mode 100644 index 0000000000..b187fd8c0e --- /dev/null +++ b/apps/explorer/test/explorer/counters/addresses_counter_test.exs @@ -0,0 +1,16 @@ +defmodule Explorer.Counters.AddressesCounterTest do + use Explorer.DataCase + + alias Explorer.Counters.AddressesCounter + + test "populates the cache with the number of all addresses" do + insert(:address, fetched_coin_balance: 0) + insert(:address, fetched_coin_balance: 1) + insert(:address, fetched_coin_balance: 2) + + start_supervised!(AddressesCounter) + AddressesCounter.consolidate() + + assert AddressesCounter.fetch() == 3 + end +end From 18e098e0dff43536b1a3b025e7d7b569e8e1b613 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 1 Nov 2019 19:10:40 +0300 Subject: [PATCH 5/6] Fix for stuck gas limit label and value --- CHANGELOG.md | 1 + .../lib/block_scout_web/templates/block/overview.html.eex | 4 +++- apps/block_scout_web/priv/gettext/default.pot | 2 +- apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f1619f6f..6d0f9adfed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify ### Fixes +- [#2829](https://github.com/poanetwork/blockscout/pull/2829) - Fix for stuck gas limit label and value - [#2800](https://github.com/poanetwork/blockscout/pull/2800) - return not found for not verified contract for token read_contract - [#2806](https://github.com/poanetwork/blockscout/pull/2806) - Fix blocks fetching on the main page - [#2803](https://github.com/poanetwork/blockscout/pull/2803) - Fix block validator custom tooltip diff --git a/apps/block_scout_web/lib/block_scout_web/templates/block/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/block/overview.html.eex index f26167fa7e..0512d07540 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/block/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/block/overview.html.eex @@ -156,7 +156,9 @@ <%= @block.gas_used |> BlockScoutWeb.Cldr.Number.to_string! %> (<%= (Decimal.to_integer(@block.gas_used) / Decimal.to_integer(@block.gas_limit)) |> BlockScoutWeb.Cldr.Number.to_string!(format: "#.#%") %>) -

<%= @block.gas_limit |> BlockScoutWeb.Cldr.Number.to_string! %><%= gettext "Gas Limit" %>

+

<%= @block.gas_limit |> BlockScoutWeb.Cldr.Number.to_string! %> + <%= " "%> + <%= gettext "Gas Limit" %>

<% end %> diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 23c32aab5d..49406a67c2 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -514,7 +514,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_tile.html.eex:57 #: lib/block_scout_web/templates/block/overview.html.eex:108 -#: lib/block_scout_web/templates/block/overview.html.eex:159 +#: lib/block_scout_web/templates/block/overview.html.eex:161 msgid "Gas Limit" msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 23c32aab5d..49406a67c2 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -514,7 +514,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_tile.html.eex:57 #: lib/block_scout_web/templates/block/overview.html.eex:108 -#: lib/block_scout_web/templates/block/overview.html.eex:159 +#: lib/block_scout_web/templates/block/overview.html.eex:161 msgid "Gas Limit" msgstr "" From dc2f816d0e4d238011ed9ad3884efdd390742d7f Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 1 Nov 2019 20:12:54 +0300 Subject: [PATCH 6/6] Currently deployed to blockscout.com xDai theme and fix for the color of copy contract icon on token instance page --- CHANGELOG.md | 1 + .../assets/css/theme/_dai_variables.scss | 59 +++++++------------ .../assets/static/images/dai_logo.svg | 2 +- .../network-selector-icons/xdai-chain.svg | 2 +- 4 files changed, 25 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f1619f6f..61f789b08d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify ### Fixes +- [#2830](https://github.com/poanetwork/blockscout/pull/2830) - Fix wrong color of contract icon on xDai chain - [#2800](https://github.com/poanetwork/blockscout/pull/2800) - return not found for not verified contract for token read_contract - [#2806](https://github.com/poanetwork/blockscout/pull/2806) - Fix blocks fetching on the main page - [#2803](https://github.com/poanetwork/blockscout/pull/2803) - Fix block validator custom tooltip diff --git a/apps/block_scout_web/assets/css/theme/_dai_variables.scss b/apps/block_scout_web/assets/css/theme/_dai_variables.scss index edfc1a26fd..7c0c2de494 100644 --- a/apps/block_scout_web/assets/css/theme/_dai_variables.scss +++ b/apps/block_scout_web/assets/css/theme/_dai_variables.scss @@ -1,23 +1,23 @@ // general -$primary: #233174; -$secondary: #15f9bb; -$tertiary: #5a77ff; +$primary: #17314f; +$secondary: #15bba6; +$tertiary: #93d7ff; $additional-font: #fff; // footer -$footer-background-color:#202d6a; +$footer-background-color: $primary; $footer-title-color: #fff; -$footer-text-color: #b5c2ff; +$footer-text-color: #96bde8; $footer-item-disc-color: $secondary; .footer-logo { filter: brightness(0) invert(1); } -.footer-social-icon { color: $secondary!important; } + // dashboard $dashboard-line-color-price: $tertiary; // price left border $dashboard-line-color-market: $secondary; $dashboard-banner-chart-legend-label-color: $footer-text-color; -$dashboard-stats-item-label-color: #b4c1ff; +$dashboard-stats-item-label-color: $footer-text-color; $dashboard-banner-chart-legend-value-color: #fff; // chart labels $dashboard-stats-item-value-color: #fff; // stat values @@ -25,11 +25,9 @@ $dashboard-stats-item-border-color: $secondary; // stat border $dashboard-banner-gradient-start: $primary; // gradient begin -$dashboard-banner-gradient-end: #1e2a63; -// gradient end +$dashboard-banner-gradient-end: lighten($primary, 5); // gradient end -$dashboard-banner-network-plain-container-background-color: #273781 -; // stats bg +$dashboard-banner-network-plain-container-background-color: #20446e; // stats bg // navigation @@ -37,20 +35,21 @@ $dashboard-banner-network-plain-container-background-color: #273781 // buttons $btn-line-bg: #fff; // button bg -$btn-line-color: $primary; // button border and font color && hover bg color -$btn-copy-color: $primary; // btn copy -$btn-qr-color: $primary; // btn qr-code +$btn-line-color: $secondary; // button border and font color && hover bg color +$btn-copy-color: $secondary; // btn copy +$btn-qr-color: $secondary; // btn qr-code $btn-address-card-icon-color: $secondary; // btn address color +$btn-contract-color: $secondary; //links & tile -$tile-body-a-color: $tertiary; -$tile-type-block-color: $primary; -$tile-type-progress-bar-color: $primary; -a.tile-title { color: $primary !important; } +$tile-body-a-color: $secondary; +$tile-type-block-color: $secondary; +$tile-type-progress-bar-color: $secondary; +a.tile-title { color: $secondary !important; } // card -$card-background-1: $primary; -$card-tab-active: $primary; +$card-background-1: $secondary; +$card-tab-active: $secondary; .layout-container { .dashboard-banner-container { @@ -68,20 +67,6 @@ $badge-neutral-background-color: rgba(#20446e, .1); $api-text-monospace-color: #20446e; // Dark theme -$dark-primary: #233174; -$dark-secondary:#15f9bb; -$dark-tertiary: #5a77ff; - -.dark-theme-applied .tile .tile-body a, .dark-theme-applied .tile span[data-address-hash] { - color: $dark-tertiary!important; -} - -.dark-theme-applied .btn-line { - background-color: transparent!important; - border-color: $dark-tertiary!important; - color: $dark-tertiary!important; -} - -.dark-theme-applied .btn-line:hover { - color: $additional-font!important; -} \ No newline at end of file +$dark-primary: #15bba6; +$dark-secondary: #93d7ff; +$dark-primary-alternate: #15bba6; \ No newline at end of file diff --git a/apps/block_scout_web/assets/static/images/dai_logo.svg b/apps/block_scout_web/assets/static/images/dai_logo.svg index 2fddff632e..9c6539f45a 100644 --- a/apps/block_scout_web/assets/static/images/dai_logo.svg +++ b/apps/block_scout_web/assets/static/images/dai_logo.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/apps/block_scout_web/assets/static/images/network-selector-icons/xdai-chain.svg b/apps/block_scout_web/assets/static/images/network-selector-icons/xdai-chain.svg index d72d61baf4..3667adec4c 100644 --- a/apps/block_scout_web/assets/static/images/network-selector-icons/xdai-chain.svg +++ b/apps/block_scout_web/assets/static/images/network-selector-icons/xdai-chain.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file