From a4a6d93834de12b1829836ec23ad08d9d71657eb Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 23 Sep 2019 12:04:19 +0300 Subject: [PATCH 01/28] get rid of json schema warnings --- apps/block_scout_web/mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/mix.exs b/apps/block_scout_web/mix.exs index de55cb0eb7..029819a202 100644 --- a/apps/block_scout_web/mix.exs +++ b/apps/block_scout_web/mix.exs @@ -131,7 +131,7 @@ defmodule BlockScoutWeb.Mixfile do # `:cowboy` `~> 2.0` and Phoenix 1.4 compatibility {:wobserver, "~> 0.2.0", github: "poanetwork/wobserver", branch: "support-https"}, {:phoenix_form_awesomplete, "~> 0.1.4"}, - {:ex_json_schema, "~> 0.6.1"} + {:ex_json_schema, "~> 0.6.2"} ] end diff --git a/mix.lock b/mix.lock index e0d75af01a..87f6e4e2f0 100644 --- a/mix.lock +++ b/mix.lock @@ -39,7 +39,7 @@ "ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.6.4", "5b1ac8451f889576bb29dee70412de1170974298727ab944aa4d17e91bdd3472", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.6", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.3", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "ex_cldr_units": {:hex, :ex_cldr_units, "2.5.1", "0e65067a22a7c5146266c313d6333c2700868c32aa6d536f47c6c0d84aac3ac1", [:mix], [{:ex_cldr, "~> 2.6", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_lists, "~> 2.2", [hex: :ex_cldr_lists, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.6", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, - "ex_json_schema": {:hex, :ex_json_schema, "0.6.1", "b57c0588385b8262b80f19d33d9b9b71fcd60d247691abf2635b57a03ec0ad44", [:mix], [], "hexpm"}, + "ex_json_schema": {:hex, :ex_json_schema, "0.6.2", "de23d80478215987469c81688208fe0ff440ee0e0e6ae2268fcadbb2ff35df9d", [:mix], [], "hexpm"}, "ex_machina": {:hex, :ex_machina, "2.3.0", "92a5ad0a8b10ea6314b876a99c8c9e3f25f4dde71a2a835845b136b9adaf199a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm"}, "ex_rlp": {:hex, :ex_rlp, "0.5.2", "7f4ce7bd55e543c054ce6d49629b01e9833c3462e3d547952be89865f39f2c58", [:mix], [], "hexpm"}, "ex_utils": {:hex, :ex_utils, "0.1.7", "2c133e0bcdc49a858cf8dacf893308ebc05bc5fba501dc3d2935e65365ec0bf3", [:mix], [], "hexpm"}, From 2f584ef19a571650545ad74e1e58afa36ccf94d3 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 23 Sep 2019 12:08:08 +0300 Subject: [PATCH 02/28] add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6402a0acd..5a40460247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ ### Chore +- [#2723](https://github.com/poanetwork/blockscout/pull/2723) - get rid of ex_json_schema warnings + ## 2.0.4-beta From a5062595378ebb6fc7762d587a7c2c83e00a9010 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 24 Sep 2019 12:59:16 +0300 Subject: [PATCH 03/28] fix library verification bytecode of a library contains address of a deployed library --- .../lib/explorer/smart_contract/verifier.ex | 14 +++++++++- .../explorer/smart_contract/verifier_test.exs | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/smart_contract/verifier.ex b/apps/explorer/lib/explorer/smart_contract/verifier.ex index 4c2daa680c..4303cf5b6b 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier.ex @@ -69,7 +69,8 @@ defmodule Explorer.SmartContract.Verifier do blockchain_bytecode_without_whisper = extract_bytecode(blockchain_bytecode) cond do - generated_bytecode != blockchain_bytecode_without_whisper -> + generated_bytecode != blockchain_bytecode_without_whisper && + !try_library_verification(generated_bytecode, blockchain_bytecode_without_whisper) -> {:error, :generated_bytecode} has_constructor_with_params?(abi) && @@ -81,6 +82,17 @@ defmodule Explorer.SmartContract.Verifier do end end + defp try_library_verification( + "730000000000000000000000000000000000000000" <> bytecode, + <<_address::binary-size(42)>> <> bytecode + ) do + true + end + + defp try_library_verification(_, _) do + false + end + @doc """ In order to discover the bytecode we need to remove the `swarm source` from the hash. diff --git a/apps/explorer/test/explorer/smart_contract/verifier_test.exs b/apps/explorer/test/explorer/smart_contract/verifier_test.exs index fba0622964..088820beea 100644 --- a/apps/explorer/test/explorer/smart_contract/verifier_test.exs +++ b/apps/explorer/test/explorer/smart_contract/verifier_test.exs @@ -144,6 +144,34 @@ defmodule Explorer.SmartContract.VerifierTest do assert abi != nil end + test "verifies a library" do + bytecode = + "0x7349f540c22cba15c47a08c235e20081474201a742301460806040526004361060335760003560e01c8063c2985578146038575b600080fd5b603e60b0565b6040805160208082528351818301528351919283929083019185019080838360005b8381101560765781810151838201526020016060565b50505050905090810190601f16801560a25780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b604080518082019091526003815262666f6f60e81b60208201529056fea265627a7a72315820174b282a3ef3b9778d79fbc2e4c36bc939c54dfaaaa51d3122ee6e648093844c64736f6c634300050b0032" + + contract_address = insert(:contract_address, contract_code: bytecode) + + code = """ + pragma solidity 0.5.11; + + library Foo { + function foo() external pure returns (string memory) { + return "foo"; + } + } + """ + + params = %{ + "contract_source_code" => code, + "compiler_version" => "v0.5.11+commit.c082d0b4", + "evm_version" => "default", + "name" => "Foo", + "optimization" => true + } + + assert {:ok, %{abi: abi}} = Verifier.evaluate_authenticity(contract_address.hash, params) + assert abi != nil + end + test "verifies smart contract compiled with Solidity 0.5.9 (includes new metadata in bytecode) with constructor args" do path = File.cwd!() <> "/test/support/fixture/smart_contract/solidity_0.5.9_smart_contract.sol" contract = File.read!(path) From 6b442635ebe8123a8c2559737cfe72742aab0526 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 24 Sep 2019 13:02:24 +0300 Subject: [PATCH 04/28] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c805d8f45..4a53de6a31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - [#2663](https://github.com/poanetwork/blockscout/pull/2663) - Fetch address counters in parallel ### Fixes +- [#2731](https://github.com/poanetwork/blockscout/pull/2731) - fix library verification - [#2718](https://github.com/poanetwork/blockscout/pull/2718) - Include all addresses taking part in transactions in wallets' addresses counter - [#2709](https://github.com/poanetwork/blockscout/pull/2709) - Fix stuck label and value for uncle block height - [#2707](https://github.com/poanetwork/blockscout/pull/2707) - fix for dashboard banner chart legend items From ec20050a662e8a37c5506944b3e021fa2198e83f Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 24 Sep 2019 14:14:21 +0300 Subject: [PATCH 05/28] add comment --- apps/explorer/lib/explorer/smart_contract/verifier.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/explorer/lib/explorer/smart_contract/verifier.ex b/apps/explorer/lib/explorer/smart_contract/verifier.ex index 4303cf5b6b..ed1b6532c5 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier.ex @@ -82,6 +82,7 @@ defmodule Explorer.SmartContract.Verifier do end end + # 730000000000000000000000000000000000000000 - default library address that returned by the compiler defp try_library_verification( "730000000000000000000000000000000000000000" <> bytecode, <<_address::binary-size(42)>> <> bytecode From 624946a12bf090e1e02e47755e5fbf5fcc954319 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Tue, 24 Sep 2019 19:13:26 +0200 Subject: [PATCH 06/28] Add pending transactions cache --- CHANGELOG.md | 1 + .../block_scout_web/test/support/conn_case.ex | 2 + .../test/support/feature_case.ex | 2 + apps/explorer/config/config.exs | 4 ++ apps/explorer/lib/explorer/application.ex | 4 +- apps/explorer/lib/explorer/chain.ex | 19 +++++++++ .../chain/cache/pending_transactions.ex | 42 +++++++++++++++++++ .../explorer/chain/import/runner/blocks.ex | 12 +----- .../chain/cache/pending_transactions_test.exs | 17 ++++++++ apps/explorer/test/support/data_case.ex | 2 + apps/indexer/lib/indexer/block/fetcher.ex | 8 ++-- .../indexer/fetcher/pending_transaction.ex | 3 +- .../lib/indexer/fetcher/uncle_block.ex | 8 ++-- 13 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/cache/pending_transactions.ex create mode 100644 apps/explorer/test/explorer/chain/cache/pending_transactions_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2311bc9d4c..68d65f4c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2735](https://github.com/poanetwork/blockscout/pull/2735) - Add pending transactions cache - [#2717](https://github.com/poanetwork/blockscout/pull/2717) - Improve speed of nonconsensus data removal - [#2679](https://github.com/poanetwork/blockscout/pull/2679) - added fixed height for card chain blocks and card chain transactions - [#2678](https://github.com/poanetwork/blockscout/pull/2678) - fixed dashboard banner height bug diff --git a/apps/block_scout_web/test/support/conn_case.ex b/apps/block_scout_web/test/support/conn_case.ex index ed3f094c34..5540346d34 100644 --- a/apps/block_scout_web/test/support/conn_case.ex +++ b/apps/block_scout_web/test/support/conn_case.ex @@ -44,6 +44,8 @@ defmodule BlockScoutWeb.ConnCase do Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Transactions.child_id()) Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Accounts.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Accounts.child_id()) + Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.PendingTransactions.child_id()) + Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.PendingTransactions.child_id()) {:ok, conn: Phoenix.ConnTest.build_conn()} end diff --git a/apps/block_scout_web/test/support/feature_case.ex b/apps/block_scout_web/test/support/feature_case.ex index f6b1aedf24..2dd1d0635c 100644 --- a/apps/block_scout_web/test/support/feature_case.ex +++ b/apps/block_scout_web/test/support/feature_case.ex @@ -31,6 +31,8 @@ defmodule BlockScoutWeb.FeatureCase do Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Transactions.child_id()) Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Accounts.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Accounts.child_id()) + Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.PendingTransactions.child_id()) + Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.PendingTransactions.child_id()) metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(Explorer.Repo, self()) {:ok, session} = Wallaby.start_session(metadata: metadata) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 0cf1a05b53..1d4fbc6204 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -145,6 +145,10 @@ config :explorer, Explorer.Chain.Cache.Accounts, ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false), global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5)) +config :explorer, Explorer.Chain.Cache.PendingTransactions, + ttl_check_interval: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(1), else: false), + global_ttl: if(System.get_env("DISABLE_INDEXER") == "true", do: :timer.seconds(5)) + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 53d8c03ea3..9a8dff98d0 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -13,6 +13,7 @@ defmodule Explorer.Application do BlockNumber, Blocks, NetVersion, + PendingTransactions, TransactionCount, Transactions } @@ -51,7 +52,8 @@ defmodule Explorer.Application do con_cache_child_spec(MarketHistoryCache.cache_name()), con_cache_child_spec(RSK.cache_name(), ttl_check_interval: :timer.minutes(1), global_ttl: :timer.minutes(30)), Transactions, - Accounts + Accounts, + PendingTransactions ] children = base_children ++ configurable_children() diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index f89d933d6d..81f6061da5 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -53,6 +53,7 @@ defmodule Explorer.Chain do BlockCount, BlockNumber, Blocks, + PendingTransactions, TransactionCount, Transactions } @@ -2215,6 +2216,24 @@ defmodule Explorer.Chain do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) paging_options = Keyword.get(options, :paging_options, @default_paging_options) + if is_nil(paging_options.key) do + paging_options.page_size + |> PendingTransactions.take_enough() + |> case do + nil -> + pending_transactions = fetch_recent_pending_transactions(paging_options, necessity_by_association) + PendingTransactions.update(pending_transactions) + pending_transactions + + pending_transactions -> + pending_transactions + end + else + fetch_recent_pending_transactions(paging_options, necessity_by_association) + end + end + + defp fetch_recent_pending_transactions(paging_options, necessity_by_association) do Transaction |> page_pending_transaction(paging_options) |> limit(^paging_options.page_size) diff --git a/apps/explorer/lib/explorer/chain/cache/pending_transactions.ex b/apps/explorer/lib/explorer/chain/cache/pending_transactions.ex new file mode 100644 index 0000000000..686b5e7372 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/cache/pending_transactions.ex @@ -0,0 +1,42 @@ +defmodule Explorer.Chain.Cache.PendingTransactions do + @moduledoc """ + Caches the latest pending transactions + """ + + alias Explorer.Chain.Transaction + + use Explorer.Chain.OrderedCache, + name: :pending_transactions, + max_size: 51, + preloads: [ + :block, + created_contract_address: :names, + from_address: :names, + to_address: :names, + token_transfers: :token, + token_transfers: :from_address, + token_transfers: :to_address + ], + ttl_check_interval: Application.get_env(:explorer, __MODULE__)[:ttl_check_interval], + global_ttl: Application.get_env(:explorer, __MODULE__)[:global_ttl] + + @type element :: Transaction.t() + + @type id :: {non_neg_integer(), non_neg_integer()} + + def element_to_id(%Transaction{inserted_at: inserted_at, hash: hash}) do + {inserted_at, hash} + end + + def update_pending(transactions) when is_nil(transactions), do: :ok + + def update_pending(transactions) do + transactions + |> Enum.filter(&pending?(&1)) + |> update() + end + + defp pending?(transaction) do + is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") + end +end diff --git a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex index 394e21cbaa..c6eab88d10 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex @@ -168,11 +168,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do query = from( transaction in where_forked(blocks_changes), - select: %{ - block_hash: transaction.block_hash, - index: transaction.index, - hash: transaction.hash - }, + select: transaction, # Enforce Transaction ShareLocks order (see docs: sharelocks.md) order_by: [asc: :hash], lock: "FOR UPDATE" @@ -196,11 +192,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do updated_at: ^updated_at ] ], - select: %{ - block_hash: s.block_hash, - index: s.index, - hash: s.hash - } + select: s ) {_num, transactions} = repo.update_all(update_query, [], timeout: timeout) diff --git a/apps/explorer/test/explorer/chain/cache/pending_transactions_test.exs b/apps/explorer/test/explorer/chain/cache/pending_transactions_test.exs new file mode 100644 index 0000000000..26339bc3d7 --- /dev/null +++ b/apps/explorer/test/explorer/chain/cache/pending_transactions_test.exs @@ -0,0 +1,17 @@ +defmodule Explorer.Chain.Cache.PendingTransactionsTest do + use Explorer.DataCase + + alias Explorer.Chain.Cache.PendingTransactions + + describe "update_pending/1" do + test "adds a new pending transaction" do + transaction = insert(:transaction, block_hash: nil, error: nil) + + PendingTransactions.update([transaction]) + + transaction_hash = transaction.hash + + assert [%{hash: transaction_hash}] = PendingTransactions.all() + end + end +end diff --git a/apps/explorer/test/support/data_case.ex b/apps/explorer/test/support/data_case.ex index e12dd24a82..90167e676d 100644 --- a/apps/explorer/test/support/data_case.ex +++ b/apps/explorer/test/support/data_case.ex @@ -47,6 +47,8 @@ defmodule Explorer.DataCase do Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Transactions.child_id()) Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.Accounts.child_id()) Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.Accounts.child_id()) + Supervisor.terminate_child(Explorer.Supervisor, Explorer.Chain.Cache.PendingTransactions.child_id()) + Supervisor.restart_child(Explorer.Supervisor, Explorer.Chain.Cache.PendingTransactions.child_id()) :ok end diff --git a/apps/indexer/lib/indexer/block/fetcher.ex b/apps/indexer/lib/indexer/block/fetcher.ex index 1b95d84086..d7cdd88664 100644 --- a/apps/indexer/lib/indexer/block/fetcher.ex +++ b/apps/indexer/lib/indexer/block/fetcher.ex @@ -13,7 +13,7 @@ defmodule Indexer.Block.Fetcher do alias Explorer.Chain alias Explorer.Chain.{Address, Block, Hash, Import, Transaction} alias Explorer.Chain.Cache.Blocks, as: BlocksCache - alias Explorer.Chain.Cache.{Accounts, BlockNumber, Transactions} + alias Explorer.Chain.Cache.{Accounts, BlockNumber, PendingTransactions, Transactions} alias Indexer.Block.Fetcher.Receipts alias Indexer.Fetcher.{ @@ -175,7 +175,7 @@ defmodule Indexer.Block.Fetcher do ) do result = {:ok, %{inserted: inserted, errors: blocks_errors}} update_block_cache(inserted[:blocks]) - update_transactions_cache(inserted[:transactions]) + update_transactions_cache(inserted[:transactions], inserted[:fork_transactions]) update_addresses_cache(inserted[:addresses]) result else @@ -194,8 +194,10 @@ defmodule Indexer.Block.Fetcher do defp update_block_cache(_), do: :ok - defp update_transactions_cache(transactions) do + defp update_transactions_cache(transactions, forked_transactions) do Transactions.update(transactions) + PendingTransactions.update_pending(transactions) + PendingTransactions.update_pending(forked_transactions) end defp update_addresses_cache(addresses), do: Accounts.drop(addresses) diff --git a/apps/indexer/lib/indexer/fetcher/pending_transaction.ex b/apps/indexer/lib/indexer/fetcher/pending_transaction.ex index 176d8dc9b7..0a8389a991 100644 --- a/apps/indexer/lib/indexer/fetcher/pending_transaction.ex +++ b/apps/indexer/lib/indexer/fetcher/pending_transaction.ex @@ -14,7 +14,7 @@ defmodule Indexer.Fetcher.PendingTransaction do alias Ecto.Changeset alias Explorer.Chain - alias Explorer.Chain.Cache.Accounts + alias Explorer.Chain.Cache.{Accounts, PendingTransactions} alias Indexer.Fetcher.PendingTransaction alias Indexer.Transform.Addresses @@ -151,6 +151,7 @@ defmodule Indexer.Fetcher.PendingTransaction do }) do {:ok, imported} -> Accounts.drop(imported[:addresses]) + PendingTransactions.update_pending(imported[:transactions]) :ok {:error, [%Changeset{} | _] = changesets} -> diff --git a/apps/indexer/lib/indexer/fetcher/uncle_block.ex b/apps/indexer/lib/indexer/fetcher/uncle_block.ex index e597d16ca2..3e7ab8da63 100644 --- a/apps/indexer/lib/indexer/fetcher/uncle_block.ex +++ b/apps/indexer/lib/indexer/fetcher/uncle_block.ex @@ -12,7 +12,7 @@ defmodule Indexer.Fetcher.UncleBlock do alias Ecto.Changeset alias EthereumJSONRPC.Blocks alias Explorer.Chain - alias Explorer.Chain.Cache.Accounts + alias Explorer.Chain.Cache.{Accounts, PendingTransactions} alias Explorer.Chain.Hash alias Indexer.{Block, BufferedTask, Tracer} alias Indexer.Fetcher.UncleBlock @@ -155,7 +155,7 @@ defmodule Indexer.Fetcher.UncleBlock do @impl Block.Fetcher def import(_, options) when is_map(options) do - with {:ok, %{block_second_degree_relations: block_second_degree_relations}} = ok <- + with {:ok, %{block_second_degree_relations: block_second_degree_relations} = imported} <- options |> Map.drop(@ignored_options) |> uncle_blocks() @@ -168,8 +168,10 @@ defmodule Indexer.Fetcher.UncleBlock do # * TokenBalance.async_fetch is not called because it uses block numbers from consensus, not uncles UncleBlock.async_fetch_blocks(block_second_degree_relations) + PendingTransactions.update_pending(imported[:transactions]) + PendingTransactions.update_pending(imported[:fork_transactions]) - ok + {:ok, imported} end end From 156c6ca4551036ff42fc9c8df8cbea371f523a65 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 25 Sep 2019 13:36:50 +0300 Subject: [PATCH 07/28] do not update cache if no blocks were inserted --- apps/indexer/lib/indexer/block/fetcher.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/indexer/lib/indexer/block/fetcher.ex b/apps/indexer/lib/indexer/block/fetcher.ex index 1b95d84086..85b47cba6f 100644 --- a/apps/indexer/lib/indexer/block/fetcher.ex +++ b/apps/indexer/lib/indexer/block/fetcher.ex @@ -184,6 +184,8 @@ defmodule Indexer.Block.Fetcher do end end + defp update_block_cache([]), do: :ok + defp update_block_cache(blocks) when is_list(blocks) do {min_block, max_block} = Enum.min_max_by(blocks, & &1.number) From 3fa83faf2caeaaada3445d9b8257c80753ab3144 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 25 Sep 2019 13:39:09 +0300 Subject: [PATCH 08/28] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6791e814b7..da3cf2b091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - [#2663](https://github.com/poanetwork/blockscout/pull/2663) - Fetch address counters in parallel ### Fixes +- [#2736](https://github.com/poanetwork/blockscout/pull/2736) - do not update cache if no blocks were inserted - [#2718](https://github.com/poanetwork/blockscout/pull/2718) - Include all addresses taking part in transactions in wallets' addresses counter - [#2709](https://github.com/poanetwork/blockscout/pull/2709) - Fix stuck label and value for uncle block height - [#2707](https://github.com/poanetwork/blockscout/pull/2707) - fix for dashboard banner chart legend items From 5665e514976cb4888c1d29223ec373f8b19413e1 Mon Sep 17 00:00:00 2001 From: Yegor San Date: Wed, 25 Sep 2019 14:30:40 +0300 Subject: [PATCH 09/28] Removed hardcoded subnetwork value. --- .../lib/block_scout_web/templates/layout/_topnav.html.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index 0463d28a15..925028503c 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -16,7 +16,7 @@ - Sokol Testnet + <%= subnetwork_title() %>