-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82cd0c4
commit 67a9e43
Showing
4 changed files
with
69 additions
and
27 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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
INSERT INTO accounts (address, latest_nonce, latest_balance, bytecode, creation_block) | ||
VALUES ($1, $2, $3, $4, $5) | ||
INSERT INTO accounts ( | ||
address, bytecode, latest_balance, latest_nonce, creation_block, previous_balance, previous_nonce | ||
) | ||
VALUES ($1, $2, $3, $4, $5, $6, $7) | ||
ON CONFLICT (address) DO | ||
UPDATE | ||
SET latest_nonce = EXCLUDED.latest_nonce, | ||
latest_balance = EXCLUDED.latest_balance | ||
WHERE accounts.latest_nonce = $6 AND accounts.latest_balance = $7 | ||
WHERE accounts.latest_nonce = excluded.previous_balance AND accounts.latest_balance = excluded.previous_balance |
49 changes: 39 additions & 10 deletions
49
src/eth/storage/postgres/queries/insert_account_batch.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 |
---|---|---|
@@ -1,14 +1,43 @@ | ||
WITH account_updates | ||
AS (SELECT * | ||
FROM UNNEST($1::bytea[], $2::bytea[], $3::numeric[], $4::numeric[], $5::numeric[], $6::numeric[], $7::numeric[]) | ||
AS t(address, bytecode, new_balance, new_nonce, creation_block, original_balance, original_nonce) | ||
WITH account_updates AS ( | ||
SELECT * | ||
FROM | ||
unnest( | ||
$50::bytea [], | ||
$51::bytea [], | ||
$52::numeric [], | ||
$53::numeric [], | ||
$54::numeric [], | ||
$55::numeric [], | ||
$56::numeric [] | ||
) | ||
AS t ( | ||
address, | ||
bytecode, | ||
new_balance, | ||
new_nonce, | ||
creation_block, | ||
previous_balance, | ||
previous_nonce | ||
) | ||
) | ||
INSERT INTO accounts (address, bytecode, latest_balance, latest_nonce, creation_block) | ||
SELECT address, bytecode, new_balance, new_nonce, creation_block | ||
|
||
INSERT INTO accounts ( | ||
address, bytecode, latest_balance, latest_nonce, creation_block, previous_balance, previous_nonce | ||
) | ||
SELECT | ||
address, | ||
bytecode, | ||
new_balance, | ||
new_nonce, | ||
creation_block, | ||
previous_balance, | ||
previous_nonce | ||
FROM account_updates | ||
ON CONFLICT (address) DO | ||
UPDATE | ||
SET latest_nonce = EXCLUDED.latest_nonce, | ||
latest_balance = EXCLUDED.latest_balance | ||
WHERE accounts.latest_nonce = (SELECT original_nonce FROM account_updates WHERE account_updates.address=accounts.address) | ||
AND accounts.latest_balance = (SELECT original_balance FROM account_updates WHERE account_updates.address=accounts.address) | ||
SET latest_nonce = excluded.latest_nonce, | ||
latest_balance = excluded.latest_balance, | ||
previous_balance = excluded.previous_balance, | ||
previous_nonce = excluded.previous_nonce | ||
WHERE accounts.latest_nonce = excluded.previous_nonce | ||
AND accounts.latest_balance = excluded.previous_balance |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
INSERT INTO account_slots VALUES ($1, $2, $3, $4) | ||
INSERT INTO account_slots(idx, value, previous_value, account_address, creation_block) | ||
VALUES ($1, $2, $3, $4, $5) | ||
ON CONFLICT (idx, account_address) | ||
DO UPDATE SET value = EXCLUDED.value | ||
WHERE account_slots.value = $5 | ||
WHERE account_slots.value = excluded.previous_value |
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 |
---|---|---|
@@ -1,16 +1,26 @@ | ||
WITH slot_updates | ||
AS (SELECT * | ||
FROM UNNEST($1::bytea[], $2::bytea[], $3::bytea[], $4::numeric[], $5::bytea[]) | ||
AS t(idx, value, account_address, creation_block, original_value) | ||
WITH slot_updates AS ( | ||
SELECT * | ||
FROM | ||
unnest( | ||
$57::bytea [], | ||
$58::bytea [], | ||
$59::bytea [], | ||
$60::numeric [], | ||
$61::bytea [] | ||
) | ||
AS t (idx, value, account_address, block_number, original_value) | ||
) | ||
INSERT INTO account_slots (idx, value, account_address, creation_block) | ||
SELECT idx, value, account_address, creation_block | ||
|
||
INSERT INTO account_slots (idx, value, previous_value, account_address, creation_block) | ||
SELECT | ||
idx, | ||
value, | ||
original_value, | ||
account_address, | ||
block_number | ||
FROM slot_updates | ||
ON CONFLICT (idx, account_address) DO | ||
UPDATE | ||
SET value = EXCLUDED.value | ||
WHERE account_slots.value = ( | ||
SELECT original_value | ||
FROM slot_updates | ||
WHERE slot_updates.idx = EXCLUDED.idx | ||
AND slot_updates.account_address = EXCLUDED.account_address) | ||
SET value = excluded.value, | ||
previous_value = excluded.previous_value | ||
WHERE account_slots.value = excluded.previous_value |