pub fn verify_consistency(
        &self,
        version: u64,
        validate_indices: bool,
    ) -> Result<(), ConsistencyError> {
        let manifest = self.db.try_manifest()?;
        let manifest = manifest.ok_or(ConsistencyError::MissingVersion(version))?;
        if version >= manifest.version_count {
            return Err(ConsistencyError::MissingVersion(version));
        }

        let root = self
            .db
            .try_root(version)?
            .ok_or(ConsistencyError::MissingRoot(version))?;
        let (leaf_count, root_node) = match root {
            Root::Empty => return Ok(()),
            Root::Filled { leaf_count, node } => (leaf_count.get(), node),
        };

        // We want to perform a depth-first walk of the tree in order to not keep
        // much in memory.
        let root_key = Nibbles::EMPTY.with_version(version);
        let leaf_data = validate_indices.then(|| LeafConsistencyData::new(leaf_count));
        self.validate_node(&root_node, root_key, leaf_data.as_ref())?;
        if let Some(leaf_data) = leaf_data {
            leaf_data.validate_count()?;
        }
        Ok(())
    }
Verifies the internal tree consistency as stored in the database.

If `validate_indices` flag is set, it will be checked that indices for all tree leaves are unique
and are sequentially assigned starting from 1.

# Errors

Returns an error (the first encountered one if there are multiple).
core/lib/merkle_tree/src/consistency.rs