From b61c651ec76a5804d12fc8fe12da18b8dfa85091 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 17 Feb 2021 16:13:19 -0600 Subject: [PATCH] gate approval-checking logic --- Cargo.toml | 1 + node/service/Cargo.toml | 4 ++++ node/service/src/grandpa_support.rs | 21 ++++++++++++--------- node/service/src/lib.rs | 9 +++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 082631cc62a6..6fd9162ff1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ panic = "unwind" [features] runtime-benchmarks=["cli/runtime-benchmarks"] real-overseer=["cli/real-overseer"] +approval-checking=["real-overseer", "service/approval-checking"] # Configuration for building a .deb package - for use with `cargo-deb` [package.metadata.deb] diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 58f5c5c23512..622ed317e585 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -136,3 +136,7 @@ real-overseer = [ "polkadot-approval-distribution", "polkadot-node-core-approval-voting", ] + +approval-checking = [ + "real-overseer" +] diff --git a/node/service/src/grandpa_support.rs b/node/service/src/grandpa_support.rs index d411c8ed817e..6468565a7b3e 100644 --- a/node/service/src/grandpa_support.rs +++ b/node/service/src/grandpa_support.rs @@ -18,17 +18,20 @@ use std::sync::Arc; -use polkadot_primitives::v1::{Block as PolkadotBlock, Header as PolkadotHeader, BlockNumber, Hash}; -use polkadot_subsystem::messages::ApprovalVotingMessage; +use polkadot_primitives::v1::Hash; use sp_runtime::traits::{Block as BlockT, NumberFor}; use sp_runtime::generic::BlockId; use sp_runtime::traits::Header as _; -use prometheus_endpoint::{self, Registry}; -use polkadot_overseer::OverseerHandler; - -use futures::channel::oneshot; +#[cfg(feature = "approval-checking")] +use { + polkadot_primitives::v1::{Block as PolkadotBlock, Header as PolkadotHeader, BlockNumber}, + 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 /// 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 /// blocks and to issue a prometheus metric on the lag behind the head that /// approval checking would indicate. -#[cfg(feature = "full-node")] +#[cfg(feature = "approval-checking")] #[derive(Clone)] pub(crate) struct ApprovalCheckingDiagnostic { checking_lag: Option, overseer: OverseerHandler, } -#[cfg(feature = "full-node")] +#[cfg(feature = "approval-checking")] impl ApprovalCheckingDiagnostic { /// Create a new approval checking diagnostic voting rule. pub fn new(overseer: OverseerHandler, registry: Option<&Registry>) @@ -68,7 +71,7 @@ impl ApprovalCheckingDiagnostic { } } -#[cfg(feature = "full-node")] +#[cfg(feature = "approval-checking")] impl grandpa::VotingRule for ApprovalCheckingDiagnostic where B: sp_blockchain::HeaderBackend { diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 1cb4b1ce0872..1d119014b8fe 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -412,8 +412,13 @@ where use polkadot_statement_distribution::StatementDistribution as StatementDistributionSubsystem; use polkadot_availability_recovery::AvailabilityRecoverySubsystem; use polkadot_approval_distribution::ApprovalDistribution as ApprovalDistributionSubsystem; + + #[cfg(feature = "approval-checking")] use polkadot_node_core_approval_voting::ApprovalVotingSubsystem; + #[cfg(not(feature = "approval-checking"))] + let _ = slot_duration; // silence. + let all_subsystems = AllSubsystems { availability_distribution: AvailabilityDistributionSubsystem::new( keystore.clone(), @@ -488,11 +493,14 @@ where approval_distribution: ApprovalDistributionSubsystem::new( Metrics::register(registry)?, ), + #[cfg(feature = "approval-checking")] approval_voting: ApprovalVotingSubsystem::new( keystore.clone(), slot_duration, runtime_client.clone(), ), + #[cfg(not(feature = "approval-checking"))] + approval_voting: polkadot_subsystem::DummySubsystem, }; Overseer::new( @@ -828,6 +836,7 @@ pub fn new_full( // given delay. let builder = grandpa::VotingRulesBuilder::default(); + #[cfg(feature = "approval-checking")] let builder = if let Some(ref overseer) = overseer_handler { builder.add(grandpa_support::ApprovalCheckingDiagnostic::new( overseer.clone(),