pub(crate) async fn run_head_change<T>(
    api: &RwLock<T>,
    pending: &RwLock<HashMap<Address, MsgSet>>,
    from: Tipset,
    to: Tipset,
    rmsgs: &mut HashMap<Address, HashMap<u64, SignedMessage>>,
) -> Result<(), Error>
where
    T: Provider + 'static,
{
    // TODO: This logic should probably be implemented in the ChainStore. It handles reorgs.
    let mut left = Arc::new(from);
    let mut right = Arc::new(to);
    let mut left_chain = Vec::new();
    let mut right_chain = Vec::new();
    while left != right {
        if left.epoch() > right.epoch() {
            left_chain.push(left.as_ref().clone());
            let par = api.read().await.load_tipset(left.parents()).await?;
            left = par;
        } else {
            right_chain.push(right.as_ref().clone());
            let par = api.read().await.load_tipset(right.parents()).await?;
            right = par;
        }
    }
    for ts in left_chain {
        let mut msgs: Vec<SignedMessage> = Vec::new();
        for block in ts.blocks() {
            let (_, smsgs) = api.read().await.messages_for_block(&block)?;
            msgs.extend(smsgs);
        }
        for msg in msgs {
            add(msg, rmsgs);
        }
    }

    for ts in right_chain {
        for b in ts.blocks() {
            let (msgs, smsgs) = api.read().await.messages_for_block(b)?;

            for msg in smsgs {
                rm(msg.from(), pending, msg.sequence(), rmsgs.borrow_mut()).await?;
            }
            for msg in msgs {
                rm(msg.from(), pending, msg.sequence(), rmsgs.borrow_mut()).await?;
            }
        }
    }
    Ok(())
}
/// Like head_change, except it doesnt change the state of the MessagePool.
/// It simulates a head change call.
Like head_change, except it doesnt change the state of the MessagePool.
It simulates a head change call.
Like head_change except it doesnt change the state of the MessagePool . It simulates a head change call .
pub(crate) async fn run_head_change<T>(
    api: &RwLock<T>,
    pending: &RwLock<HashMap<Address, MsgSet>>,
    from: Tipset,
    to: Tipset,
    rmsgs: &mut HashMap<Address, HashMap<u64, SignedMessage>>,
) -> Result<(), Error>
where
    T: Provider + 'static,
{
    // TODO: This logic should probably be implemented in the ChainStore. It handles reorgs.
    let mut left = Arc::new(from);
    let mut right = Arc::new(to);
    let mut left_chain = Vec::new();
    let mut right_chain = Vec::new();
    while left != right {
        if left.epoch() > right.epoch() {
            left_chain.push(left.as_ref().clone());
            let par = api.read().await.load_tipset(left.parents()).await?;
            left = par;
        } else {
            right_chain.push(right.as_ref().clone());
            let par = api.read().await.load_tipset(right.parents()).await?;
            right = par;
        }
    }
    for ts in left_chain {
        let mut msgs: Vec<SignedMessage> = Vec::new();
        for block in ts.blocks() {
            let (_, smsgs) = api.read().await.messages_for_block(&block)?;
            msgs.extend(smsgs);
        }
        for msg in msgs {
            add(msg, rmsgs);
        }
    }
    for ts in right_chain {
        for b in ts.blocks() {
            let (msgs, smsgs) = api.read().await.messages_for_block(b)?;
            for msg in smsgs {
                rm(msg.from(), pending, msg.sequence(), rmsgs.borrow_mut()).await?;
            }
            for msg in msgs {
                rm(msg.from(), pending, msg.sequence(), rmsgs.borrow_mut()).await?;
            }
        }
    }
    Ok(())
}
pub ( crate ) async fn run_head_change < T > ( api : & RwLock < T > , pending : & RwLock < HashMap < Address , MsgSet > > , from : Tipset , to : Tipset , rmsgs : & mut HashMap < Address , HashMap < u64 , SignedMessage > > , ) -> Result < ( ) , Error > where T : Provider + ' static , { // TODO: This logic should probably be implemented in the ChainStore. It handles reorgs. let mut left = Arc :: new ( from ) ; let mut right = Arc :: new ( to ) ; let mut left_chain = Vec :: new ( ) ; let mut right_chain = Vec :: new ( ) ; while left != right { if left . epoch ( ) > right . epoch ( ) { left_chain . push ( left . as_ref ( ) . clone ( ) ) ; let par = api . read ( ) . await . load_tipset ( left . parents ( ) ) . await ? ; left = par ; } else { right_chain . push ( right . as_ref ( ) . clone ( ) ) ; let par = api . read ( ) . await . load_tipset ( right . parents ( ) ) . await ? ; right = par ; } } for ts in left_chain { let mut msgs : Vec < SignedMessage > = Vec :: new ( ) ; for block in ts . blocks ( ) { let ( _ , smsgs ) = api . read ( ) . await . messages_for_block ( & block ) ? ; msgs . extend ( smsgs ) ; } for msg in msgs { add ( msg , rmsgs ) ; } } for ts in right_chain { for b in ts . blocks ( ) { let ( msgs , smsgs ) = api . read ( ) . await . messages_for_block ( b ) ? ; for msg in smsgs { rm ( msg . from ( ) , pending , msg . sequence ( ) , rmsgs . borrow_mut ( ) ) . await ? ; } for msg in msgs { rm ( msg . from ( ) , pending , msg . sequence ( ) , rmsgs . borrow_mut ( ) ) . await ? ; } } } Ok ( ( ) ) }
Like head_change, except it doesnt change the state of the MessagePool.
Like head_change except it doesnt change the state of the MessagePool .
api
&RwLock<T>
pending
&RwLock<HashMap<Address, MsgSet>>
from
Tipset
to
Tipset
rmsgs
&mut HashMap<Address, HashMap<u64, SignedMessage>>