From e6df337ab7c90fa4476a19cb9982c711df626b91 Mon Sep 17 00:00:00 2001 From: saneery Date: Fri, 26 Jul 2019 15:39:27 +0300 Subject: [PATCH 01/32] Send events through postgres notify --- apps/explorer/lib/explorer/application.ex | 3 ++ .../lib/explorer/chain/events/listener.ex | 54 +++++++++++++++++++ .../lib/explorer/chain/events/publisher.ex | 21 ++++---- 3 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/events/listener.ex diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index c1fb19f600..c509490525 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -16,6 +16,8 @@ defmodule Explorer.Application do Transactions } + alias Explorer.Chain.Events.Listener + alias Explorer.Chain.Supply.RSK alias Explorer.Market.MarketHistoryCache @@ -43,6 +45,7 @@ defmodule Explorer.Application do {Admin.Recovery, [[], [name: Admin.Recovery]]}, {TransactionCount, [[], []]}, {BlockCount, []}, + {Listener, []}, con_cache_child_spec(Blocks.cache_name()), con_cache_child_spec(NetVersion.cache_name()), con_cache_child_spec(MarketHistoryCache.cache_name()), diff --git a/apps/explorer/lib/explorer/chain/events/listener.ex b/apps/explorer/lib/explorer/chain/events/listener.ex new file mode 100644 index 0000000000..8ff076a014 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/events/listener.ex @@ -0,0 +1,54 @@ +defmodule Explorer.Chain.Events.Listener do + @moduledoc """ + Listens and publishes events from PG + """ + + use GenServer + + alias Postgrex.Notifications + + def start_link(_) do + GenServer.start_link(__MODULE__, "chain_event") + end + + def init(channel) do + {:ok, pid} = + :explorer + |> Application.get_env(Explorer.Repo) + |> Notifications.start_link() + + ref = Notifications.listen!(pid, channel) + + {:ok, {pid, ref, channel}} + end + + def handle_info({:notification, _pid, _ref, _topic, payload}, state) do + payload + |> decode_payload!() + |> broadcast() + + {:noreply, state} + end + + defp decode_payload!(payload) do + payload + |> Base.decode64!() + |> :erlang.binary_to_term() + end + + defp broadcast({:chain_event, event_type} = event) do + Registry.dispatch(Registry.ChainEvents, event_type, fn entries -> + for {pid, _registered_val} <- entries do + send(pid, event) + end + end) + end + + defp broadcast({:chain_event, event_type, broadcast_type, _data} = event) do + Registry.dispatch(Registry.ChainEvents, {event_type, broadcast_type}, fn entries -> + for {pid, _registered_val} <- entries do + send(pid, event) + end + end) + end +end diff --git a/apps/explorer/lib/explorer/chain/events/publisher.ex b/apps/explorer/lib/explorer/chain/events/publisher.ex index c7e01eef3a..8bb59fac65 100644 --- a/apps/explorer/lib/explorer/chain/events/publisher.ex +++ b/apps/explorer/lib/explorer/chain/events/publisher.ex @@ -2,6 +2,7 @@ defmodule Explorer.Chain.Events.Publisher do @moduledoc """ Publishes events related to the Chain context. """ + alias Explorer.Repo @allowed_events ~w(addresses address_coin_balances blocks block_rewards internal_transactions token_transfers transactions contract_verification_result)a @@ -19,11 +20,8 @@ defmodule Explorer.Chain.Events.Publisher do end defp send_data(event_type) do - Registry.dispatch(Registry.ChainEvents, event_type, fn entries -> - for {pid, _registered_val} <- entries do - send(pid, {:chain_event, event_type}) - end - end) + payload = encode_payload({:chain_event, event_type}) + Repo.query("NOTIFY chain_event, '#{payload}';") end # The :catchup type of event is not being consumed right now. @@ -32,10 +30,13 @@ defmodule Explorer.Chain.Events.Publisher do defp send_data(_event_type, :catchup, _event_data), do: :ok defp send_data(event_type, broadcast_type, event_data) do - Registry.dispatch(Registry.ChainEvents, {event_type, broadcast_type}, fn entries -> - for {pid, _registered_val} <- entries do - send(pid, {:chain_event, event_type, broadcast_type, event_data}) - end - end) + payload = encode_payload({:chain_event, event_type, broadcast_type, event_data}) + Repo.query("NOTIFY chain_event, '#{payload}';") + end + + defp encode_payload(payload) do + payload + |> :erlang.term_to_binary() + |> Base.encode64() end end From 19d84abd401c83633fb2cd35afbb17654458f9d2 Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 29 Jul 2019 15:55:35 +0300 Subject: [PATCH 02/32] Update tests to receive realtime events --- .../lib/explorer/chain/events/listener.ex | 1 + .../lib/explorer/chain/events/publisher.ex | 20 ++++++++++++++++--- .../explorer/chain/events/publisher_test.exs | 6 +++--- .../explorer/chain/events/subscriber_test.exs | 4 ++-- .../test/explorer/chain/import_test.exs | 12 +++++------ 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/events/listener.ex b/apps/explorer/lib/explorer/chain/events/listener.ex index 8ff076a014..40a4131e84 100644 --- a/apps/explorer/lib/explorer/chain/events/listener.ex +++ b/apps/explorer/lib/explorer/chain/events/listener.ex @@ -30,6 +30,7 @@ defmodule Explorer.Chain.Events.Listener do {:noreply, state} end + # sobelow_skip ["Misc.BinToTerm"] defp decode_payload!(payload) do payload |> Base.decode64!() diff --git a/apps/explorer/lib/explorer/chain/events/publisher.ex b/apps/explorer/lib/explorer/chain/events/publisher.ex index 8bb59fac65..31374e19f0 100644 --- a/apps/explorer/lib/explorer/chain/events/publisher.ex +++ b/apps/explorer/lib/explorer/chain/events/publisher.ex @@ -2,6 +2,7 @@ defmodule Explorer.Chain.Events.Publisher do @moduledoc """ Publishes events related to the Chain context. """ + alias Ecto.Adapters.SQL.Sandbox alias Explorer.Repo @allowed_events ~w(addresses address_coin_balances blocks block_rewards internal_transactions token_transfers transactions contract_verification_result)a @@ -17,11 +18,12 @@ defmodule Explorer.Chain.Events.Publisher do @spec broadcast(atom()) :: :ok def broadcast(event_type) do send_data(event_type) + :ok end defp send_data(event_type) do payload = encode_payload({:chain_event, event_type}) - Repo.query("NOTIFY chain_event, '#{payload}';") + send_notify(payload) end # The :catchup type of event is not being consumed right now. @@ -31,12 +33,24 @@ defmodule Explorer.Chain.Events.Publisher do defp send_data(event_type, broadcast_type, event_data) do payload = encode_payload({:chain_event, event_type, broadcast_type, event_data}) - Repo.query("NOTIFY chain_event, '#{payload}';") + send_notify(payload) end defp encode_payload(payload) do payload - |> :erlang.term_to_binary() + |> :erlang.term_to_binary([:compressed]) |> Base.encode64() end + + defp send_notify(payload) do + fun = fn -> + Repo.query("select pg_notify('chain_event', $1::text);", [payload]) + end + + if Mix.env() == :test do + Sandbox.unboxed_run(Repo, fun) + else + fun.() + end + end end diff --git a/apps/explorer/test/explorer/chain/events/publisher_test.exs b/apps/explorer/test/explorer/chain/events/publisher_test.exs index ef76126086..e0934a53dd 100644 --- a/apps/explorer/test/explorer/chain/events/publisher_test.exs +++ b/apps/explorer/test/explorer/chain/events/publisher_test.exs @@ -15,7 +15,7 @@ defmodule Explorer.Chain.Events.PublisherTest do Publisher.broadcast([{event_type, event_data}], broadcast_type) - assert_received {:chain_event, ^event_type, ^broadcast_type, []} + assert_receive {:chain_event, ^event_type, ^broadcast_type, []} end test "won't send chain_event of catchup type" do @@ -27,7 +27,7 @@ defmodule Explorer.Chain.Events.PublisherTest do Publisher.broadcast([{event_type, event_data}], broadcast_type) - refute_received {:chain_event, ^event_type, ^broadcast_type, []} + refute_receive {:chain_event, ^event_type, ^broadcast_type, []} end test "won't send event that is not allowed" do @@ -59,7 +59,7 @@ defmodule Explorer.Chain.Events.PublisherTest do Publisher.broadcast(event_type) - assert_received {:chain_event, ^event_type} + assert_receive {:chain_event, ^event_type} end end end diff --git a/apps/explorer/test/explorer/chain/events/subscriber_test.exs b/apps/explorer/test/explorer/chain/events/subscriber_test.exs index 531efc24b2..b26841d0ef 100644 --- a/apps/explorer/test/explorer/chain/events/subscriber_test.exs +++ b/apps/explorer/test/explorer/chain/events/subscriber_test.exs @@ -15,7 +15,7 @@ defmodule Explorer.Chain.Events.SubscriberTest do Publisher.broadcast([{event_type, event_data}], broadcast_type) - assert_received {:chain_event, :blocks, :realtime, []} + assert_receive {:chain_event, :blocks, :realtime, []} end end @@ -27,7 +27,7 @@ defmodule Explorer.Chain.Events.SubscriberTest do Publisher.broadcast(event_type) - assert_received {:chain_event, :exchange_rate} + assert_receive {:chain_event, :exchange_rate} end end end diff --git a/apps/explorer/test/explorer/chain/import_test.exs b/apps/explorer/test/explorer/chain/import_test.exs index dd3bbf1aec..0c559bdfec 100644 --- a/apps/explorer/test/explorer/chain/import_test.exs +++ b/apps/explorer/test/explorer/chain/import_test.exs @@ -470,27 +470,27 @@ defmodule Explorer.Chain.ImportTest do test "publishes addresses with updated fetched_coin_balance data to subscribers on insert" do Subscriber.to(:addresses, :realtime) Import.all(@import_data) - assert_received {:chain_event, :addresses, :realtime, [%Address{}, %Address{}, %Address{}]} + assert_receive {:chain_event, :addresses, :realtime, [%Address{}, %Address{}, %Address{}]} end test "publishes block data to subscribers on insert" do Subscriber.to(:blocks, :realtime) Import.all(@import_data) - assert_received {:chain_event, :blocks, :realtime, [%Block{}]} + assert_receive {:chain_event, :blocks, :realtime, [%Block{}]} end test "publishes internal_transaction data to subscribers on insert" do Subscriber.to(:internal_transactions, :realtime) Import.all(@import_data) - assert_received {:chain_event, :internal_transactions, :realtime, - [%{transaction_hash: _, index: _}, %{transaction_hash: _, index: _}]} + assert_receive {:chain_event, :internal_transactions, :realtime, + [%{transaction_hash: _, index: _}, %{transaction_hash: _, index: _}]} end test "publishes transactions data to subscribers on insert" do Subscriber.to(:transactions, :realtime) Import.all(@import_data) - assert_received {:chain_event, :transactions, :realtime, [%Transaction{}]} + assert_receive {:chain_event, :transactions, :realtime, [%Transaction{}]} end test "publishes token_transfers data to subscribers on insert" do @@ -498,7 +498,7 @@ defmodule Explorer.Chain.ImportTest do Import.all(@import_data) - assert_received {:chain_event, :token_transfers, :realtime, [%TokenTransfer{}]} + assert_receive {:chain_event, :token_transfers, :realtime, [%TokenTransfer{}]} end test "does not broadcast if broadcast option is false" do From ea0d47cfa4cbfb485893edb3f244452a1c1a460d Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 1 Aug 2019 11:47:43 +0300 Subject: [PATCH 03/32] Add mock to send events directly to listener --- apps/explorer/config/config.exs | 3 ++- apps/explorer/config/test.exs | 3 +++ .../lib/explorer/chain/events/listener.ex | 2 +- .../lib/explorer/chain/events/publisher.ex | 19 +++---------------- .../lib/explorer/chain/events/sender.ex | 12 ++++++++++++ .../lib/explorer/chain/events/sender_mock.ex | 10 ++++++++++ .../explorer/chain/events/publisher_test.exs | 2 +- 7 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/events/sender.ex create mode 100644 apps/explorer/lib/explorer/chain/events/sender_mock.ex diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index fed5124a2a..7e1914e89c 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -15,7 +15,8 @@ config :explorer, "homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg,default", include_uncles_in_average_block_time: if(System.get_env("UNCLES_IN_AVERAGE_BLOCK_TIME") == "false", do: false, else: true), - healthy_blocks_period: System.get_env("HEALTHY_BLOCKS_PERIOD") || :timer.minutes(5) + healthy_blocks_period: System.get_env("HEALTHY_BLOCKS_PERIOD") || :timer.minutes(5), + realtime_events_sender: Explorer.Chain.Events.Sender average_block_period = case Integer.parse(System.get_env("AVERAGE_BLOCK_CACHE_PERIOD", "")) do diff --git a/apps/explorer/config/test.exs b/apps/explorer/config/test.exs index d91f4dbdfc..4838fa8e32 100644 --- a/apps/explorer/config/test.exs +++ b/apps/explorer/config/test.exs @@ -41,6 +41,9 @@ end config :explorer, Explorer.ExchangeRates.Source.TransactionAndLog, secondary_source: Explorer.ExchangeRates.Source.OneCoinSource +config :explorer, + realtime_events_sender: Explorer.Chain.Events.SenderMock + variant = if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do "parity" diff --git a/apps/explorer/lib/explorer/chain/events/listener.ex b/apps/explorer/lib/explorer/chain/events/listener.ex index 40a4131e84..2d93eeada0 100644 --- a/apps/explorer/lib/explorer/chain/events/listener.ex +++ b/apps/explorer/lib/explorer/chain/events/listener.ex @@ -8,7 +8,7 @@ defmodule Explorer.Chain.Events.Listener do alias Postgrex.Notifications def start_link(_) do - GenServer.start_link(__MODULE__, "chain_event") + GenServer.start_link(__MODULE__, "chain_event", name: __MODULE__) end def init(channel) do diff --git a/apps/explorer/lib/explorer/chain/events/publisher.ex b/apps/explorer/lib/explorer/chain/events/publisher.ex index 31374e19f0..11a7dc1518 100644 --- a/apps/explorer/lib/explorer/chain/events/publisher.ex +++ b/apps/explorer/lib/explorer/chain/events/publisher.ex @@ -2,8 +2,7 @@ defmodule Explorer.Chain.Events.Publisher do @moduledoc """ Publishes events related to the Chain context. """ - alias Ecto.Adapters.SQL.Sandbox - alias Explorer.Repo + @sender Application.get_env(:explorer, :realtime_events_sender) @allowed_events ~w(addresses address_coin_balances blocks block_rewards internal_transactions token_transfers transactions contract_verification_result)a @@ -23,7 +22,7 @@ defmodule Explorer.Chain.Events.Publisher do defp send_data(event_type) do payload = encode_payload({:chain_event, event_type}) - send_notify(payload) + @sender.send_notify(payload) end # The :catchup type of event is not being consumed right now. @@ -33,7 +32,7 @@ defmodule Explorer.Chain.Events.Publisher do defp send_data(event_type, broadcast_type, event_data) do payload = encode_payload({:chain_event, event_type, broadcast_type, event_data}) - send_notify(payload) + @sender.send_notify(payload) end defp encode_payload(payload) do @@ -41,16 +40,4 @@ defmodule Explorer.Chain.Events.Publisher do |> :erlang.term_to_binary([:compressed]) |> Base.encode64() end - - defp send_notify(payload) do - fun = fn -> - Repo.query("select pg_notify('chain_event', $1::text);", [payload]) - end - - if Mix.env() == :test do - Sandbox.unboxed_run(Repo, fun) - else - fun.() - end - end end diff --git a/apps/explorer/lib/explorer/chain/events/sender.ex b/apps/explorer/lib/explorer/chain/events/sender.ex new file mode 100644 index 0000000000..f64728791f --- /dev/null +++ b/apps/explorer/lib/explorer/chain/events/sender.ex @@ -0,0 +1,12 @@ +defmodule Explorer.Chain.Events.Sender do + @moduledoc """ + Sends events to Postgres. + """ + alias Explorer.Repo + + @callback send_notify(String.t()) :: {:ok, any} + + def send_notify(payload) do + Repo.query!("select pg_notify('chain_event', $1::text);", [payload]) + end +end diff --git a/apps/explorer/lib/explorer/chain/events/sender_mock.ex b/apps/explorer/lib/explorer/chain/events/sender_mock.ex new file mode 100644 index 0000000000..44d55ab70d --- /dev/null +++ b/apps/explorer/lib/explorer/chain/events/sender_mock.ex @@ -0,0 +1,10 @@ +defmodule Explorer.Chain.Events.SenderMock do + @moduledoc """ + Sends events directly to Listener. + """ + alias Explorer.Chain.Events.Listener + + def send_notify(payload) do + send(Listener, {:notification, nil, nil, nil, payload}) + end +end diff --git a/apps/explorer/test/explorer/chain/events/publisher_test.exs b/apps/explorer/test/explorer/chain/events/publisher_test.exs index e0934a53dd..4a51627cc7 100644 --- a/apps/explorer/test/explorer/chain/events/publisher_test.exs +++ b/apps/explorer/test/explorer/chain/events/publisher_test.exs @@ -27,7 +27,7 @@ defmodule Explorer.Chain.Events.PublisherTest do Publisher.broadcast([{event_type, event_data}], broadcast_type) - refute_receive {:chain_event, ^event_type, ^broadcast_type, []} + refute_received {:chain_event, ^event_type, ^broadcast_type, []} end test "won't send event that is not allowed" do From 3e4e1bd2d6e5c0a261edacdc6dbd86f2d888b11d Mon Sep 17 00:00:00 2001 From: YegorSan Date: Tue, 8 Oct 2019 16:49:50 +0300 Subject: [PATCH 04/32] 422 page created --- .../static/images/errors-img/pic-404.svg | 27 +++++++++++++++++++ .../templates/422_page/index.html.eex | 13 +++++++++ 2 files changed, 40 insertions(+) create mode 100644 apps/block_scout_web/assets/static/images/errors-img/pic-404.svg create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/422_page/index.html.eex diff --git a/apps/block_scout_web/assets/static/images/errors-img/pic-404.svg b/apps/block_scout_web/assets/static/images/errors-img/pic-404.svg new file mode 100644 index 0000000000..0b4e8a594c --- /dev/null +++ b/apps/block_scout_web/assets/static/images/errors-img/pic-404.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/block_scout_web/lib/block_scout_web/templates/422_page/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/422_page/index.html.eex new file mode 100644 index 0000000000..4acd9e0125 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/422_page/index.html.eex @@ -0,0 +1,13 @@ +
+
+
+ Page Not Found +
+
+

Lorem Ipsum Dolor

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit, + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

+ Back Home +
+
+
\ No newline at end of file From ad68c42fe06e98b6ebeb9e64cd97499f5b4fc817 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 9 Oct 2019 16:50:52 +0300 Subject: [PATCH 05/32] add simple sender --- apps/explorer/config/config.exs | 2 +- apps/explorer/config/test.exs | 2 +- .../lib/explorer/chain/events/db_sender.ex | 28 +++++++++++++++++++ .../lib/explorer/chain/events/publisher.ex | 12 ++------ .../lib/explorer/chain/events/sender.ex | 12 -------- .../lib/explorer/chain/events/sender_mock.ex | 10 ------- .../explorer/chain/events/simple_sender.ex | 23 +++++++++++++++ 7 files changed, 55 insertions(+), 34 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/events/db_sender.ex delete mode 100644 apps/explorer/lib/explorer/chain/events/sender.ex delete mode 100644 apps/explorer/lib/explorer/chain/events/sender_mock.ex create mode 100644 apps/explorer/lib/explorer/chain/events/simple_sender.ex diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index fcff7aeea5..97f7391241 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -16,7 +16,7 @@ config :explorer, include_uncles_in_average_block_time: if(System.get_env("UNCLES_IN_AVERAGE_BLOCK_TIME") == "true", do: true, else: false), healthy_blocks_period: System.get_env("HEALTHY_BLOCKS_PERIOD") || :timer.minutes(5), - realtime_events_sender: Explorer.Chain.Events.Sender + realtime_events_sender: Explorer.Chain.Events.DBSender average_block_period = case Integer.parse(System.get_env("AVERAGE_BLOCK_CACHE_PERIOD", "")) do diff --git a/apps/explorer/config/test.exs b/apps/explorer/config/test.exs index c7061cd198..58050cba2c 100644 --- a/apps/explorer/config/test.exs +++ b/apps/explorer/config/test.exs @@ -44,7 +44,7 @@ config :explorer, Explorer.ExchangeRates.Source.TransactionAndLog, secondary_source: Explorer.ExchangeRates.Source.OneCoinSource config :explorer, - realtime_events_sender: Explorer.Chain.Events.SenderMock + realtime_events_sender: Explorer.Chain.Events.SimpleSender variant = if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do diff --git a/apps/explorer/lib/explorer/chain/events/db_sender.ex b/apps/explorer/lib/explorer/chain/events/db_sender.ex new file mode 100644 index 0000000000..0ea1c8eecf --- /dev/null +++ b/apps/explorer/lib/explorer/chain/events/db_sender.ex @@ -0,0 +1,28 @@ +defmodule Explorer.Chain.Events.DBSender do + @moduledoc """ + Sends events to Postgres. + """ + alias Explorer.Repo + + def send_data(event_type) do + payload = encode_payload({:chain_event, event_type}) + send_notify(payload) + end + + def send_data(_event_type, :catchup, _event_data), do: :ok + + def send_data(event_type, broadcast_type, event_data) do + payload = encode_payload({:chain_event, event_type, broadcast_type, event_data}) + send_notify(payload) + end + + defp encode_payload(payload) do + payload + |> :erlang.term_to_binary([:compressed]) + |> Base.encode64() + end + + defp send_notify(payload) do + Repo.query!("select pg_notify('chain_event', $1::text);", [payload]) + end +end diff --git a/apps/explorer/lib/explorer/chain/events/publisher.ex b/apps/explorer/lib/explorer/chain/events/publisher.ex index 11a7dc1518..142baee117 100644 --- a/apps/explorer/lib/explorer/chain/events/publisher.ex +++ b/apps/explorer/lib/explorer/chain/events/publisher.ex @@ -21,8 +21,7 @@ defmodule Explorer.Chain.Events.Publisher do end defp send_data(event_type) do - payload = encode_payload({:chain_event, event_type}) - @sender.send_notify(payload) + @sender.send_data(event_type) end # The :catchup type of event is not being consumed right now. @@ -31,13 +30,6 @@ defmodule Explorer.Chain.Events.Publisher do defp send_data(_event_type, :catchup, _event_data), do: :ok defp send_data(event_type, broadcast_type, event_data) do - payload = encode_payload({:chain_event, event_type, broadcast_type, event_data}) - @sender.send_notify(payload) - end - - defp encode_payload(payload) do - payload - |> :erlang.term_to_binary([:compressed]) - |> Base.encode64() + @sender.send_data(event_type, broadcast_type, event_data) end end diff --git a/apps/explorer/lib/explorer/chain/events/sender.ex b/apps/explorer/lib/explorer/chain/events/sender.ex deleted file mode 100644 index f64728791f..0000000000 --- a/apps/explorer/lib/explorer/chain/events/sender.ex +++ /dev/null @@ -1,12 +0,0 @@ -defmodule Explorer.Chain.Events.Sender do - @moduledoc """ - Sends events to Postgres. - """ - alias Explorer.Repo - - @callback send_notify(String.t()) :: {:ok, any} - - def send_notify(payload) do - Repo.query!("select pg_notify('chain_event', $1::text);", [payload]) - end -end diff --git a/apps/explorer/lib/explorer/chain/events/sender_mock.ex b/apps/explorer/lib/explorer/chain/events/sender_mock.ex deleted file mode 100644 index 44d55ab70d..0000000000 --- a/apps/explorer/lib/explorer/chain/events/sender_mock.ex +++ /dev/null @@ -1,10 +0,0 @@ -defmodule Explorer.Chain.Events.SenderMock do - @moduledoc """ - Sends events directly to Listener. - """ - alias Explorer.Chain.Events.Listener - - def send_notify(payload) do - send(Listener, {:notification, nil, nil, nil, payload}) - end -end diff --git a/apps/explorer/lib/explorer/chain/events/simple_sender.ex b/apps/explorer/lib/explorer/chain/events/simple_sender.ex new file mode 100644 index 0000000000..d72fe9b895 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/events/simple_sender.ex @@ -0,0 +1,23 @@ +defmodule Explorer.Chain.Events.SimpleSender do + @moduledoc """ + Publishes events through Registry without intermediate levels. + """ + + def send_data(event_type, broadcast_type, event_data) do + Registry.dispatch(Registry.ChainEvents, {event_type, broadcast_type}, fn entries -> + for {pid, _registered_val} <- entries do + send(pid, {:chain_event, event_type, broadcast_type, event_data}) + end + end) + end + + def send_data(_event_type, :catchup, _event_data), do: :ok + + def send_data(event_type) do + Registry.dispatch(Registry.ChainEvents, event_type, fn entries -> + for {pid, _registered_val} <- entries do + send(pid, {:chain_event, event_type}) + end + end) + end +end From 84b686b05484a411828196b02102af4d5f137524 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 9 Oct 2019 16:53:59 +0300 Subject: [PATCH 06/32] fix build --- apps/explorer/lib/explorer/chain/events/db_sender.ex | 2 -- apps/explorer/lib/explorer/chain/events/simple_sender.ex | 2 -- 2 files changed, 4 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/events/db_sender.ex b/apps/explorer/lib/explorer/chain/events/db_sender.ex index 0ea1c8eecf..2891e8bde2 100644 --- a/apps/explorer/lib/explorer/chain/events/db_sender.ex +++ b/apps/explorer/lib/explorer/chain/events/db_sender.ex @@ -9,8 +9,6 @@ defmodule Explorer.Chain.Events.DBSender do send_notify(payload) end - def send_data(_event_type, :catchup, _event_data), do: :ok - def send_data(event_type, broadcast_type, event_data) do payload = encode_payload({:chain_event, event_type, broadcast_type, event_data}) send_notify(payload) diff --git a/apps/explorer/lib/explorer/chain/events/simple_sender.ex b/apps/explorer/lib/explorer/chain/events/simple_sender.ex index d72fe9b895..f2a8da3e06 100644 --- a/apps/explorer/lib/explorer/chain/events/simple_sender.ex +++ b/apps/explorer/lib/explorer/chain/events/simple_sender.ex @@ -11,8 +11,6 @@ defmodule Explorer.Chain.Events.SimpleSender do end) end - def send_data(_event_type, :catchup, _event_data), do: :ok - def send_data(event_type) do Registry.dispatch(Registry.ChainEvents, event_type, fn entries -> for {pid, _registered_val} <- entries do From 5825782ecd566e151ba59d47520c3aab900c5ba6 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 9 Oct 2019 17:13:37 +0300 Subject: [PATCH 07/32] make sender configuerable --- apps/explorer/config/config.exs | 6 +++++- docs/env-variables.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 97f7391241..39124ba2e0 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -16,7 +16,11 @@ config :explorer, include_uncles_in_average_block_time: if(System.get_env("UNCLES_IN_AVERAGE_BLOCK_TIME") == "true", do: true, else: false), healthy_blocks_period: System.get_env("HEALTHY_BLOCKS_PERIOD") || :timer.minutes(5), - realtime_events_sender: Explorer.Chain.Events.DBSender + realtime_events_sender: + if(System.get_env("DISABLE_WEBAPP") != "true", + do: Explorer.Chain.Events.SimpleSender, + else: Explorer.Chain.Events.DBSender + ) average_block_period = case Integer.parse(System.get_env("AVERAGE_BLOCK_CACHE_PERIOD", "")) do diff --git a/docs/env-variables.md b/docs/env-variables.md index 88f4cfbc07..0aef06b1ae 100644 --- a/docs/env-variables.md +++ b/docs/env-variables.md @@ -59,7 +59,7 @@ $ export NETWORK=POA | `UNCLES_IN_AVERAGE_BLOCK_TIME` | Include or exclude nonconsensus blocks in avg block time calculation. Exclude if `false`. | false | v2.0.1+ | | | | `AVERAGE_BLOCK_CACHE_PERIOD` | | Update of average block cache, in seconds | 30 minutes | v2.0.2+ | | | `MARKET_HISTORY_CACHE_PERIOD` | | Update of market history cache, in seconds | 6 hours | v2.0.2+ | | -| `DISABLE_WEBAPP` | | If `true`, endpoints to webapp are hidden (compile-time) | `false` | v2.0.3+ | :white_check_mark: | | +| `DISABLE_WEBAPP` | | If `true`, endpoints to webapp are hidden (compile-time). Also, enabling it makes notifications go through `db_notify` | `false` | v2.0.3+ | :white_check_mark: | | | `DISABLE_READ_API` | | If `true`, read-only endpoints to API are hidden (compile-time) | `false` | v2.0.3+ | :white_check_mark: | | | `DISABLE_WRITE_API` | | If `true`, write endpoints to API are hidden (compile-time) | `false` | v2.0.3+ | :white_check_mark: | | | `DISABLE_INDEXER` | | If `true`, indexer application doesn't run | `false` | v2.0.3+ | :white_check_mark: | | From 1e570c1346a8b28d24043044ad3d537ad583abbc Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 10 Oct 2019 09:58:17 +0300 Subject: [PATCH 08/32] configure Explorer.Chain.Events.Listener --- apps/explorer/config/config.exs | 7 +++++++ apps/explorer/lib/explorer/application.ex | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 39124ba2e0..1ccc67dad3 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -32,6 +32,13 @@ config :explorer, Explorer.Counters.AverageBlockTime, enabled: true, period: average_block_period +config :explorer, Explorer.Chain.Events.Listener, + enabled: + if(System.get_env("DISABLE_WEBAPP") != "true", + do: false, + else: true + ) + config :explorer, Explorer.ChainSpec.GenesisData, enabled: true, chain_spec_path: System.get_env("CHAIN_SPEC_PATH"), diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 5af1477551..0752f60cea 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -49,7 +49,6 @@ defmodule Explorer.Application do {Admin.Recovery, [[], [name: Admin.Recovery]]}, TransactionCount, BlockCount, - Listener, Blocks, NetVersion, BlockNumber, @@ -74,6 +73,7 @@ defmodule Explorer.Application do configure(Explorer.ChainSpec.GenesisData), configure(Explorer.KnownTokens), configure(Explorer.Market.History.Cataloger), + configure(Explorer.Chain.Events.Listener), configure(Explorer.Counters.AddressesWithBalanceCounter), configure(Explorer.Counters.AddressesCounter), configure(Explorer.Counters.AverageBlockTime), From 5fe877e31650aab21995e3ca116dc7c8ea133196 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 10 Oct 2019 10:00:39 +0300 Subject: [PATCH 09/32] fix build --- apps/explorer/lib/explorer/application.ex | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 0752f60cea..4f3e5585f9 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -19,8 +19,6 @@ defmodule Explorer.Application do Uncles } - alias Explorer.Chain.Events.Listener - alias Explorer.Chain.Supply.RSK alias Explorer.Market.MarketHistoryCache From eb420803cc4c5e553f6ad1de45f174d4cdf904ca Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 10 Oct 2019 12:31:26 +0300 Subject: [PATCH 10/32] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b26ab858ad..93760864db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify - [#2733](https://github.com/poanetwork/blockscout/pull/2733) - Add cache for first page of uncles - [#2735](https://github.com/poanetwork/blockscout/pull/2735) - Add pending transactions cache - [#2726](https://github.com/poanetwork/blockscout/pull/2726) - Remove internal_transaction block_number setting from blocks runner From d7af9034c121493234975591575a12800cb5a06c Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 21 Oct 2019 12:47:22 +0300 Subject: [PATCH 11/32] add ipc client --- .../lib/ethereum_jsonrpc/ipc/IPCClient.ex | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex new file mode 100644 index 0000000000..ecadc47805 --- /dev/null +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex @@ -0,0 +1,58 @@ +defmodule EthereumJSONRPC.HTTP.IPCCLient do + use GenServer + @moduledoc false + + def start_link(state \\ []) do + GenServer.start_link(__MODULE__, Keyword.merge(state, socket: nil)) + end + + def init(state) do + opts = [:binary, active: false, reuseaddr: true] + + response = :gen_tcp.connect({:local, state[:path]}, 0, opts) + + case response do + {:ok, socket} -> {:ok, Keyword.put(state, :socket, socket)} + {:error, reason} -> {:error, reason} + end + end + + def post(pid, request) do + GenServer.call(pid, {:request, request}) + end + + def receive_response(data, socket, timeout, result \\ <<>>) + + def receive_response({:error, reason}, _socket, _timeout, _result) do + {:error, reason} + end + + def receive_response(:ok, socket, timeout, result) do + with {:ok, response} <- :gen_tcp.recv(socket, 0, timeout) do + new_result = result <> response + + if String.ends_with?(response, "\n") do + {:ok, new_result} + else + receive_response(:ok, socket, timeout, new_result) + end + end + end + + def receive_response(data, _socket, _timeout, _result) do + {:error, data} + end + + def handle_call( + {:request, request}, + _from, + [socket: socket, path: _, ipc_request_timeout: timeout] = state + ) do + response = + socket + |> :gen_tcp.send(request) + |> receive_response(socket, timeout) + + {:reply, response, state} + end +end From 87b1d515534391e4286ce4e878446faf7eaeca6a Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 21 Oct 2019 16:37:29 +0300 Subject: [PATCH 12/32] add json_rpc method --- .../{ipc/IPCClient.ex => ipc.ex} | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) rename apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/{ipc/IPCClient.ex => ipc.ex} (63%) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex similarity index 63% rename from apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex rename to apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex index ecadc47805..1d2d7dcea3 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc/IPCClient.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex @@ -1,7 +1,9 @@ -defmodule EthereumJSONRPC.HTTP.IPCCLient do +defmodule EthereumJSONRPC.IPC do use GenServer @moduledoc false + # Server + def start_link(state \\ []) do GenServer.start_link(__MODULE__, Keyword.merge(state, socket: nil)) end @@ -55,4 +57,31 @@ defmodule EthereumJSONRPC.HTTP.IPCCLient do {:reply, response, state} end + + # Client + + def json_rpc(pid, payload, _opts) do + with {:ok, response} <- post(pid, payload), + {:ok, decoded_body} <- Jason.decode(response) do + case decoded_body do + %{"error" => error} -> {:error, error} + result = [%{} | _] -> {:ok, format_batch(result)} + result -> {:ok, Map.get(result, "result")} + end + else + {:error, %Jason.DecodeError{data: ""}} -> {:error, :empty_response} + {:error, error} -> {:error, {:invalid_json, error}} + {:error, error} -> {:error, error} + end + end + + defp format_batch(list) do + list + |> Enum.sort(fn %{"id" => id1}, %{"id" => id2} -> + id1 <= id2 + end) + |> Enum.map(fn %{"result" => result} -> + result + end) + end end From db5d862c587191679aa7c27f9346860f8e38bd2c Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 10:38:05 +0300 Subject: [PATCH 13/32] fix listener init --- apps/explorer/config/config.exs | 2 +- apps/explorer/lib/explorer/chain/events/publisher.ex | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index ed88b4f6de..944626ae5b 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -36,7 +36,7 @@ config :explorer, Explorer.Counters.AverageBlockTime, config :explorer, Explorer.Chain.Events.Listener, enabled: - if(System.get_env("DISABLE_WEBAPP") != "true", + if((System.get_env("DISABLE_WEBAPP") == nil) && (System.get_env("DISABLE_INDEXER") == nil), do: false, else: true ) diff --git a/apps/explorer/lib/explorer/chain/events/publisher.ex b/apps/explorer/lib/explorer/chain/events/publisher.ex index 142baee117..6bdfe6eda4 100644 --- a/apps/explorer/lib/explorer/chain/events/publisher.ex +++ b/apps/explorer/lib/explorer/chain/events/publisher.ex @@ -2,7 +2,6 @@ defmodule Explorer.Chain.Events.Publisher do @moduledoc """ Publishes events related to the Chain context. """ - @sender Application.get_env(:explorer, :realtime_events_sender) @allowed_events ~w(addresses address_coin_balances blocks block_rewards internal_transactions token_transfers transactions contract_verification_result)a @@ -21,7 +20,11 @@ defmodule Explorer.Chain.Events.Publisher do end defp send_data(event_type) do - @sender.send_data(event_type) + sender().send_data(event_type) + end + + defp sender do + Application.get_env(:explorer, :realtime_events_sender) |> IO.inspect end # The :catchup type of event is not being consumed right now. @@ -30,6 +33,6 @@ defmodule Explorer.Chain.Events.Publisher do defp send_data(_event_type, :catchup, _event_data), do: :ok defp send_data(event_type, broadcast_type, event_data) do - @sender.send_data(event_type, broadcast_type, event_data) + sender().send_data(event_type, broadcast_type, event_data) end end From a9d67c61482ad4ba341cea5204d843fc461fef86 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 10:39:05 +0300 Subject: [PATCH 14/32] fix config --- apps/explorer/config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 944626ae5b..60b0afdb48 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -36,7 +36,7 @@ config :explorer, Explorer.Counters.AverageBlockTime, config :explorer, Explorer.Chain.Events.Listener, enabled: - if((System.get_env("DISABLE_WEBAPP") == nil) && (System.get_env("DISABLE_INDEXER") == nil), + if(System.get_env("DISABLE_WEBAPP") == nil && System.get_env("DISABLE_INDEXER") == nil, do: false, else: true ) From df2dda1fdbb053f461b29b269e72992f3f8cc34a Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 10:42:27 +0300 Subject: [PATCH 15/32] remove IO.inspect --- apps/explorer/lib/explorer/chain/events/publisher.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/events/publisher.ex b/apps/explorer/lib/explorer/chain/events/publisher.ex index 6bdfe6eda4..a392d15da8 100644 --- a/apps/explorer/lib/explorer/chain/events/publisher.ex +++ b/apps/explorer/lib/explorer/chain/events/publisher.ex @@ -24,7 +24,7 @@ defmodule Explorer.Chain.Events.Publisher do end defp sender do - Application.get_env(:explorer, :realtime_events_sender) |> IO.inspect + Application.get_env(:explorer, :realtime_events_sender) end # The :catchup type of event is not being consumed right now. From f03ead074cac4b19998a9183090ec30e42260cf6 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 14:25:36 +0300 Subject: [PATCH 16/32] start ipc server --- apps/ethereum_jsonrpc/config/config.exs | 5 +++++ .../lib/ethereum_jsonrpc/application.ex | 10 +++++++++- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/ethereum_jsonrpc/config/config.exs b/apps/ethereum_jsonrpc/config/config.exs index aa5ec08b49..a311073443 100644 --- a/apps/ethereum_jsonrpc/config/config.exs +++ b/apps/ethereum_jsonrpc/config/config.exs @@ -9,6 +9,11 @@ config :ethereum_jsonrpc, EthereumJSONRPC.RequestCoordinator, wait_per_timeout: :timer.seconds(20), max_jitter: :timer.seconds(2) +config :ethereum_jsonrpc, + rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", do: :http, else: :ipc), + ipc_path: System.get_env("IPC_PATH") + + # Add this configuration to add global RPC request throttling. # throttle_rate_limit: 250, # throttle_rolling_window_opts: [ diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex index 8c902e8f26..38af69a337 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex @@ -5,7 +5,7 @@ defmodule EthereumJSONRPC.Application do use Application - alias EthereumJSONRPC.{RequestCoordinator, RollingWindow} + alias EthereumJSONRPC.{IPC, RequestCoordinator, RollingWindow} @impl Application def start(_type, _args) do @@ -17,6 +17,7 @@ defmodule EthereumJSONRPC.Application do :hackney_pool.child_spec(:ethereum_jsonrpc, recv_timeout: 60_000, timeout: 60_000, max_connections: 1000), Supervisor.child_spec({RollingWindow, [rolling_window_opts]}, id: RollingWindow.ErrorThrottle) ] + |> add_ipc_client() |> add_throttle_rolling_window(config) |> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor) end @@ -37,4 +38,11 @@ defmodule EthereumJSONRPC.Application do children end end + + defp add_ipc_client(children) do + case Application.get_env(:ethereum_jsonrpc, :rpc_transport) do + :ipc -> [IPC.child_spec([path: Application.get_env(:ethereum_jsonrpc, :ipc_path)]) | children] + _ -> children + end + end end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex index 1d2d7dcea3..6c27ce4fcb 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex @@ -4,8 +4,19 @@ defmodule EthereumJSONRPC.IPC do # Server - def start_link(state \\ []) do - GenServer.start_link(__MODULE__, Keyword.merge(state, socket: nil)) + def child_spec(opts) do + IO.inspect(opts) + default = %{ + id: __MODULE__, + start: {__MODULE__, :start_link, opts}, + type: :worker + } + + Supervisor.child_spec(default, []) + end + + def start_link({:path, path}) do + GenServer.start_link(__MODULE__, [path: path, socket: nil]) end def init(state) do From 141ebda719d190faf711c37fa7d61142d1d8dc24 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 14:53:35 +0300 Subject: [PATCH 17/32] fix message handling --- apps/ethereum_jsonrpc/config/config.exs | 1 - .../lib/ethereum_jsonrpc/application.ex | 4 ++-- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex | 11 +++++------ apps/indexer/config/dev/parity.exs | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/ethereum_jsonrpc/config/config.exs b/apps/ethereum_jsonrpc/config/config.exs index a311073443..f7cf34afc9 100644 --- a/apps/ethereum_jsonrpc/config/config.exs +++ b/apps/ethereum_jsonrpc/config/config.exs @@ -13,7 +13,6 @@ config :ethereum_jsonrpc, rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", do: :http, else: :ipc), ipc_path: System.get_env("IPC_PATH") - # Add this configuration to add global RPC request throttling. # throttle_rate_limit: 250, # throttle_rolling_window_opts: [ diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex index 38af69a337..394c4de070 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex @@ -17,8 +17,8 @@ defmodule EthereumJSONRPC.Application do :hackney_pool.child_spec(:ethereum_jsonrpc, recv_timeout: 60_000, timeout: 60_000, max_connections: 1000), Supervisor.child_spec({RollingWindow, [rolling_window_opts]}, id: RollingWindow.ErrorThrottle) ] - |> add_ipc_client() |> add_throttle_rolling_window(config) + |> add_ipc_client() |> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor) end @@ -41,7 +41,7 @@ defmodule EthereumJSONRPC.Application do defp add_ipc_client(children) do case Application.get_env(:ethereum_jsonrpc, :rpc_transport) do - :ipc -> [IPC.child_spec([path: Application.get_env(:ethereum_jsonrpc, :ipc_path)]) | children] + :ipc -> [IPC.child_spec(path: Application.get_env(:ethereum_jsonrpc, :ipc_path)) | children] _ -> children end end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex index 6c27ce4fcb..992b99226b 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex @@ -5,7 +5,6 @@ defmodule EthereumJSONRPC.IPC do # Server def child_spec(opts) do - IO.inspect(opts) default = %{ id: __MODULE__, start: {__MODULE__, :start_link, opts}, @@ -16,7 +15,7 @@ defmodule EthereumJSONRPC.IPC do end def start_link({:path, path}) do - GenServer.start_link(__MODULE__, [path: path, socket: nil]) + GenServer.start_link(__MODULE__, [path: path, socket: nil], name: __MODULE__) end def init(state) do @@ -59,20 +58,20 @@ defmodule EthereumJSONRPC.IPC do def handle_call( {:request, request}, _from, - [socket: socket, path: _, ipc_request_timeout: timeout] = state + [socket: socket, path: _] = state ) do response = socket |> :gen_tcp.send(request) - |> receive_response(socket, timeout) + |> receive_response(socket, 500_000) {:reply, response, state} end # Client - def json_rpc(pid, payload, _opts) do - with {:ok, response} <- post(pid, payload), + def json_rpc(payload, _opts) do + with {:ok, response} <- post(__MODULE__, Jason.encode!(payload)), {:ok, decoded_body} <- Jason.decode(response) do case decoded_body do %{"error" => error} -> {:error, error} diff --git a/apps/indexer/config/dev/parity.exs b/apps/indexer/config/dev/parity.exs index 7a5b31a424..b5ec313191 100644 --- a/apps/indexer/config/dev/parity.exs +++ b/apps/indexer/config/dev/parity.exs @@ -3,7 +3,7 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: EthereumJSONRPC.IPC, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", From f0f3babd38732c2084fd1659d5f355bb1e9f408a Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 16:02:39 +0300 Subject: [PATCH 18/32] format result from ipc --- .../lib/ethereum_jsonrpc/http.ex | 6 ++-- .../lib/ethereum_jsonrpc/ipc.ex | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex index 6d9f946554..8e2c47dd0a 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex @@ -132,7 +132,7 @@ defmodule EthereumJSONRPC.HTTP do # restrict response to only those fields supported by the JSON-RPC 2.0 standard, which means that level of keys is # validated, so we can indicate that with switch to atom keys. - defp standardize_response(%{"jsonrpc" => "2.0" = jsonrpc, "id" => id} = unstandardized) do + def standardize_response(%{"jsonrpc" => "2.0" = jsonrpc, "id" => id} = unstandardized) do # Nethermind return string ids id = quantity_to_integer(id) @@ -155,8 +155,8 @@ defmodule EthereumJSONRPC.HTTP do # restrict error to only those fields supported by the JSON-RPC 2.0 standard, which means that level of keys is # validated, so we can indicate that with switch to atom keys. - defp standardize_error(%{"code" => code, "message" => message} = unstandardized) - when is_integer(code) and is_binary(message) do + def standardize_error(%{"code" => code, "message" => message} = unstandardized) + when is_integer(code) and is_binary(message) do standardized = %{code: code, message: message} case Map.fetch(unstandardized, "data") do diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex index 992b99226b..a387f9547f 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex @@ -2,6 +2,8 @@ defmodule EthereumJSONRPC.IPC do use GenServer @moduledoc false + import EthereumJSONRPC.HTTP, only: [standardize_response: 1] + # Server def child_spec(opts) do @@ -74,9 +76,20 @@ defmodule EthereumJSONRPC.IPC do with {:ok, response} <- post(__MODULE__, Jason.encode!(payload)), {:ok, decoded_body} <- Jason.decode(response) do case decoded_body do - %{"error" => error} -> {:error, error} - result = [%{} | _] -> {:ok, format_batch(result)} - result -> {:ok, Map.get(result, "result")} + %{"error" => error} -> + {:error, error} + + result = [%{} | _] -> + list = + result + |> Enum.reverse() + |> List.flatten() + |> Enum.map(&standardize_response/1) + + {:ok, list} + + result -> + {:ok, Map.get(result, "result")} end else {:error, %Jason.DecodeError{data: ""}} -> {:error, :empty_response} @@ -84,14 +97,4 @@ defmodule EthereumJSONRPC.IPC do {:error, error} -> {:error, error} end end - - defp format_batch(list) do - list - |> Enum.sort(fn %{"id" => id1}, %{"id" => id2} -> - id1 <= id2 - end) - |> Enum.map(fn %{"result" => result} -> - result - end) - end end From 2b4fa54a8eb257d68b46a5f1dd4fcf20957be8d5 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 16:09:45 +0300 Subject: [PATCH 19/32] allow to select IPC transport --- apps/indexer/config/dev/ganache.exs | 6 +++++- apps/indexer/config/dev/geth.exs | 6 +++++- apps/indexer/config/dev/parity.exs | 7 ++++++- apps/indexer/config/dev/rsk.exs | 6 +++++- apps/indexer/config/prod/ganache.exs | 6 +++++- apps/indexer/config/prod/geth.exs | 6 +++++- apps/indexer/config/prod/parity.exs | 6 +++++- apps/indexer/config/prod/rsk.exs | 6 +++++- 8 files changed, 41 insertions(+), 8 deletions(-) diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs index 337c2317c6..5ffdb90cf7 100644 --- a/apps/indexer/config/dev/ganache.exs +++ b/apps/indexer/config/dev/ganache.exs @@ -3,7 +3,11 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", diff --git a/apps/indexer/config/dev/geth.exs b/apps/indexer/config/dev/geth.exs index cf1113119d..a2fb7c8820 100644 --- a/apps/indexer/config/dev/geth.exs +++ b/apps/indexer/config/dev/geth.exs @@ -3,7 +3,11 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY", diff --git a/apps/indexer/config/dev/parity.exs b/apps/indexer/config/dev/parity.exs index b5ec313191..4526a76a5b 100644 --- a/apps/indexer/config/dev/parity.exs +++ b/apps/indexer/config/dev/parity.exs @@ -3,7 +3,12 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.IPC, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), + else: EthereumJSONRPC.IPC, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", diff --git a/apps/indexer/config/dev/rsk.exs b/apps/indexer/config/dev/rsk.exs index 3f7399e892..8ed8d2badf 100644 --- a/apps/indexer/config/dev/rsk.exs +++ b/apps/indexer/config/dev/rsk.exs @@ -5,7 +5,11 @@ config :indexer, blocks_concurrency: 1, receipts_concurrency: 1, json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", diff --git a/apps/indexer/config/prod/ganache.exs b/apps/indexer/config/prod/ganache.exs index 337c2317c6..5ffdb90cf7 100644 --- a/apps/indexer/config/prod/ganache.exs +++ b/apps/indexer/config/prod/ganache.exs @@ -3,7 +3,11 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", diff --git a/apps/indexer/config/prod/geth.exs b/apps/indexer/config/prod/geth.exs index 859d94319c..93af21654b 100644 --- a/apps/indexer/config/prod/geth.exs +++ b/apps/indexer/config/prod/geth.exs @@ -3,7 +3,11 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY", diff --git a/apps/indexer/config/prod/parity.exs b/apps/indexer/config/prod/parity.exs index dc9da031d5..38f662598e 100644 --- a/apps/indexer/config/prod/parity.exs +++ b/apps/indexer/config/prod/parity.exs @@ -3,7 +3,11 @@ use Mix.Config config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), diff --git a/apps/indexer/config/prod/rsk.exs b/apps/indexer/config/prod/rsk.exs index 81c8c4ac8a..4d90a5b4a3 100644 --- a/apps/indexer/config/prod/rsk.exs +++ b/apps/indexer/config/prod/rsk.exs @@ -5,7 +5,11 @@ config :indexer, blocks_concurrency: 1, receipts_concurrency: 1, json_rpc_named_arguments: [ - transport: EthereumJSONRPC.HTTP, + transport: + if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", + do: EthereumJSONRPC.HTTP, + else: EthereumJSONRPC.IPC + ), transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"), From 9dbe29f4d3a2f4dd9abc9a7ec02e35091739ad45 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 22 Oct 2019 16:24:22 +0300 Subject: [PATCH 20/32] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9d619acea..6a36e6c0db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2791](https://github.com/poanetwork/blockscout/pull/2791) - add ipc client - [#2772](https://github.com/poanetwork/blockscout/pull/2772) - add token instance images to the token inventory tab - [#2733](https://github.com/poanetwork/blockscout/pull/2733) - Add cache for first page of uncles - [#2735](https://github.com/poanetwork/blockscout/pull/2735) - Add pending transactions cache From 6769f5b31cd251930d3639fe11b08d9e7e60e8e8 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 24 Oct 2019 12:34:33 +0300 Subject: [PATCH 21/32] use poolboy for concurrent request execution --- .../lib/ethereum_jsonrpc/application.ex | 19 ++++++++++++++-- .../lib/ethereum_jsonrpc/ipc.ex | 22 +++++++------------ apps/ethereum_jsonrpc/mix.exs | 3 ++- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex index 394c4de070..6c9915f1cd 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex @@ -41,8 +41,23 @@ defmodule EthereumJSONRPC.Application do defp add_ipc_client(children) do case Application.get_env(:ethereum_jsonrpc, :rpc_transport) do - :ipc -> [IPC.child_spec(path: Application.get_env(:ethereum_jsonrpc, :ipc_path)) | children] - _ -> children + :ipc -> + [ + :poolboy.child_spec(:worker, poolboy_config(), path: Application.get_env(:ethereum_jsonrpc, :ipc_path)) + | children + ] + + _ -> + children end end + + defp poolboy_config do + [ + {:name, {:local, :ipc_worker}}, + {:worker_module, IPC}, + {:size, 10}, + {:max_overflow, 5} + ] + end end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex index a387f9547f..7f1ff401b0 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex @@ -6,18 +6,8 @@ defmodule EthereumJSONRPC.IPC do # Server - def child_spec(opts) do - default = %{ - id: __MODULE__, - start: {__MODULE__, :start_link, opts}, - type: :worker - } - - Supervisor.child_spec(default, []) - end - - def start_link({:path, path}) do - GenServer.start_link(__MODULE__, [path: path, socket: nil], name: __MODULE__) + def start_link(opts) do + GenServer.start_link(__MODULE__, Keyword.merge(opts, socket: nil)) end def init(state) do @@ -72,8 +62,8 @@ defmodule EthereumJSONRPC.IPC do # Client - def json_rpc(payload, _opts) do - with {:ok, response} <- post(__MODULE__, Jason.encode!(payload)), + def request(pid, payload) do + with {:ok, response} <- post(pid, Jason.encode!(payload)), {:ok, decoded_body} <- Jason.decode(response) do case decoded_body do %{"error" => error} -> @@ -97,4 +87,8 @@ defmodule EthereumJSONRPC.IPC do {:error, error} -> {:error, error} end end + + def json_rpc(payload, _opts) do + :poolboy.transaction(:ipc_worker, fn pid -> request(pid, payload) end, 600_000) + end end diff --git a/apps/ethereum_jsonrpc/mix.exs b/apps/ethereum_jsonrpc/mix.exs index 240a3aca52..2f5e58dc79 100644 --- a/apps/ethereum_jsonrpc/mix.exs +++ b/apps/ethereum_jsonrpc/mix.exs @@ -91,7 +91,8 @@ defmodule EthereumJsonrpc.MixProject do {:websocket_client, "~> 1.3"}, {:decimal, "~> 1.0"}, {:decorator, "~> 1.2"}, - {:hackney, "~> 1.15.2"} + {:hackney, "~> 1.15.2"}, + {:poolboy, "~> 1.5.2"} ] end end From 247b5fcb9816e675068051cddc45934f3340e1b9 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 24 Oct 2019 13:09:50 +0300 Subject: [PATCH 22/32] fix address_to_unique_tokens query --- apps/explorer/lib/explorer/chain/token_transfer.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index ef0cb4e876..900a57e759 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -280,7 +280,7 @@ defmodule Explorer.Chain.TokenTransfer do tt in TokenTransfer, left_join: instance in Instance, on: tt.token_contract_address_hash == instance.token_contract_address_hash and tt.token_id == instance.token_id, - where: tt.token_contract_address_hash == ^contract_address_hash and tt.token_id == tt.token_id, + where: tt.token_contract_address_hash == ^contract_address_hash, order_by: [desc: tt.block_number], distinct: tt.token_id, preload: [:to_address], From ea101ffdb603ed0c6be8953bb79a1cc5888e7cd1 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 24 Oct 2019 13:13:16 +0300 Subject: [PATCH 23/32] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ac75430a7..a777d66dc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes ### Chore +- [#2801](https://github.com/poanetwork/blockscout/pull/2801) - remove unused clause in address_to_unique_tokens query ## 2.1.0-beta From 7d56004111d03ffab7560b9d9a885aada42e6a99 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 25 Oct 2019 14:52:38 +0300 Subject: [PATCH 24/32] Fix block validator custom tooltip --- CHANGELOG.md | 1 + .../_custom_tooltips_block_details.scss | 51 ++----------------- .../templates/address/_link.html.eex | 2 +- .../address/_responsive_hash.html.eex | 6 ++- .../templates/block/_tile.html.eex | 3 +- .../templates/block/overview.html.eex | 5 +- .../templates/chain/_block.html.eex | 3 +- .../tokens/holder/_token_balances.html.eex | 2 +- .../tokens/inventory/_token.html.eex | 3 +- .../tokens/transfer/_token_transfer.html.eex | 6 ++- .../transaction/_pending_tile.html.eex | 4 +- .../_token_transfer.html.eex | 4 +- .../lib/block_scout_web/views/address_view.ex | 6 ++- apps/block_scout_web/priv/gettext/default.pot | 34 ++++++------- .../priv/gettext/en/LC_MESSAGES/default.po | 34 ++++++------- .../views/address_view_test.exs | 24 ++++++--- 16 files changed, 84 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e75b77e04..adb6693ae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify ### Fixes +- [#2803](https://github.com/poanetwork/blockscout/pull/2803) - Fix block validator custom tooltip ### Chore diff --git a/apps/block_scout_web/assets/css/components/_custom_tooltips_block_details.scss b/apps/block_scout_web/assets/css/components/_custom_tooltips_block_details.scss index 91eb3ad01a..e510c8e7a3 100644 --- a/apps/block_scout_web/assets/css/components/_custom_tooltips_block_details.scss +++ b/apps/block_scout_web/assets/css/components/_custom_tooltips_block_details.scss @@ -1,4 +1,5 @@ /* Custom Tooltips for Block Details Page */ +$tooltip-background-color: $btn-line-color !default; .tooltipCustom { position: relative; @@ -8,23 +9,20 @@ .tooltipCustom .tooltiptextTopMiner { visibility: hidden; position: absolute; - width: 50%; + width: 100%; background-color: white; - color: black; + color: $tooltip-background-color; text-align: center; border-radius: 6px; - left: 25%; + left: 0%; bottom: 100%; - padding: 15px 0px; + padding: 15px; display: inline-block; z-index: 1; font-family: Nunito; margin-bottom: 15px; opacity: 0; transition: opacity 0.5s; - @include media-breakpoint-down(lg) { - left: 60%; - } } .tooltipCustom .tooltiptextTopMiner::after { @@ -43,44 +41,5 @@ opacity: 1; } -.tooltipCustom .tooltiptextTopR { - visibility: hidden; - position: absolute; - width: 50%; - background-color: $primary; - color: white; - text-align: center; - border-radius: 6px; - left: 52%; - bottom: 120%; - padding: 15px 10px; - font-family: Nunito; - display: inline-block; - z-index: 1; - margin-bottom: 15px; - opacity: 0; - transition: opacity 0.5s; - @include media-breakpoint-down(lg) { - bottom: 100%; - padding: 9px 10px; - } -} - -.tooltipCustom .tooltiptextTopR::after { - content: ''; - position: absolute; - top: 100%; - left: 50%; - margin-left: -5px; - border-width: 5px; - border-style: solid; - border-color: $primary transparent transparent transparent; -} - -.tooltipCustom:hover .tooltiptextTopR { - visibility: visible; - opacity: 1; -} - /* Custom Tooltips for Block Details Page end*/ \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex index 08f35f222c..e57685a41f 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex @@ -1,5 +1,5 @@ <%= if @address do %> <%= link to: address_path(BlockScoutWeb.Endpoint, :show, @address), "data-test": "address_hash_link", class: assigns[:class] do %> - <%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address: @address, contract: @contract, truncate: assigns[:truncate] %> + <%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address: @address, contract: @contract, truncate: assigns[:truncate], use_custom_tooltip: @use_custom_tooltip %> <% end %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex index cad11f8ee6..85e97386a5 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex @@ -1,6 +1,10 @@ <%= if name = primary_name(@address) do %> - <%= name %> (<%= short_hash(@address) %>...) + <%= if @use_custom_tooltip == true do %> + <%= name %> (<%= short_hash(@address) %>...) + <% else %> + <%= name %> (<%= short_hash(@address) %>...) + <% end %> <% else %> <%= if assigns[:truncate] do %> <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/block/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/block/_tile.html.eex index 544fef63b3..143376a22a 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/block/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/block/_tile.html.eex @@ -39,7 +39,8 @@ <%= render BlockScoutWeb.AddressView, "_link.html", address: @block.miner, - contract: false %> + contract: false, + use_custom_tooltip: false %> <%= if show_reward?(@block.rewards) do %>
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 c2774ce4bd..f26167fa7e 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 @@ -124,7 +124,7 @@

<%= gettext "Miner" %>

- Validator's Name + <%= @block.miner %>

@@ -132,7 +132,8 @@ "_link.html", address: @block.miner, contract: false, - class: "" %> + class: "", + use_custom_tooltip: true %>

diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/_block.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/_block.html.eex index 0c86c88131..75f96d8c69 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/_block.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/_block.html.eex @@ -16,7 +16,8 @@ <%= render BlockScoutWeb.AddressView, "_link.html", address: @block.miner, - contract: false %> + contract: false, + use_custom_tooltip: false %> <%= if BlockScoutWeb.BlockView.show_reward?(@block.rewards) do %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/holder/_token_balances.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/holder/_token_balances.html.eex index 1c4cd5125b..105207a70c 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/holder/_token_balances.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/holder/_token_balances.html.eex @@ -2,7 +2,7 @@
- <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_balance.address, contract: BlockScoutWeb.AddressView.contract?(@token_balance.address) %> + <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_balance.address, contract: BlockScoutWeb.AddressView.contract?(@token_balance.address), use_custom_tooltip: false %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/_token.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/_token.html.eex index b99b082468..f4e70f59ac 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/_token.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/_token.html.eex @@ -20,7 +20,8 @@ <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_transfer.to_address, - contract: false %> + contract: false, + use_custom_tooltip: false %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex index 910ca1b737..1c2651a1cf 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex @@ -13,7 +13,8 @@ BlockScoutWeb.AddressView, "_responsive_hash.html", address: @token_transfer.from_address, - contract: BlockScoutWeb.AddressView.contract?(@token_transfer.from_address) + contract: BlockScoutWeb.AddressView.contract?(@token_transfer.from_address), + use_custom_tooltip: false ) %> <% end %> → @@ -22,7 +23,8 @@ BlockScoutWeb.AddressView, "_responsive_hash.html", address: @token_transfer.to_address, - contract: BlockScoutWeb.AddressView.contract?(@token_transfer.to_address) + contract: BlockScoutWeb.AddressView.contract?(@token_transfer.to_address), + use_custom_tooltip: false ) %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_pending_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_pending_tile.html.eex index f89a393501..7c8d7d733f 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_pending_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_pending_tile.html.eex @@ -8,10 +8,10 @@
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @transaction.hash %> - <%= render BlockScoutWeb.AddressView, "_link.html", address: @transaction.from_address, contract: BlockScoutWeb.AddressView.contract?(@transaction.from_address) %> + <%= render BlockScoutWeb.AddressView, "_link.html", address: @transaction.from_address, contract: BlockScoutWeb.AddressView.contract?(@transaction.from_address), use_custom_tooltip: false %> → <%= if @transaction.to_address_hash do %> - <%= render BlockScoutWeb.AddressView, "_link.html", address: @transaction.to_address, contract: BlockScoutWeb.AddressView.contract?(@transaction.to_address) %> + <%= render BlockScoutWeb.AddressView, "_link.html", address: @transaction.to_address, contract: BlockScoutWeb.AddressView.contract?(@transaction.to_address), use_custom_tooltip: false %> <% else %> <%= gettext("Contract Address Pending") %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex index 18d8bebed4..1bc1b34dc7 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex @@ -7,9 +7,9 @@
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @token_transfer.transaction_hash %> - <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_transfer.from_address, contract: BlockScoutWeb.AddressView.contract?(@token_transfer.from_address) %> + <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_transfer.from_address, contract: BlockScoutWeb.AddressView.contract?(@token_transfer.from_address), use_custom_tooltip: false %> → - <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_transfer.to_address, contract: BlockScoutWeb.AddressView.contract?(@token_transfer.to_address) %> + <%= render BlockScoutWeb.AddressView, "_link.html", address: @token_transfer.to_address, contract: BlockScoutWeb.AddressView.contract?(@token_transfer.to_address), use_custom_tooltip: false %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex index 15405beecb..4e86dc00df 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex @@ -271,7 +271,8 @@ defmodule BlockScoutWeb.AddressView do partial: "_responsive_hash.html", address: current_address, contract: contract?, - truncate: truncate + truncate: truncate, + use_custom_tooltip: false ] end @@ -281,7 +282,8 @@ defmodule BlockScoutWeb.AddressView do partial: "_link.html", address: address, contract: contract?, - truncate: truncate + truncate: truncate, + use_custom_tooltip: false ] end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index d8490ddc74..16498771d8 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -186,7 +186,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_link.html.eex:2 #: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:28 -#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:46 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:48 msgid "Block #%{number}" msgstr "" @@ -251,7 +251,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:32 #: lib/block_scout_web/templates/address/overview.html.eex:97 #: lib/block_scout_web/templates/address_validation/index.html.eex:13 -#: lib/block_scout_web/views/address_view.ex:311 +#: lib/block_scout_web/views/address_view.ex:313 msgid "Blocks Validated" msgstr "" @@ -305,13 +305,13 @@ msgstr "" #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149 -#: lib/block_scout_web/views/address_view.ex:307 +#: lib/block_scout_web/views/address_view.ex:309 msgid "Code" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:20 -#: lib/block_scout_web/views/address_view.ex:310 +#: lib/block_scout_web/views/address_view.ex:312 msgid "Coin Balance History" msgstr "" @@ -526,7 +526,7 @@ msgid "Decoded" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:308 +#: lib/block_scout_web/views/address_view.ex:310 msgid "Decompiled Code" msgstr "" @@ -546,16 +546,16 @@ msgid "Decompiler version" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/_tile.html.eex:56 +#: 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:158 +#: lib/block_scout_web/templates/block/overview.html.eex:159 msgid "Gas Limit" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/_tile.html.eex:61 +#: lib/block_scout_web/templates/block/_tile.html.eex:62 #: lib/block_scout_web/templates/block/overview.html.eex:101 -#: lib/block_scout_web/templates/block/overview.html.eex:152 +#: lib/block_scout_web/templates/block/overview.html.eex:153 msgid "Gas Used" msgstr "" @@ -934,7 +934,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:8 #: lib/block_scout_web/templates/address_token/index.html.eex:8 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:9 -#: lib/block_scout_web/views/address_view.ex:304 +#: lib/block_scout_web/views/address_view.ex:306 msgid "Tokens" msgstr "" @@ -987,7 +987,7 @@ msgstr "" #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 -#: lib/block_scout_web/views/address_view.ex:306 +#: lib/block_scout_web/views/address_view.ex:308 #: lib/block_scout_web/views/transaction_view.ex:314 msgid "Internal Transactions" msgstr "" @@ -1076,7 +1076,7 @@ msgstr "" #: lib/block_scout_web/templates/address_logs/index.html.eex:8 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 -#: lib/block_scout_web/views/address_view.ex:312 +#: lib/block_scout_web/views/address_view.ex:314 #: lib/block_scout_web/views/transaction_view.ex:315 msgid "Logs" msgstr "" @@ -1267,7 +1267,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:58 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25 -#: lib/block_scout_web/views/address_view.ex:309 +#: lib/block_scout_web/views/address_view.ex:311 #: lib/block_scout_web/views/tokens/overview_view.ex:37 msgid "Read Contract" msgstr "" @@ -1301,8 +1301,8 @@ msgid "Responses" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/_tile.html.eex:47 -#: lib/block_scout_web/templates/chain/_block.html.eex:23 +#: lib/block_scout_web/templates/block/_tile.html.eex:48 +#: lib/block_scout_web/templates/chain/_block.html.eex:24 #: lib/block_scout_web/views/internal_transaction_view.ex:28 msgid "Reward" msgstr "" @@ -1366,7 +1366,7 @@ msgid "Show Validator Info" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/overview.html.eex:145 +#: lib/block_scout_web/templates/block/overview.html.eex:146 msgid "Block Rewards" msgstr "" @@ -1559,7 +1559,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:145 #: lib/block_scout_web/templates/layout/_topnav.html.eex:64 -#: lib/block_scout_web/views/address_view.ex:305 +#: lib/block_scout_web/views/address_view.ex:307 msgid "Transactions" 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 d8490ddc74..16498771d8 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 @@ -186,7 +186,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_link.html.eex:2 #: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:28 -#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:46 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:48 msgid "Block #%{number}" msgstr "" @@ -251,7 +251,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:32 #: lib/block_scout_web/templates/address/overview.html.eex:97 #: lib/block_scout_web/templates/address_validation/index.html.eex:13 -#: lib/block_scout_web/views/address_view.ex:311 +#: lib/block_scout_web/views/address_view.ex:313 msgid "Blocks Validated" msgstr "" @@ -305,13 +305,13 @@ msgstr "" #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149 -#: lib/block_scout_web/views/address_view.ex:307 +#: lib/block_scout_web/views/address_view.ex:309 msgid "Code" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:20 -#: lib/block_scout_web/views/address_view.ex:310 +#: lib/block_scout_web/views/address_view.ex:312 msgid "Coin Balance History" msgstr "" @@ -526,7 +526,7 @@ msgid "Decoded" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:308 +#: lib/block_scout_web/views/address_view.ex:310 msgid "Decompiled Code" msgstr "" @@ -546,16 +546,16 @@ msgid "Decompiler version" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/_tile.html.eex:56 +#: 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:158 +#: lib/block_scout_web/templates/block/overview.html.eex:159 msgid "Gas Limit" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/_tile.html.eex:61 +#: lib/block_scout_web/templates/block/_tile.html.eex:62 #: lib/block_scout_web/templates/block/overview.html.eex:101 -#: lib/block_scout_web/templates/block/overview.html.eex:152 +#: lib/block_scout_web/templates/block/overview.html.eex:153 msgid "Gas Used" msgstr "" @@ -934,7 +934,7 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:8 #: lib/block_scout_web/templates/address_token/index.html.eex:8 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:9 -#: lib/block_scout_web/views/address_view.ex:304 +#: lib/block_scout_web/views/address_view.ex:306 msgid "Tokens" msgstr "" @@ -987,7 +987,7 @@ msgstr "" #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 -#: lib/block_scout_web/views/address_view.ex:306 +#: lib/block_scout_web/views/address_view.ex:308 #: lib/block_scout_web/views/transaction_view.ex:314 msgid "Internal Transactions" msgstr "" @@ -1076,7 +1076,7 @@ msgstr "" #: lib/block_scout_web/templates/address_logs/index.html.eex:8 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 -#: lib/block_scout_web/views/address_view.ex:312 +#: lib/block_scout_web/views/address_view.ex:314 #: lib/block_scout_web/views/transaction_view.ex:315 msgid "Logs" msgstr "" @@ -1267,7 +1267,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:58 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25 -#: lib/block_scout_web/views/address_view.ex:309 +#: lib/block_scout_web/views/address_view.ex:311 #: lib/block_scout_web/views/tokens/overview_view.ex:37 msgid "Read Contract" msgstr "" @@ -1301,8 +1301,8 @@ msgid "Responses" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/_tile.html.eex:47 -#: lib/block_scout_web/templates/chain/_block.html.eex:23 +#: lib/block_scout_web/templates/block/_tile.html.eex:48 +#: lib/block_scout_web/templates/chain/_block.html.eex:24 #: lib/block_scout_web/views/internal_transaction_view.ex:28 msgid "Reward" msgstr "" @@ -1366,7 +1366,7 @@ msgid "Show Validator Info" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/overview.html.eex:145 +#: lib/block_scout_web/templates/block/overview.html.eex:146 msgid "Block Rewards" msgstr "" @@ -1559,7 +1559,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:145 #: lib/block_scout_web/templates/layout/_topnav.html.eex:64 -#: lib/block_scout_web/views/address_view.ex:305 +#: lib/block_scout_web/views/address_view.ex:307 msgid "Transactions" msgstr "" diff --git a/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs index 6522f20459..97544754ec 100644 --- a/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs @@ -32,7 +32,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_link.html", address: ^to_address, contract: false, - truncate: true + truncate: true, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, nil, true) end @@ -44,7 +45,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_link.html", address: ^to_address, contract: false, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, nil) end @@ -56,7 +58,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_link.html", address: ^to_address, contract: false, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, nil) end @@ -68,7 +71,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_responsive_hash.html", address: ^to_address, contract: false, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, transaction.to_address) end @@ -81,7 +85,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_link.html", address: ^contract_address, contract: true, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, transaction.to_address) end @@ -94,7 +99,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_responsive_hash.html", address: ^contract_address, contract: true, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, contract_address) end @@ -106,7 +112,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_link.html", address: ^to_address, contract: false, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :to, nil) end @@ -118,7 +125,8 @@ defmodule BlockScoutWeb.AddressViewTest do partial: "_responsive_hash.html", address: ^from_address, contract: false, - truncate: false + truncate: false, + use_custom_tooltip: false ] = AddressView.address_partial_selector(transaction, :from, transaction.from_address) end end From c434e2546bb8c324b12cfdcd70bc6a74e156afb2 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 25 Oct 2019 17:57:21 +0300 Subject: [PATCH 25/32] Update supported chains --- CHANGELOG.md | 1 + .../lib/block_scout_web/views/layout_view.ex | 29 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e75b77e04..3738fd1ad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes ### Chore +- [#2805](https://github.com/poanetwork/blockscout/pull/2805) - Update supported chains default option ## 2.1.0-beta diff --git a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex index b2d80f28f9..51763750d5 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex @@ -19,45 +19,16 @@ defmodule BlockScoutWeb.LayoutView do title: "xDai Chain", url: "https://blockscout.com/poa/dai" }, - %{ - title: "Ethereum Mainnet", - url: "https://blockscout.com/eth/mainnet" - }, %{ title: "Kovan Testnet", url: "https://blockscout.com/eth/kovan", test_net?: true }, - %{ - title: "Ropsten Testnet", - url: "https://blockscout.com/eth/ropsten", - test_net?: true - }, - %{ - title: "Goerli Testnet", - url: "https://blockscout.com/eth/goerli", - test_net?: true - }, - %{ - title: "Rinkeby Testnet", - url: "https://blockscout.com/eth/rinkeby", - test_net?: true - }, %{ title: "Ethereum Classic", url: "https://blockscout.com/etc/mainnet", other?: true }, - %{ - title: "Aerum Mainnet", - url: "https://blockscout.com/aerum/mainnet", - other?: true - }, - %{ - title: "Callisto Mainnet", - url: "https://blockscout.com/callisto/mainnet", - other?: true - }, %{ title: "RSK Mainnet", url: "https://blockscout.com/rsk/mainnet", From bc7d297c6fffc51a9a15bbb1abbbab6946b3e0f3 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 25 Oct 2019 19:31:24 +0300 Subject: [PATCH 26/32] Fix blocks fetching on the main page --- CHANGELOG.md | 1 + apps/block_scout_web/assets/js/pages/chain.js | 4 +- .../templates/chain/show.html.eex | 64 +++++++++---------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e75b77e04..8f9fb203fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify ### Fixes +- [#2806](https://github.com/poanetwork/blockscout/pull/2806) - Fix blocks fetching on the main page ### Chore diff --git a/apps/block_scout_web/assets/js/pages/chain.js b/apps/block_scout_web/assets/js/pages/chain.js index df89d92f36..30e982553c 100644 --- a/apps/block_scout_web/assets/js/pages/chain.js +++ b/apps/block_scout_web/assets/js/pages/chain.js @@ -68,10 +68,10 @@ function baseReducer (state = initialState, action) { return Object.assign({}, state, { blocksLoading: false }) } case 'BLOCKS_FETCHED': { - return Object.assign({}, state, { blocks: [...action.msg.blocks] }) + return Object.assign({}, state, { blocks: [...action.msg.blocks], blocksLoading: false }) } case 'BLOCKS_REQUEST_ERROR': { - return Object.assign({}, state, { blocksError: true }) + return Object.assign({}, state, { blocksError: true, blocksLoading: false }) } case 'RECEIVED_NEW_EXCHANGE_RATE': { return Object.assign({}, state, { diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index cb42c2c338..df3c6728b1 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -91,49 +91,49 @@ <%= gettext "Something went wrong, click to reload." %> - diff --git a/apps/block_scout_web/lib/block_scout_web/views/error_422.ex b/apps/block_scout_web/lib/block_scout_web/views/error_422.ex new file mode 100644 index 0000000000..b813dc9383 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/views/error_422.ex @@ -0,0 +1,5 @@ +defmodule BlockScoutWeb.Error422View do + use BlockScoutWeb, :view + + @dialyzer :no_match +end From 1171096dbba23ad3b0d458eb3ea175dab2010148 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 28 Oct 2019 14:07:42 +0300 Subject: [PATCH 29/32] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e75b77e04..9c45eee1cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes ### Chore +- [#2807](https://github.com/poanetwork/blockscout/pull/2807) - 422 page ## 2.1.0-beta From 440593b219c3a943d664bb607ff6d57bf7a7eebe Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 28 Oct 2019 15:44:30 +0300 Subject: [PATCH 30/32] Add tooltip for tx input --- CHANGELOG.md | 1 + .../templates/transaction/overview.html.eex | 1 + apps/block_scout_web/priv/gettext/default.pot | 21 ++++++++++++------- .../priv/gettext/en/LC_MESSAGES/default.po | 21 ++++++++++++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e75b77e04..4f278cef33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes ### Chore +- [#2808](https://github.com/poanetwork/blockscout/pull/2808) - Add tooltip for tx input ## 2.1.0-beta diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex index c228ec9877..68f6fe98b8 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex @@ -131,6 +131,7 @@ data-clipboard-text="<%= @transaction.input %>" data-placement="top" data-toggle="tooltip" + title='<%= gettext("Copy Txn Input") %>' > diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index d8490ddc74..4864cce5c7 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -13,7 +13,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:193 msgid " Token Transfer" msgstr "" @@ -678,8 +678,8 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:62 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:29 -#: lib/block_scout_web/templates/transaction/overview.html.eex:179 -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:180 +#: lib/block_scout_web/templates/transaction/overview.html.eex:215 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -1048,7 +1048,7 @@ msgid "License ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:242 +#: lib/block_scout_web/templates/transaction/overview.html.eex:243 msgid "Limit" msgstr "" @@ -1620,7 +1620,7 @@ msgid "Use the search box to find a hosted network, or select from the list of a msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:236 +#: lib/block_scout_web/templates/transaction/overview.html.eex:237 msgid "Used" msgstr "" @@ -1650,8 +1650,8 @@ msgid "Validator Info" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:179 -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:180 +#: lib/block_scout_web/templates/transaction/overview.html.eex:215 msgid "Value" msgstr "" @@ -1826,7 +1826,7 @@ msgid "Decimals" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:232 +#: lib/block_scout_web/templates/transaction/overview.html.eex:233 msgid "Gas" msgstr "" @@ -1872,3 +1872,8 @@ msgstr "" #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:67 msgid "Transfers" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:134 +msgid "Copy Txn Input" +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 d8490ddc74..4864cce5c7 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 @@ -13,7 +13,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:193 msgid " Token Transfer" msgstr "" @@ -678,8 +678,8 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:62 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:29 -#: lib/block_scout_web/templates/transaction/overview.html.eex:179 -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:180 +#: lib/block_scout_web/templates/transaction/overview.html.eex:215 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -1048,7 +1048,7 @@ msgid "License ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:242 +#: lib/block_scout_web/templates/transaction/overview.html.eex:243 msgid "Limit" msgstr "" @@ -1620,7 +1620,7 @@ msgid "Use the search box to find a hosted network, or select from the list of a msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:236 +#: lib/block_scout_web/templates/transaction/overview.html.eex:237 msgid "Used" msgstr "" @@ -1650,8 +1650,8 @@ msgid "Validator Info" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:179 -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:180 +#: lib/block_scout_web/templates/transaction/overview.html.eex:215 msgid "Value" msgstr "" @@ -1826,7 +1826,7 @@ msgid "Decimals" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:232 +#: lib/block_scout_web/templates/transaction/overview.html.eex:233 msgid "Gas" msgstr "" @@ -1872,3 +1872,8 @@ msgstr "" #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:67 msgid "Transfers" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:134 +msgid "Copy Txn Input" +msgstr "" From 87c99e090ca2afb1756b83b8cf5ddd2483787913 Mon Sep 17 00:00:00 2001 From: Andrew Gross Date: Mon, 28 Oct 2019 22:12:02 -0600 Subject: [PATCH 31/32] link docker instructions to doc website --- docker/README.md | 78 ++---------------------------------------------- 1 file changed, 3 insertions(+), 75 deletions(-) diff --git a/docker/README.md b/docker/README.md index ba3458883d..03df272c4a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,77 +1,5 @@ -# BlockScout Docker integration +# BlockScout Docker Integration -For now this integration is not production ready. It made only for local usage only ! - -## How to use ? -First of all, blockscout requires `PostgreSQL` server for working. -It will be provided by starting script (new docker image will be created named `postgres`) - -**Starting command** -`make start` - will set everything up and start blockscout in container. -To connect it to your local environment you will have to configure it using [env variables](#env-variables) - -Example connecting to local `ganache` instance running on port `2000` on Mac/Windows: -```bash -COIN=DAI \ -ETHEREUM_JSONRPC_VARIANT=ganache \ -ETHEREUM_JSONRPC_HTTP_URL=http://host.docker.internal:2000 \ -ETHEREUM_JSONRPC_WS_URL=ws://host.docker.internal:2000 \ -make start -``` - -Blockscout will be available on `localhost:4000` - -**Note** -On mac/Windows Docker provides with a special URL `host.docker.internal` that will be available into container and routed to your local machine. -On Linux docker is starting using `--network=host` and all services should be available on `localhost` - -### Migrations - -By default, `Makefile` will do migrations for you on `PostgreSQL` creation. -But you could run migrations manually using `make migrate` command. - -**WARNING** Migrations will clean up your local database ! - -## Env variables - -BlockScout supports 3 different JSON RPC Variants. -Variant could be configured using `ETHEREUM_JSONRPC_VARIANT` environment variable. - -Example: -```bash -ETHEREUM_JSONRPC_VARIANT=ganache make start -``` - -Available options are: - - * `parity` - Parity JSON RPC (**Default one**) - * `geth` - Geth JSON RPC - * `ganache` - Ganache JSON RPC - - -| Variable | Description | Default value | -| -------- | ----------- | ------------- | -| `ETHEREUM_JSONRPC_VARIANT` | Variant of your JSON RPC service: `parity`, `geth` or `ganache` | `parity` | -| `ETHEREUM_JSONRPC_HTTP_URL` | HTTP JSON RPC URL Only for `geth` or `ganache` variant | Different per JSONRPC variant | -| `ETHEREUM_JSONRPC_WS_URL` | WS JSON RPC url | Different per JSONRPC variant | -| `ETHEREUM_JSONRPC_TRACE_URL` | Trace URL **Only for `parity` variant** | `http://localhost:8545` | -| `COIN` | Default Coin | `POA` | -| `LOGO` | Coin logo | Empty | -| `NETWORK` | Network | Empty | -| `SUBNETWORK` | Subnetwork | Empty | -| `NETWORK_ICON` | Network icon | Empty | -| `NETWORK_PATH` | Network path | `/` | - - -`ETHEREUM_JSONRPC_HTTP_URL` default values: - - * For `parity` - `http://localhost:8545` - * For `geth` - `https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY` - * For `ganache` - `http://localhost:7545` - -`ETHEREUM_JSONRPC_WS_URL` default values: - - * For `parity` - `ws://localhost:8546` - * For `geth` - `wss://mainnet.infura.io/8lTvJTKmHPCHazkneJsY/ws` - * For `ganache` - `ws://localhost:7545` +This integration is not production ready, and should be used for local BlockScout deployment only. +For usage instructions and ENV variables, see the [docker integration documentation](https://docs.blockscout.com/for-developers/information-and-settings/docker-integration-local-use-only). \ No newline at end of file From fd1f7d8dfdc4fe237d620ded72de26d5ce6b65ae Mon Sep 17 00:00:00 2001 From: Andrew Gross Date: Mon, 28 Oct 2019 22:16:13 -0600 Subject: [PATCH 32/32] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e75b77e04..18b1ad3994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes ### Chore +- [#2817](https://github.com/poanetwork/blockscout/pull/2817) - move docker integration documentation to blockscout docs ## 2.1.0-beta