[][src]Function grin_core::consensus::next_difficulty

pub fn next_difficulty<T>(height: u64, cursor: T) -> HeaderInfo where
    T: IntoIterator<Item = HeaderInfo>, 

Computes the proof-of-work difficulty that the next block should comply with. Takes an iterator over past block headers information, from latest (highest height) to oldest (lowest height).

The difficulty calculation is based on both Digishield and GravityWave family of difficulty computation, coming to something very close to Zcash. The reference difficulty is an average of the difficulty over a window of DIFFICULTY_ADJUST_WINDOW blocks. The corresponding timespan is calculated by using the difference between the median timestamps at the beginning and the end of the window.

The secondary proof-of-work factor is calculated along the same lines, as an adjustment on the deviation against the ideal value.