Merge pull request #2768 from poanetwork/pp-remove-nonconsensus-blocks-from-cache

Remove nonconsensus blocks from cache after internal transactions importing
pull/2878/head
Victor Baranov 5 years ago committed by GitHub
commit e88e779e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 18
      apps/explorer/lib/explorer/chain/cache/blocks.ex
  3. 1
      apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex
  4. 3
      apps/indexer/lib/indexer/fetcher/internal_transaction.ex

@ -68,6 +68,7 @@
- [#2777](https://github.com/poanetwork/blockscout/pull/2777) - Remove duplicate blocks from changes_list before import - [#2777](https://github.com/poanetwork/blockscout/pull/2777) - Remove duplicate blocks from changes_list before import
- [#2770](https://github.com/poanetwork/blockscout/pull/2770) - do not re-fetch token instances without uris - [#2770](https://github.com/poanetwork/blockscout/pull/2770) - do not re-fetch token instances without uris
- [#2769](https://github.com/poanetwork/blockscout/pull/2769) - optimize token token transfers query - [#2769](https://github.com/poanetwork/blockscout/pull/2769) - optimize token token transfers query
- [#2768](https://github.com/poanetwork/blockscout/pull/2768) - Remove nonconsensus blocks from cache after internal transactions importing
- [#2761](https://github.com/poanetwork/blockscout/pull/2761) - add indexes for token instances fetching queries - [#2761](https://github.com/poanetwork/blockscout/pull/2761) - add indexes for token instances fetching queries
- [#2767](https://github.com/poanetwork/blockscout/pull/2767) - fix websocket subscriptions with token instances - [#2767](https://github.com/poanetwork/blockscout/pull/2767) - fix websocket subscriptions with token instances
- [#2765](https://github.com/poanetwork/blockscout/pull/2765) - fixed width issue for cards in mobile view for Transaction Details page - [#2765](https://github.com/poanetwork/blockscout/pull/2765) - fixed width issue for cards in mobile view for Transaction Details page

@ -20,4 +20,22 @@ defmodule Explorer.Chain.Cache.Blocks do
@type id :: non_neg_integer() @type id :: non_neg_integer()
def element_to_id(%Block{number: number}), do: number def element_to_id(%Block{number: number}), do: number
def drop_nonconsensus(numbers) when is_nil(numbers) or numbers == [], do: :ok
def drop_nonconsensus(numbers) when is_list(numbers) do
ConCache.update(cache_name(), ids_list_key(), fn ids ->
nonconsensus = MapSet.new(numbers)
{lost_consensus, kept_consensus} = Enum.split_with(ids, &MapSet.member?(nonconsensus, &1))
# immediately delete the blocks that lost consensus
Enum.each(lost_consensus, &ConCache.delete(cache_name(), &1))
# ids_list is set to never expire
{:ok, %ConCache.Item{value: kept_consensus, ttl: :infinity}}
end)
end
def drop_nonconsensus(number) when not is_nil(number), do: drop_nonconsensus([number])
end end

@ -241,6 +241,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
b in Block, b in Block,
where: b.number in ^missing_transactions_block_numbers, where: b.number in ^missing_transactions_block_numbers,
where: b.hash in ^block_hashes, where: b.hash in ^block_hashes,
select: b.number,
# ShareLocks order already enforced by `internal_transactions_indexed_at_blocks` (see docs: sharelocks.md) # ShareLocks order already enforced by `internal_transactions_indexed_at_blocks` (see docs: sharelocks.md)
update: [set: [consensus: false, internal_transactions_indexed_at: nil]] update: [set: [consensus: false, internal_transactions_indexed_at: nil]]
) )

@ -14,7 +14,7 @@ defmodule Indexer.Fetcher.InternalTransaction do
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.{Block, Hash} alias Explorer.Chain.{Block, Hash}
alias Explorer.Chain.Cache.Accounts alias Explorer.Chain.Cache.{Accounts, Blocks}
alias Indexer.{BufferedTask, Tracer} alias Indexer.{BufferedTask, Tracer}
alias Indexer.Transform.Addresses alias Indexer.Transform.Addresses
@ -220,6 +220,7 @@ defmodule Indexer.Fetcher.InternalTransaction do
case imports do case imports do
{:ok, imported} -> {:ok, imported} ->
Accounts.drop(imported[:addreses]) Accounts.drop(imported[:addreses])
Blocks.drop_nonconsensus(imported[:remove_consensus_of_missing_transactions_blocks])
async_import_coin_balances(imported, %{ async_import_coin_balances(imported, %{
address_hash_to_fetched_balance_block_number: address_hash_to_block_number address_hash_to_fetched_balance_block_number: address_hash_to_block_number

Loading…
Cancel
Save