Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaderboard query #29

Merged
merged 43 commits into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1ae9425
read celo accounts using absinthe
mrsmkl Oct 24, 2019
3e5d325
added some kind of connections
mrsmkl Oct 25, 2019
93ee8d6
reading epoch rewards
mrsmkl Nov 12, 2019
5130b2f
add bogus transaction and address
mrsmkl Nov 12, 2019
a3cf8c7
working
mrsmkl Nov 12, 2019
d2203bd
updated abis
mrsmkl Nov 13, 2019
ded4396
added reading validator history
mrsmkl Nov 13, 2019
a53ca03
format
mrsmkl Nov 14, 2019
3f0cd0a
merge
mrsmkl Nov 14, 2019
43f2100
merge
mrsmkl Nov 14, 2019
4ce3984
starting
mrsmkl Nov 14, 2019
7733944
Merge branch 'absinthe-test' of github.com:mrsmkl/blockscout into lea…
mrsmkl Nov 14, 2019
2173c0a
format
mrsmkl Nov 14, 2019
4557cbf
first version working
mrsmkl Nov 14, 2019
d07684a
added account name to the leaderboard query
mrsmkl Nov 14, 2019
5b34904
reading contract addresses from registry
mrsmkl Nov 18, 2019
6f4c748
keeping track of attestation events
mrsmkl Nov 19, 2019
41da01a
merge
mrsmkl Nov 19, 2019
b945ebd
merge
mrsmkl Nov 19, 2019
da410b3
fix dialyzer
mrsmkl Nov 19, 2019
77666f6
fix credo
mrsmkl Nov 19, 2019
bc086b2
fixing unit tests
mrsmkl Nov 19, 2019
ccc0231
fixing unit tests
mrsmkl Nov 19, 2019
748e050
format
mrsmkl Nov 19, 2019
639e2e2
some flakiness
mrsmkl Nov 19, 2019
caacf71
format
mrsmkl Nov 19, 2019
c33a33f
disabled validator history for tests
mrsmkl Nov 19, 2019
1ed914b
format
mrsmkl Nov 19, 2019
042c53d
reading extra receipts
mrsmkl Nov 20, 2019
6ebd45e
working on getting all balance changes
mrsmkl Nov 20, 2019
12f624a
changing db structure to handle logs with no associated tx
mrsmkl Nov 21, 2019
a024e67
format
mrsmkl Nov 21, 2019
1c9f81f
credo
mrsmkl Nov 21, 2019
1d607fc
unit tests are going to take some time to fix
mrsmkl Nov 21, 2019
aa89f84
fixing unit tests
mrsmkl Nov 21, 2019
9a5ea3d
unit tests working?
mrsmkl Nov 21, 2019
3754783
handling changes from monorepo and blockchain
mrsmkl Nov 22, 2019
7857786
gateway fee numric
mrsmkl Nov 22, 2019
c355b9f
fixing unit tests
mrsmkl Nov 22, 2019
0ec8434
format
mrsmkl Nov 22, 2019
b43f9f1
cleaning up
mrsmkl Nov 24, 2019
3957558
Merge pull request #36 from celo-org/mrsmkl/leaderboard
mrsmkl Nov 24, 2019
16093af
Merge pull request #35 from celo-org/mrsmkl/leaderboard-2
mrsmkl Nov 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge
  • Loading branch information
mrsmkl committed Nov 14, 2019
commit 3f0cd0a665772abafec8ac44d3a450f91a804c68
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
with {:address_param, {:ok, address_param}} <- fetch_address(params),
{:format, {:ok, address_hash}} <- to_address_hash(address_param) do
address =
<<<<<<< HEAD
with {:ok, proxy_contract} <- Chain.get_proxied_address(address_hash) do
Logger.debug("Implementation address FOUND in proxy table")
Chain.address_hash_to_address_with_source_code(proxy_contract)
else
=======
case Chain.get_proxied_address(address_hash) do
{:ok, proxy_contract} ->
Logger.debug("Implementation address FOUND in proxy table")
Chain.address_hash_to_address_with_source_code(proxy_contract)

>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
{:error, :not_found} ->
Logger.debug("Implementation address NOT found in proxy table")
Chain.address_hash_to_address_with_source_code(address_hash)
Expand Down
13 changes: 13 additions & 0 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ defmodule EthereumJSONRPC.Contract do

requests_with_index = Enum.with_index(requests)

<<<<<<< HEAD
prepared =
=======
indexed_responses =
>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
requests_with_index
|> Enum.map(fn {%{contract_address: contract_address, function_name: function_name, args: args} = request, index} ->
functions[function_name]
|> Encoder.encode_function_call(args)
|> eth_call_request(contract_address, index, Map.get(request, :block_number))
end)
<<<<<<< HEAD

indexed_responses =
prepared
Expand All @@ -59,6 +64,14 @@ defmodule EthereumJSONRPC.Contract do

{:error, error} ->
raise error
=======
|> json_rpc(json_rpc_named_arguments)
|> case do
{:ok, responses} -> responses
{:error, {:bad_gateway, _request_url}} -> raise "Bad gateway"
{:error, reason} when is_atom(reason) -> raise Atom.to_string(reason)
{:error, error} -> raise error
>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
end
|> Enum.into(%{}, &{&1.id, &1})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorGroups do
end

@impl Import.Runner
def run(multi, changes_list, %{timestamps: timestamps} = options) do
insert_options =
options
|> Map.get(option_key(), %{})
|> Map.take(~w(on_conflict timeout)a)
|> Map.put_new(:timeout, @timeout)
|> Map.put(:timestamps, timestamps)
def run(multi, changes_list, options) do
insert_options = Util.make_insert_options(option_key(), @timeout, options)

# Enforce ShareLocks tables order (see docs: sharelocks.md)
multi
Expand Down Expand Up @@ -67,19 +62,15 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorGroups do
{:ok, accounts}
end

@spec insert(Repo.t(), [map()], %{
optional(:on_conflict) => Import.Runner.on_conflict(),
required(:timeout) => timeout,
required(:timestamps) => Import.timestamps()
}) ::
{:ok, [CeloValidatorGroup.t()]}
| {:error, [Changeset.t()]}
@spec insert(Repo.t(), [map()], Util.insert_option()) :: {:ok, [CeloValidatorGroup.t()]} | {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)

# Enforce ShareLocks order (see docs: sharelocks.md)
ordered_changes_list = Enum.sort_by(changes_list, & &1.address)
uniq_changes_list = Enum.dedup_by(ordered_changes_list, & &1.address)
uniq_changes_list =
changes_list
|> Enum.sort_by(& &1.address)
|> Enum.dedup_by(& &1.address)

{:ok, _} =
Import.insert_changes_list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorHistory do

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloValidatorHistory}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]

Expand All @@ -32,13 +33,8 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorHistory do
end

@impl Import.Runner
def run(multi, changes_list, %{timestamps: timestamps} = options) do
insert_options =
options
|> Map.get(option_key(), %{})
|> Map.take(~w(on_conflict timeout)a)
|> Map.put_new(:timeout, @timeout)
|> Map.put(:timestamps, timestamps)
def run(multi, changes_list, options) do
insert_options = Util.make_insert_options(option_key(), @timeout, options)

# Enforce ShareLocks tables order (see docs: sharelocks.md)
Multi.run(multi, :insert_items, fn repo, _ ->
Expand All @@ -49,19 +45,16 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorHistory do
@impl Import.Runner
def timeout, do: @timeout

@spec insert(Repo.t(), [map()], %{
optional(:on_conflict) => Import.Runner.on_conflict(),
required(:timeout) => timeout,
required(:timestamps) => Import.timestamps()
}) ::
{:ok, [CeloValidatorHistory.t()]}
| {:error, [Changeset.t()]}
@spec insert(Repo.t(), [map()], Util.insert_options()) ::
{:ok, [CeloValidatorHistory.t()]} | {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)

# Enforce ShareLocks order (see docs: sharelocks.md)
ordered_changes_list = Enum.sort_by(changes_list, &{&1.block_number, &1.index})
uniq_changes_list = Enum.dedup_by(ordered_changes_list, &{&1.block_number, &1.index})
uniq_changes_list =
changes_list
|> Enum.sort_by(&{&1.block_number, &1.index})
|> Enum.dedup_by(&{&1.block_number, &1.index})

{:ok, _} =
Import.insert_changes_list(
Expand Down
24 changes: 8 additions & 16 deletions apps/explorer/lib/explorer/chain/import/runner/celo_withdrawals.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Explorer.Chain.Import.Runner.CeloWithdrawals do

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloWithdrawal}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]

Expand All @@ -32,13 +33,8 @@ defmodule Explorer.Chain.Import.Runner.CeloWithdrawals do
end

@impl Import.Runner
def run(multi, changes_list, %{timestamps: timestamps} = options) do
insert_options =
options
|> Map.get(option_key(), %{})
|> Map.take(~w(on_conflict timeout)a)
|> Map.put_new(:timeout, @timeout)
|> Map.put(:timestamps, timestamps)
def run(multi, changes_list, options) do
insert_options = Util.make_insert_options(option_key(), @timeout, options)

# Enforce ShareLocks tables order (see docs: sharelocks.md)
Multi.run(multi, :insert_items, fn repo, _ ->
Expand All @@ -49,19 +45,15 @@ defmodule Explorer.Chain.Import.Runner.CeloWithdrawals do
@impl Import.Runner
def timeout, do: @timeout

@spec insert(Repo.t(), [map()], %{
optional(:on_conflict) => Import.Runner.on_conflict(),
required(:timeout) => timeout,
required(:timestamps) => Import.timestamps()
}) ::
{:ok, [CeloWithdrawal.t()]}
| {:error, [Changeset.t()]}
@spec insert(Repo.t(), [map()], Util.insert_options()) :: {:ok, [CeloWithdrawal.t()]} | {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)

# Enforce ShareLocks order (see docs: sharelocks.md)
ordered_changes_list = Enum.sort_by(changes_list, &{&1.address, &1.index})
uniq_changes_list = Enum.dedup_by(ordered_changes_list, &{&1.address, &1.index})
uniq_changes_list =
changes_list
|> Enum.sort_by(&{&1.address, &1.index})
|> Enum.dedup_by(&{&1.address, &1.index})

{:ok, _} =
Import.insert_changes_list(
Expand Down
17 changes: 17 additions & 0 deletions apps/indexer/lib/indexer/fetcher/celo_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Indexer.Fetcher.CeloAccount do

@behaviour BufferedTask

<<<<<<< HEAD
@defaults [
flush_interval: 300,
max_batch_size: 100,
Expand All @@ -30,6 +31,18 @@ defmodule Indexer.Fetcher.CeloAccount do
accounts.params
|> Enum.map(&entry/1)

=======
@max_retries 3

def async_fetch(accounts) do
if CeloAccountSupervisor.disabled?() do
:ok
else
params =
accounts.params
|> Enum.map(&entry/1)

>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
BufferedTask.buffer(__MODULE__, params, :infinity)
end
end
Expand All @@ -43,12 +56,16 @@ defmodule Indexer.Fetcher.CeloAccount do

@doc false
def child_spec([init_options, gen_server_options]) do
<<<<<<< HEAD
merged_init_opts =
@defaults
|> Keyword.merge(init_options)
|> Keyword.put(:state, {0, []})

Supervisor.child_spec({BufferedTask, [{__MODULE__, merged_init_opts}, gen_server_options]}, id: __MODULE__)
=======
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
end

@impl BufferedTask
Expand Down
15 changes: 2 additions & 13 deletions apps/indexer/lib/indexer/fetcher/celo_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ defmodule Indexer.Fetcher.CeloValidator do
alias Explorer.Chain.CeloValidator
alias Explorer.Chain
alias Explorer.Celo.AccountReader
alias Indexer.Fetcher.Util

alias Indexer.BufferedTask

@behaviour BufferedTask

@defaults [
flush_interval: 300,
max_batch_size: 100,
max_concurrency: 10,
task_supervisor: Indexer.Fetcher.CeloValidator.TaskSupervisor
]

@max_retries 3

def async_fetch(accounts) do
Expand All @@ -43,12 +37,7 @@ defmodule Indexer.Fetcher.CeloValidator do

@doc false
def child_spec([init_options, gen_server_options]) do
merged_init_opts =
@defaults
|> Keyword.merge(init_options)
|> Keyword.put(:state, {0, []})

Supervisor.child_spec({BufferedTask, [{__MODULE__, merged_init_opts}, gen_server_options]}, id: __MODULE__)
Util.default_child_spec(init_options, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down
17 changes: 17 additions & 0 deletions apps/indexer/lib/indexer/fetcher/celo_validator_group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Indexer.Fetcher.CeloValidatorGroup do

@behaviour BufferedTask

<<<<<<< HEAD
@defaults [
flush_interval: 300,
max_batch_size: 100,
Expand All @@ -30,6 +31,18 @@ defmodule Indexer.Fetcher.CeloValidatorGroup do
accounts.params
|> Enum.map(&entry/1)

=======
@max_retries 3

def async_fetch(accounts) do
if CeloValidatorGroupSupervisor.disabled?() do
:ok
else
params =
accounts.params
|> Enum.map(&entry/1)

>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
BufferedTask.buffer(__MODULE__, params, :infinity)
end
end
Expand All @@ -43,12 +56,16 @@ defmodule Indexer.Fetcher.CeloValidatorGroup do

@doc false
def child_spec([init_options, gen_server_options]) do
<<<<<<< HEAD
merged_init_opts =
@defaults
|> Keyword.merge(init_options)
|> Keyword.put(:state, {0, []})

Supervisor.child_spec({BufferedTask, [{__MODULE__, merged_init_opts}, gen_server_options]}, id: __MODULE__)
=======
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
>>>>>>> 1a92f710716f2d5e8138e90f2d7e88cc26faeaec
end

@impl BufferedTask
Expand Down
16 changes: 2 additions & 14 deletions apps/indexer/lib/indexer/fetcher/celo_validator_history.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ defmodule Indexer.Fetcher.CeloValidatorHistory do

@behaviour BufferedTask

@defaults [
flush_interval: 300,
max_batch_size: 100,
max_concurrency: 10,
task_supervisor: Indexer.Fetcher.CeloValidatorHistory.TaskSupervisor
]

@max_retries 3

def async_fetch(range) do
if CeloValidatorHistorySupervisor.disabled?() do
:ok
else
params = Enum.map(range, &entry/1)

BufferedTask.buffer(__MODULE__, params, :infinity)
end
end
Expand All @@ -40,12 +34,7 @@ defmodule Indexer.Fetcher.CeloValidatorHistory do

@doc false
def child_spec([init_options, gen_server_options]) do
merged_init_opts =
@defaults
|> Keyword.merge(init_options)
|> Keyword.put(:state, {0, []})

Supervisor.child_spec({BufferedTask, [{__MODULE__, merged_init_opts}, gen_server_options]}, id: __MODULE__)
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down Expand Up @@ -124,7 +113,6 @@ defmodule Indexer.Fetcher.CeloValidatorHistory do
error_count: Enum.count(blocks)
)
end
end

failed
end
Expand Down
14 changes: 1 addition & 13 deletions apps/indexer/lib/indexer/fetcher/celo_withdrawal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ defmodule Indexer.Fetcher.CeloWithdrawal do

@behaviour BufferedTask

@defaults [
flush_interval: 300,
max_batch_size: 100,
max_concurrency: 10,
task_supervisor: Indexer.Fetcher.CeloWithdrawal.TaskSupervisor
]

@max_retries 3

def async_fetch(accounts) do
Expand All @@ -43,12 +36,7 @@ defmodule Indexer.Fetcher.CeloWithdrawal do

@doc false
def child_spec([init_options, gen_server_options]) do
merged_init_opts =
@defaults
|> Keyword.merge(init_options)
|> Keyword.put(:state, {0, []})

Supervisor.child_spec({BufferedTask, [{__MODULE__, merged_init_opts}, gen_server_options]}, id: __MODULE__)
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.