Skip to content

Commit

Permalink
moved unwraps outside of dal
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Nov 6, 2023
1 parent f6736fa commit 756ba6c
Show file tree
Hide file tree
Showing 8 changed files with 764 additions and 734 deletions.
1,438 changes: 719 additions & 719 deletions core/lib/dal/sqlx-data.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion core/lib/zksync_core/src/block_reverter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ impl BlockReverter {
.unwrap()
.eth_sender_dal()
.clear_failed_transactions()
.await;
.await
.unwrap();
}

pub fn change_rollback_executed_l1_batches_allowance(
Expand Down
1 change: 1 addition & 0 deletions core/lib/zksync_core/src/consistency_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down
3 changes: 2 additions & 1 deletion core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ impl EthTxAggregator {
self.timelock_contract_address,
eth_tx_predicted_gas,
)
.await;
.await
.unwrap();

transaction
.blocks_dal()
Expand Down
35 changes: 26 additions & 9 deletions core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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!(
Expand All @@ -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)));
}
Expand Down Expand Up @@ -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
Expand All @@ -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, &eth_tx, tx_status, l1_block_numbers.finalized)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions core/lib/zksync_core/src/eth_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ async fn confirm_many() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
5
);
Expand All @@ -208,6 +209,7 @@ async fn confirm_many() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
0
);
Expand Down Expand Up @@ -257,6 +259,7 @@ async fn resend_each_block() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
1
);
Expand Down Expand Up @@ -299,6 +302,7 @@ async fn resend_each_block() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
1
);
Expand Down Expand Up @@ -346,6 +350,7 @@ async fn dont_resend_already_mined() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
1
);
Expand All @@ -371,6 +376,7 @@ async fn dont_resend_already_mined() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
1
);
Expand Down Expand Up @@ -442,6 +448,7 @@ async fn three_scenarios() -> anyhow::Result<()> {
.eth_sender_dal()
.get_inflight_txs()
.await
.unwrap()
.len(),
2
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions core/lib/zksync_core/src/sync_layer/batch_status_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -343,7 +345,8 @@ impl BatchStatusUpdater {
change.l1_tx_hash,
change.happened_at,
)
.await;
.await
.unwrap();
self.last_executed_l1_batch = change.number;
}

Expand Down

0 comments on commit 756ba6c

Please sign in to comment.