mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-08 12:21:09 +03:00
tests for difficulty adjustment scenarios (#887)
* tests for difficulty adjustment scenarios * ignore test
This commit is contained in:
parent
10addfcd79
commit
6a6e600e48
2 changed files with 66 additions and 0 deletions
|
@ -433,3 +433,33 @@ fn prepare_block_nosum(
|
||||||
b.header.pow = core::core::Proof::random(proof_size);
|
b.header.pow = core::core::Proof::random(proof_size);
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn actual_diff_iter_output() {
|
||||||
|
global::set_mining_mode(ChainTypes::AutomatedTesting);
|
||||||
|
let genesis_block = pow::mine_genesis_block(None).unwrap();
|
||||||
|
let chain = chain::Chain::init(
|
||||||
|
"../.grin".to_string(),
|
||||||
|
Arc::new(NoopAdapter {}),
|
||||||
|
genesis_block,
|
||||||
|
pow::verify_size,
|
||||||
|
).unwrap();
|
||||||
|
let iter = chain.difficulty_iter();
|
||||||
|
let mut last_time = 0;
|
||||||
|
let mut first = true;
|
||||||
|
for i in iter.into_iter() {
|
||||||
|
let elem = i.unwrap();
|
||||||
|
if first {
|
||||||
|
last_time = elem.0;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
println!(
|
||||||
|
"next_difficulty time: {}, diff: {}, duration: {} ",
|
||||||
|
elem.0,
|
||||||
|
elem.1.into_num(),
|
||||||
|
last_time - elem.0
|
||||||
|
);
|
||||||
|
last_time = elem.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,18 @@ fn add_block(
|
||||||
return_chain
|
return_chain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds many defined blocks
|
||||||
|
fn add_blocks(
|
||||||
|
intervals: Vec<u64>,
|
||||||
|
chain_sim: Vec<Result<(u64, Difficulty), TargetError>>,
|
||||||
|
) -> Vec<Result<(u64, Difficulty), TargetError>> {
|
||||||
|
let mut return_chain = chain_sim.clone();
|
||||||
|
for i in intervals {
|
||||||
|
return_chain = add_block(i, return_chain.clone());
|
||||||
|
}
|
||||||
|
return_chain
|
||||||
|
}
|
||||||
|
|
||||||
// Adds another n 'blocks' to the iterator, with difficulty calculated
|
// Adds another n 'blocks' to the iterator, with difficulty calculated
|
||||||
fn add_block_repeated(
|
fn add_block_repeated(
|
||||||
interval: u64,
|
interval: u64,
|
||||||
|
@ -83,8 +95,13 @@ fn print_chain_sim(chain_sim: &Vec<Result<(u64, Difficulty), TargetError>>) {
|
||||||
let mut chain_sim = chain_sim.clone();
|
let mut chain_sim = chain_sim.clone();
|
||||||
chain_sim.reverse();
|
chain_sim.reverse();
|
||||||
let mut last_time = 0;
|
let mut last_time = 0;
|
||||||
|
let mut first = true;
|
||||||
chain_sim.iter().enumerate().for_each(|(i, b)| {
|
chain_sim.iter().enumerate().for_each(|(i, b)| {
|
||||||
let block = b.as_ref().unwrap();
|
let block = b.as_ref().unwrap();
|
||||||
|
if first {
|
||||||
|
last_time = block.0;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
"Height: {}, Time: {}, Interval: {}, Next network difficulty:{}",
|
"Height: {}, Time: {}, Interval: {}, Next network difficulty:{}",
|
||||||
i,
|
i,
|
||||||
|
@ -179,6 +196,25 @@ fn adjustment_scenarios() {
|
||||||
println!("*********************************************************");
|
println!("*********************************************************");
|
||||||
print_chain_sim(&chain_sim);
|
print_chain_sim(&chain_sim);
|
||||||
println!("*********************************************************");
|
println!("*********************************************************");
|
||||||
|
|
||||||
|
// Actual testnet 2 timings
|
||||||
|
let testnet2_intervals = [
|
||||||
|
2880, 16701, 1882, 3466, 614, 605, 1551, 538, 931, 23, 690, 1397, 2112, 2058, 605, 721,
|
||||||
|
2148, 1605, 134, 1234, 1569, 482, 1775, 2732, 540, 958, 883, 3475, 518, 1346, 1926, 780,
|
||||||
|
865, 269, 141, 105, 781, 289, 256, 709, 68, 165, 1813, 3899, 1458, 955, 2336, 239, 674,
|
||||||
|
1059, 157, 214, 15, 157, 558, 1945, 1677,
|
||||||
|
];
|
||||||
|
|
||||||
|
global::set_mining_mode(global::ChainTypes::Testnet2);
|
||||||
|
let chain_sim = create_chain_sim(global::initial_block_difficulty());
|
||||||
|
let chain_sim = add_blocks(testnet2_intervals.to_vec(), chain_sim);
|
||||||
|
|
||||||
|
println!("");
|
||||||
|
println!("*********************************************************");
|
||||||
|
println!("Scenario 6) Testnet2");
|
||||||
|
println!("*********************************************************");
|
||||||
|
print_chain_sim(&chain_sim);
|
||||||
|
println!("*********************************************************");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks different next_target adjustments and difficulty boundaries
|
/// Checks different next_target adjustments and difficulty boundaries
|
||||||
|
|
Loading…
Reference in a new issue