zebra_state::service::read::difficulty

Function solution_rate

source
pub fn solution_rate(
    non_finalized_state: &NonFinalizedState,
    db: &ZebraDb,
    num_blocks: usize,
    start_hash: Hash,
) -> Option<u128>
Expand description

Accepts a non_finalized_state, ZebraDb, num_blocks, and a block hash to start at.

Iterates over up to the last num_blocks blocks, summing up their total work. Divides that total by the number of seconds between the timestamp of the first block in the iteration and 1 block below the last block.

Returns the solution rate per second for the current best chain, or None if the start_hash and at least 1 block below it are not found in the chain.