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

gate approval-checking logic #2470

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@ real-overseer = [
"polkadot-approval-distribution",
"polkadot-node-core-approval-voting",
]

approval-checking = [
"real-overseer"
]
21 changes: 12 additions & 9 deletions node/service/src/grandpa_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,35 @@

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.
///
/// 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<prometheus_endpoint::Histogram>,
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>)
Expand All @@ -68,7 +71,7 @@ impl ApprovalCheckingDiagnostic {
}
}

#[cfg(feature = "full-node")]
#[cfg(feature = "approval-checking")]
impl<B> grandpa::VotingRule<PolkadotBlock, B> for ApprovalCheckingDiagnostic
where B: sp_blockchain::HeaderBackend<PolkadotBlock>
{
Expand Down
9 changes: 9 additions & 0 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -828,6 +836,7 @@ pub fn new_full<RuntimeApi, Executor>(
// 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(),
Expand Down