Merge branch 'master' into ab-token-transfer-csv-export

pull/2242/head
Ayrat Badykov 6 years ago committed by GitHub
commit e52fa8977a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      apps/indexer/lib/indexer/block/realtime/fetcher.ex
  3. 21
      apps/indexer/lib/indexer/fetcher/uncle_block.ex
  4. 70
      apps/indexer/test/indexer/fetcher/uncle_block_test.exs

@ -18,6 +18,7 @@
- [#2096](https://github.com/poanetwork/blockscout/pull/2096) - RSK theme fixes - [#2096](https://github.com/poanetwork/blockscout/pull/2096) - RSK theme fixes
- [#2093](https://github.com/poanetwork/blockscout/pull/2093) - detect token transfer type for deprecated erc721 spec - [#2093](https://github.com/poanetwork/blockscout/pull/2093) - detect token transfer type for deprecated erc721 spec
- [#2108](https://github.com/poanetwork/blockscout/pull/2108) - fix uncle fetching without full transactions - [#2108](https://github.com/poanetwork/blockscout/pull/2108) - fix uncle fetching without full transactions
- [#2128](https://github.com/poanetwork/blockscout/pull/2128) - add new function clause for uncle errors
- [#2123](https://github.com/poanetwork/blockscout/pull/2123) - fix coins percentage view - [#2123](https://github.com/poanetwork/blockscout/pull/2123) - fix coins percentage view
- [#2119](https://github.com/poanetwork/blockscout/pull/2119) - fix map logging - [#2119](https://github.com/poanetwork/blockscout/pull/2119) - fix map logging
- [#2130](https://github.com/poanetwork/blockscout/pull/2130) - fix navigation - [#2130](https://github.com/poanetwork/blockscout/pull/2130) - fix navigation

@ -201,6 +201,12 @@ defmodule Indexer.Block.Realtime.Fetcher do
end end
end end
def import(_, _) do
Logger.warn("Empty parameters were provided for realtime fetcher")
{:ok, []}
end
defp start_fetch_and_import(number, block_fetcher, previous_number, max_number_seen) do defp start_fetch_and_import(number, block_fetcher, previous_number, max_number_seen) do
start_at = determine_start_at(number, previous_number, max_number_seen) start_at = determine_start_at(number, previous_number, max_number_seen)

@ -104,9 +104,9 @@ defmodule Indexer.Fetcher.UncleBlock do
{nephew_hash_bytes, index} {nephew_hash_bytes, index}
end end
defp run_blocks(%Blocks{blocks_params: []}, _, original_entries), do: {:retry, original_entries} def run_blocks(%Blocks{blocks_params: []}, _, original_entries), do: {:retry, original_entries}
defp run_blocks( def run_blocks(
%Blocks{ %Blocks{
blocks_params: blocks_params, blocks_params: blocks_params,
transactions_params: transactions_params, transactions_params: transactions_params,
@ -235,7 +235,17 @@ defmodule Indexer.Fetcher.UncleBlock do
Enum.map(errors, &error_to_entry/1) Enum.map(errors, &error_to_entry/1)
end end
defp error_to_entry(%{data: %{hash: hash}}) when is_binary(hash), do: hash defp error_to_entry(%{data: %{hash: hash, index: index}}) when is_binary(hash) do
{:ok, %Hash{bytes: nephew_hash_bytes}} = Hash.Full.cast(hash)
{nephew_hash_bytes, index}
end
defp error_to_entry(%{data: %{nephew_hash: hash, index: index}}) when is_binary(hash) do
{:ok, %Hash{bytes: nephew_hash_bytes}} = Hash.Full.cast(hash)
{nephew_hash_bytes, index}
end
defp errors_to_iodata(errors) when is_list(errors) do defp errors_to_iodata(errors) when is_list(errors) do
errors_to_iodata(errors, []) errors_to_iodata(errors, [])
@ -251,4 +261,9 @@ defmodule Indexer.Fetcher.UncleBlock do
when is_integer(code) and is_binary(message) and is_binary(hash) do when is_integer(code) and is_binary(message) and is_binary(hash) do
[hash, ": (", to_string(code), ") ", message, ?\n] [hash, ": (", to_string(code), ") ", message, ?\n]
end end
defp error_to_iodata(%{code: code, message: message, data: %{nephew_hash: hash}})
when is_integer(code) and is_binary(message) and is_binary(hash) do
[hash, ": (", to_string(code), ") ", message, ?\n]
end
end end

@ -6,7 +6,9 @@ defmodule Indexer.Fetcher.UncleBlockTest do
import EthereumJSONRPC, only: [integer_to_quantity: 1] import EthereumJSONRPC, only: [integer_to_quantity: 1]
alias EthereumJSONRPC.Blocks
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.Hash
alias Indexer.Block alias Indexer.Block
alias Indexer.Fetcher.UncleBlock alias Indexer.Fetcher.UncleBlock
@ -138,6 +140,74 @@ defmodule Indexer.Fetcher.UncleBlockTest do
end end
end end
describe "run/2" do
test "retries failed request", %{json_rpc_named_arguments: json_rpc_named_arguments} do
%Hash{bytes: block_hash_bytes} = block_hash()
entries = [{block_hash_bytes, 0}]
EthereumJSONRPC.Mox
|> expect(:json_rpc, fn [
%{
id: id,
method: "eth_getUncleByBlockHashAndIndex"
}
],
_ ->
{:ok,
[
%{
id: id,
error: %{
code: 404,
data: %{index: 0, nephew_hash: "0xa0814f0478fe90c82852f812fd74c96df148654c326d2600d836e6908ebb62b4"},
message: "Not Found"
}
}
]}
end)
assert {:retry, ^entries} =
UncleBlock.run(entries, %Block.Fetcher{json_rpc_named_arguments: json_rpc_named_arguments})
end
end
describe "run_blocks/2" do
test "converts errors to entries for retry", %{json_rpc_named_arguments: json_rpc_named_arguments} do
miner_hash =
address_hash()
|> to_string()
block_number = 1
index = 0
hash = "0xa0814f0478fe90c82852f812fd74c96df148654c326d2600d836e6908ebb62b4"
params = %Blocks{
errors: [
%{
code: 404,
data: %{index: index, nephew_hash: hash},
message: "Not Found"
}
],
blocks_params: [%{miner_hash: miner_hash, number: block_number}]
}
assert {:retry, [{bin_hash, ^index}]} =
UncleBlock.run_blocks(
params,
%Block.Fetcher{
json_rpc_named_arguments: json_rpc_named_arguments,
callback_module: Indexer.Block.Realtime.Fetcher
},
[]
)
assert Hash.Full.cast(bin_hash) == Hash.Full.cast(hash)
end
end
defp wait(producer) do defp wait(producer) do
producer.() producer.()
rescue rescue

Loading…
Cancel
Save