From 19af21189a9b5ccb0629786c7203eca772a70e81 Mon Sep 17 00:00:00 2001 From: Qwerty5Uiop Date: Wed, 10 Jan 2024 14:06:13 +0400 Subject: [PATCH] Merge addresses stage with address referencing --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain/import.ex | 3 +- .../chain/import/stage/address_referencing.ex | 26 -------------- .../explorer/chain/import/stage/addresses.ex | 22 ------------ .../stage/addresses_blocks_coin_balances.ex | 34 +++++++++++++++++++ .../chain/import/stage/block_following.ex | 4 +-- .../chain/import/stage/block_pending.ex | 4 +-- .../chain/import/stage/block_referencing.ex | 3 +- 8 files changed, 39 insertions(+), 58 deletions(-) delete mode 100644 apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex delete mode 100644 apps/explorer/lib/explorer/chain/import/stage/addresses.ex create mode 100644 apps/explorer/lib/explorer/chain/import/stage/addresses_blocks_coin_balances.ex diff --git a/CHANGELOG.md b/CHANGELOG.md index e9fc17df2c..f5161e7410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - [#9155](https://github.com/blockscout/blockscout/pull/9155) - Allow bypassing avg block time in proxy implementation re-fetch ttl calculation +- [#9131](https://github.com/blockscout/blockscout/pull/9131) - Merge addresses stage with address referencing - [#9072](https://github.com/blockscout/blockscout/pull/9072) - Add tracing by block logic for geth - [#9056](https://github.com/blockscout/blockscout/pull/9056) - Noves.fi API proxy diff --git a/apps/explorer/lib/explorer/chain/import.ex b/apps/explorer/lib/explorer/chain/import.ex index 138db2c676..9372a55c01 100644 --- a/apps/explorer/lib/explorer/chain/import.ex +++ b/apps/explorer/lib/explorer/chain/import.ex @@ -12,8 +12,7 @@ defmodule Explorer.Chain.Import do require Logger @stages [ - Import.Stage.Addresses, - Import.Stage.AddressReferencing, + Import.Stage.AddressesBlocksCoinBalances, Import.Stage.BlockReferencing, Import.Stage.BlockFollowing, Import.Stage.BlockPending diff --git a/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex b/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex deleted file mode 100644 index 2d40ad74fb..0000000000 --- a/apps/explorer/lib/explorer/chain/import/stage/address_referencing.ex +++ /dev/null @@ -1,26 +0,0 @@ -defmodule Explorer.Chain.Import.Stage.AddressReferencing do - @moduledoc """ - Imports any tables that reference `t:Explorer.Chain.Address.t/0` and that were imported by - `Explorer.Chain.Import.Stage.Addresses`. - """ - - alias Explorer.Chain.Import.{Runner, Stage} - - @behaviour Stage - - @impl Stage - def runners, - do: [ - Runner.Address.CoinBalances, - Runner.Blocks, - Runner.Address.CoinBalancesDaily - ] - - @impl Stage - def multis(runner_to_changes_list, options) do - {final_multi, final_remaining_runner_to_changes_list} = - Stage.single_multi(runners(), runner_to_changes_list, options) - - {[final_multi], final_remaining_runner_to_changes_list} - end -end diff --git a/apps/explorer/lib/explorer/chain/import/stage/addresses.ex b/apps/explorer/lib/explorer/chain/import/stage/addresses.ex deleted file mode 100644 index 03c8a57724..0000000000 --- a/apps/explorer/lib/explorer/chain/import/stage/addresses.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule Explorer.Chain.Import.Stage.Addresses do - @moduledoc """ - Imports addresses before anything else that references them because an unused address is still valid and recoverable - if the other stage(s) don't commit. - """ - - alias Explorer.Chain.Import.{Runner, Stage} - - @behaviour Stage - - @runner Runner.Addresses - - @impl Stage - def runners, do: [@runner] - - @chunk_size 50 - - @impl Stage - def multis(runner_to_changes_list, options) do - Stage.chunk_every(runner_to_changes_list, @runner, @chunk_size, options) - end -end diff --git a/apps/explorer/lib/explorer/chain/import/stage/addresses_blocks_coin_balances.ex b/apps/explorer/lib/explorer/chain/import/stage/addresses_blocks_coin_balances.ex new file mode 100644 index 0000000000..bdd8ae478e --- /dev/null +++ b/apps/explorer/lib/explorer/chain/import/stage/addresses_blocks_coin_balances.ex @@ -0,0 +1,34 @@ +defmodule Explorer.Chain.Import.Stage.AddressesBlocksCoinBalances do + @moduledoc """ + Import addresses, blocks and balances. + No tables have foreign key to addresses anymore, so it's possible to import addresses along with them. + """ + + alias Explorer.Chain.Import.{Runner, Stage} + + @behaviour Stage + + @addresses_runner Runner.Addresses + + @rest_runners [ + Runner.Address.CoinBalances, + Runner.Blocks, + Runner.Address.CoinBalancesDaily + ] + + @impl Stage + def runners, do: [@addresses_runner | @rest_runners] + + @addresses_chunk_size 50 + + @impl Stage + def multis(runner_to_changes_list, options) do + {addresses_multis, remaining_runner_to_changes_list} = + Stage.chunk_every(runner_to_changes_list, Runner.Addresses, @addresses_chunk_size, options) + + {final_multi, final_remaining_runner_to_changes_list} = + Stage.single_multi(@rest_runners, remaining_runner_to_changes_list, options) + + {[final_multi | addresses_multis], final_remaining_runner_to_changes_list} + end +end diff --git a/apps/explorer/lib/explorer/chain/import/stage/block_following.ex b/apps/explorer/lib/explorer/chain/import/stage/block_following.ex index 8abbf9f79b..2a533c1b68 100644 --- a/apps/explorer/lib/explorer/chain/import/stage/block_following.ex +++ b/apps/explorer/lib/explorer/chain/import/stage/block_following.ex @@ -1,9 +1,7 @@ defmodule Explorer.Chain.Import.Stage.BlockFollowing do @moduledoc """ Imports any tables that follows and cannot be imported at the same time as - those imported by `Explorer.Chain.Import.Stage.Addresses`, - `Explorer.Chain.Import.Stage.AddressReferencing` and - `Explorer.Chain.Import.Stage.BlockReferencing` + those imported by `Explorer.Chain.Import.Stage.AddressesBlocksCoinBalances` and `Explorer.Chain.Import.Stage.BlockReferencing` """ alias Explorer.Chain.Import.{Runner, Stage} diff --git a/apps/explorer/lib/explorer/chain/import/stage/block_pending.ex b/apps/explorer/lib/explorer/chain/import/stage/block_pending.ex index fba315e142..824a4dc3ce 100644 --- a/apps/explorer/lib/explorer/chain/import/stage/block_pending.ex +++ b/apps/explorer/lib/explorer/chain/import/stage/block_pending.ex @@ -2,9 +2,7 @@ defmodule Explorer.Chain.Import.Stage.BlockPending do @moduledoc """ Imports any tables that uses `Explorer.Chain.PendingBlockOperation` to track progress and cannot be imported at the same time as those imported by - `Explorer.Chain.Import.Stage.Addresses`, - `Explorer.Chain.Import.Stage.AddressReferencing` and - `Explorer.Chain.Import.Stage.BlockReferencing` + `Explorer.Chain.Import.Stage.AddressesBlocksCoinBalances` and `Explorer.Chain.Import.Stage.BlockReferencing` """ alias Explorer.Chain.Import.{Runner, Stage} diff --git a/apps/explorer/lib/explorer/chain/import/stage/block_referencing.ex b/apps/explorer/lib/explorer/chain/import/stage/block_referencing.ex index 1589c95a38..142a232654 100644 --- a/apps/explorer/lib/explorer/chain/import/stage/block_referencing.ex +++ b/apps/explorer/lib/explorer/chain/import/stage/block_referencing.ex @@ -1,8 +1,7 @@ defmodule Explorer.Chain.Import.Stage.BlockReferencing do @moduledoc """ Imports any tables that reference `t:Explorer.Chain.Block.t/0` and that were - imported by `Explorer.Chain.Import.Stage.Addresses` and - `Explorer.Chain.Import.Stage.AddressReferencing`. + imported by `Explorer.Chain.Import.Stage.AddressesBlocksCoinBalances`. """ alias Explorer.Chain.Import.{Runner, Stage}