Skip to content

Commit

Permalink
add tx pool kernel counts to tui status page (#3111)
Browse files Browse the repository at this point in the history
* add tx pool kernel counts to tui status page

* fix formatting on tui
  • Loading branch information
antiochp authored Nov 14, 2019
1 parent a1061f0 commit 8d2c43d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
6 changes: 6 additions & 0 deletions pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ impl Pool {
self.entries.len()
}

/// Number of transaction kernels in the pool.
/// This may differ from the size (number of transactions) due to tx aggregation.
pub fn kernel_count(&self) -> usize {
self.entries.iter().map(|x| x.tx.kernels().len()).sum()
}

/// Is the pool empty?
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
Expand Down
4 changes: 4 additions & 0 deletions servers/src/common/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ pub struct ChainStats {
pub struct TxStats {
/// Number of transactions in the transaction pool
pub tx_pool_size: usize,
/// Number of transaction kernels in the transaction pool
pub tx_pool_kernels: usize,
/// Number of transactions in the stem pool
pub stem_pool_size: usize,
/// Number of transaction kernels in the stem pool
pub stem_pool_kernels: usize,
}
/// Struct to return relevant information about stratum workers
#[derive(Clone, Serialize, Debug)]
Expand Down
25 changes: 15 additions & 10 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,24 @@ impl Server {
.map(|p| PeerStats::from_peer(&p))
.collect();

let (tx_pool_size, stem_pool_size) = {
let tx_pool_lock = self.tx_pool.try_read();
match tx_pool_lock {
Some(l) => (l.txpool.entries.len(), l.stempool.entries.len()),
None => (0, 0),
let tx_stats = {
let pool = self.tx_pool.try_read();
match pool {
Some(pool) => TxStats {
tx_pool_size: pool.txpool.size(),
tx_pool_kernels: pool.txpool.kernel_count(),
stem_pool_size: pool.stempool.size(),
stem_pool_kernels: pool.stempool.kernel_count(),
},
None => TxStats {
tx_pool_size: 0,
tx_pool_kernels: 0,
stem_pool_size: 0,
stem_pool_kernels: 0,
},
}
};

let tx_stats = TxStats {
tx_pool_size,
stem_pool_size,
};

let head = self.chain.head_header()?;
let head_stats = ChainStats {
latest_timestamp: head.timestamp,
Expand Down
16 changes: 14 additions & 2 deletions src/bin/tui/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ impl TUIStatusListener for TUIStatusView {
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Transaction Pool Size: "))
.child(TextView::new(" ").with_id("tx_pool_size")),
.child(TextView::new("0").with_id("tx_pool_size"))
.child(TextView::new(" ("))
.child(TextView::new("0").with_id("tx_pool_kernels"))
.child(TextView::new(")")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Stem Pool Size: "))
.child(TextView::new(" ").with_id("stem_pool_size")),
.child(TextView::new("0").with_id("stem_pool_size"))
.child(TextView::new(" ("))
.child(TextView::new("0").with_id("stem_pool_kernels"))
.child(TextView::new(")")),
)
.child(
LinearLayout::new(Orientation::Horizontal).child(TextView::new(
Expand Down Expand Up @@ -307,6 +313,12 @@ impl TUIStatusListener for TUIStatusView {
c.call_on_id("stem_pool_size", |t: &mut TextView| {
t.set_content(stats.tx_stats.stem_pool_size.to_string());
});
c.call_on_id("tx_pool_kernels", |t: &mut TextView| {
t.set_content(stats.tx_stats.tx_pool_kernels.to_string());
});
c.call_on_id("stem_pool_kernels", |t: &mut TextView| {
t.set_content(stats.tx_stats.stem_pool_kernels.to_string());
});
/*c.call_on_id("basic_mining_config_status", |t: &mut TextView| {
t.set_content(basic_mining_config_status);
});
Expand Down

0 comments on commit 8d2c43d

Please sign in to comment.