/// This function updates the state of the MMR cache based on the current state of the shared checkpoints.
This function updates the state of the MMR cache based on the current state of the shared checkpoints.
This function updates the state of the MMR cache based on the current state of the shared checkpoints .
pub fn update(&mut self) -> Result<(), MerkleMountainRangeError> {
        let cp_count = self
            .checkpoints
            .len()
            .map_err(|e| MerkleMountainRangeError::BackendError(e.to_string()))?;
        if cp_count <= self.base_cp_index {
            // Checkpoint before or the same as the base MMR index, this will require a full reconstruction of the
            // cache.
            self.create_base_mmr()?;
            self.create_curr_mmr()?;
        } else if cp_count < self.curr_cp_index {
            // A short checkpoint reorg has occurred, and requires the current MMR to be reconstructed.
            self.create_curr_mmr()?;
        } else if cp_count > self.curr_cp_index {
            // The cache has fallen behind and needs to update to the new checkpoint state.
            self.update_base_mmr()?;
            self.create_curr_mmr()?;
        }
        Ok(())
    }
pub fn update ( & mut self ) -> Result < ( ) , MerkleMountainRangeError > { let cp_count = self . checkpoints . len ( ) . map_err ( | e | MerkleMountainRangeError :: BackendError ( e . to_string ( ) ) ) ? ; if cp_count <= self . base_cp_index { // Checkpoint before or the same as the base MMR index, this will require a full reconstruction of the // cache. self . create_base_mmr ( ) ? ; self . create_curr_mmr ( ) ? ; } else if cp_count < self . curr_cp_index { // A short checkpoint reorg has occurred, and requires the current MMR to be reconstructed. self . create_curr_mmr ( ) ? ; } else if cp_count > self . curr_cp_index { // The cache has fallen behind and needs to update to the new checkpoint state. self . update_base_mmr ( ) ? ; self . create_curr_mmr ( ) ? ; } Ok ( ( ) ) }
This function updates the state of the MMR cache based on the current state of the shared checkpoints.
This function updates the state of the MMR cache based on the current state of the shared checkpoints .
&mut self