fn commit_mmrs(&mut self, tx: DbTransaction) -> Result<(), ChainStorageError> {
        for op in tx.operations.into_iter() {
            match op {
                WriteOperation::RewindMmr(tree, steps_back) => match tree {
                    MmrTree::Kernel => {
                        let last_cp = checkpoint_utils::rewind_checkpoints(&mut self.kernel_checkpoints, steps_back)?;
                        self.kernel_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_kernel_checkpoint.reset_to(&last_cp);
                    },
                    MmrTree::Utxo => {
                        let last_cp = checkpoint_utils::rewind_checkpoints(&mut self.utxo_checkpoints, steps_back)?;
                        self.utxo_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_utxo_checkpoint.reset_to(&last_cp);
                    },
                    MmrTree::RangeProof => {
                        let last_cp =
                            checkpoint_utils::rewind_checkpoints(&mut self.range_proof_checkpoints, steps_back)?;
                        self.range_proof_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_range_proof_checkpoint.reset_to(&last_cp);
                    },
                },
                WriteOperation::CreateMmrCheckpoint(tree) => match tree {
                    MmrTree::Kernel => {
                        let curr_checkpoint = self.curr_kernel_checkpoint.clone();
                        self.kernel_checkpoints
                            .push(curr_checkpoint)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_kernel_checkpoint.reset();

                        self.kernel_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                    },
                    MmrTree::Utxo => {
                        let curr_checkpoint = self.curr_utxo_checkpoint.clone();
                        self.utxo_checkpoints
                            .push(curr_checkpoint)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_utxo_checkpoint.reset();

                        self.utxo_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                    },
                    MmrTree::RangeProof => {
                        let curr_checkpoint = self.curr_range_proof_checkpoint.clone();
                        self.range_proof_checkpoints
                            .push(curr_checkpoint)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_range_proof_checkpoint.reset();

                        self.range_proof_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                    },
                },
                WriteOperation::MergeMmrCheckpoints(tree, max_cp_count) => match tree {
                    MmrTree::Kernel => {
                        let (num_cps_merged, _) =
                            checkpoint_utils::merge_checkpoints(&mut self.kernel_checkpoints, max_cp_count)?;
                        self.kernel_mmr
                            .checkpoints_merged(num_cps_merged)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        trace!(target: LOG_TARGET, "Merged {} kernel checkpoints", num_cps_merged);
                    },
                    MmrTree::Utxo => {
                        let (num_cps_merged, stxo_leaf_indices) =
                            checkpoint_utils::merge_checkpoints(&mut self.utxo_checkpoints, max_cp_count)?;
                        self.utxo_mmr
                            .checkpoints_merged(num_cps_merged)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        trace!(target: LOG_TARGET, "Merged {} utxo checkpoints", num_cps_merged);
                        let num_stxo_leaf_indices = stxo_leaf_indices.len();
                        let num_stxos_discarded = self.discard_stxos(stxo_leaf_indices)?;
                        trace!(
                            target: LOG_TARGET,
                            "Discarded {} of {} STXOs",
                            num_stxo_leaf_indices,
                            num_stxos_discarded
                        );
                    },
                    MmrTree::RangeProof => {
                        let (num_cps_merged, _) =
                            checkpoint_utils::merge_checkpoints(&mut self.range_proof_checkpoints, max_cp_count)?;
                        self.range_proof_mmr
                            .checkpoints_merged(num_cps_merged)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        trace!(target: LOG_TARGET, "Merged {} range proof checkpoints", num_cps_merged);
                    },
                },
                _ => { /* ignore operations which do not apply */ },
            }
        }
        Ok(())
    }
// Perform the RewindMmr and CreateMmrCheckpoint operations after MMR txns and storage txns have been applied.
Perform the RewindMmr and CreateMmrCheckpoint operations after MMR txns and storage txns have been applied.
Perform the RewindMmr and CreateMmrCheckpoint operations after MMR txns and storage txns have been applied .
fn commit_mmrs(&mut self, tx: DbTransaction) -> Result<(), ChainStorageError> {
        for op in tx.operations.into_iter() {
            match op {
                WriteOperation::RewindMmr(tree, steps_back) => match tree {
                    MmrTree::Kernel => {
                        let last_cp = checkpoint_utils::rewind_checkpoints(&mut self.kernel_checkpoints, steps_back)?;
                        self.kernel_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_kernel_checkpoint.reset_to(&last_cp);
                    },
                    MmrTree::Utxo => {
                        let last_cp = checkpoint_utils::rewind_checkpoints(&mut self.utxo_checkpoints, steps_back)?;
                        self.utxo_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_utxo_checkpoint.reset_to(&last_cp);
                    },
                    MmrTree::RangeProof => {
                        let last_cp =
                            checkpoint_utils::rewind_checkpoints(&mut self.range_proof_checkpoints, steps_back)?;
                        self.range_proof_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_range_proof_checkpoint.reset_to(&last_cp);
                    },
                },
                WriteOperation::CreateMmrCheckpoint(tree) => match tree {
                    MmrTree::Kernel => {
                        let curr_checkpoint = self.curr_kernel_checkpoint.clone();
                        self.kernel_checkpoints
                            .push(curr_checkpoint)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_kernel_checkpoint.reset();
                        self.kernel_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                    },
                    MmrTree::Utxo => {
                        let curr_checkpoint = self.curr_utxo_checkpoint.clone();
                        self.utxo_checkpoints
                            .push(curr_checkpoint)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_utxo_checkpoint.reset();
                        self.utxo_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                    },
                    MmrTree::RangeProof => {
                        let curr_checkpoint = self.curr_range_proof_checkpoint.clone();
                        self.range_proof_checkpoints
                            .push(curr_checkpoint)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        self.curr_range_proof_checkpoint.reset();
                        self.range_proof_mmr
                            .update()
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                    },
                },
                WriteOperation::MergeMmrCheckpoints(tree, max_cp_count) => match tree {
                    MmrTree::Kernel => {
                        let (num_cps_merged, _) =
                            checkpoint_utils::merge_checkpoints(&mut self.kernel_checkpoints, max_cp_count)?;
                        self.kernel_mmr
                            .checkpoints_merged(num_cps_merged)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        trace!(target: LOG_TARGET, "Merged {} kernel checkpoints", num_cps_merged);
                    },
                    MmrTree::Utxo => {
                        let (num_cps_merged, stxo_leaf_indices) =
                            checkpoint_utils::merge_checkpoints(&mut self.utxo_checkpoints, max_cp_count)?;
                        self.utxo_mmr
                            .checkpoints_merged(num_cps_merged)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        trace!(target: LOG_TARGET, "Merged {} utxo checkpoints", num_cps_merged);
                        let num_stxo_leaf_indices = stxo_leaf_indices.len();
                        let num_stxos_discarded = self.discard_stxos(stxo_leaf_indices)?;
                        trace!(
                            target: LOG_TARGET,
                            "Discarded {} of {} STXOs",
                            num_stxo_leaf_indices,
                            num_stxos_discarded
                        );
                    },
                    MmrTree::RangeProof => {
                        let (num_cps_merged, _) =
                            checkpoint_utils::merge_checkpoints(&mut self.range_proof_checkpoints, max_cp_count)?;
                        self.range_proof_mmr
                            .checkpoints_merged(num_cps_merged)
                            .map_err(|e| ChainStorageError::AccessError(e.to_string()))?;
                        trace!(target: LOG_TARGET, "Merged {} range proof checkpoints", num_cps_merged);
                    },
                },
                _ => { /* ignore operations which do not apply */ },
            }
        }
        Ok(())
    }
fn commit_mmrs ( & mut self , tx : DbTransaction ) -> Result < ( ) , ChainStorageError > { for op in tx . operations . into_iter ( ) { match op { WriteOperation :: RewindMmr ( tree , steps_back ) => match tree { MmrTree :: Kernel => { let last_cp = checkpoint_utils :: rewind_checkpoints ( & mut self . kernel_checkpoints , steps_back ) ? ; self . kernel_mmr . update ( ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; self . curr_kernel_checkpoint . reset_to ( & last_cp ) ; } , MmrTree :: Utxo => { let last_cp = checkpoint_utils :: rewind_checkpoints ( & mut self . utxo_checkpoints , steps_back ) ? ; self . utxo_mmr . update ( ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; self . curr_utxo_checkpoint . reset_to ( & last_cp ) ; } , MmrTree :: RangeProof => { let last_cp = checkpoint_utils :: rewind_checkpoints ( & mut self . range_proof_checkpoints , steps_back ) ? ; self . range_proof_mmr . update ( ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; self . curr_range_proof_checkpoint . reset_to ( & last_cp ) ; } , } , WriteOperation :: CreateMmrCheckpoint ( tree ) => match tree { MmrTree :: Kernel => { let curr_checkpoint = self . curr_kernel_checkpoint . clone ( ) ; self . kernel_checkpoints . push ( curr_checkpoint ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; self . curr_kernel_checkpoint . reset ( ) ; self . kernel_mmr . update ( ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; } , MmrTree :: Utxo => { let curr_checkpoint = self . curr_utxo_checkpoint . clone ( ) ; self . utxo_checkpoints . push ( curr_checkpoint ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; self . curr_utxo_checkpoint . reset ( ) ; self . utxo_mmr . update ( ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; } , MmrTree :: RangeProof => { let curr_checkpoint = self . curr_range_proof_checkpoint . clone ( ) ; self . range_proof_checkpoints . push ( curr_checkpoint ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; self . curr_range_proof_checkpoint . reset ( ) ; self . range_proof_mmr . update ( ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; } , } , WriteOperation :: MergeMmrCheckpoints ( tree , max_cp_count ) => match tree { MmrTree :: Kernel => { let ( num_cps_merged , _ ) = checkpoint_utils :: merge_checkpoints ( & mut self . kernel_checkpoints , max_cp_count ) ? ; self . kernel_mmr . checkpoints_merged ( num_cps_merged ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; trace ! ( target LOG_TARGET " " num_cps_merged ) ; } , MmrTree :: Utxo => { let ( num_cps_merged , stxo_leaf_indices ) = checkpoint_utils :: merge_checkpoints ( & mut self . utxo_checkpoints , max_cp_count ) ? ; self . utxo_mmr . checkpoints_merged ( num_cps_merged ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; trace ! ( target LOG_TARGET " " num_cps_merged ) ; let num_stxo_leaf_indices = stxo_leaf_indices . len ( ) ; let num_stxos_discarded = self . discard_stxos ( stxo_leaf_indices ) ? ; trace ! ( target LOG_TARGET " " num_stxo_leaf_indices num_stxos_discarded ) ; } , MmrTree :: RangeProof => { let ( num_cps_merged , _ ) = checkpoint_utils :: merge_checkpoints ( & mut self . range_proof_checkpoints , max_cp_count ) ? ; self . range_proof_mmr . checkpoints_merged ( num_cps_merged ) . map_err ( | e | ChainStorageError :: AccessError ( e . to_string ( ) ) ) ? ; trace ! ( target LOG_TARGET " " num_cps_merged ) ; } , } , _ => { /* ignore operations which do not apply */ } , } } Ok ( ( ) ) }
Perform the RewindMmr and CreateMmrCheckpoint operations after MMR txns and storage txns have been applied.
Perform the RewindMmr and CreateMmrCheckpoint operations after MMR txns and storage txns have been applied .
&mut self
tx
DbTransaction
&mut self
tx
DbTransaction