-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(db): add tx blob gas used * feat(db): add tx blob gas used backfill migration * feat(db): make tx blob gas used field mandatory * feat: add tx blob gas used * chore: add changeset
- Loading branch information
Showing
21 changed files
with
137 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@blobscan/db": minor | ||
"@blobscan/api": patch | ||
--- | ||
|
||
Added blob gas used to `Transaction` model |
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
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
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: 2 additions & 0 deletions
2
packages/db/prisma/migrations/20240910013656_add_tx_blob_gas_used/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "transaction" ADD COLUMN "blob_gas_used" DECIMAL(100,0); |
36 changes: 36 additions & 0 deletions
36
packages/db/prisma/migrations/20240910013741_backfill_tx_blob_gas_used/migration.sql
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,36 @@ | ||
DO $$ | ||
DECLARE | ||
batch_size INT := 1000; -- Define the size of each batch | ||
update_count INT := 0; -- Variable to store the count of updated rows | ||
BEGIN | ||
-- Loop indefinitely until no rows are updated | ||
LOOP | ||
WITH candidate_rows AS ( | ||
-- Select rows for update in batches of 1000, using NOWAIT to avoid locking conflicts | ||
SELECT hash | ||
FROM transaction | ||
WHERE blob_gas_used IS NULL | ||
LIMIT batch_size | ||
FOR UPDATE NOWAIT | ||
), update_rows AS ( | ||
-- Perform the update for the selected rows | ||
UPDATE transaction | ||
SET blob_gas_used = ( | ||
SELECT COUNT(btx.blob_hash) * 131072 AS blob_gas_used | ||
FROM blobs_on_transactions btx | ||
WHERE btx.tx_hash = transaction.hash | ||
) | ||
FROM candidate_rows | ||
WHERE candidate_rows.hash = transaction.hash | ||
RETURNING transaction.hash | ||
) | ||
-- Count the number of updated rows in this batch | ||
SELECT count(1) INTO update_count FROM update_rows; | ||
|
||
-- Exit the loop if no rows were updated in this batch | ||
EXIT WHEN update_count = 0; | ||
|
||
-- Optional: Sleep briefly to reduce load on the database | ||
PERFORM pg_sleep(0.1); | ||
END LOOP; | ||
END $$; |
8 changes: 8 additions & 0 deletions
8
...s/db/prisma/migrations/20240910015119_make_tx_blob_gas_used_field_mandatory/migration.sql
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,8 @@ | ||
/* | ||
Warnings: | ||
- Made the column `blob_gas_used` on table `transaction` required. This step will fail if there are existing NULL values in that column. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "transaction" ALTER COLUMN "blob_gas_used" SET NOT NULL; |
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
Oops, something went wrong.