From 0a32431f2045f0d1a5b02326e4a08b222d32f204 Mon Sep 17 00:00:00 2001 From: zachdaniel Date: Mon, 20 May 2019 16:46:11 -0400 Subject: [PATCH 1/7] fix: consolidate address w/ balance one at a time --- CHANGELOG.md | 1 + .../addresses_with_balance_counter.ex | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e60b218c2..8d193835fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - [#1956](https://github.com/poanetwork/blockscout/pull/1956) - add logs tab to address - [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method - [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default +- [#1989](https://github.com/poanetwork/blockscout/pull/1989) - fix: consolidate address w/ balance one at a time ### Fixes diff --git a/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex b/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex index 3a03a7bcd5..cdc2530f93 100644 --- a/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex +++ b/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex @@ -40,15 +40,10 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do end @impl true - def init(args) do + def init(_args) do create_table() - if enable_consolidation?() do - Task.start_link(&consolidate/0) - schedule_next_consolidation() - end - - {:ok, args} + {:ok, %{consolidate?: enable_consolidation?()}, {:continue, :ok}} end def create_table do @@ -63,9 +58,7 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do end defp schedule_next_consolidation do - if enable_consolidation?() do - Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) - end + Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) end @doc """ @@ -75,6 +68,19 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter 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() From c35e6bbdb784181d803937409cc1265df3a0e340 Mon Sep 17 00:00:00 2001 From: zachdaniel Date: Tue, 21 May 2019 15:17:31 -0400 Subject: [PATCH 2/7] fix: support https for wobserver polling --- CHANGELOG.md | 1 + apps/block_scout_web/mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3d9ef4a3..5acc29c729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ - [#1937](https://github.com/poanetwork/blockscout/pull/1937) - Check the presence of overlap[i] object before retrieving properties from it - [#1960](https://github.com/poanetwork/blockscout/pull/1960) - do not remove bold text in decompiled contacts - [#1917](https://github.com/poanetwork/blockscout/pull/1917) - Force block refetch if transaction is re-collated in a different block +- [#1992](https://github.com/poanetwork/blockscout/pull/1992) - fix: support https for wobserver polling ### Chore diff --git a/apps/block_scout_web/mix.exs b/apps/block_scout_web/mix.exs index 34289ec672..02e9d203fb 100644 --- a/apps/block_scout_web/mix.exs +++ b/apps/block_scout_web/mix.exs @@ -128,7 +128,7 @@ defmodule BlockScoutWeb.Mixfile do {:timex, "~> 3.4"}, {:wallaby, "~> 0.22", only: [:test], runtime: false}, # `:cowboy` `~> 2.0` and Phoenix 1.4 compatibility - {:wobserver, "~> 0.2.0", github: "KronicDeth/wobserver", ref: "99683a936c75c0a94ebb884cef019f7ed0b97112"}, + {:wobserver, "~> 0.2.0", github: "poanetwork/wobserver", branch: "support-https"}, {:phoenix_form_awesomplete, "~> 0.1.4"} ] end diff --git a/mix.lock b/mix.lock index e9066554b1..df1be8c242 100644 --- a/mix.lock +++ b/mix.lock @@ -109,5 +109,5 @@ "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, "wallaby": {:hex, :wallaby, "0.22.0", "e5d16bfa7ab23562c8a6e3b0a31445a2fd470ca622082a910114807ba823780d", [:mix], [{:httpoison, "~> 0.12 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm"}, "websocket_client": {:hex, :websocket_client, "1.3.0", "2275d7daaa1cdacebf2068891c9844b15f4fdc3de3ec2602420c2fb486db59b6", [:rebar3], [], "hexpm"}, - "wobserver": {:git, "https://github.com/KronicDeth/wobserver.git", "99683a936c75c0a94ebb884cef019f7ed0b97112", [ref: "99683a936c75c0a94ebb884cef019f7ed0b97112"]}, + "wobserver": {:git, "https://github.com/poanetwork/wobserver.git", "13bcda30a87f4f0be1878920a79433ad831eefbe", [branch: "support-https"]}, } From b996e8b7eaeeddc458d7859c4e534f8aea59d463 Mon Sep 17 00:00:00 2001 From: Michael Ira Krufky Date: Wed, 22 May 2019 07:21:25 -0400 Subject: [PATCH 3/7] docker/Makefile: always set a container name --- docker/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Makefile b/docker/Makefile index 1f49ff50b5..ac1c2677d6 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,6 +1,7 @@ SYSTEM = $(shell uname -s) HOST = host.docker.internal DOCKER_IMAGE = blockscout_prod +BS_CONTAINER_NAME = blockscout PG_CONTAINER_NAME = postgres PG_CONTAINER_IMAGE = postgres:10.4 THIS_FILE = $(lastword $(MAKEFILE_LIST)) @@ -87,7 +88,7 @@ endif start: build postgres @echo "==> Starting blockscout" - @docker run --rm \ + @docker run --rm --name $(BS_CONTAINER_NAME) \ $(BLOCKSCOUT_CONTAINNER_PARAMS) \ -p 4000:4000 \ $(DOCKER_IMAGE) /bin/sh -c "mix phx.server" From 2a2ed1ff78e4f67f43d494fd88f9ad9e2d0ff6f4 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 22 May 2019 15:27:22 +0300 Subject: [PATCH 4/7] get estimated count of blocks when cache is empty --- apps/explorer/lib/explorer/chain.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 0977df1dd2..092e5c3a34 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1997,7 +1997,9 @@ defmodule Explorer.Chain do cached_value = BlockCountCache.count() if is_nil(cached_value) do - block_consensus_count() + %Postgrex.Result{rows: [[count]]} = Repo.query!("SELECT reltuples FROM pg_class WHERE relname = 'blocks';") + + trunc(count * 0.90) else cached_value end From 249fc56bf8c49400f7ae0aba86974ac1ea98039e Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 22 May 2019 15:44:24 +0300 Subject: [PATCH 5/7] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc77993902..da11db2952 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method - [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default - [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct +- [#2002](https://github.com/poanetwork/blockscout/pull/2002) - Get estimated count of blocks when cache is empty ### Fixes From f0a559efaaf7d7e9e2abf7250c5b35454fcd99c2 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 22 May 2019 16:32:57 +0300 Subject: [PATCH 6/7] remove block_consensus_count function --- apps/explorer/lib/explorer/chain.ex | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 092e5c3a34..087375afeb 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -363,21 +363,6 @@ defmodule Explorer.Chain do Repo.aggregate(Block, :count, :hash) end - @doc """ - The number of consensus blocks. - - iex> insert(:block, consensus: true) - iex> insert(:block, consensus: false) - iex> Explorer.Chain.block_consensus_count() - 1 - - """ - def block_consensus_count do - Block - |> where(consensus: true) - |> Repo.aggregate(:count, :hash) - end - @doc """ Reward for mining a block. From 833e4e609737eab6994e192061a8212ec8bd3501 Mon Sep 17 00:00:00 2001 From: Michael Ira Krufky Date: Wed, 22 May 2019 11:28:37 -0400 Subject: [PATCH 7/7] CHANGELOG: #2000 - docker/Makefile: always set a container name --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc77993902..8e4915d775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Current +- [#2000](https://github.com/poanetwork/blockscout/pull/2000) - docker/Makefile: always set a container name ### Features - [#1963](https://github.com/poanetwork/blockscout/pull/1963) - added rinkeby theme and rinkeby logo