fn extend_fork_diff_to_common_anscestor(
        &mut self,
        new_block: &BlockWrapper,
        cur_block: &BlockWrapper,
        new_chain: &mut Vec<BlockWrapper>,
        cur_chain: &mut Vec<BlockWrapper>,
    ) -> Result<(), ForkResolutionError> {
        let mut new = new_block.clone();
        let mut current = cur_block.clone();

        while current.header_signature() != new.header_signature() {
            if current.previous_block_id() == journal::NULL_BLOCK_IDENTIFIER
                || new.previous_block_id() == journal::NULL_BLOCK_IDENTIFIER
            {
                loop {
                    match new_chain.pop() {
                        Some(mut block) => {
                            block.set_status(BlockStatus::Invalid);
                            // need to put it back in the cache
                            self.block_cache.put(block);
                        }
                        None => break,
                    }
                }

                return Err(ForkResolutionError(format!(
                    "Block {} rejected due to wrong genesis {}",
                    current, new
                )));
            }

            new_chain.push(new);
            new = self.get_from_cache_strict(
                &new_chain.last().unwrap().previous_block_id(),
                "Failed to extend new chain",
            )?;

            cur_chain.push(current);
            current = self.block_cache
                .get(&cur_chain.last().unwrap().previous_block_id())
                .expect("Could not find current chain predecessor in block cache");
        }

        Ok(())
    }
/// Finds a common ancestor of the two chains. new_blkw and cur_blkw must be
/// at the same height, or this will always fail.
Finds a common ancestor of the two chains. new_blkw and cur_blkw must be
at the same height, or this will always fail.
Finds a common ancestor of the two chains . new_blkw and cur_blkw must be at the same height or this will always fail .
fn extend_fork_diff_to_common_anscestor(
        &mut self,
        new_block: &BlockWrapper,
        cur_block: &BlockWrapper,
        new_chain: &mut Vec<BlockWrapper>,
        cur_chain: &mut Vec<BlockWrapper>,
    ) -> Result<(), ForkResolutionError> {
        let mut new = new_block.clone();
        let mut current = cur_block.clone();
        while current.header_signature() != new.header_signature() {
            if current.previous_block_id() == journal::NULL_BLOCK_IDENTIFIER
                || new.previous_block_id() == journal::NULL_BLOCK_IDENTIFIER
            {
                loop {
                    match new_chain.pop() {
                        Some(mut block) => {
                            block.set_status(BlockStatus::Invalid);
                            // need to put it back in the cache
                            self.block_cache.put(block);
                        }
                        None => break,
                    }
                }
                return Err(ForkResolutionError(format!(
                    "Block {} rejected due to wrong genesis {}",
                    current, new
                )));
            }
            new_chain.push(new);
            new = self.get_from_cache_strict(
                &new_chain.last().unwrap().previous_block_id(),
                "Failed to extend new chain",
            )?;
            cur_chain.push(current);
            current = self.block_cache
                .get(&cur_chain.last().unwrap().previous_block_id())
                .expect("Could not find current chain predecessor in block cache");
        }
        Ok(())
    }
fn extend_fork_diff_to_common_anscestor ( & mut self , new_block : & BlockWrapper , cur_block : & BlockWrapper , new_chain : & mut Vec < BlockWrapper > , cur_chain : & mut Vec < BlockWrapper > , ) -> Result < ( ) , ForkResolutionError > { let mut new = new_block . clone ( ) ; let mut current = cur_block . clone ( ) ; while current . header_signature ( ) != new . header_signature ( ) { if current . previous_block_id ( ) == journal :: NULL_BLOCK_IDENTIFIER || new . previous_block_id ( ) == journal :: NULL_BLOCK_IDENTIFIER { loop { match new_chain . pop ( ) { Some ( mut block ) => { block . set_status ( BlockStatus :: Invalid ) ; // need to put it back in the cache self . block_cache . put ( block ) ; } None => break , } } return Err ( ForkResolutionError ( format ! ( " " current new ) ) ) ; } new_chain . push ( new ) ; new = self . get_from_cache_strict ( & new_chain . last ( ) . unwrap ( ) . previous_block_id ( ) , " " , ) ? ; cur_chain . push ( current ) ; current = self . block_cache . get ( & cur_chain . last ( ) . unwrap ( ) . previous_block_id ( ) ) . expect ( " " ) ; } Ok ( ( ) ) }
Finds a common ancestor of the two chains.
Finds a common ancestor of the two chains .
&mut self
new_block
&BlockWrapper
cur_block
&BlockWrapper
new_chain
&mut Vec<BlockWrapper>
cur_chain
&mut Vec<BlockWrapper>
&mut self
new_block
&BlockWrapper
cur_block
&BlockWrapper
new_chain
&mut Vec<BlockWrapper>
cur_chain
&mut Vec<BlockWrapper>