Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tx pool kernel counts to tui status page #3111

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -475,19 +475,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