Skip to content

Commit

Permalink
Remove old migrations and fix order
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo committed Jan 28, 2022
1 parent fcd2ab7 commit a2e20d8
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 374 deletions.
27 changes: 0 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ members = [
"core/bin/parse_pub_data",
"core/bin/block_revert",
"core/bin/remove_proofs",
"core/bin/update_sequnce_number",

"core/bin/remove_outstanding_tx_filters",
# Server micro-services
"core/bin/zksync_api",
"core/bin/zksync_core",
Expand Down
26 changes: 0 additions & 26 deletions core/bin/remove_outstanding_tx_filters/Cargo.toml

This file was deleted.

12 changes: 0 additions & 12 deletions core/bin/remove_outstanding_tx_filters/src/main.rs

This file was deleted.

24 changes: 0 additions & 24 deletions core/bin/update_sequnce_number/Cargo.toml

This file was deleted.

42 changes: 0 additions & 42 deletions core/bin/update_sequnce_number/src/main.rs

This file was deleted.

18 changes: 10 additions & 8 deletions core/lib/storage/src/chain/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
success,
fail_reason,
created_at,
batch_id
batch_id,
sequence_number
FROM executed_transactions
WHERE block_number = $1
), priority_ops AS (
Expand All @@ -250,7 +251,8 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
true as success,
Null as fail_reason,
created_at,
Null::bigint as batch_id
Null::bigint as batch_id,
sequence_number
FROM executed_priority_operations
WHERE block_number = $1
), everything AS (
Expand All @@ -267,7 +269,7 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
created_at as "created_at!",
batch_id as "batch_id?"
FROM everything
ORDER BY created_at DESC
ORDER BY sequence_number DESC
"#,
i64::from(*block)
)
Expand Down Expand Up @@ -1362,7 +1364,7 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
priority_op_serialid as "priority_op_serialid?",
batch_id as "batch_id?"
FROM everything
ORDER BY created_at ASC, block_index ASC
ORDER BY sequence_number ASC
LIMIT $3
"#,
i64::from(*query.from.block_number),
Expand Down Expand Up @@ -1423,7 +1425,7 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
priority_op_serialid as "priority_op_serialid?",
batch_id as "batch_id?"
FROM everything
ORDER BY created_at DESC, block_index DESC
ORDER BY sequence_number DESC
LIMIT $3
"#,
i64::from(*query.from.block_number),
Expand Down Expand Up @@ -1654,11 +1656,11 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
let records = sqlx::query!(
r#"
WITH transactions AS (
SELECT tx_hash, created_at, block_index
SELECT tx_hash, sequence_number
FROM executed_transactions
WHERE block_number = $1
), priority_ops AS (
SELECT tx_hash, created_at, block_index
SELECT tx_hash, sequence_number
FROM executed_priority_operations
WHERE block_number = $1
), everything AS (
Expand All @@ -1668,7 +1670,7 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
)
SELECT tx_hash as "tx_hash!"
FROM everything
ORDER BY created_at, block_index
ORDER BY sequence_number
"#,
i64::from(*block_number)
)
Expand Down
76 changes: 0 additions & 76 deletions core/lib/storage/src/chain/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,82 +306,6 @@ impl<'a, 'c> OperationsSchema<'a, 'c> {
Ok(())
}

// TODO remove it ZKS-931
pub async fn remove_outstanding_tx_filters(&mut self) -> QueryResult<()> {
// We can do something like this, but this query will block tx_filter table for a long long time.
// So I have to rewrite this logic to rust
// sqlx::query!(
// r#"DELETE FROM tx_filters WHERE tx_hash NOT IN (
// WITH transactions AS (
// SELECT tx_hash
// FROM executed_transactions
// ), priority_ops AS (
// SELECT tx_hash
// FROM executed_priority_operations
// ), everything AS (
// SELECT * FROM transactions
// UNION ALL
// SELECT * FROM priority_ops
// )
// SELECT
// tx_hash as "tx_hash!"
// FROM everything
// )"#
// )
// .execute(self.0.conn())
// .await?;

let mut transaction = self.0.start_transaction().await?;
let tx_hashes: HashSet<Vec<u8>> = sqlx::query!(
r#"
WITH transactions AS (
SELECT tx_hash
FROM executed_transactions
), priority_ops AS (
SELECT tx_hash
FROM executed_priority_operations
), everything AS (
SELECT * FROM transactions
UNION ALL
SELECT * FROM priority_ops
)
SELECT
tx_hash as "tx_hash!"
FROM everything"#
)
.fetch_all(transaction.conn())
.await?
.into_iter()
.map(|value| value.tx_hash)
.collect();

println!("Txs len {:?}", tx_hashes.len());
let tx_filter_hashes: HashSet<Vec<u8>> =
sqlx::query!("SELECT DISTINCT tx_hash FROM tx_filters")
.fetch_all(transaction.conn())
.await?
.into_iter()
.map(|value| value.tx_hash)
.collect();
println!("Filters len {:?}", tx_filter_hashes.len());

let difference: Vec<Vec<u8>> = tx_filter_hashes
.difference(&tx_hashes)
.into_iter()
.cloned()
.collect();

println!("Difference len {:?}", difference.len());
for chunk in difference.chunks(100) {
sqlx::query!("DELETE FROM tx_filters WHERE tx_hash = ANY ($1)", chunk)
.execute(transaction.conn())
.await?;
}

transaction.commit().await?;

Ok(())
}
/// Stores executed priority operation in database.
///
/// This method is made public to fill the database for tests, do not use it for
Expand Down
Loading

0 comments on commit a2e20d8

Please sign in to comment.