diff --git a/polkadot/node/core/approval-voting/src/approval_db/v1/mod.rs b/polkadot/node/core/approval-voting/src/approval_db/v1/mod.rs index 4f7c8b58d3..8c76953fea 100644 --- a/polkadot/node/core/approval-voting/src/approval_db/v1/mod.rs +++ b/polkadot/node/core/approval-voting/src/approval_db/v1/mod.rs @@ -502,9 +502,14 @@ impl Transaction { let _ = self.candidate_entries.insert(hash, entry); } + /// Returns true if the transaction contains no actions + pub(crate) fn is_empty(&self) -> bool { + self.block_entries.is_empty() && self.candidate_entries.is_empty() + } + /// Write the contents of the transaction, atomically, to the DB. pub(crate) fn write(self, db: &dyn KeyValueDB) -> Result<()> { - if self.block_entries.is_empty() && self.candidate_entries.is_empty() { + if self.is_empty() { return Ok(()) } diff --git a/polkadot/node/core/approval-voting/src/lib.rs b/polkadot/node/core/approval-voting/src/lib.rs index d04ab79f0c..c079724a5a 100644 --- a/polkadot/node/core/approval-voting/src/lib.rs +++ b/polkadot/node/core/approval-voting/src/lib.rs @@ -109,6 +109,7 @@ struct MetricsInner { wakeups_triggered_total: prometheus::Counter, candidate_approval_time_ticks: prometheus::Histogram, block_approval_time_ticks: prometheus::Histogram, + time_db_transaction: prometheus::Histogram, } /// Aproval Voting metrics. @@ -157,6 +158,10 @@ impl Metrics { metrics.block_approval_time_ticks.observe(ticks as f64); } } + + fn time_db_transaction(&self) -> Option { + self.0.as_ref().map(|metrics| metrics.time_db_transaction.start_timer()) + } } impl metrics::Metrics for Metrics { @@ -217,6 +222,15 @@ impl metrics::Metrics for Metrics { )?, registry, )?, + time_db_transaction: prometheus::register( + prometheus::Histogram::with_opts( + prometheus::HistogramOpts::new( + "parachain_time_approval_db_transaction", + "Time spent writing an approval db transaction.", + ) + )?, + registry, + )?, }; Ok(Metrics(Some(metrics))) @@ -570,8 +584,12 @@ async fn handle_actions( } } - transaction.write(db) - .map_err(|e| SubsystemError::with_origin("approval-voting", e))?; + if !transaction.is_empty() { + let _timer = metrics.time_db_transaction(); + + transaction.write(db) + .map_err(|e| SubsystemError::with_origin("approval-voting", e))?; + } Ok(conclude) } @@ -1609,6 +1627,11 @@ async fn launch_approval( let candidate = candidate.clone(); let background = async move { + let _span = jaeger::Span::from_encodable((block_hash, candidate_hash), "launch-approval") + .with_relay_parent(block_hash) + .with_candidate(candidate_hash) + .with_stage(jaeger::Stage::ApprovalChecking); + let available_data = match a_rx.await { Err(_) => return, Ok(Ok(a)) => a,