Merge branch 'master' into ab-cache-for-chart-data

pull/2182/head
Ayrat Badykov 6 years ago committed by GitHub
commit 583e86996a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      CHANGELOG.md
  2. 1
      apps/block_scout_web/assets/js/lib/currency.js
  3. 5
      apps/block_scout_web/lib/block_scout_web/channels/reward_channel.ex
  4. 3
      apps/block_scout_web/lib/block_scout_web/controllers/pending_transaction_controller.ex
  5. 12
      apps/block_scout_web/lib/block_scout_web/views/wei_helpers.ex
  6. 6
      apps/block_scout_web/priv/gettext/default.pot
  7. 6
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  8. 2
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex
  9. 6
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity/fetched_beneficiaries.ex
  10. 6
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/block_test.exs
  11. 3
      apps/explorer/lib/explorer/chain.ex
  12. 2
      apps/explorer/lib/explorer/counters/average_block_time.ex
  13. 4
      apps/explorer/lib/explorer/exchange_rates/source.ex
  14. 7
      apps/explorer/priv/repo/migrations/20190613065856_add_tx_hash_inserted_at_index.exs
  15. 34
      apps/explorer/test/explorer/counters/average_block_time_test.exs
  16. 2
      docker/Dockerfile

@ -6,6 +6,11 @@
- [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty - [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty
### Fixes ### Fixes
- [#2179](https://github.com/poanetwork/blockscout/pull/2179) - fix docker build error
- [#2165](https://github.com/poanetwork/blockscout/pull/2165) - sort blocks by timestamp when calculating average block time
- [#2175](https://github.com/poanetwork/blockscout/pull/2175) - fix coinmarketcap response errors
- [#2164](https://github.com/poanetwork/blockscout/pull/2164) - fix large numbers in balance view card
- [#2155](https://github.com/poanetwork/blockscout/pull/2155) - fix pending transaction query
- [#2183](https://github.com/poanetwork/blockscout/pull/2183) - tile content aligning for mobile resolution fix, dai logo fix - [#2183](https://github.com/poanetwork/blockscout/pull/2183) - tile content aligning for mobile resolution fix, dai logo fix
- [#2162](https://github.com/poanetwork/blockscout/pull/2162) - contract creation tile color changed - [#2162](https://github.com/poanetwork/blockscout/pull/2162) - contract creation tile color changed
- [#2144](https://github.com/poanetwork/blockscout/pull/2144) - 'page not found' images path fixed for goerli - [#2144](https://github.com/poanetwork/blockscout/pull/2144) - 'page not found' images path fixed for goerli
@ -29,6 +34,9 @@
- [#2130](https://github.com/poanetwork/blockscout/pull/2130) - fix navigation - [#2130](https://github.com/poanetwork/blockscout/pull/2130) - fix navigation
- [#2147](https://github.com/poanetwork/blockscout/pull/2147) - add rsk format of checksum - [#2147](https://github.com/poanetwork/blockscout/pull/2147) - add rsk format of checksum
- [#2149](https://github.com/poanetwork/blockscout/pull/2149) - remove pending transaction count - [#2149](https://github.com/poanetwork/blockscout/pull/2149) - remove pending transaction count
- [#2169](https://github.com/poanetwork/blockscout/pull/2169) - add more validator reward types for xDai
- [#2173](https://github.com/poanetwork/blockscout/pull/2173) - handle correctly empty transactions
- [#2174](https://github.com/poanetwork/blockscout/pull/2174) - fix reward channel joining
- [#2186](https://github.com/poanetwork/blockscout/pull/2186) - fix net version test - [#2186](https://github.com/poanetwork/blockscout/pull/2186) - fix net version test
### Chore ### Chore

@ -18,6 +18,7 @@ function formatCurrencyValue (value, symbol) {
if (value < 0.000001) return `${window.localized['Less than']} ${symbol}0.000001` if (value < 0.000001) return `${window.localized['Less than']} ${symbol}0.000001`
if (value < 1) return `${symbol}${numeral(value).format('0.000000')}` if (value < 1) return `${symbol}${numeral(value).format('0.000000')}`
if (value < 100000) return `${symbol}${numeral(value).format('0,0.00')}` if (value < 100000) return `${symbol}${numeral(value).format('0,0.00')}`
if (value > 1000000000) return `${symbol}${numeral(value).format('0.000e+0')}`
return `${symbol}${numeral(value).format('0,0')}` return `${symbol}${numeral(value).format('0,0')}`
} }

@ -11,10 +11,11 @@ defmodule BlockScoutWeb.RewardChannel do
intercept(["new_reward"]) intercept(["new_reward"])
def join("rewards:" <> address_hash, _params, socket) do def join("rewards:" <> address_hash, _params, socket) do
{:ok, hash} = Chain.string_to_address_hash(address_hash) with {:ok, hash} <- Chain.string_to_address_hash(address_hash),
{:ok, address} = Chain.hash_to_address(hash) {:ok, address} <- Chain.hash_to_address(hash) do
{:ok, %{}, assign(socket, :current_address, address)} {:ok, %{}, assign(socket, :current_address, address)}
end end
end
def handle_out("new_reward", %{emission_funds: emission_funds, validator: validator}, socket) do def handle_out("new_reward", %{emission_funds: emission_funds, validator: validator}, socket) do
Gettext.put_locale(BlockScoutWeb.Gettext, socket.assigns.locale) Gettext.put_locale(BlockScoutWeb.Gettext, socket.assigns.locale)

@ -13,7 +13,8 @@ defmodule BlockScoutWeb.PendingTransactionController do
[ [
necessity_by_association: %{ necessity_by_association: %{
[from_address: :names] => :optional, [from_address: :names] => :optional,
[to_address: :names] => :optional [to_address: :names] => :optional,
[created_contract_address: :names] => :optional
} }
], ],
paging_options(params) paging_options(params)

@ -57,13 +57,19 @@ defmodule BlockScoutWeb.WeiHelpers do
converted_value = converted_value =
wei wei
|> Wei.to(unit) |> Wei.to(unit)
|> Cldr.Number.to_string!(format: "#,##0.##################")
formatted_value =
if Decimal.cmp(converted_value, 1_000_000_000_000) == :gt do
Cldr.Number.to_string!(converted_value, format: "0.###E+0")
else
Cldr.Number.to_string!(converted_value, format: "#,##0.##################")
end
if Keyword.get(options, :include_unit_label, true) do if Keyword.get(options, :include_unit_label, true) do
display_unit = display_unit(unit) display_unit = display_unit(unit)
"#{converted_value} #{display_unit}" "#{formatted_value} #{display_unit}"
else else
converted_value formatted_value
end end
end end

@ -378,7 +378,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:30 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30
#: lib/block_scout_web/templates/transaction/overview.html.eex:192 #: lib/block_scout_web/templates/transaction/overview.html.eex:192
#: lib/block_scout_web/views/wei_helpers.ex:72 #: lib/block_scout_web/views/wei_helpers.ex:78
msgid "Ether" msgid "Ether"
msgstr "" msgstr ""
@ -436,7 +436,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/block_view.ex:20 #: lib/block_scout_web/views/block_view.ex:20
#: lib/block_scout_web/views/wei_helpers.ex:71 #: lib/block_scout_web/views/wei_helpers.ex:77
msgid "Gwei" msgid "Gwei"
msgstr "" msgstr ""
@ -982,7 +982,7 @@ msgid "Wallet addresses"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/wei_helpers.ex:70 #: lib/block_scout_web/views/wei_helpers.ex:76
msgid "Wei" msgid "Wei"
msgstr "" msgstr ""

@ -378,7 +378,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:30 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30
#: lib/block_scout_web/templates/transaction/overview.html.eex:192 #: lib/block_scout_web/templates/transaction/overview.html.eex:192
#: lib/block_scout_web/views/wei_helpers.ex:72 #: lib/block_scout_web/views/wei_helpers.ex:78
msgid "Ether" msgid "Ether"
msgstr "POA" msgstr "POA"
@ -436,7 +436,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/block_view.ex:20 #: lib/block_scout_web/views/block_view.ex:20
#: lib/block_scout_web/views/wei_helpers.ex:71 #: lib/block_scout_web/views/wei_helpers.ex:77
msgid "Gwei" msgid "Gwei"
msgstr "" msgstr ""
@ -982,7 +982,7 @@ msgid "Wallet addresses"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/wei_helpers.ex:70 #: lib/block_scout_web/views/wei_helpers.ex:76
msgid "Wei" msgid "Wei"
msgstr "" msgstr ""

@ -319,6 +319,8 @@ defmodule EthereumJSONRPC.Block do
@spec elixir_to_transactions(elixir) :: Transactions.elixir() @spec elixir_to_transactions(elixir) :: Transactions.elixir()
def elixir_to_transactions(%{"transactions" => transactions}), do: transactions def elixir_to_transactions(%{"transactions" => transactions}), do: transactions
def elixir_to_transactions(_), do: []
@doc """ @doc """
Get `t:EthereumJSONRPC.Uncles.elixir/0` from `t:elixir/0`. Get `t:EthereumJSONRPC.Uncles.elixir/0` from `t:elixir/0`.

@ -174,6 +174,12 @@ defmodule EthereumJSONRPC.Parity.FetchedBeneficiaries do
defp get_address_type(reward_type, index) when reward_type == "external" and index == 2, do: :validator defp get_address_type(reward_type, index) when reward_type == "external" and index == 2, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 3, do: :validator defp get_address_type(reward_type, index) when reward_type == "external" and index == 3, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 4, do: :validator defp get_address_type(reward_type, index) when reward_type == "external" and index == 4, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 5, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 6, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 7, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 8, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 9, do: :validator
defp get_address_type(reward_type, index) when reward_type == "external" and index == 10, do: :validator
defp get_address_type(reward_type, _index) when reward_type == "block", do: :validator defp get_address_type(reward_type, _index) when reward_type == "block", do: :validator
defp get_address_type(reward_type, _index) when reward_type == "uncle", do: :uncle defp get_address_type(reward_type, _index) when reward_type == "uncle", do: :uncle
end end

@ -56,4 +56,10 @@ defmodule EthereumJSONRPC.BlockTest do
} }
end end
end end
describe "elixir_to_transactions/1" do
test "converts to empty list if there is not transaction key" do
assert Block.elixir_to_transactions(%{}) == []
end
end
end end

@ -1966,7 +1966,6 @@ defmodule Explorer.Chain do
|> page_pending_transaction(paging_options) |> page_pending_transaction(paging_options)
|> limit(^paging_options.page_size) |> limit(^paging_options.page_size)
|> pending_transactions_query() |> pending_transactions_query()
|> where([transaction], is_nil(transaction.error) or transaction.error != "dropped/replaced")
|> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash) |> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash)
|> join_associations(necessity_by_association) |> join_associations(necessity_by_association)
|> preload([{:token_transfers, [:token, :from_address, :to_address]}]) |> preload([{:token_transfers, [:token, :from_address, :to_address]}])
@ -1975,7 +1974,7 @@ defmodule Explorer.Chain do
defp pending_transactions_query(query) do defp pending_transactions_query(query) do
from(transaction in query, from(transaction in query,
where: is_nil(transaction.block_hash) where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced")
) )
end end

@ -66,7 +66,7 @@ defmodule Explorer.Counters.AverageBlockTime do
from(block in Block, from(block in Block,
limit: 100, limit: 100,
offset: 0, offset: 0,
order_by: [desc: block.number], order_by: [desc: block.number, desc: block.timestamp],
select: {block.number, block.timestamp} select: {block.number, block.timestamp}
) )

@ -28,7 +28,7 @@ defmodule Explorer.ExchangeRates.Source do
true -> fetch_exchange_rates_from_paginable_source(source, page + 1) true -> fetch_exchange_rates_from_paginable_source(source, page + 1)
end end
{:ok, %Response{body: body, status_code: status_code}} when status_code in 400..499 -> {:ok, %Response{body: body, status_code: status_code}} when status_code in 400..502 ->
{:error, decode_json(body)["error"]} {:error, decode_json(body)["error"]}
{:error, %Error{reason: reason}} -> {:error, %Error{reason: reason}} ->
@ -65,6 +65,8 @@ defmodule Explorer.ExchangeRates.Source do
def decode_json(data) do def decode_json(data) do
Jason.decode!(data) Jason.decode!(data)
rescue
_ -> data
end end
def to_decimal(nil), do: nil def to_decimal(nil), do: nil

@ -0,0 +1,7 @@
defmodule Explorer.Repo.Migrations.AddTxHashInsertedAtIndex do
use Ecto.Migration
def change do
create(index(:transactions, [:hash, :inserted_at]))
end
end

@ -3,7 +3,9 @@ defmodule Explorer.Counters.AverageBlockTimeTest do
doctest Explorer.Counters.AverageBlockTimeDurationFormat doctest Explorer.Counters.AverageBlockTimeDurationFormat
alias Explorer.Chain.Block
alias Explorer.Counters.AverageBlockTime alias Explorer.Counters.AverageBlockTime
alias Explorer.Repo
setup do setup do
start_supervised!(AverageBlockTime) start_supervised!(AverageBlockTime)
@ -24,5 +26,37 @@ defmodule Explorer.Counters.AverageBlockTimeTest do
test "without blocks duration is 0" do test "without blocks duration is 0" do
assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT0S") assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT0S")
end end
test "considers both uncles and consensus blocks" do
block_number = 99_999_999
first_timestamp = Timex.now()
insert(:block, number: block_number, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 3))
insert(:block, number: block_number, consensus: false, timestamp: Timex.shift(first_timestamp, seconds: 9))
insert(:block, number: block_number, consensus: false, timestamp: Timex.shift(first_timestamp, seconds: 6))
assert Repo.aggregate(Block, :count, :hash) == 3
AverageBlockTime.refresh()
assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT3S")
end
test "when there are no uncles sorts by block number" do
block_number = 99_999_999
first_timestamp = Timex.now()
insert(:block, number: block_number, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 3))
insert(:block, number: block_number + 2, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 9))
insert(:block, number: block_number + 1, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 6))
assert Repo.aggregate(Block, :count, :hash) == 3
AverageBlockTime.refresh()
assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT3S")
end
end end
end end

@ -33,7 +33,7 @@ RUN cd apps/block_scout_web/assets/ && \
RUN cd apps/explorer/ && \ RUN cd apps/explorer/ && \
npm install && \ npm install && \
apk del --force-broken-world alpine-sdk gmp-dev automake libtool inotify-tools autoconf python apk update && apk del --force-broken-world alpine-sdk gmp-dev automake libtool inotify-tools autoconf python
# RUN mix do ecto.drop --force, ecto.create, ecto.migrate # RUN mix do ecto.drop --force, ecto.create, ecto.migrate

Loading…
Cancel
Save