Skip to content

Commit

Permalink
fix(metrics): Use latest block for non pos ethereum as safe (#1022)
Browse files Browse the repository at this point in the history
## What ❔

We have a hack and if we set number of confirmations, it's possible to
use our network in PoW Ethereum, but it wasn't the case for our metrics.

## Why ❔

We need to run zk stack locally in PoW Ethereum 

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] 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`.

Signed-off-by: Danil <deniallugo@gmail.com>
Co-authored-by: Fedor Sakharov <fedor.sakharov@gmail.com>
  • Loading branch information
Deniallugo and montekki committed Feb 7, 2024
1 parent 908ac42 commit 49ec843
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,36 @@ impl EthTxManager {
}

async fn get_l1_block_numbers(&self) -> Result<L1BlockNumbers, ETHSenderError> {
let finalized = if let Some(confirmations) = self.config.wait_confirmations {
let (finalized, safe) = if let Some(confirmations) = self.config.wait_confirmations {
let latest_block_number = self
.ethereum_gateway
.block_number("eth_tx_manager")
.await?
.as_u64();
(latest_block_number.saturating_sub(confirmations) as u32).into()

let finalized = (latest_block_number.saturating_sub(confirmations) as u32).into();
(finalized, finalized)
} else {
self.ethereum_gateway
let finalized = self
.ethereum_gateway
.block(BlockId::Number(BlockNumber::Finalized), "eth_tx_manager")
.await?
.expect("Finalized block must be present on L1")
.number
.expect("Finalized block must contain number")
.as_u32()
.into()
.into();

let safe = self
.ethereum_gateway
.block(BlockId::Number(BlockNumber::Safe), "eth_tx_manager")
.await?
.expect("Safe block must be present on L1")
.number
.expect("Safe block must contain number")
.as_u32()
.into();
(finalized, safe)
};

let latest = self
Expand All @@ -302,16 +316,6 @@ impl EthTxManager {
.as_u32()
.into();

let safe = self
.ethereum_gateway
.block(BlockId::Number(BlockNumber::Safe), "eth_tx_manager")
.await?
.expect("Safe block must be present on L1")
.number
.expect("Safe block must contain number")
.as_u32()
.into();

Ok(L1BlockNumbers {
finalized,
latest,
Expand Down

0 comments on commit 49ec843

Please sign in to comment.