pub fn weight<DB>(db: &DB, ts: &Tipset) -> Result<BigInt, String>
where
    DB: BlockStore,
{
    let state = StateTree::new_from_root(db, ts.parent_state()).map_err(|e| e.to_string())?;

    let act = state
        .get_actor(power::ADDRESS)
        .map_err(|e| e.to_string())?
        .ok_or("Failed to load power actor for calculating weight")?;

    let state = power::State::load(db, &act).map_err(|e| e.to_string())?;

    let tpow = state.into_total_quality_adj_power();

    let log2_p = if tpow > BigInt::zero() {
        BigInt::from(tpow.bits() - 1)
    } else {
        return Err(
            "All power in the net is gone. You network might be disconnected, or the net is dead!"
                .to_owned(),
        );
    };

    let mut total_j = 0;
    for b in ts.blocks() {
        total_j += b
            .election_proof()
            .as_ref()
            .ok_or("Block contained no election proof when calculating weight")?
            .win_count;
    }

    let mut out = ts.weight().to_owned();
    out += &log2_p << 8;
    let mut e_weight: BigInt = log2_p * W_RATIO_NUM;
    e_weight <<= 8;
    e_weight *= total_j;
    e_weight = e_weight.div_floor(&(BigInt::from(BLOCKS_PER_EPOCH * W_RATIO_DEN)));
    out += &e_weight;
    Ok(out)
}
/// Returns the weight of provided tipset
Returns the weight of provided tipset
Returns the weight of provided tipset
pub fn weight<DB>(db: &DB, ts: &Tipset) -> Result<BigInt, String>
where
    DB: BlockStore,
{
    let state = StateTree::new_from_root(db, ts.parent_state()).map_err(|e| e.to_string())?;
    let act = state
        .get_actor(power::ADDRESS)
        .map_err(|e| e.to_string())?
        .ok_or("Failed to load power actor for calculating weight")?;
    let state = power::State::load(db, &act).map_err(|e| e.to_string())?;
    let tpow = state.into_total_quality_adj_power();
    let log2_p = if tpow > BigInt::zero() {
        BigInt::from(tpow.bits() - 1)
    } else {
        return Err(
            "All power in the net is gone. You network might be disconnected, or the net is dead!"
                .to_owned(),
        );
    };
    let mut total_j = 0;
    for b in ts.blocks() {
        total_j += b
            .election_proof()
            .as_ref()
            .ok_or("Block contained no election proof when calculating weight")?
            .win_count;
    }
    let mut out = ts.weight().to_owned();
    out += &log2_p << 8;
    let mut e_weight: BigInt = log2_p * W_RATIO_NUM;
    e_weight <<= 8;
    e_weight *= total_j;
    e_weight = e_weight.div_floor(&(BigInt::from(BLOCKS_PER_EPOCH * W_RATIO_DEN)));
    out += &e_weight;
    Ok(out)
}
pub fn weight < DB > ( db : & DB , ts : & Tipset ) -> Result < BigInt , String > where DB : BlockStore , { let state = StateTree :: new_from_root ( db , ts . parent_state ( ) ) . map_err ( | e | e . to_string ( ) ) ? ; let act = state . get_actor ( power :: ADDRESS ) . map_err ( | e | e . to_string ( ) ) ? . ok_or ( " " ) ? ; let state = power :: State :: load ( db , & act ) . map_err ( | e | e . to_string ( ) ) ? ; let tpow = state . into_total_quality_adj_power ( ) ; let log2_p = if tpow > BigInt :: zero ( ) { BigInt :: from ( tpow . bits ( ) - 1 ) } else { return Err ( " " . to_owned ( ) , ) ; } ; let mut total_j = 0 ; for b in ts . blocks ( ) { total_j += b . election_proof ( ) . as_ref ( ) . ok_or ( " " ) ? . win_count ; } let mut out = ts . weight ( ) . to_owned ( ) ; out += & log2_p << 8 ; let mut e_weight : BigInt = log2_p * W_RATIO_NUM ; e_weight <<= 8 ; e_weight *= total_j ; e_weight = e_weight . div_floor ( & ( BigInt :: from ( BLOCKS_PER_EPOCH * W_RATIO_DEN ) ) ) ; out += & e_weight ; Ok ( out ) }
Returns the weight of provided tipset
Returns the weight of provided tipset
db
&DB
ts
&Tipset