pub fn next_difficulty<T>(height: u64, cursor: T) -> HeaderInfo
where
	T: IntoIterator<Item = HeaderInfo>,
{
	// Create vector of difficulty data running from earliest
	// to latest, and pad with simulated pre-genesis data to allow earlier
	// adjustment if there isn't enough window data length will be
	// DIFFICULTY_ADJUST_WINDOW + 1 (for initial block time bound)
	let diff_data = global::difficulty_data_to_vector(cursor);

	// First, get the ratio of secondary PoW vs primary, skipping initial header
	let sec_pow_scaling = secondary_pow_scaling(height, &diff_data[1..]);

	// Get the timestamp delta across the window
	let ts_delta: u64 =
		diff_data[DIFFICULTY_ADJUST_WINDOW as usize].timestamp - diff_data[0].timestamp;

	// Get the difficulty sum of the last DIFFICULTY_ADJUST_WINDOW elements
	let diff_sum: u64 = diff_data
		.iter()
		.skip(1)
		.map(|dd| dd.difficulty.to_num())
		.sum();

	// adjust time delta toward goal subject to dampening and clamping
	let adj_ts = clamp(
		damp(ts_delta, BLOCK_TIME_WINDOW, DIFFICULTY_DAMP_FACTOR),
		BLOCK_TIME_WINDOW,
		CLAMP_FACTOR,
	);
	// minimum difficulty avoids getting stuck due to dampening
	let difficulty = max(MIN_DIFFICULTY, diff_sum * BLOCK_TIME_SEC / adj_ts);

	HeaderInfo::from_diff_scaling(Difficulty::from_num(difficulty), sec_pow_scaling)
}
/// 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.
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.
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 .
pub fn next_difficulty<T>(height: u64, cursor: T) -> HeaderInfo
where
	T: IntoIterator<Item = HeaderInfo>,
{
	// Create vector of difficulty data running from earliest
	// to latest, and pad with simulated pre-genesis data to allow earlier
	// adjustment if there isn't enough window data length will be
	// DIFFICULTY_ADJUST_WINDOW + 1 (for initial block time bound)
	let diff_data = global::difficulty_data_to_vector(cursor);
	// First, get the ratio of secondary PoW vs primary, skipping initial header
	let sec_pow_scaling = secondary_pow_scaling(height, &diff_data[1..]);
	// Get the timestamp delta across the window
	let ts_delta: u64 =
		diff_data[DIFFICULTY_ADJUST_WINDOW as usize].timestamp - diff_data[0].timestamp;
	// Get the difficulty sum of the last DIFFICULTY_ADJUST_WINDOW elements
	let diff_sum: u64 = diff_data
		.iter()
		.skip(1)
		.map(|dd| dd.difficulty.to_num())
		.sum();
	// adjust time delta toward goal subject to dampening and clamping
	let adj_ts = clamp(
		damp(ts_delta, BLOCK_TIME_WINDOW, DIFFICULTY_DAMP_FACTOR),
		BLOCK_TIME_WINDOW,
		CLAMP_FACTOR,
	);
	// minimum difficulty avoids getting stuck due to dampening
	let difficulty = max(MIN_DIFFICULTY, diff_sum * BLOCK_TIME_SEC / adj_ts);
	HeaderInfo::from_diff_scaling(Difficulty::from_num(difficulty), sec_pow_scaling)
}
pub fn next_difficulty < T > ( height : u64 , cursor : T ) -> HeaderInfo where T : IntoIterator < Item = HeaderInfo > , { // Create vector of difficulty data running from earliest // to latest, and pad with simulated pre-genesis data to allow earlier // adjustment if there isn't enough window data length will be // DIFFICULTY_ADJUST_WINDOW + 1 (for initial block time bound) let diff_data = global :: difficulty_data_to_vector ( cursor ) ; // First, get the ratio of secondary PoW vs primary, skipping initial header let sec_pow_scaling = secondary_pow_scaling ( height , & diff_data [ 1 .. ] ) ; // Get the timestamp delta across the window let ts_delta : u64 = diff_data [ DIFFICULTY_ADJUST_WINDOW as usize ] . timestamp - diff_data [ 0 ] . timestamp ; // Get the difficulty sum of the last DIFFICULTY_ADJUST_WINDOW elements let diff_sum : u64 = diff_data . iter ( ) . skip ( 1 ) . map ( | dd | dd . difficulty . to_num ( ) ) . sum ( ) ; // adjust time delta toward goal subject to dampening and clamping let adj_ts = clamp ( damp ( ts_delta , BLOCK_TIME_WINDOW , DIFFICULTY_DAMP_FACTOR ) , BLOCK_TIME_WINDOW , CLAMP_FACTOR , ) ; // minimum difficulty avoids getting stuck due to dampening let difficulty = max ( MIN_DIFFICULTY , diff_sum * BLOCK_TIME_SEC / adj_ts ) ; HeaderInfo :: from_diff_scaling ( Difficulty :: from_num ( difficulty ) , sec_pow_scaling ) }
Computes the proof-of-work difficulty that the next block should comply
with.
Computes the proof - of - work difficulty that the next block should comply with .
height
u64
cursor
T
height
u64
cursor
T