From 5311b7c5b0dc86d62702f7df6ecca4156041488c Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Mon, 6 Nov 2023 15:00:31 +0100 Subject: [PATCH] moved unwraps outside of dal --- .../lib/zksync_core/src/block_reverter/mod.rs | 3 +- .../src/consistency_checker/mod.rs | 1 + .../src/eth_sender/eth_tx_aggregator.rs | 3 +- .../src/eth_sender/eth_tx_manager.rs | 35 ++++++++++++++----- core/lib/zksync_core/src/eth_sender/tests.rs | 7 ++++ .../src/house_keeper/blocks_state_reporter.rs | 2 +- .../src/sync_layer/batch_status_updater.rs | 9 +++-- 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/core/lib/zksync_core/src/block_reverter/mod.rs b/core/lib/zksync_core/src/block_reverter/mod.rs index a2b716ad5502..cec90b56a93a 100644 --- a/core/lib/zksync_core/src/block_reverter/mod.rs +++ b/core/lib/zksync_core/src/block_reverter/mod.rs @@ -422,7 +422,8 @@ impl BlockReverter { .unwrap() .eth_sender_dal() .clear_failed_transactions() - .await; + .await + .unwrap(); } pub fn change_rollback_executed_l1_batches_allowance( diff --git a/core/lib/zksync_core/src/consistency_checker/mod.rs b/core/lib/zksync_core/src/consistency_checker/mod.rs index 3613cd568981..f6310d9f3cb3 100644 --- a/core/lib/zksync_core/src/consistency_checker/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/mod.rs @@ -64,6 +64,7 @@ impl ConsistencyChecker { .eth_sender_dal() .get_confirmed_tx_hash_by_eth_tx_id(commit_tx_id) .await + .unwrap() .unwrap_or_else(|| { panic!( "Commit tx hash not found in the database. Commit tx id: {}", diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index ca8314b434c2..539ac88093f5 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -501,7 +501,8 @@ impl EthTxAggregator { self.timelock_contract_address, eth_tx_predicted_gas, ) - .await; + .await + .unwrap(); transaction .blocks_dal() diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs index e66e75f739fa..da11e9056474 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs @@ -86,6 +86,7 @@ where .eth_sender_dal() .get_tx_history_to_check(op.id) .await + .unwrap() { // `status` is a Result here and we don't unwrap it with `?` // because if we do and get an `Err`, we won't finish the for loop, @@ -152,6 +153,7 @@ where .eth_sender_dal() .get_last_sent_eth_tx(eth_tx_id) .await + .unwrap() .unwrap(); let previous_base_fee = previous_sent_tx.base_fee_per_gas; @@ -208,6 +210,7 @@ where signed_tx.raw_tx.clone(), ) .await + .unwrap() { if let Err(error) = self .send_raw_transaction(storage, tx_history_id, signed_tx.raw_tx, current_block) @@ -237,14 +240,16 @@ where storage .eth_sender_dal() .set_sent_at_block(tx_history_id, current_block.0) - .await; + .await + .unwrap(); Ok(tx_hash) } Err(error) => { storage .eth_sender_dal() .remove_tx_history(tx_history_id) - .await; + .await + .unwrap(); Err(error.into()) } } @@ -309,7 +314,7 @@ where .last_known_l1_block .set(l1_block_numbers.latest.0.into()); let operator_nonce = self.get_operator_nonce(l1_block_numbers).await?; - let inflight_txs = storage.eth_sender_dal().get_inflight_txs().await; + let inflight_txs = storage.eth_sender_dal().get_inflight_txs().await.unwrap(); METRICS.number_of_inflight_txs.set(inflight_txs.len()); tracing::trace!( @@ -335,6 +340,7 @@ where .eth_sender_dal() .get_block_number_on_first_sent_attempt(tx.id) .await + .unwrap() .unwrap_or(l1_block_numbers.latest.0); return Ok(Some((tx, first_sent_at_block))); } @@ -402,7 +408,7 @@ where storage: &mut StorageProcessor<'_>, l1_block_numbers: L1BlockNumbers, ) { - for tx in storage.eth_sender_dal().get_unsent_txs().await { + for tx in storage.eth_sender_dal().get_unsent_txs().await.unwrap() { // Check already sent txs not marked as sent and mark them as sent. // The common reason for this behaviour is that we sent tx and stop the server // before updating the database @@ -413,12 +419,14 @@ where storage .eth_sender_dal() .set_sent_at_block(tx.id, tx_status.receipt.block_number.unwrap().as_u32()) - .await; + .await + .unwrap(); let eth_tx = storage .eth_sender_dal() .get_eth_tx(tx.eth_tx_id) .await + .unwrap() .expect("Eth tx should exist"); self.apply_tx_status(storage, ð_tx, tx_status, l1_block_numbers.finalized) @@ -469,7 +477,8 @@ where storage .eth_sender_dal() .mark_failed_transaction(tx.id) - .await; + .await + .unwrap(); let failure_reason = self .ethereum_gateway .failure_reason(tx_status.receipt.transaction_hash) @@ -502,7 +511,8 @@ where storage .eth_sender_dal() .confirm_tx(tx_status.tx_hash, gas_used) - .await; + .await + .unwrap(); METRICS .track_eth_tx_metrics(storage, BlockL1Stage::Mined, tx) @@ -531,6 +541,7 @@ where .eth_sender_dal() .get_block_number_on_first_sent_attempt(tx.id) .await + .unwrap() .unwrap_or(0); let waited_blocks = tx_status.receipt.block_number.unwrap().as_u32() - sent_at_block; METRICS.l1_blocks_waited_in_mempool[&tx_type_label].observe(waited_blocks.into()); @@ -580,7 +591,12 @@ where storage: &mut StorageProcessor<'_>, current_block: L1BlockNumber, ) { - let number_inflight_txs = storage.eth_sender_dal().get_inflight_txs().await.len(); + let number_inflight_txs = storage + .eth_sender_dal() + .get_inflight_txs() + .await + .unwrap() + .len(); let number_of_available_slots_for_eth_txs = self .config .max_txs_in_flight @@ -591,7 +607,8 @@ where let new_eth_tx = storage .eth_sender_dal() .get_new_eth_txs(number_of_available_slots_for_eth_txs) - .await; + .await + .unwrap(); for tx in new_eth_tx { let _ = self.send_eth_tx(storage, &tx, 0, current_block).await; diff --git a/core/lib/zksync_core/src/eth_sender/tests.rs b/core/lib/zksync_core/src/eth_sender/tests.rs index 81837e58099a..46a1572eff84 100644 --- a/core/lib/zksync_core/src/eth_sender/tests.rs +++ b/core/lib/zksync_core/src/eth_sender/tests.rs @@ -182,6 +182,7 @@ async fn confirm_many() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 5 ); @@ -208,6 +209,7 @@ async fn confirm_many() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 0 ); @@ -257,6 +259,7 @@ async fn resend_each_block() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 1 ); @@ -299,6 +302,7 @@ async fn resend_each_block() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 1 ); @@ -346,6 +350,7 @@ async fn dont_resend_already_mined() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 1 ); @@ -371,6 +376,7 @@ async fn dont_resend_already_mined() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 1 ); @@ -442,6 +448,7 @@ async fn three_scenarios() -> anyhow::Result<()> { .eth_sender_dal() .get_inflight_txs() .await + .unwrap() .len(), 2 ); diff --git a/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs b/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs index 58ffc4f479db..6ba94cbac6dd 100644 --- a/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs +++ b/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs @@ -46,7 +46,7 @@ impl L1BatchMetricsReporter { ), ]; - let eth_stats = conn.eth_sender_dal().get_eth_l1_batches().await; + let eth_stats = conn.eth_sender_dal().get_eth_l1_batches().await.unwrap(); for (tx_type, l1_batch) in eth_stats.saved { let stage = BlockStage::L1 { l1_stage: BlockL1Stage::Saved, diff --git a/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs b/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs index 9bf4f45a732c..c7a141341135 100644 --- a/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs +++ b/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs @@ -306,7 +306,8 @@ impl BatchStatusUpdater { change.l1_tx_hash, change.happened_at, ) - .await; + .await + .unwrap(); self.last_committed_l1_batch = change.number; } for change in changes.prove.into_iter() { @@ -324,7 +325,8 @@ impl BatchStatusUpdater { change.l1_tx_hash, change.happened_at, ) - .await; + .await + .unwrap(); self.last_proven_l1_batch = change.number; } for change in changes.execute.into_iter() { @@ -343,7 +345,8 @@ impl BatchStatusUpdater { change.l1_tx_hash, change.happened_at, ) - .await; + .await + .unwrap(); self.last_executed_l1_batch = change.number; }