From 269812ed71f88ba0c33280d93b8b978f35a3e5c8 Mon Sep 17 00:00:00 2001 From: perekopskiy <53865202+perekopskiy@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:56:38 +0200 Subject: [PATCH] fix(gas-adjuster): Do not unwrap in gas-adjuster (#1400) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Do not unwrap in gas-adjuster ## Why ❔ Avoid panics ## Checklist - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`. --- .../lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index db3a8e059cf..94d511061d0 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -97,9 +97,12 @@ impl GasAdjuster { ) .await?; - METRICS - .current_base_fee_per_gas - .set(*base_fee_history.last().unwrap()); + // We shouldn't rely on L1 provider to return consistent results, so we check that we have at least one new sample. + if let Some(current_base_fee_per_gas) = base_fee_history.last() { + METRICS + .current_base_fee_per_gas + .set(*current_base_fee_per_gas); + } self.base_fee_statistics.add_samples(&base_fee_history); if let Some(current_blob_base_fee) = blob_base_fee_history.last() {