diff --git a/applications/tari_app_grpc/proto/base_node.proto b/applications/tari_app_grpc/proto/base_node.proto index 4e71b47518..fdee0b57ca 100644 --- a/applications/tari_app_grpc/proto/base_node.proto +++ b/applications/tari_app_grpc/proto/base_node.proto @@ -441,10 +441,9 @@ enum TransactionLocation { } message MempoolStatsResponse { - uint64 total_txs = 1; uint64 unconfirmed_txs = 2; uint64 reorg_txs = 3; - uint64 total_weight = 4; + uint64 unconfirmed_weight = 4; } message GetConstitutionsRequest { diff --git a/applications/tari_base_node/src/commands/command/status.rs b/applications/tari_base_node/src/commands/command/status.rs index eaad1e9d36..896e537008 100644 --- a/applications/tari_base_node/src/commands/command/status.rs +++ b/applications/tari_base_node/src/commands/command/status.rs @@ -88,11 +88,11 @@ impl CommandContext { format!( "{}tx ({}g, +/- {}blks)", mempool_stats.unconfirmed_txs, - mempool_stats.total_weight, - if mempool_stats.total_weight == 0 { + mempool_stats.unconfirmed_weight, + if mempool_stats.unconfirmed_weight == 0 { 0 } else { - 1 + mempool_stats.total_weight / constants.get_max_block_transaction_weight() + 1 + mempool_stats.unconfirmed_weight / constants.get_max_block_transaction_weight() }, ), ); diff --git a/applications/tari_base_node/src/grpc/base_node_grpc_server.rs b/applications/tari_base_node/src/grpc/base_node_grpc_server.rs index 3859312589..1e9e8dd604 100644 --- a/applications/tari_base_node/src/grpc/base_node_grpc_server.rs +++ b/applications/tari_base_node/src/grpc/base_node_grpc_server.rs @@ -1865,10 +1865,9 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer { })?; let response = tari_rpc::MempoolStatsResponse { - total_txs: mempool_stats.total_txs as u64, unconfirmed_txs: mempool_stats.unconfirmed_txs as u64, reorg_txs: mempool_stats.reorg_txs as u64, - total_weight: mempool_stats.total_weight, + unconfirmed_weight: mempool_stats.unconfirmed_weight, }; Ok(Response::new(response)) diff --git a/base_layer/core/src/mempool/mempool_storage.rs b/base_layer/core/src/mempool/mempool_storage.rs index 4f765edf79..5af7c1e139 100644 --- a/base_layer/core/src/mempool/mempool_storage.rs +++ b/base_layer/core/src/mempool/mempool_storage.rs @@ -285,19 +285,13 @@ impl MempoolStorage { .ok_or(MempoolError::TransactionNoKernels) } - // Returns the total number of transactions in the Mempool. - fn len(&self) -> usize { - self.unconfirmed_pool.len() + self.reorg_pool.len() - } - /// Gathers and returns the stats of the Mempool. pub fn stats(&self) -> StatsResponse { let weighting = self.get_transaction_weighting(0); StatsResponse { - total_txs: self.len() as u64, unconfirmed_txs: self.unconfirmed_pool.len() as u64, reorg_txs: self.reorg_pool.len() as u64, - total_weight: self.unconfirmed_pool.calculate_weight(&weighting), + unconfirmed_weight: self.unconfirmed_pool.calculate_weight(&weighting), } } diff --git a/base_layer/core/src/mempool/mod.rs b/base_layer/core/src/mempool/mod.rs index 188e6f2e12..9a9db98db6 100644 --- a/base_layer/core/src/mempool/mod.rs +++ b/base_layer/core/src/mempool/mod.rs @@ -81,18 +81,17 @@ use crate::{ #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct StatsResponse { - pub total_txs: u64, pub unconfirmed_txs: u64, pub reorg_txs: u64, - pub total_weight: u64, + pub unconfirmed_weight: u64, } impl Display for StatsResponse { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { write!( fmt, - "Mempool stats: Total transactions: {}, Unconfirmed: {}, Published: {}, Total Weight: {}g", - self.total_txs, self.unconfirmed_txs, self.reorg_txs, self.total_weight + "Mempool stats: Unconfirmed: {}, In Reorg Pool: {}, Total Weight: {}g", + self.unconfirmed_txs, self.reorg_txs, self.unconfirmed_weight ) } } diff --git a/base_layer/core/src/mempool/proto/stats_response.proto b/base_layer/core/src/mempool/proto/stats_response.proto index fe0fdcfd90..9839c34cb9 100644 --- a/base_layer/core/src/mempool/proto/stats_response.proto +++ b/base_layer/core/src/mempool/proto/stats_response.proto @@ -6,8 +6,7 @@ syntax = "proto3"; package tari.mempool; message StatsResponse { - uint64 total_txs = 1; uint64 unconfirmed_txs = 2; uint64 reorg_txs = 5; - uint64 total_weight = 6; + uint64 unconfirmed_weight = 6; } diff --git a/base_layer/core/src/mempool/proto/stats_response.rs b/base_layer/core/src/mempool/proto/stats_response.rs index 2dea6e7e92..92e3a0703b 100644 --- a/base_layer/core/src/mempool/proto/stats_response.rs +++ b/base_layer/core/src/mempool/proto/stats_response.rs @@ -29,10 +29,9 @@ impl TryFrom for StatsResponse { fn try_from(stats: ProtoStatsResponse) -> Result { Ok(Self { - total_txs: stats.total_txs, unconfirmed_txs: stats.unconfirmed_txs, reorg_txs: stats.reorg_txs, - total_weight: stats.total_weight, + unconfirmed_weight: stats.unconfirmed_weight, }) } } @@ -40,10 +39,9 @@ impl TryFrom for StatsResponse { impl From for ProtoStatsResponse { fn from(stats: StatsResponse) -> Self { Self { - total_txs: stats.total_txs, unconfirmed_txs: stats.unconfirmed_txs, reorg_txs: stats.reorg_txs, - total_weight: stats.total_weight, + unconfirmed_weight: stats.unconfirmed_weight, } } } diff --git a/base_layer/core/src/mempool/rpc/test.rs b/base_layer/core/src/mempool/rpc/test.rs index 1dc43e7c8e..4dddd3643d 100644 --- a/base_layer/core/src/mempool/rpc/test.rs +++ b/base_layer/core/src/mempool/rpc/test.rs @@ -52,7 +52,7 @@ mod get_stats { unconfirmed_txs: 2, reorg_txs: 5, - total_weight: 6, + unconfirmed_weight: 6, }; mempool.set_get_stats_response(expected_stats.clone()).await; diff --git a/base_layer/core/src/mempool/service/local_service.rs b/base_layer/core/src/mempool/service/local_service.rs index cb236146df..552a7749ff 100644 --- a/base_layer/core/src/mempool/service/local_service.rs +++ b/base_layer/core/src/mempool/service/local_service.rs @@ -121,7 +121,7 @@ mod test { total_txs: 10, unconfirmed_txs: 3, reorg_txs: 4, - total_weight: 1000, + unconfirmed_weight: 1000, } } diff --git a/base_layer/core/src/mempool/test_utils/mock.rs b/base_layer/core/src/mempool/test_utils/mock.rs index f01d6a022b..f77a0dc124 100644 --- a/base_layer/core/src/mempool/test_utils/mock.rs +++ b/base_layer/core/src/mempool/test_utils/mock.rs @@ -61,7 +61,7 @@ impl Default for MempoolMockState { total_txs: 0, unconfirmed_txs: 0, reorg_txs: 0, - total_weight: 0, + unconfirmed_weight: 0, })), get_state: Arc::new(Mutex::new(StateResponse { unconfirmed_pool: vec![], diff --git a/base_layer/core/tests/mempool.rs b/base_layer/core/tests/mempool.rs index 2c3b5d8017..edee2a27ac 100644 --- a/base_layer/core/tests/mempool.rs +++ b/base_layer/core/tests/mempool.rs @@ -187,7 +187,7 @@ async fn test_insert_and_process_published_block() { 2, TestParams::new().get_size_for_default_metadata(2), ); - assert_eq!(stats.total_weight, expected_weight); + assert_eq!(stats.unconfirmed_weight, expected_weight); // Spend tx2, so it goes in Reorg pool generate_block(&store, &mut blocks, vec![tx2.deref().clone()], &consensus_manager).unwrap(); @@ -236,7 +236,7 @@ async fn test_insert_and_process_published_block() { assert_eq!(stats.total_txs, 1); assert_eq!(stats.unconfirmed_txs, 0); assert_eq!(stats.reorg_txs, 1); - assert_eq!(stats.total_weight, 0); + assert_eq!(stats.unconfirmed_weight, 0); } #[tokio::test] @@ -607,7 +607,7 @@ async fn test_zero_conf() { // Try to retrieve all transactions in the mempool (a couple of our transactions should be missing from retrieved) let retrieved_txs = mempool - .retrieve(mempool.stats().await.unwrap().total_weight) + .retrieve(mempool.stats().await.unwrap().unconfirmed_weight) .await .unwrap(); assert_eq!(retrieved_txs.len(), 10); @@ -659,7 +659,7 @@ async fn test_zero_conf() { // Try to retrieve all transactions in the mempool (all transactions should be retrieved) let retrieved_txs = mempool - .retrieve(mempool.stats().await.unwrap().total_weight) + .retrieve(mempool.stats().await.unwrap().unconfirmed_weight) .await .unwrap(); assert_eq!(retrieved_txs.len(), 16); @@ -682,7 +682,7 @@ async fn test_zero_conf() { // Verify that a higher priority transaction is not retrieved due to its zero-conf dependency instead of the lowest // priority transaction - let weight = mempool.stats().await.unwrap().total_weight - 1; + let weight = mempool.stats().await.unwrap().unconfirmed_weight - 1; let retrieved_txs = mempool.retrieve(weight).await.unwrap(); assert_eq!(retrieved_txs.len(), 15); assert!(retrieved_txs.contains(&Arc::new(tx01)));