Skip to content

Commit

Permalink
fix inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaVashchuk committed Nov 7, 2023
1 parent 2cfa2c4 commit afdff76
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 313 deletions.
137 changes: 0 additions & 137 deletions core/lib/server_dal/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3083,24 +3083,6 @@
},
"query": "SELECT hashed_key, index FROM initial_writes WHERE l1_batch_number = $1 ORDER BY index"
},
"5a27a65fa105897b60a99c1e0015e4b8c93c45e0c448e77b03565db5c36695ed": {
"describe": {
"columns": [
{
"name": "max",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": []
}
},
"query": "SELECT MAX(l1_batch_number) FROM witness_inputs WHERE merkel_tree_paths_blob_url IS NOT NULL"
},
"5a2f35f3b0135ab88451ea141e97b1160ea1b4cf495b6700b5d178a43499e0d8": {
"describe": {
"columns": [
Expand Down Expand Up @@ -3910,32 +3892,6 @@
},
"query": "SELECT * FROM call_traces WHERE tx_hash IN (SELECT hash FROM transactions WHERE miniblock_number = $1)"
},
"7acba1f016450b084a5fd97199a757a471f8b8a880a800c29737f1bceae3ff46": {
"describe": {
"columns": [
{
"name": "l1_batch_number",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "merkel_tree_paths_blob_url",
"ordinal": 1,
"type_info": "Text"
}
],
"nullable": [
false,
true
],
"parameters": {
"Left": [
"Int8"
]
}
},
"query": "SELECT l1_batch_number, merkel_tree_paths_blob_url FROM witness_inputs WHERE status = 'successful' AND is_blob_cleaned = FALSE AND merkel_tree_paths_blob_url is NOT NULL AND updated_at < NOW() - INTERVAL '30 days' LIMIT $1"
},
"7ca78be8b18638857111cdbc6117ed2c204e3eb22682d5e4553ac4f47efab6e2": {
"describe": {
"columns": [
Expand Down Expand Up @@ -6625,24 +6581,6 @@
},
"query": "SELECT * FROM eth_txs WHERE confirmed_eth_tx_history_id IS NULL \n AND id <= (SELECT COALESCE(MAX(eth_tx_id), 0) FROM eth_txs_history WHERE sent_at_block IS NOT NULL)\n ORDER BY id"
},
"b6f9874059c57e5e59f3021936437e9ff71a68065dfc19c295d806d7a9aafc93": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Int4",
"Int8",
"Bytea",
"Bytea",
"Bytea",
"Bytea",
"Bytea"
]
}
},
"query": "INSERT INTO prover_protocol_versions\n (id, timestamp, recursion_scheduler_level_vk_hash, recursion_node_level_vk_hash,\n recursion_leaf_level_vk_hash, recursion_circuits_set_vks_hash, verifier_address, created_at)\n VALUES ($1, $2, $3, $4, $5, $6, $7, now())\n "
},
"b79f02c8663c6b99d0aa46b430de32103afa0333e8293cf8661cfc1c3f9fc12e": {
"describe": {
"columns": [
Expand Down Expand Up @@ -7120,18 +7058,6 @@
},
"query": "SELECT usd_price, usd_price_updated_at FROM tokens WHERE l2_address = $1"
},
"c92a84c15a8641f73417a03de99a0fb7e07fd0da7b376e65b3ed61209e55a5fa": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Int8Array"
]
}
},
"query": "UPDATE witness_inputs SET is_blob_cleaned = TRUE WHERE l1_batch_number = ANY($1)"
},
"cc20350af9e837ae6b6160be65f88e6b675f62e207252f91f2ce7dcaaddb12b1": {
"describe": {
"columns": [],
Expand Down Expand Up @@ -7259,29 +7185,6 @@
},
"query": "UPDATE tokens SET token_list_name = $2, token_list_symbol = $3,\n token_list_decimals = $4, well_known = true, updated_at = now()\n WHERE l1_address = $1\n "
},
"d7060880fe56fd99af7b7ed3f4c7fb9d0858cee30f44c5197821aae83c6c9666": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int4"
}
],
"nullable": [
false
],
"parameters": {
"Left": [
"Bytea",
"Bytea",
"Bytea",
"Bytea"
]
}
},
"query": "\n SELECT id\n FROM prover_protocol_versions\n WHERE recursion_circuits_set_vks_hash = $1\n AND recursion_leaf_level_vk_hash = $2\n AND recursion_node_level_vk_hash = $3\n AND recursion_scheduler_level_vk_hash = $4\n "
},
"d8515595d34dca53e50bbd4ed396f6208e33f596195a5ed02fba9e8364ceb33c": {
"describe": {
"columns": [
Expand Down Expand Up @@ -7352,26 +7255,6 @@
},
"query": "SELECT COUNT(miniblocks.number) FROM miniblocks WHERE l1_batch_number IS NULL"
},
"dd330bc075a163974c59ec55ecfddd769d05801963b3e0e840e7f11e7bc6d3e9": {
"describe": {
"columns": [
{
"name": "l1_batch_number",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
false
],
"parameters": {
"Left": [
"Int8"
]
}
},
"query": "SELECT l1_batch_number FROM witness_inputs WHERE length(merkle_tree_paths) <> 0 ORDER BY l1_batch_number DESC LIMIT $1"
},
"dd8aa1c9d4dcea22c9a13cca5ae45e951cf963b0608046b88be40309d7379ec2": {
"describe": {
"columns": [],
Expand Down Expand Up @@ -8725,26 +8608,6 @@
},
"query": "\n UPDATE contract_verification_requests\n SET status = 'successful', updated_at = now()\n WHERE id = $1\n "
},
"ff7ff36b86b0e8d1cd7280aa447baef172cb054ffe7e1d742c59bf09b4f414cb": {
"describe": {
"columns": [
{
"name": "count!",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4"
]
}
},
"query": "SELECT COUNT(*) as \"count!\" FROM prover_protocol_versions WHERE id = $1"
},
"ff9c6a53717f0455089e27018e069809891249555e7ee38393927b2b25555fea": {
"describe": {
"columns": [
Expand Down
73 changes: 0 additions & 73 deletions core/lib/server_dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,79 +1261,6 @@ impl BlocksDal<'_, '_> {
Ok(count != 0)
}

pub async fn get_last_l1_batch_number_with_witness_inputs(
&mut self,
) -> sqlx::Result<L1BatchNumber> {
let row = sqlx::query!(
"SELECT MAX(l1_batch_number) FROM witness_inputs \
WHERE merkel_tree_paths_blob_url IS NOT NULL",
)
.fetch_one(self.storage.conn())
.await?;

Ok(row
.max
.map(|l1_batch_number| L1BatchNumber(l1_batch_number as u32))
.unwrap_or_default())
}

pub async fn get_l1_batches_with_blobs_in_db(
&mut self,
limit: u8,
) -> sqlx::Result<Vec<L1BatchNumber>> {
let rows = sqlx::query!(
"SELECT l1_batch_number FROM witness_inputs \
WHERE length(merkle_tree_paths) <> 0 \
ORDER BY l1_batch_number DESC \
LIMIT $1",
limit as i32
)
.fetch_all(self.storage.conn())
.await?;

Ok(rows
.into_iter()
.map(|row| L1BatchNumber(row.l1_batch_number as u32))
.collect())
}

pub async fn get_merkle_tree_paths_blob_urls_to_be_cleaned(
&mut self,
limit: u8,
) -> Result<Vec<(i64, String)>, sqlx::Error> {
let rows = sqlx::query!(
"SELECT l1_batch_number, merkel_tree_paths_blob_url \
FROM witness_inputs \
WHERE status = 'successful' AND is_blob_cleaned = FALSE \
AND merkel_tree_paths_blob_url is NOT NULL \
AND updated_at < NOW() - INTERVAL '30 days' \
LIMIT $1",
limit as i32
)
.fetch_all(self.storage.conn())
.await?;

Ok(rows
.into_iter()
.map(|row| (row.l1_batch_number, row.merkel_tree_paths_blob_url.unwrap()))
.collect())
}

pub async fn mark_gcs_blobs_as_cleaned(
&mut self,
l1_batch_numbers: &[i64],
) -> Result<(), sqlx::Error> {
sqlx::query!(
"UPDATE witness_inputs \
SET is_blob_cleaned = TRUE \
WHERE l1_batch_number = ANY($1)",
l1_batch_numbers
)
.execute(self.storage.conn())
.await?;
Ok(())
}

// methods used for measuring Eth tx stage transition latencies
// and emitting metrics base on these measured data
pub async fn oldest_uncommitted_batch_timestamp(&mut self) -> sqlx::Result<Option<u64>> {
Expand Down
68 changes: 0 additions & 68 deletions core/lib/server_dal/src/protocol_versions_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,6 @@ impl ProtocolVersionsDal<'_, '_> {
db_transaction.commit().await.unwrap();
}

pub async fn save_prover_protocol_version(&mut self, version: ProtocolVersion) {
sqlx::query!(
"INSERT INTO prover_protocol_versions
(id, timestamp, recursion_scheduler_level_vk_hash, recursion_node_level_vk_hash,
recursion_leaf_level_vk_hash, recursion_circuits_set_vks_hash, verifier_address, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, now())
",
version.id as i32,
version.timestamp as i64,
version.l1_verifier_config.recursion_scheduler_level_vk_hash.as_bytes(),
version.l1_verifier_config.params.recursion_node_level_vk_hash.as_bytes(),
version.l1_verifier_config.params.recursion_leaf_level_vk_hash.as_bytes(),
version.l1_verifier_config.params.recursion_circuits_set_vks_hash.as_bytes(),
version.verifier_address.as_bytes(),
)
.execute(self.storage.conn())
.await
.unwrap();
}

pub async fn base_system_contracts_by_timestamp(
&mut self,
current_timestamp: u64,
Expand Down Expand Up @@ -267,52 +247,4 @@ impl ProtocolVersionsDal<'_, '_> {
None
}
}

pub async fn protocol_version_for(
&mut self,
vk_commitments: &L1VerifierConfig,
) -> Vec<ProtocolVersionId> {
sqlx::query!(
r#"
SELECT id
FROM prover_protocol_versions
WHERE recursion_circuits_set_vks_hash = $1
AND recursion_leaf_level_vk_hash = $2
AND recursion_node_level_vk_hash = $3
AND recursion_scheduler_level_vk_hash = $4
"#,
vk_commitments
.params
.recursion_circuits_set_vks_hash
.as_bytes(),
vk_commitments
.params
.recursion_leaf_level_vk_hash
.as_bytes(),
vk_commitments
.params
.recursion_node_level_vk_hash
.as_bytes(),
vk_commitments.recursion_scheduler_level_vk_hash.as_bytes(),
)
.fetch_all(self.storage.conn())
.await
.unwrap()
.into_iter()
.map(|row| ProtocolVersionId::try_from(row.id as u16).unwrap())
.collect()
}

pub async fn prover_protocol_version_exists(&mut self, id: ProtocolVersionId) -> bool {
sqlx::query!(
"SELECT COUNT(*) as \"count!\" FROM prover_protocol_versions \
WHERE id = $1",
id as i32
)
.fetch_one(self.storage.conn())
.await
.unwrap()
.count
> 0
}
}
Loading

0 comments on commit afdff76

Please sign in to comment.