pub fn build_revert_context(
    db: &StoreTransaction,
    reverted_blocks: &[L2Block],
) -> Result<RevertContext> {
    // Build main chain block proof
    let reverted_blocks = reverted_blocks.iter();
    let reverted_raw_blocks: Vec<RawL2Block> = reverted_blocks.map(|rb| rb.raw()).collect();
    let (_, block_proof) = build_block_proof(db, &reverted_raw_blocks)?;
    log::debug!("build main chain block proof");

    // Build reverted block proof
    let (post_reverted_block_root, reverted_block_proof) = {
        let mut smt = db.reverted_block_smt()?;
        let to_key = |b: &RawL2Block| H256::from(b.hash());
        let to_leave = |b: &RawL2Block| (to_key(b), H256::one());

        let keys: Vec<H256> = reverted_raw_blocks.iter().map(to_key).collect();
        for key in keys.iter() {
            smt.update(key.to_owned(), H256::one())?;
        }

        let root = smt.root().to_owned();
        let leaves = reverted_raw_blocks.iter().map(to_leave).collect();
        let proof = smt.merkle_proof(keys)?.compile(leaves)?;

        (root, proof)
    };
    log::debug!("build reverted block proof");

    let new_tip_block = {
        let first_reverted_block = reverted_raw_blocks.first();
        let tip_block_hash = first_reverted_block.map(|b| b.parent_block_hash().unpack());
        let to_block = tip_block_hash.map(|h| db.get_block(&h)).transpose()?;
        let to_raw = to_block.flatten().map(|b| b.raw());
        to_raw.ok_or_else(|| anyhow!("block not found"))?
    };

    let reverted_blocks = RawL2BlockVec::new_builder()
        .extend(reverted_raw_blocks)
        .build();

    let revert_witness = RevertWitness {
        new_tip_block,
        reverted_blocks,
        block_proof,
        reverted_block_proof,
    };

    Ok(RevertContext {
        post_reverted_block_root,
        revert_witness,
    })
}
/// NOTE: Caller should rollback db, only update reverted_block_smt in L1ActionContext::Revert
Caller should rollback db, only update reverted_block_smt in L1ActionContext::Revert
Caller should rollback db only update reverted_block_smt in L1ActionContext :: Revert
pub fn build_revert_context(
    db: &StoreTransaction,
    reverted_blocks: &[L2Block],
) -> Result<RevertContext> {
    // Build main chain block proof
    let reverted_blocks = reverted_blocks.iter();
    let reverted_raw_blocks: Vec<RawL2Block> = reverted_blocks.map(|rb| rb.raw()).collect();
    let (_, block_proof) = build_block_proof(db, &reverted_raw_blocks)?;
    log::debug!("build main chain block proof");
    // Build reverted block proof
    let (post_reverted_block_root, reverted_block_proof) = {
        let mut smt = db.reverted_block_smt()?;
        let to_key = |b: &RawL2Block| H256::from(b.hash());
        let to_leave = |b: &RawL2Block| (to_key(b), H256::one());
        let keys: Vec<H256> = reverted_raw_blocks.iter().map(to_key).collect();
        for key in keys.iter() {
            smt.update(key.to_owned(), H256::one())?;
        }
        let root = smt.root().to_owned();
        let leaves = reverted_raw_blocks.iter().map(to_leave).collect();
        let proof = smt.merkle_proof(keys)?.compile(leaves)?;
        (root, proof)
    };
    log::debug!("build reverted block proof");
    let new_tip_block = {
        let first_reverted_block = reverted_raw_blocks.first();
        let tip_block_hash = first_reverted_block.map(|b| b.parent_block_hash().unpack());
        let to_block = tip_block_hash.map(|h| db.get_block(&h)).transpose()?;
        let to_raw = to_block.flatten().map(|b| b.raw());
        to_raw.ok_or_else(|| anyhow!("block not found"))?
    };
    let reverted_blocks = RawL2BlockVec::new_builder()
        .extend(reverted_raw_blocks)
        .build();
    let revert_witness = RevertWitness {
        new_tip_block,
        reverted_blocks,
        block_proof,
        reverted_block_proof,
    };
    Ok(RevertContext {
        post_reverted_block_root,
        revert_witness,
    })
}
pub fn build_revert_context ( db : & StoreTransaction , reverted_blocks : & [ L2Block ] , ) -> Result < RevertContext > { // Build main chain block proof let reverted_blocks = reverted_blocks . iter ( ) ; let reverted_raw_blocks : Vec < RawL2Block > = reverted_blocks . map ( | rb | rb . raw ( ) ) . collect ( ) ; let ( _ , block_proof ) = build_block_proof ( db , & reverted_raw_blocks ) ? ; log :: debug ! ( " " ) ; // Build reverted block proof let ( post_reverted_block_root , reverted_block_proof ) = { let mut smt = db . reverted_block_smt ( ) ? ; let to_key = | b : & RawL2Block | H256 :: from ( b . hash ( ) ) ; let to_leave = | b : & RawL2Block | ( to_key ( b ) , H256 :: one ( ) ) ; let keys : Vec < H256 > = reverted_raw_blocks . iter ( ) . map ( to_key ) . collect ( ) ; for key in keys . iter ( ) { smt . update ( key . to_owned ( ) , H256 :: one ( ) ) ? ; } let root = smt . root ( ) . to_owned ( ) ; let leaves = reverted_raw_blocks . iter ( ) . map ( to_leave ) . collect ( ) ; let proof = smt . merkle_proof ( keys ) ? . compile ( leaves ) ? ; ( root , proof ) } ; log :: debug ! ( " " ) ; let new_tip_block = { let first_reverted_block = reverted_raw_blocks . first ( ) ; let tip_block_hash = first_reverted_block . map ( | b | b . parent_block_hash ( ) . unpack ( ) ) ; let to_block = tip_block_hash . map ( | h | db . get_block ( & h ) ) . transpose ( ) ? ; let to_raw = to_block . flatten ( ) . map ( | b | b . raw ( ) ) ; to_raw . ok_or_else ( | | anyhow ! ( " " ) ) ? } ; let reverted_blocks = RawL2BlockVec :: new_builder ( ) . extend ( reverted_raw_blocks ) . build ( ) ; let revert_witness = RevertWitness { new_tip_block , reverted_blocks , block_proof , reverted_block_proof , } ; Ok ( RevertContext { post_reverted_block_root , revert_witness , } ) }
NOTE: Caller should rollback db, only update reverted_block_smt in L1ActionContext::Revert
NOTE : Caller should rollback db only update reverted_block_smt in L1ActionContext :: Revert
db
&StoreTransaction
reverted_blocks
&[L2Block]
db
&StoreTransaction
reverted_blocks
&[L2Block]