251: Remove uses of canonical_header_hash() and get_storage_at() fns in light of v5 schema updates. (#253)
* Remove canonical_header_hash() uses and update SQL queries for latest v5 schema. * Remove get_storage_at() uses.
This commit is contained in:
parent
51c36adbea
commit
6470bf2f01
290
pkg/eth/sql.go
290
pkg/eth/sql.go
@ -1,13 +1,17 @@
|
|||||||
package eth
|
package eth
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RetrieveHeaderByHashPgStr = `SELECT cid, data
|
RetrieveHeaderByHashPgStr = `
|
||||||
FROM eth.header_cids
|
SELECT header_cids.cid,
|
||||||
INNER JOIN ipld.blocks ON (
|
blocks.data
|
||||||
header_cids.cid = blocks.key
|
FROM ipld.blocks,
|
||||||
AND header_cids.block_number = blocks.block_number
|
eth.header_cids
|
||||||
)
|
WHERE header_cids.block_hash = $1
|
||||||
WHERE block_hash = $1`
|
AND header_cids.canonical
|
||||||
|
AND blocks.key = header_cids.cid
|
||||||
|
AND blocks.block_number = header_cids.block_number
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
RetrieveUnclesPgStr = `SELECT uncle_cids.cid, data
|
RetrieveUnclesPgStr = `SELECT uncle_cids.cid, data
|
||||||
FROM eth.uncle_cids
|
FROM eth.uncle_cids
|
||||||
INNER JOIN eth.header_cids ON (
|
INNER JOIN eth.header_cids ON (
|
||||||
@ -35,79 +39,94 @@ const (
|
|||||||
WHERE header_cids.block_hash = $1
|
WHERE header_cids.block_hash = $1
|
||||||
ORDER BY uncle_cids.parent_hash
|
ORDER BY uncle_cids.parent_hash
|
||||||
LIMIT 1`
|
LIMIT 1`
|
||||||
RetrieveTransactionsPgStr = `SELECT transaction_cids.cid, data
|
RetrieveTransactionsPgStr = `
|
||||||
FROM eth.transaction_cids
|
SELECT transaction_cids.cid,
|
||||||
INNER JOIN eth.header_cids ON (
|
blocks.data
|
||||||
transaction_cids.header_id = header_cids.block_hash
|
FROM eth.transaction_cids,
|
||||||
AND transaction_cids.block_number = header_cids.block_number
|
eth.header_cids,
|
||||||
)
|
ipld.blocks
|
||||||
INNER JOIN ipld.blocks ON (
|
WHERE header_cids.block_hash = $1
|
||||||
transaction_cids.cid = blocks.key
|
|
||||||
AND transaction_cids.block_number = blocks.block_number
|
|
||||||
)
|
|
||||||
WHERE block_hash = $1
|
|
||||||
AND header_cids.block_number = $2
|
AND header_cids.block_number = $2
|
||||||
ORDER BY eth.transaction_cids.index ASC`
|
AND header_cids.canonical
|
||||||
RetrieveTransactionsByBlockHashPgStr = `SELECT transaction_cids.cid, data
|
|
||||||
FROM eth.transaction_cids
|
|
||||||
INNER JOIN eth.header_cids ON (
|
|
||||||
transaction_cids.header_id = header_cids.block_hash
|
|
||||||
AND transaction_cids.block_number = header_cids.block_number
|
AND transaction_cids.block_number = header_cids.block_number
|
||||||
)
|
AND transaction_cids.header_id = header_cids.block_hash
|
||||||
INNER JOIN ipld.blocks ON (
|
AND blocks.block_number = header_cids.block_number
|
||||||
transaction_cids.cid = blocks.key
|
AND blocks.key = transaction_cids.cid
|
||||||
AND transaction_cids.block_number = blocks.block_number
|
ORDER BY eth.transaction_cids.index ASC
|
||||||
)
|
`
|
||||||
WHERE block_hash = $1
|
RetrieveTransactionsByBlockHashPgStr = `
|
||||||
ORDER BY eth.transaction_cids.index ASC`
|
SELECT transaction_cids.cid,
|
||||||
RetrieveReceiptsPgStr = `SELECT receipt_cids.cid, data, eth.transaction_cids.tx_hash
|
blocks.data
|
||||||
FROM eth.receipt_cids
|
FROM eth.transaction_cids,
|
||||||
INNER JOIN eth.transaction_cids ON (
|
eth.header_cids,
|
||||||
receipt_cids.tx_id = transaction_cids.tx_hash
|
ipld.blocks
|
||||||
AND receipt_cids.header_id = transaction_cids.header_id
|
WHERE header_cids.block_hash = $1
|
||||||
AND receipt_cids.block_number = transaction_cids.block_number
|
AND header_cids.canonical
|
||||||
)
|
|
||||||
INNER JOIN eth.header_cids ON (
|
|
||||||
transaction_cids.header_id = header_cids.block_hash
|
|
||||||
AND transaction_cids.block_number = header_cids.block_number
|
AND transaction_cids.block_number = header_cids.block_number
|
||||||
)
|
AND transaction_cids.header_id = header_cids.block_hash
|
||||||
INNER JOIN ipld.blocks ON (
|
AND blocks.block_number = header_cids.block_number
|
||||||
receipt_cids.cid = blocks.key
|
AND blocks.key = transaction_cids.cid
|
||||||
AND receipt_cids.block_number = blocks.block_number
|
ORDER BY eth.transaction_cids.index ASC
|
||||||
)
|
`
|
||||||
WHERE block_hash = $1
|
RetrieveReceiptsPgStr = `
|
||||||
|
SELECT receipt_cids.cid,
|
||||||
|
blocks.data,
|
||||||
|
eth.transaction_cids.tx_hash
|
||||||
|
FROM eth.receipt_cids,
|
||||||
|
eth.transaction_cids,
|
||||||
|
eth.header_cids,
|
||||||
|
ipld.blocks
|
||||||
|
WHERE header_cids.block_hash = $1
|
||||||
AND header_cids.block_number = $2
|
AND header_cids.block_number = $2
|
||||||
ORDER BY eth.transaction_cids.index ASC`
|
AND header_cids.canonical
|
||||||
RetrieveReceiptsByBlockHashPgStr = `SELECT receipt_cids.cid, data, eth.transaction_cids.tx_hash
|
AND receipt_cids.block_number = header_cids.block_number
|
||||||
FROM eth.receipt_cids
|
AND receipt_cids.header_id = header_cids.block_hash
|
||||||
INNER JOIN eth.transaction_cids ON (
|
AND receipt_cids.TX_ID = transaction_cids.TX_HASH
|
||||||
receipt_cids.tx_id = transaction_cids.tx_hash
|
|
||||||
AND receipt_cids.header_id = transaction_cids.header_id
|
|
||||||
AND receipt_cids.block_number = transaction_cids.block_number
|
|
||||||
)
|
|
||||||
INNER JOIN eth.header_cids ON (
|
|
||||||
transaction_cids.header_id = header_cids.block_hash
|
|
||||||
AND transaction_cids.block_number = header_cids.block_number
|
AND transaction_cids.block_number = header_cids.block_number
|
||||||
)
|
AND transaction_cids.header_id = header_cids.block_hash
|
||||||
INNER JOIN ipld.blocks ON (
|
AND blocks.block_number = header_cids.block_number
|
||||||
receipt_cids.cid = blocks.key
|
AND blocks.key = receipt_cids.cid
|
||||||
AND receipt_cids.block_number = blocks.block_number
|
ORDER BY eth.transaction_cids.index ASC
|
||||||
)
|
`
|
||||||
WHERE block_hash = $1
|
RetrieveReceiptsByBlockHashPgStr = `
|
||||||
ORDER BY eth.transaction_cids.index ASC`
|
SELECT receipt_cids.cid,
|
||||||
RetrieveAccountByLeafKeyAndBlockHashPgStr = `SELECT state_cids.nonce, state_cids.balance, state_cids.storage_root, state_cids.code_hash, state_cids.removed
|
blocks.data,
|
||||||
FROM eth.state_cids
|
eth.transaction_cids.tx_hash
|
||||||
INNER JOIN eth.header_cids ON (
|
FROM eth.receipt_cids,
|
||||||
state_cids.header_id = header_cids.block_hash
|
eth.transaction_cids,
|
||||||
AND state_cids.block_number = header_cids.block_number
|
eth.header_cids,
|
||||||
)
|
ipld.blocks
|
||||||
WHERE state_leaf_key = $1
|
WHERE header_cids.block_hash = $1
|
||||||
AND header_cids.block_number <= (SELECT block_number
|
AND header_cids.canonical
|
||||||
|
AND receipt_cids.block_number = header_cids.block_number
|
||||||
|
AND receipt_cids.header_id = header_cids.block_hash
|
||||||
|
AND receipt_cids.TX_ID = transaction_cids.TX_HASH
|
||||||
|
AND transaction_cids.block_number = header_cids.block_number
|
||||||
|
AND transaction_cids.header_id = header_cids.block_hash
|
||||||
|
AND blocks.block_number = header_cids.block_number
|
||||||
|
AND blocks.key = receipt_cids.cid
|
||||||
|
ORDER BY eth.transaction_cids.index ASC
|
||||||
|
`
|
||||||
|
RetrieveAccountByLeafKeyAndBlockHashPgStr = `
|
||||||
|
SELECT state_cids.nonce,
|
||||||
|
state_cids.balance,
|
||||||
|
state_cids.storage_root,
|
||||||
|
state_cids.code_hash,
|
||||||
|
state_cids.removed
|
||||||
|
FROM eth.state_cids,
|
||||||
|
eth.header_cids
|
||||||
|
WHERE state_cids.state_leaf_key = $1
|
||||||
|
AND state_cids.block_number <=
|
||||||
|
(SELECT block_number
|
||||||
FROM eth.header_cids
|
FROM eth.header_cids
|
||||||
WHERE block_hash = $2)
|
WHERE block_hash = $2
|
||||||
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
|
LIMIT 1)
|
||||||
ORDER BY header_cids.block_number DESC
|
AND header_cids.canonical
|
||||||
LIMIT 1`
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
|
AND state_cids.block_number = header_cids.block_number
|
||||||
|
ORDER BY state_cids.block_number DESC
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
RetrieveFilteredGQLLogs = `SELECT CAST(eth.log_cids.block_number as TEXT), eth.log_cids.header_id as block_hash,
|
RetrieveFilteredGQLLogs = `SELECT CAST(eth.log_cids.block_number as TEXT), eth.log_cids.header_id as block_hash,
|
||||||
eth.log_cids.cid, eth.log_cids.index, eth.log_cids.rct_id, eth.log_cids.address,
|
eth.log_cids.cid, eth.log_cids.index, eth.log_cids.rct_id, eth.log_cids.address,
|
||||||
eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
|
eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
|
||||||
@ -125,7 +144,7 @@ const (
|
|||||||
ipld.blocks.data, eth.receipt_cids.cid AS rct_cid, eth.receipt_cids.post_status, log_cids.header_id AS block_hash
|
ipld.blocks.data, eth.receipt_cids.cid AS rct_cid, eth.receipt_cids.post_status, log_cids.header_id AS block_hash
|
||||||
FROM eth.log_cids, eth.receipt_cids, eth.transaction_cids, ipld.blocks
|
FROM eth.log_cids, eth.receipt_cids, eth.transaction_cids, ipld.blocks
|
||||||
WHERE eth.log_cids.block_number >= $1 AND eth.log_cids.block_number <= $2
|
WHERE eth.log_cids.block_number >= $1 AND eth.log_cids.block_number <= $2
|
||||||
AND eth.log_cids.header_id IN (SELECT canonical_header_hash(block_number) from eth.header_cids where eth.header_cids.block_number >= $1 AND header_cids.block_number <= $2)
|
AND eth.log_cids.header_id IN (SELECT block_hash from eth.header_cids where eth.header_cids.block_number >= $1 AND eth.header_cids.block_number <= $2 and eth.header_cids.canonical)
|
||||||
AND eth.transaction_cids.block_number = eth.log_cids.block_number
|
AND eth.transaction_cids.block_number = eth.log_cids.block_number
|
||||||
AND eth.transaction_cids.header_id = eth.log_cids.header_id
|
AND eth.transaction_cids.header_id = eth.log_cids.header_id
|
||||||
AND eth.receipt_cids.block_number = eth.log_cids.block_number
|
AND eth.receipt_cids.block_number = eth.log_cids.block_number
|
||||||
@ -149,47 +168,96 @@ const (
|
|||||||
AND eth.receipt_cids.tx_id = eth.transaction_cids.tx_hash
|
AND eth.receipt_cids.tx_id = eth.transaction_cids.tx_hash
|
||||||
AND ipld.blocks.block_number = eth.log_cids.block_number
|
AND ipld.blocks.block_number = eth.log_cids.block_number
|
||||||
AND ipld.blocks.key = eth.log_cids.cid`
|
AND ipld.blocks.key = eth.log_cids.cid`
|
||||||
RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr = `SELECT cid, val, block_number, removed, state_leaf_removed FROM get_storage_at_by_hash($1, $2, $3)`
|
RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr = `
|
||||||
|
SELECT storage_cids.cid,
|
||||||
|
storage_cids.val,
|
||||||
|
storage_cids.block_number,
|
||||||
|
storage_cids.removed,
|
||||||
|
was_state_leaf_removed_by_number(storage_cids.state_leaf_key, storage_cids.block_number) AS state_leaf_removed
|
||||||
|
FROM eth.storage_cids, eth.header_cids
|
||||||
|
WHERE header_cids.block_number <= (SELECT block_number from eth.header_cids where block_hash = $3 LIMIT 1)
|
||||||
|
AND header_cids.canonical
|
||||||
|
AND storage_cids.block_number = header_cids.block_number
|
||||||
|
AND storage_cids.header_id = header_cids.block_hash
|
||||||
|
AND storage_cids.storage_leaf_key = $2
|
||||||
|
AND storage_cids.state_leaf_key = $1
|
||||||
|
ORDER BY storage_cids.block_number DESC LIMIT 1
|
||||||
|
`
|
||||||
RetrieveStorageAndRLPByAddressHashAndLeafKeyAndBlockHashPgStr = `
|
RetrieveStorageAndRLPByAddressHashAndLeafKeyAndBlockHashPgStr = `
|
||||||
SELECT cid, val, storage.block_number, removed, state_leaf_removed, data
|
SELECT storage_cids.cid,
|
||||||
FROM get_storage_at_by_hash($1, $2, $3) AS storage
|
storage_cids.val,
|
||||||
INNER JOIN ipld.blocks ON (
|
storage_cids.block_number,
|
||||||
storage.cid = blocks.key
|
storage_cids.removed,
|
||||||
AND storage.block_number = blocks.block_number
|
was_state_leaf_removed_by_number(storage_cids.state_leaf_key, storage_cids.block_number) AS state_leaf_removed,
|
||||||
)`
|
blocks.data
|
||||||
RetrieveCanonicalBlockHashByNumber = `SELECT block_hash
|
FROM eth.storage_cids, eth.header_cids, ipld.blocks
|
||||||
FROM canonical_header_hash($1) AS block_hash
|
WHERE header_cids.block_number <= (SELECT block_number from eth.header_cids where block_hash = $3 LIMIT 1)
|
||||||
WHERE block_hash IS NOT NULL`
|
AND header_cids.canonical
|
||||||
RetrieveCanonicalHeaderByNumber = `SELECT cid, data FROM eth.header_cids
|
AND storage_cids.block_number = header_cids.block_number
|
||||||
INNER JOIN ipld.blocks ON (
|
AND storage_cids.header_id = header_cids.block_hash
|
||||||
header_cids.cid = blocks.key
|
AND storage_cids.storage_leaf_key = $2
|
||||||
AND header_cids.block_number = blocks.block_number
|
AND storage_cids.state_leaf_key = $1
|
||||||
)
|
AND blocks.key = storage_cids.cid
|
||||||
WHERE block_hash = (SELECT canonical_header_hash($1))`
|
AND blocks.block_number = storage_cids.block_number
|
||||||
RetrieveCanonicalHeaderAndHashByNumber = `SELECT data, block_hash FROM eth.header_cids
|
ORDER BY storage_cids.block_number DESC LIMIT 1
|
||||||
INNER JOIN ipld.blocks ON (
|
`
|
||||||
header_cids.cid = blocks.key
|
RetrieveCanonicalBlockHashByNumber = `SELECT block_hash FROM eth.header_cids WHERE block_number = $1 AND canonical`
|
||||||
AND header_cids.block_number = blocks.block_number
|
RetrieveCanonicalHeaderByNumber = `
|
||||||
)
|
SELECT header_cids.cid,
|
||||||
WHERE block_hash = (SELECT canonical_header_hash($1))`
|
blocks.data
|
||||||
|
FROM ipld.blocks,
|
||||||
|
eth.header_cids
|
||||||
|
WHERE header_cids.block_number = $1
|
||||||
|
AND header_cids.canonical
|
||||||
|
AND blocks.key = header_cids.cid
|
||||||
|
AND blocks.block_number = header_cids.block_number
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
|
RetrieveCanonicalHeaderAndHashByNumber = `
|
||||||
|
SELECT blocks.data,
|
||||||
|
header_cids.block_hash
|
||||||
|
FROM ipld.blocks,
|
||||||
|
eth.header_cids
|
||||||
|
WHERE header_cids.block_number = $1
|
||||||
|
AND header_cids.canonical
|
||||||
|
AND blocks.key = header_cids.cid
|
||||||
|
AND blocks.block_number = header_cids.block_number
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
RetrieveTD = `SELECT CAST(td as TEXT) FROM eth.header_cids
|
RetrieveTD = `SELECT CAST(td as TEXT) FROM eth.header_cids
|
||||||
WHERE header_cids.block_hash = $1`
|
WHERE header_cids.block_hash = $1`
|
||||||
RetrieveRPCTransaction = `SELECT blocks.data, header_id, transaction_cids.block_number, index
|
RetrieveRPCTransaction = `
|
||||||
FROM ipld.blocks, eth.transaction_cids
|
SELECT blocks.data,
|
||||||
WHERE blocks.key = transaction_cids.cid
|
transaction_cids.header_id,
|
||||||
|
transaction_cids.block_number,
|
||||||
|
transaction_cids.index
|
||||||
|
FROM eth.transaction_cids,
|
||||||
|
ipld.blocks,
|
||||||
|
eth.header_cids
|
||||||
|
WHERE transaction_cids.TX_HASH = $1
|
||||||
|
AND header_cids.block_hash = transaction_cids.header_id
|
||||||
|
AND header_cids.block_number = transaction_cids.block_number
|
||||||
|
AND header_cids.canonical
|
||||||
|
AND blocks.key = transaction_cids.cid
|
||||||
AND blocks.block_number = transaction_cids.block_number
|
AND blocks.block_number = transaction_cids.block_number
|
||||||
AND transaction_cids.tx_hash = $1
|
`
|
||||||
AND transaction_cids.header_id = (SELECT canonical_header_hash(transaction_cids.block_number))`
|
RetrieveCodeHashByLeafKeyAndBlockHash = `
|
||||||
RetrieveCodeHashByLeafKeyAndBlockHash = `SELECT code_hash FROM eth.state_cids, eth.header_cids
|
SELECT state_cids.code_hash
|
||||||
WHERE state_cids.header_id = header_cids.block_hash
|
FROM eth.state_cids,
|
||||||
AND state_cids.block_number = header_cids.block_number
|
eth.header_cids
|
||||||
AND state_leaf_key = $1
|
WHERE
|
||||||
AND header_cids.block_number <= (SELECT block_number
|
state_cids.state_leaf_key = $1
|
||||||
|
AND state_cids.block_number <=
|
||||||
|
(SELECT block_number
|
||||||
FROM eth.header_cids
|
FROM eth.header_cids
|
||||||
WHERE block_hash = $2)
|
WHERE block_hash = $2
|
||||||
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
|
LIMIT 1)
|
||||||
ORDER BY header_cids.block_number DESC
|
AND header_cids.canonical
|
||||||
LIMIT 1`
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
|
AND state_cids.block_number = header_cids.block_number
|
||||||
|
ORDER BY state_cids.block_number DESC
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
RetrieveCodeByKey = `SELECT data FROM ipld.blocks WHERE key = $1`
|
RetrieveCodeByKey = `SELECT data FROM ipld.blocks WHERE key = $1`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user