From 3c6b5a0a9cc5c22d0cfd347ef841ff8b03bf046e Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Mon, 15 Oct 2018 22:24:13 +0000 Subject: [PATCH] Fix chain tests missing difficulty scaling --- chain/tests/data_file_integrity.rs | 1 + chain/tests/mine_simple_chain.rs | 2 ++ chain/tests/test_coinbase_maturity.rs | 16 ++++++++-------- core/src/consensus.rs | 7 ------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/chain/tests/data_file_integrity.rs b/chain/tests/data_file_integrity.rs index 14bd6af59..16506bfcc 100644 --- a/chain/tests/data_file_integrity.rs +++ b/chain/tests/data_file_integrity.rs @@ -89,6 +89,7 @@ fn data_files() { core::core::Block::new(&prev, vec![], next_header_info.clone().difficulty, reward) .unwrap(); b.header.timestamp = prev.timestamp + Duration::seconds(60); + b.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut b, false).unwrap(); diff --git a/chain/tests/mine_simple_chain.rs b/chain/tests/mine_simple_chain.rs index 267a4b895..121532c1d 100644 --- a/chain/tests/mine_simple_chain.rs +++ b/chain/tests/mine_simple_chain.rs @@ -71,6 +71,7 @@ fn mine_empty_chain() { core::core::Block::new(&prev, vec![], next_header_info.clone().difficulty, reward) .unwrap(); b.header.timestamp = prev.timestamp + Duration::seconds(60); + b.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut b, false).unwrap(); @@ -394,6 +395,7 @@ fn output_header_mappings() { core::core::Block::new(&prev, vec![], next_header_info.clone().difficulty, reward) .unwrap(); b.header.timestamp = prev.timestamp + Duration::seconds(60); + b.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut b, false).unwrap(); diff --git a/chain/tests/test_coinbase_maturity.rs b/chain/tests/test_coinbase_maturity.rs index 13ef499ab..7a268d0cc 100644 --- a/chain/tests/test_coinbase_maturity.rs +++ b/chain/tests/test_coinbase_maturity.rs @@ -68,11 +68,11 @@ fn test_coinbase_maturity() { let key_id3 = ExtKeychainPath::new(1, 3, 0, 0, 0).to_identifier(); let key_id4 = ExtKeychainPath::new(1, 4, 0, 0, 0).to_identifier(); + let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter()); let reward = libtx::reward::output(&keychain, &key_id1, 0, prev.height).unwrap(); let mut block = core::core::Block::new(&prev, vec![], Difficulty::one(), reward).unwrap(); block.header.timestamp = prev.timestamp + Duration::seconds(60); - - let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter()); + block.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut block, false).unwrap(); @@ -117,9 +117,9 @@ fn test_coinbase_maturity() { let fees = txs.iter().map(|tx| tx.fee()).sum(); let reward = libtx::reward::output(&keychain, &key_id3, fees, prev.height).unwrap(); let mut block = core::core::Block::new(&prev, txs, Difficulty::one(), reward).unwrap(); - block.header.timestamp = prev.timestamp + Duration::seconds(60); - let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter()); + block.header.timestamp = prev.timestamp + Duration::seconds(60); + block.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut block, false).unwrap(); @@ -150,9 +150,9 @@ fn test_coinbase_maturity() { let reward = libtx::reward::output(&keychain, &pk, 0, prev.height).unwrap(); let mut block = core::core::Block::new(&prev, vec![], Difficulty::one(), reward).unwrap(); - block.header.timestamp = prev.timestamp + Duration::seconds(60); - let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter()); + block.header.timestamp = prev.timestamp + Duration::seconds(60); + block.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut block, false).unwrap(); @@ -174,12 +174,12 @@ fn test_coinbase_maturity() { let txs = vec![coinbase_txn]; let fees = txs.iter().map(|tx| tx.fee()).sum(); + let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter()); let reward = libtx::reward::output(&keychain, &key_id4, fees, prev.height).unwrap(); let mut block = core::core::Block::new(&prev, txs, Difficulty::one(), reward).unwrap(); block.header.timestamp = prev.timestamp + Duration::seconds(60); - - let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter()); + block.header.pow.scaling_difficulty = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut block, false).unwrap(); diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 44d6712d1..b966b0eaa 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -312,13 +312,6 @@ pub fn secondary_pow_scaling(height: u64, diff_data: &Vec) -> u32 { // what's the ideal ratio at the current height let ratio = secondary_pow_ratio(height); - println!( - "-- {} {} {} {}", - scaling_median, - secondary_count, - diff_data.len(), - ratio - ); // adjust the past median based on ideal ratio vs actual ratio let scaling = scaling_median * diff_data.len() as u64 * ratio / 100 / secondary_count as u64;