Skip to content

Commit

Permalink
Merge #2126
Browse files Browse the repository at this point in the history
2126: Make priority ops tx hashes unique and get the latest created at for non unique priority ops r=Deniallugo a=Deniallugo


Signed-off-by: deniallugo <[email protected]>

Co-authored-by: deniallugo <[email protected]>
  • Loading branch information
bors-matterlabs-dev[bot] and Deniallugo authored Jan 10, 2022
2 parents 3e0667c + 50cf56d commit 9b31620
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
52 changes: 26 additions & 26 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1739,32 +1739,6 @@
"nullable": []
}
},
"311eb879affeff3c877d978d0a7ac443d904edbc606a213ecc5959dbedc16b3e": {
"query": "SELECT created_at, block_number FROM executed_priority_operations\n WHERE tx_hash = $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 1,
"name": "block_number",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Bytea"
]
},
"nullable": [
false,
false
]
}
},
"3186e2d96b7f1e1339ac9f09221ae15aba8dff112083079fc6ef5f3acbfc1553": {
"query": "\n INSERT INTO tokens ( id, address, symbol, decimals, kind )\n VALUES ( $1, $2, $3, $4, $5 )\n ON CONFLICT (id)\n DO\n UPDATE SET address = $2, symbol = $3, decimals = $4, kind = $5\n ",
"describe": {
Expand Down Expand Up @@ -7278,6 +7252,32 @@
"nullable": []
}
},
"ee7dd724ce25e19db5af8db44976eaf7767a464574aaa3a18e40717a20b4d828": {
"query": "SELECT created_at, block_number FROM executed_priority_operations\n WHERE tx_hash = $1 ORDER BY created_at DESC",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 1,
"name": "block_number",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Bytea"
]
},
"nullable": [
false,
false
]
}
},
"f057b85811c3991b73c58991fc8dae8bf4cdf9d2238171ca13a3fdf1172f2c91": {
"query": "SELECT * FROM data_restore_events_state\n WHERE block_type = $1\n ORDER BY block_num ASC",
"describe": {
Expand Down
4 changes: 3 additions & 1 deletion core/lib/storage/src/chain/operations_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,9 +1389,11 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
let result = if let Some(record) = record {
Some((record.created_at, BlockNumber(record.block_number as u32)))
} else {
// TxHash is not unique for priority operations so we have to get the max created_at
// because we are using this function for paginating starting from the latest transaction
let record = sqlx::query!(
"SELECT created_at, block_number FROM executed_priority_operations
WHERE tx_hash = $1",
WHERE tx_hash = $1 ORDER BY created_at DESC",
tx_hash.as_ref()
)
.fetch_optional(transaction.conn())
Expand Down
3 changes: 2 additions & 1 deletion core/lib/types/src/priority_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,11 @@ impl PriorityOp {
}

pub fn tx_hash(&self) -> TxHash {
let mut bytes = Vec::with_capacity(48);
let mut bytes = Vec::with_capacity(56);
bytes.extend_from_slice(self.eth_hash.as_bytes());
bytes.extend_from_slice(&self.eth_block.to_be_bytes());
bytes.extend_from_slice(&self.eth_block_index.unwrap_or(0).to_be_bytes());
bytes.extend_from_slice(&self.serial_id.to_be_bytes());

let hash = sha256(&bytes);
let mut out = [0u8; 32];
Expand Down

0 comments on commit 9b31620

Please sign in to comment.