pub fn extend(mut self, entries: Vec<TreeEntry>) -> (BlockOutput, PatchSet) {
        let load_nodes_latency = BLOCK_TIMINGS.load_nodes.start();
        let sorted_keys = SortedKeys::new(entries.iter().map(|entry| entry.key));
        let parent_nibbles = self.updater.load_ancestors(&sorted_keys, self.db);
        let load_nodes_latency = load_nodes_latency.observe();
        tracing::debug!("Load stage took {load_nodes_latency:?}");

        let extend_patch_latency = BLOCK_TIMINGS.extend_patch.start();
        let mut logs = Vec::with_capacity(entries.len());
        for (entry, parent_nibbles) in entries.into_iter().zip(parent_nibbles) {
            let (log, _) = self.updater.insert(entry, &parent_nibbles);
            if matches!(log, TreeLogEntry::Inserted) {
                self.leaf_count += 1;
            }
            logs.push(log);
        }
        let extend_patch_latency = extend_patch_latency.observe();
        tracing::debug!("Tree traversal stage took {extend_patch_latency:?}");

        let leaf_count = self.leaf_count;
        let (root_hash, patch) = self.finalize();
        let output = BlockOutput {
            root_hash,
            leaf_count,
            logs,
        };
        (output, patch)
    }
Extends the Merkle tree in the lightweight operation mode, without intermediate hash
computations.
core/lib/merkle_tree/src/storage/mod.rs