Fix chain tests missing difficulty scaling

This commit is contained in:
Ignotus Peverell 2018-10-15 22:24:13 +00:00
parent eeb7680981
commit 3c6b5a0a9c
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
4 changed files with 11 additions and 15 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -312,13 +312,6 @@ pub fn secondary_pow_scaling(height: u64, diff_data: &Vec<HeaderInfo>) -> 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;