|
|
|
@ -60,11 +60,37 @@ defmodule Explorer.Repo.Migrations.AddPendingInternalTxsOperation do |
|
|
|
|
DECLARE |
|
|
|
|
duplicates_count INTEGER := 0; |
|
|
|
|
blocks_scanned INTEGER := 0; |
|
|
|
|
int_txs_count INTEGER := 0; |
|
|
|
|
temprow RECORD; |
|
|
|
|
BEGIN |
|
|
|
|
FOR temprow IN |
|
|
|
|
SELECT number, hash FROM blocks |
|
|
|
|
LOOP |
|
|
|
|
SELECT COUNT(*) INTO int_txs_count FROM internal_transactions; |
|
|
|
|
IF int_txs_count < 10000000 THEN |
|
|
|
|
|
|
|
|
|
FOR temprow IN |
|
|
|
|
SELECT block_hash FROM internal_transactions |
|
|
|
|
GROUP BY block_hash, block_index HAVING COUNT(*) > 1 |
|
|
|
|
LOOP |
|
|
|
|
duplicates_count := duplicates_count + 1; |
|
|
|
|
RAISE NOTICE '% duplicates, blocks scanned %, block #%, block hash is %', duplicates_count, blocks_scanned, temprow.number , temprow.hash; |
|
|
|
|
|
|
|
|
|
IF NOT EXISTS ( |
|
|
|
|
SELECT 1 FROM pending_block_operations |
|
|
|
|
WHERE block_hash = temprow.block_hash |
|
|
|
|
) THEN |
|
|
|
|
INSERT INTO pending_block_operations |
|
|
|
|
(block_hash, inserted_at, updated_at, fetch_internal_transactions) |
|
|
|
|
SELECT b.hash, now(), now(), TRUE FROM blocks b |
|
|
|
|
WHERE b.hash = temprow.block_hash; |
|
|
|
|
END IF; |
|
|
|
|
|
|
|
|
|
DELETE FROM internal_transactions |
|
|
|
|
WHERE block_hash = temprow.block_hash; |
|
|
|
|
|
|
|
|
|
RAISE NOTICE 'DELETED'; |
|
|
|
|
END LOOP; |
|
|
|
|
|
|
|
|
|
ELSE |
|
|
|
|
FOR temprow IN SELECT number, hash FROM blocks LOOP |
|
|
|
|
blocks_scanned := blocks_scanned + 1; |
|
|
|
|
IF EXISTS ( |
|
|
|
|
SELECT 1 FROM transactions WHERE block_hash = temprow.hash |
|
|
|
@ -93,7 +119,8 @@ defmodule Explorer.Repo.Migrations.AddPendingInternalTxsOperation do |
|
|
|
|
RAISE NOTICE 'DELETED'; |
|
|
|
|
END IF; |
|
|
|
|
END IF; |
|
|
|
|
END LOOP; |
|
|
|
|
END LOOP; |
|
|
|
|
END IF; |
|
|
|
|
RAISE NOTICE 'SCRIPT FINISHED'; |
|
|
|
|
END $$; |
|
|
|
|
""") |
|
|
|
|