diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 233186aa47..9503b7e0a6 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -129,6 +129,7 @@ config :explorer, Explorer.Migrator.TransactionBlockConsensus, enabled: true config :explorer, Explorer.Migrator.TokenTransferBlockConsensus, enabled: true config :explorer, Explorer.Migrator.RestoreOmittedWETHTransfers, enabled: true config :explorer, Explorer.Migrator.SanitizeMissingTokenBalances, enabled: true +config :explorer, Explorer.Migrator.SanitizeReplacedTransactions, enabled: true config :explorer, Explorer.Chain.Fetcher.CheckBytecodeMatchingOnDemand, enabled: true diff --git a/apps/explorer/config/runtime/test.exs b/apps/explorer/config/runtime/test.exs index eeae8772a7..01874f4bbf 100644 --- a/apps/explorer/config/runtime/test.exs +++ b/apps/explorer/config/runtime/test.exs @@ -50,6 +50,7 @@ config :explorer, Explorer.Migrator.TokenTransferBlockConsensus, enabled: false config :explorer, Explorer.Migrator.ShrinkInternalTransactions, enabled: false config :explorer, Explorer.Migrator.RestoreOmittedWETHTransfers, enabled: false config :explorer, Explorer.Migrator.SanitizeMissingTokenBalances, enabled: false +config :explorer, Explorer.Migrator.SanitizeReplacedTransactions, enabled: false config :explorer, realtime_events_sender: Explorer.Chain.Events.SimpleSender diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 96685ea646..b5b4fcee2f 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -146,7 +146,8 @@ defmodule Explorer.Application do configure_mode_dependent_process(Explorer.Migrator.ShrinkInternalTransactions, :indexer), configure_chain_type_dependent_process(Explorer.Chain.Cache.BlackfortValidatorsCounters, :blackfort), configure_chain_type_dependent_process(Explorer.Chain.Cache.StabilityValidatorsCounters, :stability), - configure_mode_dependent_process(Explorer.Migrator.SanitizeMissingTokenBalances, :indexer) + configure_mode_dependent_process(Explorer.Migrator.SanitizeMissingTokenBalances, :indexer), + configure_mode_dependent_process(Explorer.Migrator.SanitizeReplacedTransactions, :indexer) ] |> List.flatten() diff --git a/apps/explorer/lib/explorer/migrator/sanitize_replaced_transactions.ex b/apps/explorer/lib/explorer/migrator/sanitize_replaced_transactions.ex new file mode 100644 index 0000000000..5b92f7176d --- /dev/null +++ b/apps/explorer/lib/explorer/migrator/sanitize_replaced_transactions.ex @@ -0,0 +1,46 @@ +defmodule Explorer.Migrator.SanitizeReplacedTransactions do + @moduledoc """ + Cleans the transactions that are related to non-consensus blocks. + """ + + use Explorer.Migrator.FillingMigration + + import Ecto.Query + + alias Explorer.Chain.Transaction + alias Explorer.Migrator.FillingMigration + alias Explorer.Repo + + @migration_name "sanitize_replaced_transactions" + + @impl FillingMigration + def migration_name, do: @migration_name + + @impl FillingMigration + def last_unprocessed_identifiers(state) do + limit = batch_size() * concurrency() + + ids = + unprocessed_data_query() + |> select([t], t.hash) + |> limit(^limit) + |> Repo.all(timeout: :infinity) + + {ids, state} + end + + @impl FillingMigration + def unprocessed_data_query do + from(t in Transaction, where: t.block_consensus == false) + end + + @impl FillingMigration + def update_batch(transaction_hashes) do + query = from(t in Transaction, where: t.hash in ^transaction_hashes) + + Repo.delete_all(query, timeout: :infinity) + end + + @impl FillingMigration + def update_cache, do: :ok +end