pub async fn block_store_state(&mut self) -> anyhow::Result<BlockStoreState> {
        let first = self.first_block().await.context("first_block()")?;
        let cfg = self
            .global_config()
            .await
            .context("global_config()")?
            .context("global config is missing")?;

        // If there is a cert in storage, then the block range visible to consensus
        // is [first block, block of last cert].
        if let Some(row) = sqlx::query!(
            r#"
            SELECT
                versioned_certificate
            FROM
                miniblocks_consensus
            ORDER BY
                number DESC
            LIMIT
                1
            "#,
        )
        .instrument("block_certificate_range")
        .report_latency()
        .fetch_optional(self.storage)
        .await?
        {
            let d = zksync_protobuf::serde::Deserialize {
                deny_unknown_fields: true,
            };

            let cert: Option<BlockCertificate> = row
                .versioned_certificate
                .as_ref()
                .map(|cert| d.proto_fmt(cert))
                .transpose()?;

            if let Some(cert) = cert {
                return Ok(BlockStoreState {
                    first,
                    last: Some(cert.into()),
                });
            }
        }

        // Otherwise it is [first block, min(genesis.first_block-1,last block)].
        let next = self
            .next_block()
            .await
            .context("next_block()")?
            .min(cfg.genesis.first_block);

        Ok(BlockStoreState {
            first,
            // unwrap is ok, because `next > first >= 0`.
            last: if next > first {
                Some(Last::PreGenesis(next.prev().unwrap()))
            } else {
                None
            },
        })
    }
Fetches the block store state.
The blocks that are available to consensus are either pre-genesis or
have a consensus certificate.
Currently, certificates are NOT generated synchronously with L2 blocks,
so the `BlockStoreState.last` might be different than the last block in storage.
core/lib/dal/src/consensus_dal/mod.rs