mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
Scaling multiplier fix and slightly clearer structure
This commit is contained in:
parent
febe9076f0
commit
9a15859b81
1 changed files with 7 additions and 10 deletions
|
@ -55,27 +55,24 @@ impl Difficulty {
|
|||
/// provided hash and applies the Cuckoo sizeshift adjustment factor (see
|
||||
/// https://lists.launchpad.net/mimblewimble/msg00494.html).
|
||||
pub fn from_proof_adjusted(proof: &Proof) -> Difficulty {
|
||||
let max_target = <u64>::max_value();
|
||||
let target = proof.hash().to_u64();
|
||||
let shift = proof.cuckoo_sizeshift;
|
||||
|
||||
// Adjust the difficulty based on a 2^(N-M)*(N-1) factor, with M being
|
||||
// the minimum sizeshift and N the provided sizeshift
|
||||
let shift = proof.cuckoo_sizeshift;
|
||||
let adjust_factor = (1 << (shift - global::ref_sizeshift()) as u64) * (shift as u64 - 1);
|
||||
let difficulty = (max_target / target) * adjust_factor;
|
||||
|
||||
Difficulty::from_num(difficulty)
|
||||
Difficulty::from_num(Difficulty::raw_difficulty(proof) * adjust_factor)
|
||||
}
|
||||
|
||||
/// Same as `from_proof_adjusted` but instead of an adjustment based on
|
||||
/// cycle size, scales based on a provided factor. Used by dual PoW system
|
||||
/// to scale one PoW against the other.
|
||||
pub fn from_proof_scaled(proof: &Proof, scaling: u64) -> Difficulty {
|
||||
let max_target = <u64>::max_value();
|
||||
let target = proof.hash().to_u64();
|
||||
|
||||
// Scaling between 2 proof of work algos
|
||||
Difficulty::from_num((max_target / scaling) / target)
|
||||
Difficulty::from_num(Difficulty::raw_difficulty(proof) * scaling)
|
||||
}
|
||||
|
||||
fn raw_difficulty(proof: &Proof) -> u64 {
|
||||
<u64>::max_value() / proof.hash().to_u64()
|
||||
}
|
||||
|
||||
/// Converts the difficulty into a u64
|
||||
|
|
Loading…
Reference in a new issue