Minor boundary adjustments for 2nd PoW scaling

This commit is contained in:
Ignotus Peverell 2018-10-16 00:42:32 +00:00
parent 34646ddf51
commit d0ed5cd4a3
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211

View file

@ -72,10 +72,10 @@ pub const SECOND_POW_EDGE_BITS: u8 = 29;
/// Cuckoo graph sizes, changing this would hard fork /// Cuckoo graph sizes, changing this would hard fork
pub const BASE_EDGE_BITS: u8 = 24; pub const BASE_EDGE_BITS: u8 = 24;
/// maximum scaling factor for secondary pow, enforced in diff retargetting /// Maximum scaling factor for secondary pow, enforced in diff retargetting
/// increasing scaling factor increases frequency of secondary blocks /// increasing scaling factor increases frequency of secondary blocks
/// ONLY IN TESTNET4 LIMITED TO ABOUT 8 TIMES THE NATURAL SCALE /// ONLY IN TESTNET4 LIMITED TO ABOUT 8 TIMES THE NATURAL SCALE
pub const MAX_SECOND_POW_SCALE: u64 = 8 << 11; pub const MAX_SECONDARY_SCALING: u64 = 8 << 11;
/// Default number of blocks in the past when cross-block cut-through will start /// Default number of blocks in the past when cross-block cut-through will start
/// happening. Needs to be long enough to not overlap with a long reorg. /// happening. Needs to be long enough to not overlap with a long reorg.
@ -294,8 +294,6 @@ where
HeaderInfo::from_diff_scaling(Difficulty::from_num(difficulty), sec_pow_scaling) HeaderInfo::from_diff_scaling(Difficulty::from_num(difficulty), sec_pow_scaling)
} }
pub const MAX_SECONDARY_SCALING: u64 = (::std::u32::MAX / 70) as u64;
/// Factor by which the secondary proof of work difficulty will be adjusted /// Factor by which the secondary proof of work difficulty will be adjusted
pub fn secondary_pow_scaling(height: u64, diff_data: &Vec<HeaderInfo>) -> u32 { pub fn secondary_pow_scaling(height: u64, diff_data: &Vec<HeaderInfo>) -> u32 {
// median of past scaling factors, scaling is 1 if none found // median of past scaling factors, scaling is 1 if none found
@ -317,10 +315,10 @@ pub fn secondary_pow_scaling(height: u64, diff_data: &Vec<HeaderInfo>) -> u32 {
let scaling = scaling_median * diff_data.len() as u64 * ratio / 100 / secondary_count as u64; let scaling = scaling_median * diff_data.len() as u64 * ratio / 100 / secondary_count as u64;
// various bounds // various bounds
let bounded_scaling = if scaling < scaling_median / 4 || scaling == 0 { let bounded_scaling = if scaling < scaling_median / 2 || scaling == 0 {
max(scaling_median / 4, 1) max(scaling_median / 2, 1)
} else if scaling > MAX_SECONDARY_SCALING || scaling > scaling_median * 4 { } else if scaling > MAX_SECONDARY_SCALING || scaling > scaling_median * 2 {
min(MAX_SECONDARY_SCALING, scaling_median * 4) min(MAX_SECONDARY_SCALING, scaling_median * 2)
} else { } else {
scaling scaling
}; };