Skip to content

Commit

Permalink
Fix block last tx hash
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo committed Jul 29, 2022
1 parent 35a3a51 commit 938e5dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
40 changes: 20 additions & 20 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@
]
}
},
"0503311e607839221d1f3d32259f29a811b7abffbd4ae3808136eba8984741dd": {
"query": "\n SELECT tx_hash as \"tx_hash!\"\n FROM tx_filters as f\n WHERE address = $1\n ORDER BY\n GREATEST\n (\n (SELECT t1.sequence_number FROM executed_transactions AS t1 WHERE t1.tx_hash = f.tx_hash ORDER BY t1.sequence_number DESC LIMIT 1 ),\n (SELECT t2.sequence_number FROM executed_priority_operations AS t2 WHERE t2.tx_hash = f.tx_hash ORDER BY t2.sequence_number DESC LIMIT 1 )\n )\n DESC\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "tx_hash!",
"type_info": "Bytea"
}
],
"parameters": {
"Left": [
"Bytea"
]
},
"nullable": [
false
]
}
},
"052bc740befe43cd3d8d915371cb055187d4ff4ebf019fe12c8dc85b296acc47": {
"query": "SELECT tx_hash, tx FROM executed_transactions WHERE block_number BETWEEN $1 AND $2",
"describe": {
Expand Down Expand Up @@ -3296,26 +3316,6 @@
]
}
},
"67cad4f873f4a8b41b5574aae3c64a88795fe69b7ef353a785f9b12357f12913": {
"query": "\n WITH tx_hashes AS (\n SELECT DISTINCT tx_hash FROM tx_filters\n WHERE address = $1\n ), transactions AS (\n SELECT executed_transactions.tx_hash, sequence_number\n FROM tx_hashes\n INNER JOIN executed_transactions\n ON tx_hashes.tx_hash = executed_transactions.tx_hash\n ORDER BY sequence_number DESC\n LIMIT 1\n ), priority_ops AS (\n SELECT executed_priority_operations.tx_hash, executed_priority_operations.sequence_number\n FROM tx_hashes\n INNER JOIN executed_priority_operations\n ON tx_hashes.tx_hash = executed_priority_operations.tx_hash\n ORDER BY sequence_number DESC\n LIMIT 1\n ), everything AS (\n SELECT * FROM transactions\n UNION ALL\n SELECT * FROM priority_ops\n )\n SELECT\n tx_hash as \"tx_hash!\"\n FROM everything\n ORDER BY sequence_number DESC\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "tx_hash!",
"type_info": "Bytea"
}
],
"parameters": {
"Left": [
"Bytea"
]
},
"nullable": [
null
]
}
},
"681359f99d0e4bafdd3109f67c7af4d235dc1197ba88cd0d6148f632ae0cdf8f": {
"query": "SELECT * FROM aggregated_proofs WHERE first_block = $1 and last_block = $2",
"describe": {
Expand Down
36 changes: 10 additions & 26 deletions core/lib/storage/src/chain/operations_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,32 +1288,16 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {

let record = sqlx::query!(
r#"
WITH tx_hashes AS (
SELECT DISTINCT tx_hash FROM tx_filters
WHERE address = $1
), transactions AS (
SELECT executed_transactions.tx_hash, sequence_number
FROM tx_hashes
INNER JOIN executed_transactions
ON tx_hashes.tx_hash = executed_transactions.tx_hash
ORDER BY sequence_number DESC
LIMIT 1
), priority_ops AS (
SELECT executed_priority_operations.tx_hash, executed_priority_operations.sequence_number
FROM tx_hashes
INNER JOIN executed_priority_operations
ON tx_hashes.tx_hash = executed_priority_operations.tx_hash
ORDER BY sequence_number DESC
LIMIT 1
), everything AS (
SELECT * FROM transactions
UNION ALL
SELECT * FROM priority_ops
)
SELECT
tx_hash as "tx_hash!"
FROM everything
ORDER BY sequence_number DESC
SELECT tx_hash as "tx_hash!"
FROM tx_filters as f
WHERE address = $1
ORDER BY
GREATEST
(
(SELECT t1.sequence_number FROM executed_transactions AS t1 WHERE t1.tx_hash = f.tx_hash ORDER BY t1.sequence_number DESC LIMIT 1 ),
(SELECT t2.sequence_number FROM executed_priority_operations AS t2 WHERE t2.tx_hash = f.tx_hash ORDER BY t2.sequence_number DESC LIMIT 1 )
)
DESC
LIMIT 1
"#,
address.as_bytes()
Expand Down

0 comments on commit 938e5dd

Please sign in to comment.