Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit b7b60fa

Browse files
NikVolfmxinden
andauthored
Add prometheus registry to transaction pool, with couple of initial metrics (#5657)
* make new contructor * add metrics to txpool * fix review * fix doc comment * change to counters * Update client/transaction-pool/src/metrics.rs Co-Authored-By: Max Inden <[email protected]> * Update client/transaction-pool/src/metrics.rs Co-Authored-By: Max Inden <[email protected]> * Update client/transaction-pool/src/metrics.rs Co-Authored-By: Max Inden <[email protected]> * Update client/transaction-pool/src/lib.rs Co-Authored-By: Max Inden <[email protected]> * Update client/transaction-pool/src/lib.rs Co-Authored-By: Max Inden <[email protected]> * use dedicated wrapper Co-authored-by: Max Inden <[email protected]>
1 parent 86824f8 commit b7b60fa

File tree

15 files changed

+157
-26
lines changed

15 files changed

+157
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template/node/src/service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ macro_rules! new_full_start {
3535
.with_select_chain(|_config, backend| {
3636
Ok(sc_client::LongestChain::new(backend.clone()))
3737
})?
38-
.with_transaction_pool(|config, client, _fetcher| {
38+
.with_transaction_pool(|config, client, _fetcher, prometheus_registry| {
3939
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
40-
Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api)))
40+
Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api), prometheus_registry))
4141
})?
4242
.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {
4343
let select_chain = select_chain.take()
@@ -183,13 +183,13 @@ pub fn new_light(config: Configuration)
183183
.with_select_chain(|_config, backend| {
184184
Ok(LongestChain::new(backend.clone()))
185185
})?
186-
.with_transaction_pool(|config, client, fetcher| {
186+
.with_transaction_pool(|config, client, fetcher, prometheus_registry| {
187187
let fetcher = fetcher
188188
.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
189189

190190
let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());
191191
let pool = sc_transaction_pool::BasicPool::with_revalidation_type(
192-
config, Arc::new(pool_api), sc_transaction_pool::RevalidationType::Light,
192+
config, Arc::new(pool_api), prometheus_registry, sc_transaction_pool::RevalidationType::Light,
193193
);
194194
Ok(pool)
195195
})?

bin/node/cli/src/service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ macro_rules! new_full_start {
5656
.with_select_chain(|_config, backend| {
5757
Ok(sc_client::LongestChain::new(backend.clone()))
5858
})?
59-
.with_transaction_pool(|config, client, _fetcher| {
59+
.with_transaction_pool(|config, client, _fetcher, prometheus_registry| {
6060
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
61-
Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api)))
61+
Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api), prometheus_registry))
6262
})?
6363
.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {
6464
let select_chain = select_chain.take()
@@ -312,12 +312,12 @@ pub fn new_light(config: Configuration)
312312
.with_select_chain(|_config, backend| {
313313
Ok(LongestChain::new(backend.clone()))
314314
})?
315-
.with_transaction_pool(|config, client, fetcher| {
315+
.with_transaction_pool(|config, client, fetcher, prometheus_registry| {
316316
let fetcher = fetcher
317317
.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
318318
let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());
319319
let pool = sc_transaction_pool::BasicPool::with_revalidation_type(
320-
config, Arc::new(pool_api), sc_transaction_pool::RevalidationType::Light,
320+
config, Arc::new(pool_api), prometheus_registry, sc_transaction_pool::RevalidationType::Light,
321321
);
322322
Ok(pool)
323323
})?

client/basic-authorship/src/basic_authorship.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ mod tests {
360360
// given
361361
let client = Arc::new(substrate_test_runtime_client::new());
362362
let txpool = Arc::new(
363-
BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0
363+
BasicPool::new(
364+
Default::default(),
365+
Arc::new(FullChainApi::new(client.clone())),
366+
None,
367+
).0
364368
);
365369

366370
futures::executor::block_on(
@@ -408,7 +412,11 @@ mod tests {
408412
fn should_not_panic_when_deadline_is_reached() {
409413
let client = Arc::new(substrate_test_runtime_client::new());
410414
let txpool = Arc::new(
411-
BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0
415+
BasicPool::new(
416+
Default::default(),
417+
Arc::new(FullChainApi::new(client.clone())),
418+
None,
419+
).0
412420
);
413421

414422
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());
@@ -440,8 +448,13 @@ mod tests {
440448
.build_with_backend();
441449
let client = Arc::new(client);
442450
let txpool = Arc::new(
443-
BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0
451+
BasicPool::new(
452+
Default::default(),
453+
Arc::new(FullChainApi::new(client.clone())),
454+
None,
455+
).0
444456
);
457+
445458
let genesis_hash = client.info().best_hash;
446459
let block_id = BlockId::Hash(genesis_hash);
447460

@@ -493,7 +506,11 @@ mod tests {
493506
// given
494507
let mut client = Arc::new(substrate_test_runtime_client::new());
495508
let txpool = Arc::new(
496-
BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0
509+
BasicPool::new(
510+
Default::default(),
511+
Arc::new(FullChainApi::new(client.clone())),
512+
None,
513+
).0
497514
);
498515

499516
futures::executor::block_on(

client/basic-authorship/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! # use substrate_test_runtime_client::{self, runtime::{Extrinsic, Transfer}, AccountKeyring};
2727
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
2828
//! # let client = Arc::new(substrate_test_runtime_client::new());
29-
//! # let txpool = Arc::new(BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0);
29+
//! # let txpool = Arc::new(BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone())), None).0);
3030
//! // The first step is to create a `ProposerFactory`.
3131
//! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());
3232
//!

client/consensus/manual-seal/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mod tests {
217217
let (client, select_chain) = builder.build_with_longest_chain();
218218
let client = Arc::new(client);
219219
let inherent_data_providers = InherentDataProviders::new();
220-
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
220+
let pool = Arc::new(BasicPool::new(Options::default(), api(), None).0);
221221
let env = ProposerFactory::new(
222222
client.clone(),
223223
pool.clone()
@@ -281,7 +281,7 @@ mod tests {
281281
let (client, select_chain) = builder.build_with_longest_chain();
282282
let client = Arc::new(client);
283283
let inherent_data_providers = InherentDataProviders::new();
284-
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
284+
let pool = Arc::new(BasicPool::new(Options::default(), api(), None).0);
285285
let env = ProposerFactory::new(
286286
client.clone(),
287287
pool.clone()
@@ -349,7 +349,7 @@ mod tests {
349349
let client = Arc::new(client);
350350
let inherent_data_providers = InherentDataProviders::new();
351351
let pool_api = api();
352-
let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone()).0);
352+
let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone(), None).0);
353353
let env = ProposerFactory::new(
354354
client.clone(),
355355
pool.clone(),

client/offchain/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ mod tests {
206206
let pool = Arc::new(TestPool(BasicPool::new(
207207
Default::default(),
208208
Arc::new(FullChainApi::new(client.clone())),
209+
None,
209210
).0));
210211
client.execution_extensions()
211212
.register_transaction_pool(Arc::downgrade(&pool.clone()) as _);

client/rpc/src/author/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl Default for TestSetup {
6565
let pool = Arc::new(BasicPool::new(
6666
Default::default(),
6767
Arc::new(FullChainApi::new(client.clone())),
68+
None,
6869
).0);
6970
TestSetup {
7071
runtime: runtime::Runtime::new().expect("Failed to create runtime in test setup"),

client/service/src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use wasm_timer::SystemTime;
5353
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
5454
use sp_transaction_pool::{MaintainedTransactionPool, ChainEvent};
5555
use sp_blockchain;
56+
use prometheus_endpoint::Registry as PrometheusRegistry;
5657

5758
pub type BackgroundTask = Pin<Box<dyn Future<Output=()> + Send>>;
5859

@@ -585,6 +586,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
585586
sc_transaction_pool::txpool::Options,
586587
Arc<TCl>,
587588
Option<TFchr>,
589+
Option<&PrometheusRegistry>,
588590
) -> Result<(UExPool, Option<BackgroundTask>), Error>
589591
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
590592
UExPool, TRpc, Backend>, Error>
@@ -593,6 +595,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
593595
self.config.transaction_pool.clone(),
594596
self.client.clone(),
595597
self.fetcher.clone(),
598+
self.config.prometheus_config.as_ref().map(|config| &config.registry),
596599
)?;
597600

598601
if let Some(background_task) = background_task{

client/service/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ mod tests {
696696
let pool = Arc::new(BasicPool::new(
697697
Default::default(),
698698
Arc::new(FullChainApi::new(client.clone())),
699+
None,
699700
).0);
700701
let source = sp_runtime::transaction_validity::TransactionSource::External;
701702
let best = longest_chain.best_chain().unwrap();

0 commit comments

Comments
 (0)