pub async fn process_l1_batch(
        &mut self,
        batch: L1BatchWithLogs,
    ) -> anyhow::Result<TreeMetadata> {
        anyhow::ensure!(
            batch.mode == self.mode,
            "Cannot process L1 batch with mode {:?} in tree with mode {:?}",
            batch.mode,
            self.mode
        );
        let batch_number = batch.stats.number;

        let mut tree = self.inner.take().context(Self::INCONSISTENT_MSG)?;
        let span = tracing::Span::current();
        let (tree, metadata) = tokio::task::spawn_blocking(move || {
            let _entered_span = span.entered();
            let _guard = AllocationGuard::new("tree#process_batch");
            let metadata = tree.process_l1_batch(&batch.storage_logs)?;
            anyhow::Ok((tree, metadata))
        })
        .await
        .with_context(|| {
            format!("Merkle tree panicked when processing L1 batch #{batch_number}")
        })??;

        self.inner = Some(tree);
        Ok(metadata)
    }
Returned errors are unrecoverable; the tree must not be used after an error is returned.
core/node/metadata_calculator/src/helpers.rs