gate approval-checking logic (#2470)

This commit is contained in:
Robert Habermeier
2021-02-18 01:05:13 -06:00
committed by GitHub
parent b7aac51341
commit fb0106a00e
4 changed files with 26 additions and 9 deletions
+1
View File
@@ -91,6 +91,7 @@ panic = "unwind"
[features] [features]
runtime-benchmarks=["cli/runtime-benchmarks"] runtime-benchmarks=["cli/runtime-benchmarks"]
real-overseer=["cli/real-overseer"] real-overseer=["cli/real-overseer"]
approval-checking=["real-overseer", "service/approval-checking"]
# Configuration for building a .deb package - for use with `cargo-deb` # Configuration for building a .deb package - for use with `cargo-deb`
[package.metadata.deb] [package.metadata.deb]
+4
View File
@@ -136,3 +136,7 @@ real-overseer = [
"polkadot-approval-distribution", "polkadot-approval-distribution",
"polkadot-node-core-approval-voting", "polkadot-node-core-approval-voting",
] ]
approval-checking = [
"real-overseer"
]
+12 -9
View File
@@ -18,17 +18,20 @@
use std::sync::Arc; use std::sync::Arc;
use polkadot_primitives::v1::{Block as PolkadotBlock, Header as PolkadotHeader, BlockNumber, Hash}; use polkadot_primitives::v1::Hash;
use polkadot_subsystem::messages::ApprovalVotingMessage;
use sp_runtime::traits::{Block as BlockT, NumberFor}; use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_runtime::generic::BlockId; use sp_runtime::generic::BlockId;
use sp_runtime::traits::Header as _; use sp_runtime::traits::Header as _;
use prometheus_endpoint::{self, Registry}; #[cfg(feature = "approval-checking")]
use polkadot_overseer::OverseerHandler; use {
polkadot_primitives::v1::{Block as PolkadotBlock, Header as PolkadotHeader, BlockNumber},
use futures::channel::oneshot; polkadot_subsystem::messages::ApprovalVotingMessage,
prometheus_endpoint::{self, Registry},
polkadot_overseer::OverseerHandler,
futures::channel::oneshot,
};
/// A custom GRANDPA voting rule that acts as a diagnostic for the approval /// A custom GRANDPA voting rule that acts as a diagnostic for the approval
/// voting subsystem's desired votes. /// voting subsystem's desired votes.
@@ -36,14 +39,14 @@ use futures::channel::oneshot;
/// The practical effect of this voting rule is to implement a fixed delay of /// The practical effect of this voting rule is to implement a fixed delay of
/// blocks and to issue a prometheus metric on the lag behind the head that /// blocks and to issue a prometheus metric on the lag behind the head that
/// approval checking would indicate. /// approval checking would indicate.
#[cfg(feature = "full-node")] #[cfg(feature = "approval-checking")]
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct ApprovalCheckingDiagnostic { pub(crate) struct ApprovalCheckingDiagnostic {
checking_lag: Option<prometheus_endpoint::Histogram>, checking_lag: Option<prometheus_endpoint::Histogram>,
overseer: OverseerHandler, overseer: OverseerHandler,
} }
#[cfg(feature = "full-node")] #[cfg(feature = "approval-checking")]
impl ApprovalCheckingDiagnostic { impl ApprovalCheckingDiagnostic {
/// Create a new approval checking diagnostic voting rule. /// Create a new approval checking diagnostic voting rule.
pub fn new(overseer: OverseerHandler, registry: Option<&Registry>) pub fn new(overseer: OverseerHandler, registry: Option<&Registry>)
@@ -68,7 +71,7 @@ impl ApprovalCheckingDiagnostic {
} }
} }
#[cfg(feature = "full-node")] #[cfg(feature = "approval-checking")]
impl<B> grandpa::VotingRule<PolkadotBlock, B> for ApprovalCheckingDiagnostic impl<B> grandpa::VotingRule<PolkadotBlock, B> for ApprovalCheckingDiagnostic
where B: sp_blockchain::HeaderBackend<PolkadotBlock> where B: sp_blockchain::HeaderBackend<PolkadotBlock>
{ {
+9
View File
@@ -412,8 +412,13 @@ where
use polkadot_statement_distribution::StatementDistribution as StatementDistributionSubsystem; use polkadot_statement_distribution::StatementDistribution as StatementDistributionSubsystem;
use polkadot_availability_recovery::AvailabilityRecoverySubsystem; use polkadot_availability_recovery::AvailabilityRecoverySubsystem;
use polkadot_approval_distribution::ApprovalDistribution as ApprovalDistributionSubsystem; use polkadot_approval_distribution::ApprovalDistribution as ApprovalDistributionSubsystem;
#[cfg(feature = "approval-checking")]
use polkadot_node_core_approval_voting::ApprovalVotingSubsystem; use polkadot_node_core_approval_voting::ApprovalVotingSubsystem;
#[cfg(not(feature = "approval-checking"))]
let _ = slot_duration; // silence.
let all_subsystems = AllSubsystems { let all_subsystems = AllSubsystems {
availability_distribution: AvailabilityDistributionSubsystem::new( availability_distribution: AvailabilityDistributionSubsystem::new(
keystore.clone(), keystore.clone(),
@@ -488,11 +493,14 @@ where
approval_distribution: ApprovalDistributionSubsystem::new( approval_distribution: ApprovalDistributionSubsystem::new(
Metrics::register(registry)?, Metrics::register(registry)?,
), ),
#[cfg(feature = "approval-checking")]
approval_voting: ApprovalVotingSubsystem::new( approval_voting: ApprovalVotingSubsystem::new(
keystore.clone(), keystore.clone(),
slot_duration, slot_duration,
runtime_client.clone(), runtime_client.clone(),
), ),
#[cfg(not(feature = "approval-checking"))]
approval_voting: polkadot_subsystem::DummySubsystem,
}; };
Overseer::new( Overseer::new(
@@ -828,6 +836,7 @@ pub fn new_full<RuntimeApi, Executor>(
// given delay. // given delay.
let builder = grandpa::VotingRulesBuilder::default(); let builder = grandpa::VotingRulesBuilder::default();
#[cfg(feature = "approval-checking")]
let builder = if let Some(ref overseer) = overseer_handler { let builder = if let Some(ref overseer) = overseer_handler {
builder.add(grandpa_support::ApprovalCheckingDiagnostic::new( builder.add(grandpa_support::ApprovalCheckingDiagnostic::new(
overseer.clone(), overseer.clone(),