From 4540dd7042aaf3f08906332a04bc795618e09c02 Mon Sep 17 00:00:00 2001 From: renancloudwalk <53792026+renancloudwalk@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:45:37 -0300 Subject: [PATCH] chore: fix column names and FROM without alias (#334) * chore: fix column names and FROM without alias * fix: remove wrong files from commit --- ...68fd02451d51f76e0256ba5de7507cfad075.json} | 4 +-- ...419cab2f276ed2817e2278f8166bd8c2bdc41.json | 29 ------------------- .../postgres/queries/insert_entire_block.sql | 4 +-- src/infra/postgres.rs | 1 - 4 files changed, 4 insertions(+), 34 deletions(-) rename .sqlx/{query-dabff00b1d2f5797afafabb135a018043577aaab2e774cf451ba20698b274f1f.json => query-2fd2736ed6e47d28c94966ae96b568fd02451d51f76e0256ba5de7507cfad075.json} (97%) delete mode 100644 .sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json diff --git a/.sqlx/query-dabff00b1d2f5797afafabb135a018043577aaab2e774cf451ba20698b274f1f.json b/.sqlx/query-2fd2736ed6e47d28c94966ae96b568fd02451d51f76e0256ba5de7507cfad075.json similarity index 97% rename from .sqlx/query-dabff00b1d2f5797afafabb135a018043577aaab2e774cf451ba20698b274f1f.json rename to .sqlx/query-2fd2736ed6e47d28c94966ae96b568fd02451d51f76e0256ba5de7507cfad075.json index 5f7f7a615..9e551a6b3 100644 --- a/.sqlx/query-dabff00b1d2f5797afafabb135a018043577aaab2e774cf451ba20698b274f1f.json +++ b/.sqlx/query-2fd2736ed6e47d28c94966ae96b568fd02451d51f76e0256ba5de7507cfad075.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "WITH block_insert AS (\n INSERT INTO blocks (\n number,\n hash,\n transactions_root,\n gas_limit,\n gas_used,\n logs_bloom,\n timestamp_in_secs,\n parent_hash,\n author,\n extra_data,\n miner,\n difficulty,\n receipts_root,\n uncle_hash,\n size,\n state_root,\n total_difficulty,\n nonce,\n created_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, current_timestamp)\n RETURNING 1 as res\n),\n\ntransaction_insert AS (\n INSERT INTO transactions (\n hash,\n signer_address,\n nonce,\n address_from,\n address_to,\n input,\n output,\n gas,\n gas_price,\n idx_in_block,\n block_number,\n block_hash,\n v,\n r,\n s,\n value,\n result\n )\n SELECT *\n FROM\n unnest(\n $19::bytea [],\n $20::bytea [],\n $21::numeric [],\n $22::bytea [],\n $23::bytea [],\n $24::bytea [],\n $25::bytea [],\n $26::numeric [],\n $27::numeric [],\n $28::numeric [],\n $29::numeric [],\n $30::bytea [],\n $31::bytea [],\n $32::bytea [],\n $33::bytea [],\n $34::numeric [],\n $35::text []\n )\n RETURNING 1 as res\n),\n\nlog_insert AS (\n INSERT INTO logs (\n address,\n data,\n transaction_hash,\n transaction_idx,\n log_idx,\n block_number,\n block_hash\n )\n SELECT *\n FROM\n unnest(\n $36::bytea [],\n $37::bytea [],\n $38::bytea [],\n $39::numeric [],\n $40::numeric [],\n $41::numeric [],\n $42::bytea []\n )\n RETURNING 1 as res\n),\n\ntopic_insert AS (\n INSERT INTO topics (\n topic,\n transaction_hash,\n transaction_idx,\n log_idx,\n topic_idx,\n block_number,\n block_hash\n )\n SELECT *\n FROM\n unnest(\n $43::bytea [],\n $44::bytea [],\n $45::numeric [],\n $46::numeric [],\n $47::numeric [],\n $48::numeric [],\n $49::bytea []\n )\n RETURNING 1 as res\n),\n\naccount_insert AS (\n WITH account_updates AS (\n SELECT *\n FROM\n unnest(\n $50::bytea [],\n $51::bytea [],\n $52::numeric [],\n $53::numeric [],\n $54::numeric [],\n $55::numeric [],\n $56::numeric []\n )\n AS t (\n address,\n bytecode,\n new_balance,\n new_nonce,\n creation_block,\n previous_balance,\n previous_nonce\n )\n )\n\n INSERT INTO accounts (\n address, bytecode, latest_balance, latest_nonce, creation_block, previous_balance, previous_nonce\n )\n SELECT\n address,\n bytecode,\n new_balance,\n new_nonce,\n creation_block,\n previous_balance,\n previous_nonce\n FROM account_updates\n ON CONFLICT (address) DO\n UPDATE\n SET latest_nonce = excluded.latest_nonce,\n latest_balance = excluded.latest_balance,\n previous_balance = excluded.previous_balance,\n previous_nonce = excluded.previous_nonce\n WHERE accounts.latest_nonce = excluded.previous_nonce\n AND accounts.latest_balance = excluded.previous_balance\n RETURNING 1 as res\n),\n\nslot_insert AS (\n WITH slot_updates AS (\n SELECT *\n FROM\n unnest(\n $57::bytea [],\n $58::bytea [],\n $59::bytea [],\n $60::numeric [],\n $61::bytea []\n )\n AS t (idx, value, account_address, creation_block, original_value)\n )\n\n INSERT INTO account_slots (idx, value, previous_value, account_address, creation_block)\n SELECT\n idx,\n value,\n original_value,\n account_address,\n creation_block\n FROM slot_updates\n ON CONFLICT (idx, account_address) DO\n UPDATE\n SET value = excluded.value,\n previous_value = excluded.previous_value\n WHERE account_slots.value = excluded.previous_value\n RETURNING 1 as res\n),\n\nhistorical_nonce_insert AS (\n INSERT INTO historical_nonces (address, nonce, block_number)\n SELECT * FROM unnest($62::bytea [], $63::numeric [], $64::numeric [])\n RETURNING 1 as res\n),\n\nhistorical_balance_insert AS (\n INSERT INTO historical_balances (address, balance, block_number)\n SELECT * FROM unnest($65::bytea [], $66::numeric [], $67::numeric [])\n RETURNING 1 as res\n),\n\nhistorical_slots_insert AS (\n INSERT INTO historical_slots (idx, value, account_address, block_number)\n SELECT *\n FROM unnest($68::bytea [], $69::bytea [], $70::bytea [], $71::numeric [])\n RETURNING 1 as res\n)\n\nSELECT modified_accounts, modified_slots FROM\n(SELECT count(*) AS modified_accounts FROM account_insert)\nCROSS JOIN\n(SELECT count(*) AS modified_slots FROM slot_insert);\n", + "query": "WITH block_insert AS (\n INSERT INTO blocks (\n number,\n hash,\n transactions_root,\n gas_limit,\n gas_used,\n logs_bloom,\n timestamp_in_secs,\n parent_hash,\n author,\n extra_data,\n miner,\n difficulty,\n receipts_root,\n uncle_hash,\n size,\n state_root,\n total_difficulty,\n nonce,\n created_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, current_timestamp)\n RETURNING 1 as res\n),\n\ntransaction_insert AS (\n INSERT INTO transactions (\n hash,\n signer_address,\n nonce,\n address_from,\n address_to,\n input,\n output,\n gas,\n gas_price,\n idx_in_block,\n block_number,\n block_hash,\n v,\n r,\n s,\n value,\n result\n )\n SELECT *\n FROM\n unnest(\n $19::bytea [],\n $20::bytea [],\n $21::numeric [],\n $22::bytea [],\n $23::bytea [],\n $24::bytea [],\n $25::bytea [],\n $26::numeric [],\n $27::numeric [],\n $28::numeric [],\n $29::numeric [],\n $30::bytea [],\n $31::bytea [],\n $32::bytea [],\n $33::bytea [],\n $34::numeric [],\n $35::text []\n )\n RETURNING 1 as res\n),\n\nlog_insert AS (\n INSERT INTO logs (\n address,\n data,\n transaction_hash,\n transaction_idx,\n log_idx,\n block_number,\n block_hash\n )\n SELECT *\n FROM\n unnest(\n $36::bytea [],\n $37::bytea [],\n $38::bytea [],\n $39::numeric [],\n $40::numeric [],\n $41::numeric [],\n $42::bytea []\n )\n RETURNING 1 as res\n),\n\ntopic_insert AS (\n INSERT INTO topics (\n topic,\n transaction_hash,\n transaction_idx,\n log_idx,\n topic_idx,\n block_number,\n block_hash\n )\n SELECT *\n FROM\n unnest(\n $43::bytea [],\n $44::bytea [],\n $45::numeric [],\n $46::numeric [],\n $47::numeric [],\n $48::numeric [],\n $49::bytea []\n )\n RETURNING 1 as res\n),\n\naccount_insert AS (\n WITH account_updates AS (\n SELECT *\n FROM\n unnest(\n $50::bytea [],\n $51::bytea [],\n $52::numeric [],\n $53::numeric [],\n $54::numeric [],\n $55::numeric [],\n $56::numeric []\n )\n AS t (\n address,\n bytecode,\n new_balance,\n new_nonce,\n creation_block,\n previous_balance,\n previous_nonce\n )\n )\n\n INSERT INTO accounts (\n address, bytecode, latest_balance, latest_nonce, creation_block, previous_balance, previous_nonce\n )\n SELECT\n address,\n bytecode,\n new_balance,\n new_nonce,\n creation_block,\n previous_balance,\n previous_nonce\n FROM account_updates\n ON CONFLICT (address) DO\n UPDATE\n SET latest_nonce = excluded.latest_nonce,\n latest_balance = excluded.latest_balance,\n previous_balance = excluded.previous_balance,\n previous_nonce = excluded.previous_nonce\n WHERE accounts.latest_nonce = excluded.previous_nonce\n AND accounts.latest_balance = excluded.previous_balance\n RETURNING 1 as res\n),\n\nslot_insert AS (\n WITH slot_updates AS (\n SELECT *\n FROM\n unnest(\n $57::bytea [],\n $58::bytea [],\n $59::bytea [],\n $60::numeric [],\n $61::bytea []\n )\n AS t (idx, value, account_address, creation_block, original_value)\n )\n\n INSERT INTO account_slots (idx, value, previous_value, account_address, creation_block)\n SELECT\n idx,\n value,\n original_value,\n account_address,\n creation_block\n FROM slot_updates\n ON CONFLICT (idx, account_address) DO\n UPDATE\n SET value = excluded.value,\n previous_value = excluded.previous_value\n WHERE account_slots.value = excluded.previous_value\n RETURNING 1 as res\n),\n\nhistorical_nonce_insert AS (\n INSERT INTO historical_nonces (address, nonce, block_number)\n SELECT * FROM unnest($62::bytea [], $63::numeric [], $64::numeric [])\n RETURNING 1 as res\n),\n\nhistorical_balance_insert AS (\n INSERT INTO historical_balances (address, balance, block_number)\n SELECT * FROM unnest($65::bytea [], $66::numeric [], $67::numeric [])\n RETURNING 1 as res\n),\n\nhistorical_slots_insert AS (\n INSERT INTO historical_slots (idx, value, account_address, block_number)\n SELECT *\n FROM unnest($68::bytea [], $69::bytea [], $70::bytea [], $71::numeric [])\n RETURNING 1 as res\n)\n\nSELECT modified_accounts, modified_slots FROM\n(SELECT count(*) AS modified_accounts FROM account_insert) as account_results\nCROSS JOIN\n(SELECT count(*) AS modified_slots FROM slot_insert) as slot_results;\n", "describe": { "columns": [ { @@ -94,5 +94,5 @@ null ] }, - "hash": "dabff00b1d2f5797afafabb135a018043577aaab2e774cf451ba20698b274f1f" + "hash": "2fd2736ed6e47d28c94966ae96b568fd02451d51f76e0256ba5de7507cfad075" } diff --git a/.sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json b/.sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json deleted file mode 100644 index 13b6eaac5..000000000 --- a/.sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT\n idx as \"index: _\",\n value as \"value: _\"\nFROM account_slots\nWHERE account_address = $1\nAND idx = $2\n", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "index: _", - "type_info": "Bytea" - }, - { - "ordinal": 1, - "name": "value: _", - "type_info": "Bytea" - } - ], - "parameters": { - "Left": [ - "Bytea", - "Bytea" - ] - }, - "nullable": [ - false, - false - ] - }, - "hash": "e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41" -} diff --git a/src/eth/storage/postgres/queries/insert_entire_block.sql b/src/eth/storage/postgres/queries/insert_entire_block.sql index 7726e93be..bd2d70ade 100644 --- a/src/eth/storage/postgres/queries/insert_entire_block.sql +++ b/src/eth/storage/postgres/queries/insert_entire_block.sql @@ -213,6 +213,6 @@ historical_slots_insert AS ( ) SELECT modified_accounts, modified_slots FROM -(SELECT count(*) AS modified_accounts FROM account_insert) +(SELECT count(*) AS modified_accounts FROM account_insert) as account_results CROSS JOIN -(SELECT count(*) AS modified_slots FROM slot_insert); +(SELECT count(*) AS modified_slots FROM slot_insert) as slot_results; diff --git a/src/infra/postgres.rs b/src/infra/postgres.rs index 7d2195de4..21beb1e64 100644 --- a/src/infra/postgres.rs +++ b/src/infra/postgres.rs @@ -83,7 +83,6 @@ impl Postgres { let mut sload_cache = HashMap::new(); raw_sload.into_iter().for_each(|s| { - dbg!(s.address.clone()); sload_cache.insert((s.address, s.index), (s.value, s.block)); });