diff --git a/CHANGELOG.md b/CHANGELOG.md index b26ab858ad..3a0b91e943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - [#2642](https://github.com/poanetwork/blockscout/pull/2642) - add ERC721 coin instance page ### Fixes +- [#2768](https://github.com/poanetwork/blockscout/pull/2768) - Remove nonconsensus blocks from cache after internal transactions importing - [#2753](https://github.com/poanetwork/blockscout/pull/2753) - fix nft token instance images - [#2750](https://github.com/poanetwork/blockscout/pull/2750) - fixed contract buttons color for NFT token instance on each theme - [#2746](https://github.com/poanetwork/blockscout/pull/2746) - fixed wrong alignment in logs decoded view diff --git a/apps/explorer/lib/explorer/chain/cache/blocks.ex b/apps/explorer/lib/explorer/chain/cache/blocks.ex index d2a5b47061..11b75a4d09 100644 --- a/apps/explorer/lib/explorer/chain/cache/blocks.ex +++ b/apps/explorer/lib/explorer/chain/cache/blocks.ex @@ -20,4 +20,22 @@ defmodule Explorer.Chain.Cache.Blocks do @type id :: non_neg_integer() def element_to_id(%Block{number: number}), do: number + + def drop_nonconsensus([]), 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 diff --git a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex index b4704d382b..9d16328555 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex @@ -241,6 +241,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do b in Block, where: b.number in ^missing_transactions_block_numbers, where: b.hash in ^block_hashes, + select: b.number, # ShareLocks order already enforced by `internal_transactions_indexed_at_blocks` (see docs: sharelocks.md) update: [set: [consensus: false, internal_transactions_indexed_at: nil]] ) diff --git a/apps/indexer/lib/indexer/fetcher/internal_transaction.ex b/apps/indexer/lib/indexer/fetcher/internal_transaction.ex index 5ad7c5d506..77ba3cd6ec 100644 --- a/apps/indexer/lib/indexer/fetcher/internal_transaction.ex +++ b/apps/indexer/lib/indexer/fetcher/internal_transaction.ex @@ -14,7 +14,7 @@ defmodule Indexer.Fetcher.InternalTransaction do alias Explorer.Chain alias Explorer.Chain.{Block, Hash} - alias Explorer.Chain.Cache.Accounts + alias Explorer.Chain.Cache.{Accounts, Blocks} alias Indexer.{BufferedTask, Tracer} alias Indexer.Transform.Addresses @@ -220,6 +220,7 @@ defmodule Indexer.Fetcher.InternalTransaction do case imports do {:ok, imported} -> Accounts.drop(imported[:addreses]) + Blocks.drop_nonconsensus(imported[:remove_consensus_of_missing_transactions_blocks]) async_import_coin_balances(imported, %{ address_hash_to_fetched_balance_block_number: address_hash_to_block_number