diff --git a/storage/.sqlx/query-fceb9c1b2af1a60725ee1ffd2824431ed581508f3f93df9c28afa441a3ab1404.json b/storage/.sqlx/query-1429bfeafe86ef0ce1449e07709bcce578fe6c917592a00654294c881dcc609a.json similarity index 84% rename from storage/.sqlx/query-fceb9c1b2af1a60725ee1ffd2824431ed581508f3f93df9c28afa441a3ab1404.json rename to storage/.sqlx/query-1429bfeafe86ef0ce1449e07709bcce578fe6c917592a00654294c881dcc609a.json index 2e6136eb..a5835dd3 100644 --- a/storage/.sqlx/query-fceb9c1b2af1a60725ee1ffd2824431ed581508f3f93df9c28afa441a3ab1404.json +++ b/storage/.sqlx/query-1429bfeafe86ef0ce1449e07709bcce578fe6c917592a00654294c881dcc609a.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT\n w.tx_hash,\n w.event_index_in_tx,\n withdrawal_id,\n finalization_data.l2_block_number,\n l1_batch_number,\n l2_message_index,\n l2_tx_number_in_block,\n message,\n sender,\n proof\n FROM\n finalization_data\n JOIN withdrawals w ON finalization_data.withdrawal_id = w.id\n WHERE\n finalization_tx IS NULL\n AND failed_finalization_attempts < 3\n AND finalization_data.l2_block_number <= COALESCE(\n (\n SELECT\n MAX(l2_block_number)\n FROM\n l2_blocks\n WHERE\n execute_l1_block_number IS NOT NULL\n ),\n 1\n )\n ORDER BY\n finalization_data.l2_block_number\n LIMIT\n $1\n ", + "query": "\n SELECT\n w.tx_hash,\n w.event_index_in_tx,\n withdrawal_id,\n finalization_data.l2_block_number,\n l1_batch_number,\n l2_message_index,\n l2_tx_number_in_block,\n message,\n sender,\n proof\n FROM\n finalization_data\n JOIN withdrawals w ON finalization_data.withdrawal_id = w.id\n WHERE\n finalization_tx IS NULL\n AND failed_finalization_attempts < 3\n AND finalization_data.l2_block_number <= COALESCE(\n (\n SELECT\n MAX(l2_block_number)\n FROM\n l2_blocks\n WHERE\n execute_l1_block_number IS NOT NULL\n ),\n 1\n )\n AND (\n last_finalization_attempt IS NULL\n OR\n last_finalization_attempt < NOW() - INTERVAL '1 minutes'\n )\n ORDER BY\n finalization_data.l2_block_number\n LIMIT\n $1\n ", "describe": { "columns": [ { @@ -72,5 +72,5 @@ false ] }, - "hash": "fceb9c1b2af1a60725ee1ffd2824431ed581508f3f93df9c28afa441a3ab1404" + "hash": "1429bfeafe86ef0ce1449e07709bcce578fe6c917592a00654294c881dcc609a" } diff --git a/storage/.sqlx/query-660e3d86db6ed4255862bc7aa8f345b990f4e95ebfb05a611da57643580922f8.json b/storage/.sqlx/query-660e3d86db6ed4255862bc7aa8f345b990f4e95ebfb05a611da57643580922f8.json new file mode 100644 index 00000000..1094de78 --- /dev/null +++ b/storage/.sqlx/query-660e3d86db6ed4255862bc7aa8f345b990f4e95ebfb05a611da57643580922f8.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE\n finalization_data\n SET\n last_finalization_attempt = NOW(),\n failed_finalization_attempts = failed_finalization_attempts + 1\n FROM\n (\n SELECT\n UNNEST ($1 :: BYTEA []) AS tx_hash,\n UNNEST ($2 :: integer []) AS event_index_in_tx\n ) AS u\n WHERE\n finalization_data.withdrawal_id = (\n SELECT\n id\n FROM\n withdrawals\n WHERE\n tx_hash = u.tx_hash\n AND event_index_in_tx = u.event_index_in_tx\n )\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "ByteaArray", + "Int4Array" + ] + }, + "nullable": [] + }, + "hash": "660e3d86db6ed4255862bc7aa8f345b990f4e95ebfb05a611da57643580922f8" +} diff --git a/storage/.sqlx/query-9930a0b464fd0cdc81ae5830912b1914354ff4777351ba0494e97a977ddb582f.json b/storage/.sqlx/query-9930a0b464fd0cdc81ae5830912b1914354ff4777351ba0494e97a977ddb582f.json deleted file mode 100644 index 679e3e57..00000000 --- a/storage/.sqlx/query-9930a0b464fd0cdc81ae5830912b1914354ff4777351ba0494e97a977ddb582f.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE\n finalization_data\n SET\n failed_finalization_attempts = failed_finalization_attempts + 1\n FROM\n (\n SELECT\n UNNEST ($1 :: BYTEA []) AS tx_hash,\n UNNEST ($2 :: integer []) AS event_index_in_tx\n ) AS u\n WHERE\n finalization_data.withdrawal_id = (\n SELECT\n id\n FROM\n withdrawals\n WHERE\n tx_hash = u.tx_hash\n AND event_index_in_tx = u.event_index_in_tx\n )\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "ByteaArray", - "Int4Array" - ] - }, - "nullable": [] - }, - "hash": "9930a0b464fd0cdc81ae5830912b1914354ff4777351ba0494e97a977ddb582f" -} diff --git a/storage/migrations/20231013101851_finalize_attempts_timestamps.down.sql b/storage/migrations/20231013101851_finalize_attempts_timestamps.down.sql new file mode 100644 index 00000000..a2584161 --- /dev/null +++ b/storage/migrations/20231013101851_finalize_attempts_timestamps.down.sql @@ -0,0 +1 @@ +ALTER TABLE finalization_data DROP COLUMN last_finalization_attempt; diff --git a/storage/migrations/20231013101851_finalize_attempts_timestamps.up.sql b/storage/migrations/20231013101851_finalize_attempts_timestamps.up.sql new file mode 100644 index 00000000..7b94f33c --- /dev/null +++ b/storage/migrations/20231013101851_finalize_attempts_timestamps.up.sql @@ -0,0 +1 @@ +ALTER TABLE finalization_data ADD last_finalization_attempt TIMESTAMP; diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 202a096a..586e0a3d 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -749,6 +749,11 @@ pub async fn withdrwals_to_finalize(pool: &PgPool, limit_by: u64) -> Result