[T4] Add sec pow info to TUI, change magic number, genesis diff to 1 (temporarily) (#1768)

* add sec scaling stats to tui

* rustfmt
This commit is contained in:
Yeastplume 2018-10-17 10:37:28 +01:00 committed by GitHub
parent fbf955dd11
commit 404165a8fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 45 deletions

View file

@ -18,9 +18,8 @@
use consensus::HeaderInfo;
use consensus::{
BASE_EDGE_BITS, BLOCK_TIME_SEC, COINBASE_MATURITY, CUT_THROUGH_HORIZON,
DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, PROOFSIZE, DAY_HEIGHT,
SECOND_POW_EDGE_BITS,
BASE_EDGE_BITS, BLOCK_TIME_SEC, COINBASE_MATURITY, CUT_THROUGH_HORIZON, DAY_HEIGHT,
DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, PROOFSIZE, SECOND_POW_EDGE_BITS,
};
use pow::{self, CuckatooContext, EdgeType, PoWContext};
/// An enum collecting sets of parameters used throughout the
@ -65,7 +64,9 @@ pub const TESTNET3_INITIAL_DIFFICULTY: u64 = 30000;
/// Testnet 4 initial block difficulty
/// 1_000 times natural scale factor for cuckatoo29
pub const TESTNET4_INITIAL_DIFFICULTY: u64 = 1_000 * (2<<(29-24)) * 29;
// TODO: Enable this on real testnet
// pub const TESTNET4_INITIAL_DIFFICULTY: u64 = 1_000 * (2<<(29-24)) * 29;
pub const TESTNET4_INITIAL_DIFFICULTY: u64 = 1;
/// Trigger compaction check on average every day for FAST_SYNC_NODE,
/// roll the dice on every block to decide,

View file

@ -35,7 +35,7 @@ pub const PROTOCOL_VERSION: u32 = 1;
pub const USER_AGENT: &'static str = concat!("MW/Grin ", env!("CARGO_PKG_VERSION"));
/// Magic number expected in the header of every message
const MAGIC: [u8; 2] = [0x47, 0x31];
const MAGIC: [u8; 2] = [0x47, 0x32];
/// Size in bytes of a message header
pub const HEADER_LEN: u64 = 11;

View file

@ -131,6 +131,10 @@ pub struct DiffBlock {
pub time: u64,
/// Duration since previous block (epoch seconds)
pub duration: u64,
/// secondary scaling
pub secondary_scaling: u32,
/// is secondary
pub is_secondary: bool,
}
/// Struct to return relevant information about peers
@ -155,7 +159,8 @@ pub struct PeerStats {
impl StratumStats {
/// Calculate network hashrate
pub fn network_hashrate(&self) -> f64 {
42.0 * (self.network_difficulty as f64 / Difficulty::scale(self.edge_bits as u8) as f64) / 60.0
42.0 * (self.network_difficulty as f64 / Difficulty::scale(self.edge_bits as u8) as f64)
/ 60.0
}
}

View file

@ -422,6 +422,8 @@ impl Server {
difficulty: n.difficulty.to_num(),
time: n.timestamp,
duration: dur,
secondary_scaling: n.secondary_scaling,
is_secondary: n.is_secondary,
}
}).collect();

View file

@ -100,7 +100,9 @@ impl TableViewItem<StratumWorkerColumn> for WorkerStats {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
enum DiffColumn {
BlockNumber,
PoWType,
Difficulty,
SecondaryScaling,
Time,
Duration,
}
@ -109,7 +111,9 @@ impl DiffColumn {
fn _as_str(&self) -> &str {
match *self {
DiffColumn::BlockNumber => "Block Number",
DiffColumn::PoWType => "Type",
DiffColumn::Difficulty => "Network Difficulty",
DiffColumn::SecondaryScaling => "Sec. Scaling",
DiffColumn::Time => "Block Time",
DiffColumn::Duration => "Duration",
}
@ -120,10 +124,16 @@ impl TableViewItem<DiffColumn> for DiffBlock {
fn to_column(&self, column: DiffColumn) -> String {
let naive_datetime = NaiveDateTime::from_timestamp(self.time as i64, 0);
let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
let pow_type = match self.is_secondary {
true => String::from("Secondary"),
false => String::from("Primary"),
};
match column {
DiffColumn::BlockNumber => self.block_number.to_string(),
DiffColumn::PoWType => pow_type,
DiffColumn::Difficulty => self.difficulty.to_string(),
DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(),
DiffColumn::Time => format!("{}", datetime).to_string(),
DiffColumn::Duration => format!("{}s", self.duration).to_string(),
}
@ -135,7 +145,9 @@ impl TableViewItem<DiffColumn> for DiffBlock {
{
match column {
DiffColumn::BlockNumber => Ordering::Equal,
DiffColumn::PoWType => Ordering::Equal,
DiffColumn::Difficulty => Ordering::Equal,
DiffColumn::SecondaryScaling => Ordering::Equal,
DiffColumn::Time => Ordering::Equal,
DiffColumn::Duration => Ordering::Equal,
}
@ -170,23 +182,17 @@ impl TUIStatusListener for TUIMiningView {
let table_view = TableView::<WorkerStats, StratumWorkerColumn>::new()
.column(StratumWorkerColumn::Id, "Worker ID", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::IsConnected, "Connected", |c| {
}).column(StratumWorkerColumn::IsConnected, "Connected", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::LastSeen, "Last Seen", |c| {
}).column(StratumWorkerColumn::LastSeen, "Last Seen", |c| {
c.width_percent(20)
})
.column(StratumWorkerColumn::PowDifficulty, "Pow Difficulty", |c| {
}).column(StratumWorkerColumn::PowDifficulty, "Pow Difficulty", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::NumAccepted, "Num Accepted", |c| {
}).column(StratumWorkerColumn::NumAccepted, "Num Accepted", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::NumRejected, "Num Rejected", |c| {
}).column(StratumWorkerColumn::NumRejected, "Num Rejected", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::NumStale, "Num Stale", |c| {
}).column(StratumWorkerColumn::NumStale, "Num Stale", |c| {
c.width_percent(10)
});
@ -194,28 +200,22 @@ impl TUIStatusListener for TUIMiningView {
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_config_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_is_running_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_num_workers_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_block_height_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_network_difficulty_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_network_hashrate")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_edge_bits_status")),
);
@ -225,26 +225,22 @@ impl TUIStatusListener for TUIMiningView {
.child(BoxView::with_full_screen(
Dialog::around(table_view.with_id(TABLE_MINING_STATUS).min_size((50, 20)))
.title("Mining Workers"),
))
.with_id("mining_device_view");
)).with_id("mining_device_view");
let diff_status_view = LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Tip Height: "))
.child(TextView::new("").with_id("diff_cur_height")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Difficulty Adjustment Window: "))
.child(TextView::new("").with_id("diff_adjust_window")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Average Block Time: "))
.child(TextView::new("").with_id("diff_avg_block_time")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Average Difficulty: "))
.child(TextView::new("").with_id("diff_avg_difficulty")),
@ -252,12 +248,13 @@ impl TUIStatusListener for TUIMiningView {
let diff_table_view = TableView::<DiffBlock, DiffColumn>::new()
.column(DiffColumn::BlockNumber, "Block Number", |c| {
c.width_percent(25)
})
c.width_percent(15)
}).column(DiffColumn::PoWType, "Type", |c| c.width_percent(10))
.column(DiffColumn::Difficulty, "Network Difficulty", |c| {
c.width_percent(25)
})
.column(DiffColumn::Time, "Block Time", |c| c.width_percent(25))
c.width_percent(15)
}).column(DiffColumn::SecondaryScaling, "Sec. Scaling", |c| {
c.width_percent(10)
}).column(DiffColumn::Time, "Block Time", |c| c.width_percent(25))
.column(DiffColumn::Duration, "Duration", |c| c.width_percent(25));
let mining_difficulty_view = LinearLayout::new(Orientation::Vertical)
@ -268,8 +265,7 @@ impl TUIStatusListener for TUIMiningView {
.with_id(TABLE_MINING_DIFF_STATUS)
.min_size((50, 20)),
).title("Mining Difficulty Data"),
))
.with_id("mining_difficulty_view");
)).with_id("mining_difficulty_view");
let view_stack = StackView::new()
.layer(mining_difficulty_view)