diff --git a/core/lib/dal/.sqlx/query-bab1857df66bbef57705ae7796161f3a71f5c6737e08745a37b41b22f4dfd030.json b/core/lib/dal/.sqlx/query-bab1857df66bbef57705ae7796161f3a71f5c6737e08745a37b41b22f4dfd030.json new file mode 100644 index 00000000000..4510b6084d2 --- /dev/null +++ b/core/lib/dal/.sqlx/query-bab1857df66bbef57705ae7796161f3a71f5c6737e08745a37b41b22f4dfd030.json @@ -0,0 +1,202 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n number,\n timestamp,\n l1_tx_count,\n l2_tx_count,\n bloom,\n priority_ops_onchain_data,\n hash,\n commitment,\n eth_prove_tx_id,\n eth_commit_tx_id,\n eth_execute_tx_id,\n merkle_root_hash,\n l2_to_l1_logs,\n l2_to_l1_messages,\n used_contract_hashes,\n compressed_initial_writes,\n compressed_repeated_writes,\n l2_l1_merkle_root,\n rollup_last_leaf_index,\n zkporter_is_available,\n bootloader_code_hash,\n default_aa_code_hash,\n aux_data_hash,\n pass_through_data_hash,\n meta_parameters_hash,\n protocol_version,\n compressed_state_diffs,\n system_logs,\n events_queue_commitment,\n bootloader_initial_content_commitment,\n pubdata_input\n FROM\n l1_batches\n LEFT JOIN commitments ON commitments.l1_batch_number = l1_batches.number\n WHERE\n eth_commit_tx_id IS NOT NULL\n AND eth_prove_tx_id IS NULL\n ORDER BY\n number\n LIMIT\n $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "number", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "timestamp", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "l1_tx_count", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "l2_tx_count", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "bloom", + "type_info": "Bytea" + }, + { + "ordinal": 5, + "name": "priority_ops_onchain_data", + "type_info": "ByteaArray" + }, + { + "ordinal": 6, + "name": "hash", + "type_info": "Bytea" + }, + { + "ordinal": 7, + "name": "commitment", + "type_info": "Bytea" + }, + { + "ordinal": 8, + "name": "eth_prove_tx_id", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "eth_commit_tx_id", + "type_info": "Int4" + }, + { + "ordinal": 10, + "name": "eth_execute_tx_id", + "type_info": "Int4" + }, + { + "ordinal": 11, + "name": "merkle_root_hash", + "type_info": "Bytea" + }, + { + "ordinal": 12, + "name": "l2_to_l1_logs", + "type_info": "ByteaArray" + }, + { + "ordinal": 13, + "name": "l2_to_l1_messages", + "type_info": "ByteaArray" + }, + { + "ordinal": 14, + "name": "used_contract_hashes", + "type_info": "Jsonb" + }, + { + "ordinal": 15, + "name": "compressed_initial_writes", + "type_info": "Bytea" + }, + { + "ordinal": 16, + "name": "compressed_repeated_writes", + "type_info": "Bytea" + }, + { + "ordinal": 17, + "name": "l2_l1_merkle_root", + "type_info": "Bytea" + }, + { + "ordinal": 18, + "name": "rollup_last_leaf_index", + "type_info": "Int8" + }, + { + "ordinal": 19, + "name": "zkporter_is_available", + "type_info": "Bool" + }, + { + "ordinal": 20, + "name": "bootloader_code_hash", + "type_info": "Bytea" + }, + { + "ordinal": 21, + "name": "default_aa_code_hash", + "type_info": "Bytea" + }, + { + "ordinal": 22, + "name": "aux_data_hash", + "type_info": "Bytea" + }, + { + "ordinal": 23, + "name": "pass_through_data_hash", + "type_info": "Bytea" + }, + { + "ordinal": 24, + "name": "meta_parameters_hash", + "type_info": "Bytea" + }, + { + "ordinal": 25, + "name": "protocol_version", + "type_info": "Int4" + }, + { + "ordinal": 26, + "name": "compressed_state_diffs", + "type_info": "Bytea" + }, + { + "ordinal": 27, + "name": "system_logs", + "type_info": "ByteaArray" + }, + { + "ordinal": 28, + "name": "events_queue_commitment", + "type_info": "Bytea" + }, + { + "ordinal": 29, + "name": "bootloader_initial_content_commitment", + "type_info": "Bytea" + }, + { + "ordinal": 30, + "name": "pubdata_input", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + true, + true, + true, + true, + true, + false, + false, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + true, + true, + true + ] + }, + "hash": "bab1857df66bbef57705ae7796161f3a71f5c6737e08745a37b41b22f4dfd030" +} diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index 79dc66c26c8..8430d4c601b 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -1096,19 +1096,10 @@ impl BlocksDal<'_, '_> { /// respective commit transactions have been confirmed by the network. pub async fn get_ready_for_dummy_proof_l1_batches( &mut self, - only_commited_batches: bool, limit: usize, ) -> anyhow::Result> { - let (confirmed_at_not_null, join_on_eth_tx_history) = if only_commited_batches { - ( - "AND confirmed_at IS NOT NULL", - "JOIN eth_txs_history ON eth_commit_tx_id = eth_tx_id", - ) - } else { - ("", "") - }; - - let query = format!( + let raw_batches = sqlx::query_as!( + StorageL1Batch, r#" SELECT number, @@ -1145,27 +1136,20 @@ impl BlocksDal<'_, '_> { FROM l1_batches LEFT JOIN commitments ON commitments.l1_batch_number = l1_batches.number - {join_on_eth_tx_history} WHERE eth_commit_tx_id IS NOT NULL AND eth_prove_tx_id IS NULL - {confirmed_at_not_null} ORDER BY number LIMIT $1 "#, - ); - - let mut query = sqlx::query_as(&query); - - query = query.bind(limit as i32); - - let raw_batches: Vec = query - .instrument("get_ready_for_dummy_proof_l1_batches") - .with_arg("limit", &limit) - .fetch_all(self.storage) - .await?; + limit as i32 + ) + .instrument("get_ready_for_dummy_proof_l1_batches") + .with_arg("limit", &limit) + .fetch_all(self.storage) + .await?; self.map_l1_batches(raw_batches) .await diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index b93dbd7cffb..208f6a3aed9 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -248,6 +248,50 @@ impl Aggregator { }) } + async fn load_dummy_proof_operations( + storage: &mut StorageProcessor<'_>, + limit: usize, + is_4844_mode: bool, + ) -> Vec { + let mut ready_for_proof_l1_batches = storage + .blocks_dal() + .get_ready_for_dummy_proof_l1_batches(limit) + .await + .unwrap(); + + // need to find first batch with an unconfirmed commit transaction + // and discard it and all the following ones. + if is_4844_mode { + let mut committed_batches = vec![]; + + for batch in ready_for_proof_l1_batches.into_iter() { + let Some(commit_tx_id) = storage + .blocks_dal() + .get_eth_commit_tx_id(batch.header.number) + .await + .unwrap() + else { + break; + }; + + if storage + .eth_sender_dal() + .get_confirmed_tx_hash_by_eth_tx_id(commit_tx_id as u32) + .await + .unwrap() + .is_none() + { + break; + } + committed_batches.push(batch); + } + + ready_for_proof_l1_batches = committed_batches; + } + + ready_for_proof_l1_batches + } + async fn load_real_proof_operation( storage: &mut StorageProcessor<'_>, l1_verifier_config: L1VerifierConfig, @@ -390,11 +434,8 @@ impl Aggregator { } ProofSendingMode::SkipEveryProof => { - let ready_for_proof_l1_batches = storage - .blocks_dal() - .get_ready_for_dummy_proof_l1_batches(self.operate_4844_mode, limit) - .await - .unwrap(); + let ready_for_proof_l1_batches = + Self::load_dummy_proof_operations(storage, limit, self.operate_4844_mode).await; self.prepare_dummy_proof_operation( storage, ready_for_proof_l1_batches,