pub async fn loop_updating_tree(
        mut self,
        delayer: Delayer,
        pool: &ConnectionPool<Core>,
        mut stop_receiver: watch::Receiver<bool>,
    ) -> anyhow::Result<()> {
        let tree = &mut self.tree;
        let mut next_l1_batch_to_process = tree.next_l1_batch_number();
        tracing::info!(
            "Initialized metadata calculator with {max_batches_per_iter} max L1 batches per iteration. \
             Next L1 batch for Merkle tree: {next_l1_batch_to_process}",
            max_batches_per_iter = self.max_l1_batches_per_iter
        );

        loop {
            if *stop_receiver.borrow_and_update() {
                tracing::info!("Stop request received, metadata_calculator is shutting down");
                break;
            }

            let snapshot = *next_l1_batch_to_process;
            self.step(pool, &mut next_l1_batch_to_process).await?;
            let delay = if snapshot == *next_l1_batch_to_process {
                tracing::trace!(
                    "Metadata calculator (next L1 batch: #{next_l1_batch_to_process}) \
                     didn't make any progress; delaying it using {delayer:?}"
                );
                delayer.wait(&self.tree).left_future()
            } else {
                tracing::trace!(
                    "Metadata calculator (next L1 batch: #{next_l1_batch_to_process}) made progress from #{snapshot}"
                );
                future::ready(()).right_future()
            };

            // The delays we're operating with are reasonably small, but selecting between the delay
            // and the stop receiver still allows to be more responsive during shutdown.
            tokio::select! {
                _ = stop_receiver.changed() => {
                    tracing::info!("Stop request received, metadata_calculator is shutting down");
                    break;
                }
                () = delay => { /* The delay has passed */ }
            }
        }
        Ok(())
    }
The processing loop for this updater.
core/node/metadata_calculator/src/updater.rs