Skip to content

Commit

Permalink
fix: Fix tokens and transactions deadlocks (blockscout#11620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwerty5Uiop authored Jan 8, 2025
1 parent 84babac commit 4d29cc2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/explorer/lib/explorer/chain/import.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule Explorer.Chain.Import do
[
Import.Stage.BlockTransactionReferencing,
Import.Stage.TokenReferencing,
Import.Stage.TokenInstances,
Import.Stage.InternalTransactions,
Import.Stage.ChainTypeSpecific
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ defmodule Explorer.Chain.Import.Runner.SignedAuthorizations do
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
conflict_target = [:transaction_hash, :index]
ordered_changes_list = Enum.sort_by(changes_list, &{&1.transaction_hash, &1.index})

{:ok, _} =
Import.insert_changes_list(
repo,
changes_list,
ordered_changes_list,
for: SignedAuthorization,
on_conflict: on_conflict,
conflict_target: conflict_target,
Expand Down
27 changes: 27 additions & 0 deletions apps/explorer/lib/explorer/chain/import/stage/token_instances.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Explorer.Chain.Import.Stage.TokenInstances do
@moduledoc """
Import token instances.
"""

alias Explorer.Chain.Import.{Runner, Stage}

@behaviour Stage

@runners [
Runner.TokenInstances
]

@impl Stage
def runners, do: @runners

@impl Stage
def all_runners, do: runners()

@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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Explorer.Chain.Import.Stage.TokenReferencing do
@behaviour Stage

@runners [
Runner.TokenInstances,
Runner.Address.TokenBalances,
Runner.Address.CurrentTokenBalances
]
Expand Down

0 comments on commit 4d29cc2

Please sign in to comment.