forked from blockscout/blockscout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/blockscout/blockscout int…
…o sync-15-07-24
- Loading branch information
Showing
14 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/explorer/lib/explorer/chain/import/stage/block_following.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
apps/explorer/lib/explorer/chain/import/stage/block_referencing.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/explorer/lib/explorer/migrator/token_transfer_block_consensus.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
52 changes: 52 additions & 0 deletions
52
apps/explorer/lib/explorer/migrator/transaction_block_consensus.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters