use ccp_shared::types::*;
pub fn generate_epoch_params(nonce: u8, difficulty: u8) -> EpochParameters {
let global_nonce = generate_global_nonce(nonce);
let difficulty = generate_difficulty(difficulty);
EpochParameters::new(global_nonce, difficulty)
}
pub fn generate_global_nonce(first_byte: u8) -> GlobalNonce {
GlobalNonce::new([
first_byte, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 1, 2, 3, 2, 3, 3, 4, 2, 1, 4, 5, 6, 1, 2,
3, 4, 6, 3, 2,
])
}
pub fn generate_local_nonce(first_byte: u8) -> LocalNonce {
LocalNonce::new([
first_byte, 2, 3, 4, 3, 4, 3, 1, 2, 4, 4, 5, 6, 1, 2, 3, 2, 3, 3, 4, 2, 1, 4, 5, 6, 1, 2,
3, 4, 6, 3, 2,
])
}
pub fn generate_cu_id(first_byte: u8) -> CUID {
CUID::new([
first_byte, 2, 3, 4, 5, 6, 7, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
])
}
pub fn generate_difficulty(difficulty: u8) -> Difficulty {
Difficulty::new([
0, difficulty, 3, 4, 3, 4, 3, 1, 2, 4, 4, 5, 6, 1, 2, 3, 2, 3, 3, 4, 2, 1, 4, 5, 6, 1, 2,
3, 4, 6, 3, 2,
])
}
pub fn generate_allocation(cores: &[u8]) -> CUAllocation {
cores
.iter()
.map(|core_id| {
(
PhysicalCoreId::from(*core_id as u32),
generate_cu_id(*core_id),
)
})
.collect()
}
pub fn generate_random_allocation(
rng: &mut impl rand::Rng,
size: usize,
range: std::ops::Range<u8>,
) -> CUAllocation {
use rand::Rng;
let distr = rand::distr::Uniform::try_from(range).expect("Wrong range");
rng.sample_iter(distr)
.take(size)
.map(|core_id| {
(
PhysicalCoreId::from(core_id as u32),
generate_cu_id(core_id),
)
})
.collect()
}