mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 14:25:41 +00:00
Update substrate, add block construction metrics (#1112)
* add metrics * reset & update * update
This commit is contained in:
Generated
+141
-139
File diff suppressed because it is too large
Load Diff
@@ -388,6 +388,7 @@ macro_rules! new_full {
|
|||||||
validation_service_handle,
|
validation_service_handle,
|
||||||
slot_duration,
|
slot_duration,
|
||||||
backend,
|
backend,
|
||||||
|
service.prometheus_registry().as_ref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
|
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] }
|
|||||||
runtime_babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
|
runtime_babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
|
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" }
|
keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
sc-proposer-metrics = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
|||||||
@@ -42,10 +42,14 @@ use inherents::InherentData;
|
|||||||
use sp_timestamp::TimestampInherentData;
|
use sp_timestamp::TimestampInherentData;
|
||||||
use log::{info, debug, warn, trace};
|
use log::{info, debug, warn, trace};
|
||||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||||
|
use prometheus_endpoint::Registry as PrometheusRegistry;
|
||||||
|
use sc_proposer_metrics::MetricsLink as PrometheusMetrics;
|
||||||
|
|
||||||
use crate::validation_service::ServiceHandle;
|
use crate::{
|
||||||
use crate::dynamic_inclusion::DynamicInclusion;
|
Error,
|
||||||
use crate::Error;
|
dynamic_inclusion::DynamicInclusion,
|
||||||
|
validation_service::ServiceHandle,
|
||||||
|
};
|
||||||
|
|
||||||
// block size limit.
|
// block size limit.
|
||||||
pub(crate) const MAX_TRANSACTIONS_SIZE: usize = 4 * 1024 * 1024;
|
pub(crate) const MAX_TRANSACTIONS_SIZE: usize = 4 * 1024 * 1024;
|
||||||
@@ -57,6 +61,7 @@ pub struct ProposerFactory<Client, TxPool, Backend> {
|
|||||||
service_handle: ServiceHandle,
|
service_handle: ServiceHandle,
|
||||||
babe_slot_duration: u64,
|
babe_slot_duration: u64,
|
||||||
backend: Arc<Backend>,
|
backend: Arc<Backend>,
|
||||||
|
metrics: PrometheusMetrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Client, TxPool, Backend> ProposerFactory<Client, TxPool, Backend> {
|
impl<Client, TxPool, Backend> ProposerFactory<Client, TxPool, Backend> {
|
||||||
@@ -67,6 +72,7 @@ impl<Client, TxPool, Backend> ProposerFactory<Client, TxPool, Backend> {
|
|||||||
service_handle: ServiceHandle,
|
service_handle: ServiceHandle,
|
||||||
babe_slot_duration: u64,
|
babe_slot_duration: u64,
|
||||||
backend: Arc<Backend>,
|
backend: Arc<Backend>,
|
||||||
|
prometheus: Option<&PrometheusRegistry>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ProposerFactory {
|
ProposerFactory {
|
||||||
client,
|
client,
|
||||||
@@ -74,6 +80,7 @@ impl<Client, TxPool, Backend> ProposerFactory<Client, TxPool, Backend> {
|
|||||||
service_handle: service_handle,
|
service_handle: service_handle,
|
||||||
babe_slot_duration,
|
babe_slot_duration,
|
||||||
backend,
|
backend,
|
||||||
|
metrics: PrometheusMetrics::new(prometheus),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,6 +116,7 @@ where
|
|||||||
let transaction_pool = self.transaction_pool.clone();
|
let transaction_pool = self.transaction_pool.clone();
|
||||||
let backend = self.backend.clone();
|
let backend = self.backend.clone();
|
||||||
let slot_duration = self.babe_slot_duration.clone();
|
let slot_duration = self.babe_slot_duration.clone();
|
||||||
|
let metrics = self.metrics.clone();
|
||||||
|
|
||||||
let maybe_proposer = self.service_handle
|
let maybe_proposer = self.service_handle
|
||||||
.clone()
|
.clone()
|
||||||
@@ -120,6 +128,7 @@ where
|
|||||||
transaction_pool,
|
transaction_pool,
|
||||||
slot_duration,
|
slot_duration,
|
||||||
backend,
|
backend,
|
||||||
|
metrics,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
Box::pin(maybe_proposer)
|
Box::pin(maybe_proposer)
|
||||||
@@ -134,6 +143,7 @@ pub struct Proposer<Client, TxPool, Backend> {
|
|||||||
transaction_pool: Arc<TxPool>,
|
transaction_pool: Arc<TxPool>,
|
||||||
slot_duration: u64,
|
slot_duration: u64,
|
||||||
backend: Arc<Backend>,
|
backend: Arc<Backend>,
|
||||||
|
metrics: PrometheusMetrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Client, TxPool, Backend> consensus::Proposer<Block> for Proposer<Client, TxPool, Backend> where
|
impl<Client, TxPool, Backend> consensus::Proposer<Block> for Proposer<Client, TxPool, Backend> where
|
||||||
@@ -175,8 +185,10 @@ impl<Client, TxPool, Backend> consensus::Proposer<Block> for Proposer<Client, Tx
|
|||||||
let transaction_pool = self.transaction_pool.clone();
|
let transaction_pool = self.transaction_pool.clone();
|
||||||
let table = self.tracker.table().clone();
|
let table = self.tracker.table().clone();
|
||||||
let backend = self.backend.clone();
|
let backend = self.backend.clone();
|
||||||
|
let metrics = self.metrics.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
|
let block_timer = metrics.report(|metrics| metrics.block_constructed.start_timer());
|
||||||
let enough_candidates = dynamic_inclusion.acceptable_in(
|
let enough_candidates = dynamic_inclusion.acceptable_in(
|
||||||
now,
|
now,
|
||||||
initial_included,
|
initial_included,
|
||||||
@@ -214,11 +226,18 @@ impl<Client, TxPool, Backend> consensus::Proposer<Block> for Proposer<Client, Tx
|
|||||||
|
|
||||||
Delay::new(enough_candidates).await;
|
Delay::new(enough_candidates).await;
|
||||||
|
|
||||||
tokio::task::spawn_blocking(move || {
|
let result = tokio::task::spawn_blocking(
|
||||||
let proposed_candidates = table.proposed_set();
|
move || {
|
||||||
data.propose_with(proposed_candidates)
|
let proposed_candidates = table.proposed_set();
|
||||||
})
|
data.propose_with(proposed_candidates)
|
||||||
.await?
|
}
|
||||||
|
).await?;
|
||||||
|
|
||||||
|
drop(block_timer);
|
||||||
|
let transactions = result.as_ref().map(|proposal| proposal.block.extrinsics.len()).unwrap_or_default();
|
||||||
|
metrics.report(|metrics| metrics.number_of_transactions.set(transactions as u64));
|
||||||
|
|
||||||
|
result
|
||||||
}.boxed()
|
}.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user