mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
fix: for TUI status try to acquire read lock on pmmr_header but if no… (#3119)
fix: for TUI status try to acquire read lock on pmmr_header but if not available just leave the header stats alone
This commit is contained in:
parent
8d2c43d7e8
commit
29b871841a
4 changed files with 38 additions and 20 deletions
|
@ -1216,6 +1216,18 @@ impl Chain {
|
|||
.map_err(|e| ErrorKind::StoreErr(e, "chain tail".to_owned()).into())
|
||||
}
|
||||
|
||||
/// Tip (head) of the header chain if read lock can be acquired right now.
|
||||
pub fn try_header_head(&self) -> Result<Option<Tip>, Error> {
|
||||
match self.header_pmmr.try_read() {
|
||||
Some(lock) => {
|
||||
let hash = lock.head_hash()?;
|
||||
let header = self.store.get_block_header(&hash)?;
|
||||
Ok(Some(Tip::from_header(&header)))
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Tip (head) of the header chain.
|
||||
pub fn header_head(&self) -> Result<Tip, Error> {
|
||||
let hash = self.header_pmmr.read().head_hash()?;
|
||||
|
|
|
@ -53,7 +53,7 @@ pub struct ServerStats {
|
|||
/// Chain head
|
||||
pub chain_stats: ChainStats,
|
||||
/// sync header head
|
||||
pub header_stats: ChainStats,
|
||||
pub header_stats: Option<ChainStats>,
|
||||
/// Whether we're currently syncing
|
||||
pub sync_status: SyncStatus,
|
||||
/// Handle to current stratum server stats
|
||||
|
|
|
@ -506,13 +506,17 @@ impl Server {
|
|||
total_difficulty: head.total_difficulty(),
|
||||
};
|
||||
|
||||
let header_tip = self.chain.header_head()?;
|
||||
let header = self.chain.get_block_header(&header_tip.hash())?;
|
||||
let header_stats = ChainStats {
|
||||
latest_timestamp: header.timestamp,
|
||||
height: header.height,
|
||||
last_block_h: header.prev_hash,
|
||||
total_difficulty: header.total_difficulty(),
|
||||
let header_stats = match self.chain.try_header_head()? {
|
||||
Some(tip) => {
|
||||
let header = self.chain.get_block_header(&tip.hash())?;
|
||||
Some(ChainStats {
|
||||
latest_timestamp: header.timestamp,
|
||||
height: header.height,
|
||||
last_block_h: header.prev_hash,
|
||||
total_difficulty: header.total_difficulty(),
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let disk_usage_bytes = WalkDir::new(&self.config.db_root)
|
||||
|
|
|
@ -295,18 +295,20 @@ impl TUIStatusListener for TUIStatusView {
|
|||
c.call_on_id("chain_timestamp", |t: &mut TextView| {
|
||||
t.set_content(stats.chain_stats.latest_timestamp.to_string());
|
||||
});
|
||||
c.call_on_id("basic_header_tip_hash", |t: &mut TextView| {
|
||||
t.set_content(stats.header_stats.last_block_h.to_string() + "...");
|
||||
});
|
||||
c.call_on_id("basic_header_chain_height", |t: &mut TextView| {
|
||||
t.set_content(stats.header_stats.height.to_string());
|
||||
});
|
||||
c.call_on_id("basic_header_total_difficulty", |t: &mut TextView| {
|
||||
t.set_content(stats.header_stats.total_difficulty.to_string());
|
||||
});
|
||||
c.call_on_id("basic_header_timestamp", |t: &mut TextView| {
|
||||
t.set_content(stats.header_stats.latest_timestamp.to_string());
|
||||
});
|
||||
if let Some(header_stats) = &stats.header_stats {
|
||||
c.call_on_id("basic_header_tip_hash", |t: &mut TextView| {
|
||||
t.set_content(header_stats.last_block_h.to_string() + "...");
|
||||
});
|
||||
c.call_on_id("basic_header_chain_height", |t: &mut TextView| {
|
||||
t.set_content(header_stats.height.to_string());
|
||||
});
|
||||
c.call_on_id("basic_header_total_difficulty", |t: &mut TextView| {
|
||||
t.set_content(header_stats.total_difficulty.to_string());
|
||||
});
|
||||
c.call_on_id("basic_header_timestamp", |t: &mut TextView| {
|
||||
t.set_content(header_stats.latest_timestamp.to_string());
|
||||
});
|
||||
}
|
||||
c.call_on_id("tx_pool_size", |t: &mut TextView| {
|
||||
t.set_content(stats.tx_stats.tx_pool_size.to_string());
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue