Fix shift by 1 block in TUI (#1780) (#1810)

* Fix shift by 1 block in TUI (#1780)
* Only use graph_weight
* Fix shift by 1 in block
* Remove debug logging
This commit is contained in:
Quentin Le Sceller 2018-10-22 19:44:14 +02:00 committed by Ignotus Peverell
parent d11088c987
commit 5f2e8db092
3 changed files with 3 additions and 10 deletions

View file

@ -76,11 +76,6 @@ impl Difficulty {
Difficulty { num: max(num, 1) } Difficulty { num: max(num, 1) }
} }
/// Compute difficulty scaling factor for graph defined by 2 * 2^edge_bits * edge_bits bits
pub fn scale(edge_bits: u8) -> u64 {
(2 << (edge_bits - global::base_edge_bits()) as u64) * (edge_bits as u64)
}
/// Computes the difficulty from a hash. Divides the maximum target by the /// Computes the difficulty from a hash. Divides the maximum target by the
/// provided hash and applies the Cuck(at)oo size adjustment factor (see /// provided hash and applies the Cuck(at)oo size adjustment factor (see
/// https://lists.launchpad.net/mimblewimble/msg00494.html). /// https://lists.launchpad.net/mimblewimble/msg00494.html).

View file

@ -20,7 +20,7 @@ use std::sync::Arc;
use std::time::SystemTime; use std::time::SystemTime;
use util::RwLock; use util::RwLock;
use core::pow::Difficulty; use core::consensus::graph_weight;
use chrono::prelude::*; use chrono::prelude::*;
@ -164,8 +164,7 @@ pub struct PeerStats {
impl StratumStats { impl StratumStats {
/// Calculate network hashrate /// Calculate network hashrate
pub fn network_hashrate(&self) -> f64 { pub fn network_hashrate(&self) -> f64 {
42.0 * (self.network_difficulty as f64 / Difficulty::scale(self.edge_bits as u8) as f64) 42.0 * (self.network_difficulty as f64 / graph_weight(self.edge_bits as u8) as f64) / 60.0
/ 60.0
} }
} }

View file

@ -400,7 +400,6 @@ impl Server {
let mut last_time = last_blocks[0].timestamp; let mut last_time = last_blocks[0].timestamp;
let tip_height = self.chain.head().unwrap().height as i64; let tip_height = self.chain.head().unwrap().height as i64;
let earliest_block_height = tip_height as i64 - last_blocks.len() as i64; let earliest_block_height = tip_height as i64 - last_blocks.len() as i64;
let mut i = 1; let mut i = 1;
let diff_entries: Vec<DiffBlock> = last_blocks let diff_entries: Vec<DiffBlock> = last_blocks
@ -408,7 +407,7 @@ impl Server {
.skip(1) .skip(1)
.map(|n| { .map(|n| {
let dur = n.timestamp - last_time; let dur = n.timestamp - last_time;
let height = earliest_block_height + i + 1; let height = earliest_block_height + i;
i += 1; i += 1;
last_time = n.timestamp; last_time = n.timestamp;
DiffBlock { DiffBlock {