Skip to content

Commit

Permalink
fix: import clique genesis blocks
Browse files Browse the repository at this point in the history
Additionally resolves a few small issues that arose in doing so
  • Loading branch information
zachdaniel committed Feb 4, 2019
1 parent ebf4bf4 commit 949a971
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Block Height -->
<h3 data-test="block_detail_number">
<%= if block_type(@block) == "Block" do %>
<%= gettext("Block Height: %{height}", height: @block.number) %>
<%= gettext("Block Height: %{height}", height: @block.number) %> <%= if @block.number == 0, do: "- " <> gettext("Genesis Block")%>
<% else %>
<%= gettext("%{block_type} Height:", block_type: block_type(@block)) %>
<%= link(@block, to: block_path(BlockScoutWeb.Endpoint, :show, @block.number)) %>
Expand All @@ -37,17 +37,19 @@
<dd class="col-sm-9"> <%= to_string(@block.hash) %> </dd>
</dl>

<!-- Parent Hash -->
<dl class="row">
<dt class="col-sm-3 text-muted"> <%= gettext "Parent Hash" %> </dt>
<dd class="col-sm-9">
<%= link(
@block.parent_hash,
class: "block__link",
to: block_path(@conn, :show, @block.number - 1)
) %>
</dd>
</dl>
<%= unless @block.number == 0 do %>
<!-- Parent Hash -->
<dl class="row">
<dt class="col-sm-3 text-muted"> <%= gettext "Parent Hash" %> </dt>
<dd class="col-sm-9">
<%= link(
@block.parent_hash,
class: "block__link",
to: block_path(@conn, :show, @block.number - 1)
) %>
</dd>
</dl>
<% end %>

<!-- Difficulty value -->
<dl class="row">
Expand Down
29 changes: 17 additions & 12 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ msgid "Details"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:54
#: lib/block_scout_web/templates/block/overview.html.eex:56
msgid "Difficulty"
msgstr ""

Expand Down Expand Up @@ -437,15 +437,15 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:57
#: lib/block_scout_web/templates/block/overview.html.eex:102
#: lib/block_scout_web/templates/block/overview.html.eex:157
#: lib/block_scout_web/templates/block/overview.html.eex:104
#: 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:62
#: lib/block_scout_web/templates/block/overview.html.eex:94
#: lib/block_scout_web/templates/block/overview.html.eex:148
#: lib/block_scout_web/templates/block/overview.html.eex:96
#: lib/block_scout_web/templates/block/overview.html.eex:150
msgid "Gas Used"
msgstr ""

Expand Down Expand Up @@ -539,7 +539,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:37
#: lib/block_scout_web/templates/block/overview.html.eex:117
#: lib/block_scout_web/templates/block/overview.html.eex:119
#: lib/block_scout_web/templates/chain/_block.html.eex:14
msgid "Miner"
msgstr ""
Expand Down Expand Up @@ -608,7 +608,7 @@ msgid "No"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:69
#: lib/block_scout_web/templates/block/overview.html.eex:71
#: lib/block_scout_web/templates/transaction/overview.html.eex:67
msgid "Nonce"
msgstr ""
Expand Down Expand Up @@ -655,7 +655,7 @@ msgid "Parameters"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:42
#: lib/block_scout_web/templates/block/overview.html.eex:43
msgid "Parent Hash"
msgstr ""

Expand All @@ -674,7 +674,7 @@ msgid "Pending Transactions"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:80
#: lib/block_scout_web/templates/block/overview.html.eex:82
msgid "Position %{index}"
msgstr ""

Expand Down Expand Up @@ -917,7 +917,7 @@ msgid "Topics"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:63
#: lib/block_scout_web/templates/block/overview.html.eex:65
msgid "Total Difficulty"
msgstr ""

Expand Down Expand Up @@ -989,7 +989,7 @@ msgid "Twitter"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:76
#: lib/block_scout_web/templates/block/overview.html.eex:78
#: lib/block_scout_web/templates/layout/_topnav.html.eex:23
msgid "Uncles"
msgstr ""
Expand Down Expand Up @@ -1475,7 +1475,7 @@ msgid "Validator Info"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:137
#: lib/block_scout_web/templates/block/overview.html.eex:139
msgid "Block Rewards"
msgstr ""

Expand Down Expand Up @@ -1563,3 +1563,8 @@ msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:39
msgid "Copy Source Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:13
msgid "Genesis Block"
msgstr ""
31 changes: 18 additions & 13 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ msgid "Details"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:54
#: lib/block_scout_web/templates/block/overview.html.eex:56
msgid "Difficulty"
msgstr ""

Expand Down Expand Up @@ -437,15 +437,15 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:57
#: lib/block_scout_web/templates/block/overview.html.eex:102
#: lib/block_scout_web/templates/block/overview.html.eex:157
#: lib/block_scout_web/templates/block/overview.html.eex:104
#: 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:62
#: lib/block_scout_web/templates/block/overview.html.eex:94
#: lib/block_scout_web/templates/block/overview.html.eex:148
#: lib/block_scout_web/templates/block/overview.html.eex:96
#: lib/block_scout_web/templates/block/overview.html.eex:150
msgid "Gas Used"
msgstr ""

Expand Down Expand Up @@ -539,7 +539,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:37
#: lib/block_scout_web/templates/block/overview.html.eex:117
#: lib/block_scout_web/templates/block/overview.html.eex:119
#: lib/block_scout_web/templates/chain/_block.html.eex:14
msgid "Miner"
msgstr ""
Expand Down Expand Up @@ -608,7 +608,7 @@ msgid "No"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:69
#: lib/block_scout_web/templates/block/overview.html.eex:71
#: lib/block_scout_web/templates/transaction/overview.html.eex:67
msgid "Nonce"
msgstr ""
Expand Down Expand Up @@ -655,7 +655,7 @@ msgid "Parameters"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:42
#: lib/block_scout_web/templates/block/overview.html.eex:43
msgid "Parent Hash"
msgstr ""

Expand All @@ -674,7 +674,7 @@ msgid "Pending Transactions"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:80
#: lib/block_scout_web/templates/block/overview.html.eex:82
msgid "Position %{index}"
msgstr ""

Expand Down Expand Up @@ -917,7 +917,7 @@ msgid "Topics"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:63
#: lib/block_scout_web/templates/block/overview.html.eex:65
msgid "Total Difficulty"
msgstr ""

Expand Down Expand Up @@ -989,7 +989,7 @@ msgid "Twitter"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:76
#: lib/block_scout_web/templates/block/overview.html.eex:78
#: lib/block_scout_web/templates/layout/_topnav.html.eex:23
msgid "Uncles"
msgstr ""
Expand Down Expand Up @@ -1475,7 +1475,7 @@ msgid "Validator Info"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:137
#: lib/block_scout_web/templates/block/overview.html.eex:139
msgid "Block Rewards"
msgstr ""

Expand Down Expand Up @@ -1554,7 +1554,7 @@ msgstr ""
msgid "Copy ABI"
msgstr ""

#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:65
msgid "Copy Contract Creation Code"
msgstr ""
Expand All @@ -1563,3 +1563,8 @@ msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:39
msgid "Copy Source Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/overview.html.eex:13
msgid "Genesis Block"
msgstr ""
26 changes: 25 additions & 1 deletion apps/indexer/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,32 @@ use Mix.Config

import Bitwise

block_transformers = %{
"clique" => Indexer.Block.Transform.Clique,
"base" => Indexer.Block.Transform.Base
}

# Compile time environment variable access requires recompilation.
configured_transformer = System.get_env("BLOCK_TRANSFORMER") || "base"

block_transformer =
case Map.get(block_transformers, configured_transformer) do
nil ->
raise """
No such block transformer: #{configured_transformer}.
Valid values are:
#{Enum.join(Map.keys(block_transformers), "\n")}
Please update environment variable BLOCK_TRANSFORMER accordingly.
"""

transformer ->
transformer
end

config :indexer,
block_transformer: Indexer.Block.Transform.Base,
block_transformer: block_transformer,
ecto_repos: [Explorer.Repo],
metadata_updater_days_interval: 7,
# bytes
Expand Down
4 changes: 4 additions & 0 deletions apps/indexer/lib/indexer/block/realtime/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ defmodule Indexer.Block.Realtime.Fetcher do

defp determine_start_at(number, nil, nil), do: number

defp determine_start_at(number, nil, max_number_seen) do
determine_start_at(number, number - 1, max_number_seen)
end

defp determine_start_at(number, previous_number, max_number_seen) do
if reorg?(number, max_number_seen) do
# set start_at to NOT fill in skipped numbers
Expand Down
3 changes: 3 additions & 0 deletions apps/indexer/lib/indexer/block/reward/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ defmodule Indexer.Block.Reward.Fetcher do
{:ok, fetched_beneficiaries} ->
run_fetched_beneficiaries(fetched_beneficiaries, hash_string_by_number)

:ignore ->
:ok

{:error, reason} ->
Logger.error(
fn ->
Expand Down
10 changes: 0 additions & 10 deletions apps/indexer/lib/indexer/block/transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ defmodule Indexer.Block.Transform do
def transform_blocks(blocks) when is_list(blocks) do
transformer = Application.get_env(:indexer, :block_transformer)

unless transformer do
raise ArgumentError,
"""
No block transformer defined. Set a blocker transformer."
config :indexer,
block_transformer: Indexer.Block.Transform.Base
"""
end

Enum.map(blocks, &transformer.transform/1)
end
end
2 changes: 2 additions & 0 deletions apps/indexer/lib/indexer/block/transform/clique.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Indexer.Block.Transform.Clique do
@behaviour Transform

@impl Transform
def transform(%{number: 0} = block), do: block

def transform(block) when is_map(block) do
miner_address = Util.signer(block)

Expand Down
6 changes: 0 additions & 6 deletions apps/indexer/test/indexer/block/transform_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,5 @@ defmodule Indexer.Block.TransformTest do
test "transforms a list of blocks" do
assert Transform.transform_blocks(@blocks)
end

test "raises when no transformer is configured" do
Application.put_env(:indexer, :block_transformer, nil)

assert_raise ArgumentError, fn -> Transform.transform_blocks(@blocks) end
end
end
end

0 comments on commit 949a971

Please sign in to comment.