Skip to content

Commit

Permalink
chore!: ups the min difficulty (#5999)
Browse files Browse the repository at this point in the history
Description
---
Ups the minimum difficulty for stagenet. 

Motivation and Context
---
See #5620 
The numbers chosen represent 2 Apple M1 cpus mining at 100%. 

How Has This Been Tested?
---
Manual
  • Loading branch information
SWvheerden authored Dec 1, 2023
1 parent d7ab283 commit fc1e555
Showing 1 changed file with 12 additions and 40 deletions.
52 changes: 12 additions & 40 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl ConsensusConstants {
coinbase_output_features_extra_max_length: 64,
}];
#[cfg(any(test, debug_assertions))]
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40], CheckDifficultyRatio::No);
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40]);
consensus_constants
}

Expand Down Expand Up @@ -452,13 +452,7 @@ impl ConsensusConstants {
coinbase_output_features_extra_max_length: 64,
}];
#[cfg(any(test, debug_assertions))]
assert_hybrid_pow_constants(
&consensus_constants,
&[target_time],
&[randomx_split],
&[sha3x_split],
CheckDifficultyRatio::No,
);
assert_hybrid_pow_constants(&consensus_constants, &[target_time], &[randomx_split], &[sha3x_split]);
consensus_constants
}

Expand Down Expand Up @@ -512,7 +506,7 @@ impl ConsensusConstants {
coinbase_output_features_extra_max_length: 64,
}];
#[cfg(any(test, debug_assertions))]
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40], CheckDifficultyRatio::Yes);
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40]);
consensus_constants
}

Expand All @@ -525,12 +519,12 @@ impl ConsensusConstants {
pub fn stagenet() -> Vec<Self> {
let mut algos = HashMap::new();
algos.insert(PowAlgorithm::Sha3x, PowAlgorithmConstants {
min_difficulty: Difficulty::from_u64(60_000_000).expect("valid difficulty"),
min_difficulty: Difficulty::from_u64(1_200_000_000).expect("valid difficulty"),
max_difficulty: Difficulty::max(),
target_time: 300,
});
algos.insert(PowAlgorithm::RandomX, PowAlgorithmConstants {
min_difficulty: Difficulty::from_u64(60_000).expect("valid difficulty"),
min_difficulty: Difficulty::from_u64(1_200_000).expect("valid difficulty"),
max_difficulty: Difficulty::max(),
target_time: 200,
});
Expand Down Expand Up @@ -567,19 +561,19 @@ impl ConsensusConstants {
coinbase_output_features_extra_max_length: 64,
}];
#[cfg(any(test, debug_assertions))]
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40], CheckDifficultyRatio::Yes);
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40]);
consensus_constants
}

pub fn nextnet() -> Vec<Self> {
let mut algos = HashMap::new();
algos.insert(PowAlgorithm::Sha3x, PowAlgorithmConstants {
min_difficulty: Difficulty::from_u64(60_000_000).expect("valid difficulty"),
min_difficulty: Difficulty::from_u64(1_200_000_000).expect("valid difficulty"),
max_difficulty: Difficulty::max(),
target_time: 300,
});
algos.insert(PowAlgorithm::RandomX, PowAlgorithmConstants {
min_difficulty: Difficulty::from_u64(60_000).expect("valid difficulty"),
min_difficulty: Difficulty::from_u64(1_200_000).expect("valid difficulty"),
max_difficulty: Difficulty::max(),
target_time: 200,
});
Expand Down Expand Up @@ -616,7 +610,7 @@ impl ConsensusConstants {
coinbase_output_features_extra_max_length: 64,
}];
#[cfg(any(test, debug_assertions))]
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40], CheckDifficultyRatio::Yes);
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40]);
consensus_constants
}

Expand All @@ -625,12 +619,12 @@ impl ConsensusConstants {
let difficulty_block_window = 90;
let mut algos = HashMap::new();
algos.insert(PowAlgorithm::Sha3x, PowAlgorithmConstants {
min_difficulty: Difficulty::from_u64(60_000_000).expect("valid difficulty"),
min_difficulty: Difficulty::from_u64(1_200_000_000).expect("valid difficulty"),
max_difficulty: Difficulty::max(),
target_time: 300,
});
algos.insert(PowAlgorithm::RandomX, PowAlgorithmConstants {
min_difficulty: Difficulty::from_u64(60_000).expect("valid difficulty"),
min_difficulty: Difficulty::from_u64(1_200_000).expect("valid difficulty"),
max_difficulty: Difficulty::max(),
target_time: 200,
});
Expand Down Expand Up @@ -666,7 +660,7 @@ impl ConsensusConstants {
coinbase_output_features_extra_max_length: 64,
}];
#[cfg(any(test, debug_assertions))]
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40], CheckDifficultyRatio::Yes);
assert_hybrid_pow_constants(&consensus_constants, &[120], &[60], &[40]);
consensus_constants
}

Expand Down Expand Up @@ -700,28 +694,19 @@ impl ConsensusConstants {
}
}

#[derive(PartialEq)]
#[cfg(any(test, debug_assertions))]
enum CheckDifficultyRatio {
Yes,
No,
}

// Assert the hybrid POW constants.
// Note: The math and constants in this function should not be changed without ample consideration that should include
// discussion with the Tari community, modelling and system level tests.
// For SHA3/Monero to have a 40/60 split:
// > sha3x_target_time = randomx_target_time * (100 - 40) / 40
// > randomx_target_time = sha3x_target_time * (100 - 60) / 60
// > target_time = randomx_target_time * sha3x_target_time / (ramdomx_target_time + sha3x_target_time)
// `CheckDifficultyRatio` is optional for internal testing (Network::LocalNet and Network::Igor).
#[cfg(any(test, debug_assertions))]
fn assert_hybrid_pow_constants(
consensus_constants: &[ConsensusConstants],
target_time: &[u64],
randomx_split: &[u64], // RamdomX
sha3x_split: &[u64],
check_difficulty_ratio: CheckDifficultyRatio,
) {
assert_eq!(consensus_constants.len(), target_time.len());
assert_eq!(consensus_constants.len(), randomx_split.len());
Expand All @@ -747,19 +732,6 @@ fn assert_hybrid_pow_constants(
randomx_constants.min_difficulty <= randomx_constants.max_difficulty,
"RandomX min_difficulty > max_difficulty"
);
// - Starting difficulty (these should enable an average home use miner to mine a block in 2 minutes)
if check_difficulty_ratio == CheckDifficultyRatio::Yes {
assert_eq!(
sha3x_constants.min_difficulty.as_u64(),
sha3x_constants.target_time * 200_000,
"SHA3X min_difficulty is not 200,000x SHA3X target_time"
);
assert_eq!(
randomx_constants.min_difficulty.as_u64(),
randomx_constants.target_time * 300,
"RandomX min_difficulty is not 300x RandomX target_time"
);
}
// - Target time (the ratios here are important to determine the SHA3/Monero split and overall block time)
assert_eq!(randomx_split[i] + sha3x_split[i], 100, "Split must add up to 100");
assert_eq!(
Expand Down

0 comments on commit fc1e555

Please sign in to comment.