Skip to content

Commit

Permalink
fix: mempool stats reflects unconfirmed pool (#3398)
Browse files Browse the repository at this point in the history
Description
---
Mempool stats total grams from uncofirmed pool only.

How Has This Been Tested?
---
Manually.
  • Loading branch information
Cifko authored Sep 30, 2021
1 parent b59e3cc commit 596ea4a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 23 deletions.
7 changes: 1 addition & 6 deletions base_layer/core/src/mempool/mempool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,13 @@ impl MempoolStorage {
Ok(self.unconfirmed_pool.len())
}

// Returns the total weight of all transactions stored in the Mempool.
fn calculate_weight(&self) -> Result<u64, MempoolError> {
Ok(self.unconfirmed_pool.calculate_weight() + self.reorg_pool.calculate_weight()?)
}

/// Gathers and returns the stats of the Mempool.
pub fn stats(&self) -> Result<StatsResponse, MempoolError> {
Ok(StatsResponse {
total_txs: self.len()?,
unconfirmed_txs: self.unconfirmed_pool.len(),
reorg_txs: self.reorg_pool.len()?,
total_weight: self.calculate_weight()?,
total_weight: self.unconfirmed_pool.calculate_weight(),
})
}

Expand Down
9 changes: 0 additions & 9 deletions base_layer/core/src/mempool/reorg_pool/reorg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ impl ReorgPool {
.map_err(|e| ReorgPoolError::BackendError(e.to_string()))?
.snapshot())
}

/// Returns the total weight of all transactions stored in the pool.
pub fn calculate_weight(&self) -> Result<u64, ReorgPoolError> {
Ok(self
.pool_storage
.write()
.map_err(|e| ReorgPoolError::BackendError(e.to_string()))?
.calculate_weight())
}
}

impl Clone for ReorgPool {
Expand Down
7 changes: 0 additions & 7 deletions base_layer/core/src/mempool/reorg_pool/reorg_pool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,4 @@ impl ReorgPoolStorage {
pub fn snapshot(&mut self) -> Vec<Arc<Transaction>> {
self.txs_by_signature.iter().map(|(_, tx)| tx).cloned().collect()
}

/// Returns the total weight of all transactions stored in the pool.
pub fn calculate_weight(&mut self) -> u64 {
self.txs_by_signature
.iter()
.fold(0, |weight, (_, tx)| weight + tx.calculate_weight())
}
}
2 changes: 1 addition & 1 deletion base_layer/core/tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async fn test_insert_and_process_published_block() {
assert_eq!(stats.total_txs, 0);
assert_eq!(stats.unconfirmed_txs, 0);
assert_eq!(stats.reorg_txs, 1);
assert_eq!(stats.total_weight, 30);
assert_eq!(stats.total_weight, 0);
}

#[tokio::test]
Expand Down

0 comments on commit 596ea4a

Please sign in to comment.