Skip to content

Commit

Permalink
test: expose get_mempool_stats via gRPC and add cucumber test (#3203)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Aug 18, 2021
2 parents d4497fc + af5b246 commit cc9c2ca
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions applications/tari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ service BaseNode {
rpc GetNetworkStatus(Empty) returns (NetworkStatusResponse);
// List currently connected peers
rpc ListConnectedPeers(Empty) returns (ListConnectedPeersResponse);
// Get mempool stats
rpc GetMempoolStats(Empty) returns (MempoolStatsResponse);
}

message SubmitBlockResponse {
Expand Down Expand Up @@ -337,3 +339,10 @@ message SoftwareUpdate {
string sha = 3;
string download_url = 4;
}

message MempoolStatsResponse {
uint64 total_txs = 1;
uint64 unconfirmed_txs = 2;
uint64 reorg_txs = 3;
uint64 total_weight = 4;
}
21 changes: 21 additions & 0 deletions applications/tari_base_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,27 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {

Ok(Response::new(resp))
}

async fn get_mempool_stats(
&self,
_: Request<tari_rpc::Empty>,
) -> Result<Response<tari_rpc::MempoolStatsResponse>, Status> {
let mut mempool_handle = self.mempool_service.clone();

let mempool_stats = mempool_handle.get_mempool_stats().await.map_err(|e| {
error!(target: LOG_TARGET, "Error submitting query:{}", e);
Status::internal(e.to_string())
})?;

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,
};

Ok(Response::new(response))
}
}

enum BlockGroupType {
Expand Down
18 changes: 18 additions & 0 deletions integration_tests/features/Mempool.feature
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,21 @@ Feature: Mempool
Then SENDER has TX11 in MINED state
Then SENDER has TX12 in MINED state
Then SENDER has TX13 in MINED state

@critical
Scenario: Mempool unconfirmed transactions
Given I have 1 seed nodes
And I have a base node BN1 connected to all seed nodes
When I mine a block on BN1 with coinbase CB1
When I mine 5 blocks on BN1
When I create a custom fee transaction TX1 spending CB1 to UTX1 with fee 80
When I create a custom fee transaction TX2 spending CB1 to UTX1 with fee 80
When I create a custom fee transaction TX3 spending CB1 to UTX1 with fee 80
When I create a custom fee transaction TX4 spending CB1 to UTX1 with fee 80
When I create a custom fee transaction TX5 spending CB1 to UTX1 with fee 80
When I submit transaction TX1 to BN1
When I submit transaction TX2 to BN1
When I submit transaction TX3 to BN1
When I submit transaction TX4 to BN1
When I submit transaction TX5 to BN1
Then I wait until base node BN1 has 5 unconfirmed transactions in its mempool
26 changes: 26 additions & 0 deletions integration_tests/features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3306,3 +3306,29 @@ Then("I want to get emoji id of ffi wallet {word}", function (name) {
`Emoji id has wrong length : ${emoji_id}`
);
});

Then(
/I wait until base node (.*) has (.*) unconfirmed transactions in its mempool/,
{ timeout: 180 * 1000 },
async function (baseNode, numTransactions) {
const client = this.getClient(baseNode);
await waitFor(
async () => {
let stats = await client.getMempoolStats();
return stats.unconfirmed_txs;
},
numTransactions,
120 * 1000
);

let stats = await client.getMempoolStats();
console.log(
"Base node",
baseNode,
"has ",
stats.unconfirmed_txs,
" unconfirmed transaction in its mempool"
);
expect(stats.unconfirmed_txs).to.equal(numTransactions);
}
);
5 changes: 5 additions & 0 deletions integration_tests/helpers/baseNodeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ class BaseNodeClient {
await client.connect(port);
return client;
}

async getMempoolStats() {
const mempoolStats = await this.client.getMempoolStats().sendMessage({});
return mempoolStats;
}
}

module.exports = BaseNodeClient;

0 comments on commit cc9c2ca

Please sign in to comment.