fix: Transactions and token transfers block_consensus (#10285)
parent
b8d77f856a
commit
86b10d9e62
@ -0,0 +1,57 @@ |
||||
defmodule Explorer.Migrator.TokenTransferBlockConsensus do |
||||
@moduledoc """ |
||||
Fixes token transfers block_consensus field |
||||
""" |
||||
|
||||
use Explorer.Migrator.FillingMigration |
||||
|
||||
import Ecto.Query |
||||
|
||||
alias Explorer.Chain.TokenTransfer |
||||
alias Explorer.Migrator.FillingMigration |
||||
alias Explorer.Repo |
||||
|
||||
@migration_name "token_transfers_block_consensus" |
||||
|
||||
@impl FillingMigration |
||||
def migration_name, do: @migration_name |
||||
|
||||
@impl FillingMigration |
||||
def last_unprocessed_identifiers do |
||||
limit = batch_size() * concurrency() |
||||
|
||||
unprocessed_data_query() |
||||
|> select([tt], {tt.transaction_hash, tt.block_hash, tt.log_index}) |
||||
|> limit(^limit) |
||||
|> Repo.all(timeout: :infinity) |
||||
end |
||||
|
||||
@impl FillingMigration |
||||
def unprocessed_data_query do |
||||
from( |
||||
tt in TokenTransfer, |
||||
join: block in assoc(tt, :block), |
||||
where: tt.block_consensus != block.consensus |
||||
) |
||||
end |
||||
|
||||
@impl FillingMigration |
||||
def update_batch(token_transfer_ids) do |
||||
token_transfer_ids |
||||
|> build_update_query() |
||||
|> Repo.query!([], timeout: :infinity) |
||||
end |
||||
|
||||
@impl FillingMigration |
||||
def update_cache, do: :ok |
||||
|
||||
defp build_update_query(token_transfer_ids) do |
||||
""" |
||||
UPDATE token_transfers tt |
||||
SET block_consensus = b.consensus |
||||
FROM blocks b |
||||
WHERE tt.block_hash = b.hash |
||||
AND (tt.transaction_hash, tt.block_hash, tt.log_index) IN #{TokenTransfer.encode_token_transfer_ids(token_transfer_ids)}; |
||||
""" |
||||
end |
||||
end |
@ -0,0 +1,52 @@ |
||||
defmodule Explorer.Migrator.TransactionBlockConsensus do |
||||
@moduledoc """ |
||||
Fixes transactions block_consensus field |
||||
""" |
||||
|
||||
use Explorer.Migrator.FillingMigration |
||||
|
||||
import Ecto.Query |
||||
|
||||
alias Explorer.Chain.Transaction |
||||
alias Explorer.Migrator.FillingMigration |
||||
alias Explorer.Repo |
||||
|
||||
@migration_name "transactions_block_consensus" |
||||
|
||||
@impl FillingMigration |
||||
def migration_name, do: @migration_name |
||||
|
||||
@impl FillingMigration |
||||
def last_unprocessed_identifiers do |
||||
limit = batch_size() * concurrency() |
||||
|
||||
unprocessed_data_query() |
||||
|> select([t], t.hash) |
||||
|> limit(^limit) |
||||
|> Repo.all(timeout: :infinity) |
||||
end |
||||
|
||||
@impl FillingMigration |
||||
def unprocessed_data_query do |
||||
from( |
||||
transaction in Transaction, |
||||
join: block in assoc(transaction, :block), |
||||
where: transaction.block_consensus != block.consensus |
||||
) |
||||
end |
||||
|
||||
@impl FillingMigration |
||||
def update_batch(transaction_hashes) do |
||||
query = |
||||
from(transaction in Transaction, |
||||
join: block in assoc(transaction, :block), |
||||
where: transaction.hash in ^transaction_hashes, |
||||
update: [set: [block_consensus: block.consensus]] |
||||
) |
||||
|
||||
Repo.update_all(query, [], timeout: :infinity) |
||||
end |
||||
|
||||
@impl FillingMigration |
||||
def update_cache, do: :ok |
||||
end |
Loading…
Reference in new issue