mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Add Prometheus timers to the subsystems (#1923)
* reexport prometheus-super for ease of use of other subsystems * add some prometheus timers for collation generation subsystem * add timing metrics to av-store * add metrics to candidate backing * add timing metric to bitfield signing * add timing metrics to candidate selection * add timing metrics to candidate-validation * add timing metrics to chain-api * add timing metrics to provisioner * add timing metrics to runtime-api * add timing metrics to availability-distribution * add timing metrics to bitfield-distribution * add timing metrics to collator protocol: collator side * add timing metrics to collator protocol: validator side * fix candidate validation test failures * add timing metrics to pov distribution * add timing metrics to statement-distribution * use substrate_prometheus_endpoint prometheus reexport instead of prometheus_super * don't include JOB_DELAY in bitfield-signing metrics * give adder-collator ability to easily export its genesis-state and validation code * wip: adder-collator pushbutton script * don't attempt to register the adder-collator automatically Instead, get these values with ```sh target/release/adder-collator export-genesis-state target/release/adder-collator export-genesis-wasm ``` And then register the parachain on https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer To collect prometheus data, after running the script, create `prometheus.yml` per the instructions at https://www.notion.so/paritytechnologies/Setting-up-Prometheus-locally-835cb3a9df7541a781c381006252b5ff and then run: ```sh docker run -v `pwd`/prometheus.yml:/etc/prometheus/prometheus.yml:z --network host prom/prometheus ``` Demonstrates that data makes it across to prometheus, though it is likely to be useful in the future to tweak the buckets. * Update parachain/test-parachains/adder/collator/src/cli.rs Co-authored-by: Andronik Ordian <write@reusable.software> * use the grandpa-pause parameter * skip metrics in tracing instrumentation * remove unnecessary grandpa_pause cli param Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
committed by
GitHub
parent
e49989971d
commit
0a5bc82529
@@ -26,6 +26,7 @@ polkadot-node-subsystem = { path = "../../../../node/subsystem" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
polkadot-parachain = { path = "../../.." }
|
||||
|
||||
@@ -13,3 +13,5 @@ cargo run --features=real-overseer --release -p test-parachain-adder-collator --
|
||||
|
||||
The last step is to register the parachain using polkadot-js. The parachain id is
|
||||
100. The genesis state and the validation code are printed at startup by the collator.
|
||||
|
||||
To do this automatically, run `scripts/adder-collator.sh`.
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Polkadot CLI library.
|
||||
|
||||
use sc_cli::{RuntimeVersion, SubstrateCli};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Sub-commands supported by the collator.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub enum Subcommand {
|
||||
/// Export the genesis state of the parachain.
|
||||
#[structopt(name = "export-genesis-state")]
|
||||
ExportGenesisState(ExportGenesisStateCommand),
|
||||
|
||||
/// Export the genesis wasm of the parachain.
|
||||
#[structopt(name = "export-genesis-wasm")]
|
||||
ExportGenesisWasm(ExportGenesisWasmCommand),
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis state of the parachain
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ExportGenesisStateCommand {}
|
||||
|
||||
/// Command for exporting the genesis wasm file.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ExportGenesisWasmCommand {}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct RunCmd {
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub base: sc_cli::RunCmd,
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct Cli {
|
||||
#[structopt(subcommand)]
|
||||
pub subcommand: Option<Subcommand>,
|
||||
|
||||
#[structopt(flatten)]
|
||||
pub run: RunCmd,
|
||||
}
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
fn impl_name() -> String {
|
||||
"Parity Polkadot".into()
|
||||
}
|
||||
|
||||
fn impl_version() -> String {
|
||||
"0.0.0".into()
|
||||
}
|
||||
|
||||
fn description() -> String {
|
||||
env!("CARGO_PKG_DESCRIPTION").into()
|
||||
}
|
||||
|
||||
fn author() -> String {
|
||||
env!("CARGO_PKG_AUTHORS").into()
|
||||
}
|
||||
|
||||
fn support_url() -> String {
|
||||
"https://github.com/paritytech/polkadot/issues/new".into()
|
||||
}
|
||||
|
||||
fn copyright_start_year() -> i32 {
|
||||
2017
|
||||
}
|
||||
|
||||
fn executable_name() -> String {
|
||||
"polkadot".into()
|
||||
}
|
||||
|
||||
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
let id = if id.is_empty() { "rococo" } else { id };
|
||||
Ok(match id {
|
||||
"rococo-staging" => {
|
||||
Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?)
|
||||
}
|
||||
"rococo-local" => {
|
||||
Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?)
|
||||
}
|
||||
"rococo" => Box::new(polkadot_service::chain_spec::rococo_config()?),
|
||||
_ => Err("adder collator only supports rococo")?,
|
||||
})
|
||||
}
|
||||
|
||||
fn native_runtime_version(
|
||||
_spec: &Box<dyn polkadot_service::ChainSpec>,
|
||||
) -> &'static RuntimeVersion {
|
||||
&polkadot_service::rococo_runtime::VERSION
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,17 @@
|
||||
|
||||
//! Collator for the adder test parachain.
|
||||
|
||||
use std::{sync::{Arc, Mutex}, collections::HashMap, time::Duration};
|
||||
use test_parachain_adder::{hash_state, BlockData, HeadData, execute};
|
||||
use futures_timer::Delay;
|
||||
use polkadot_primitives::v1::{PoV, CollatorId, CollatorPair};
|
||||
use polkadot_node_primitives::{Collation, CollatorFn};
|
||||
use polkadot_primitives::v1::{CollatorId, CollatorPair, PoV};
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use sp_core::Pair;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
};
|
||||
use test_parachain_adder::{execute, hash_state, BlockData, HeadData};
|
||||
|
||||
/// The amount we add when producing a new block.
|
||||
///
|
||||
@@ -60,15 +64,19 @@ impl State {
|
||||
self.best_block = parent_head.number;
|
||||
|
||||
let block = BlockData {
|
||||
state: *self.head_to_state.get(&parent_head).expect("Getting state using parent head"),
|
||||
state: *self
|
||||
.head_to_state
|
||||
.get(&parent_head)
|
||||
.expect("Getting state using parent head"),
|
||||
add: ADD,
|
||||
};
|
||||
|
||||
let new_head = execute(parent_head.hash(), parent_head, &block)
|
||||
.expect("Produces valid block");
|
||||
let new_head =
|
||||
execute(parent_head.hash(), parent_head, &block).expect("Produces valid block");
|
||||
|
||||
let new_head_arc = Arc::new(new_head.clone());
|
||||
self.head_to_state.insert(new_head_arc.clone(), block.state.wrapping_add(ADD));
|
||||
self.head_to_state
|
||||
.insert(new_head_arc.clone(), block.state.wrapping_add(ADD));
|
||||
self.number_to_head.insert(new_head.number, new_head_arc);
|
||||
|
||||
(block, new_head)
|
||||
@@ -92,7 +100,13 @@ impl Collator {
|
||||
|
||||
/// Get the SCALE encoded genesis head of the adder parachain.
|
||||
pub fn genesis_head(&self) -> Vec<u8> {
|
||||
self.state.lock().unwrap().number_to_head.get(&0).expect("Genesis header exists").encode()
|
||||
self.state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.number_to_head
|
||||
.get(&0)
|
||||
.expect("Genesis header exists")
|
||||
.encode()
|
||||
}
|
||||
|
||||
/// Get the validation code of the adder parachain.
|
||||
@@ -113,9 +127,7 @@ impl Collator {
|
||||
/// Create the collation function.
|
||||
///
|
||||
/// This collation function can be plugged into the overseer to generate collations for the adder parachain.
|
||||
pub fn create_collation_function(
|
||||
&self,
|
||||
) -> CollatorFn {
|
||||
pub fn create_collation_function(&self) -> CollatorFn {
|
||||
use futures::FutureExt as _;
|
||||
|
||||
let state = self.state.clone();
|
||||
@@ -137,7 +149,9 @@ impl Collator {
|
||||
horizontal_messages: Vec::new(),
|
||||
new_validation_code: None,
|
||||
head_data: head_data.encode().into(),
|
||||
proof_of_validity: PoV { block_data: block_data.encode().into() },
|
||||
proof_of_validity: PoV {
|
||||
block_data: block_data.encode().into(),
|
||||
},
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: validation_data.persisted.block_number,
|
||||
};
|
||||
@@ -155,7 +169,7 @@ impl Collator {
|
||||
let current_block = self.state.lock().unwrap().best_block;
|
||||
|
||||
if start_block + blocks <= current_block {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,8 +181,7 @@ mod tests {
|
||||
|
||||
use futures::executor::block_on;
|
||||
use polkadot_parachain::{primitives::ValidationParams, wasm_executor::IsolationStrategy};
|
||||
use polkadot_primitives::v1::{ValidationData, PersistedValidationData};
|
||||
use parity_scale_codec::Decode;
|
||||
use polkadot_primitives::v1::{PersistedValidationData, ValidationData};
|
||||
|
||||
#[test]
|
||||
fn collator_works() {
|
||||
@@ -176,7 +189,14 @@ mod tests {
|
||||
let collation_function = collator.create_collation_function();
|
||||
|
||||
for i in 0..5 {
|
||||
let parent_head = collator.state.lock().unwrap().number_to_head.get(&i).unwrap().clone();
|
||||
let parent_head = collator
|
||||
.state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.number_to_head
|
||||
.get(&i)
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
let validation_data = ValidationData {
|
||||
persisted: PersistedValidationData {
|
||||
@@ -186,7 +206,8 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let collation = block_on(collation_function(Default::default(), &validation_data)).unwrap();
|
||||
let collation =
|
||||
block_on(collation_function(Default::default(), &validation_data)).unwrap();
|
||||
validate_collation(&collator, (*parent_head).clone(), collation);
|
||||
}
|
||||
}
|
||||
@@ -203,9 +224,19 @@ mod tests {
|
||||
},
|
||||
&IsolationStrategy::InProcess,
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
assert_eq!(**collator.state.lock().unwrap().number_to_head.get(&(parent_head.number + 1)).unwrap(), new_head);
|
||||
assert_eq!(
|
||||
**collator
|
||||
.state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.number_to_head
|
||||
.get(&(parent_head.number + 1))
|
||||
.unwrap(),
|
||||
new_head
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,71 +16,88 @@
|
||||
|
||||
//! Collator for the adder test parachain.
|
||||
|
||||
use sc_cli::{Result, Role, SubstrateCli};
|
||||
use polkadot_cli::Cli;
|
||||
use polkadot_node_subsystem::messages::{CollatorProtocolMessage, CollationGenerationMessage};
|
||||
use polkadot_node_primitives::CollationGenerationConfig;
|
||||
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
|
||||
use polkadot_primitives::v1::Id as ParaId;
|
||||
use test_parachain_adder_collator::Collator;
|
||||
use sc_cli::{Result, Role, SubstrateCli};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use std::time::Duration;
|
||||
use test_parachain_adder_collator::Collator;
|
||||
|
||||
const PARA_ID: ParaId = ParaId::new(100);
|
||||
|
||||
mod cli;
|
||||
use cli::Cli;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::from_args();
|
||||
|
||||
if cli.subcommand.is_some() {
|
||||
return Err("Subcommands are not supported".into())
|
||||
}
|
||||
match cli.subcommand {
|
||||
Some(cli::Subcommand::ExportGenesisState(_params)) => {
|
||||
let collator = Collator::new();
|
||||
println!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
|
||||
|
||||
let runner = cli.create_runner(&cli.run.base)?;
|
||||
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
let role = config.role.clone();
|
||||
|
||||
match role {
|
||||
Role::Light => Err("Light client not supported".into()),
|
||||
_ => {
|
||||
let collator = Collator::new();
|
||||
|
||||
let full_node = polkadot_service::build_full(
|
||||
config,
|
||||
polkadot_service::IsCollator::Yes(collator.collator_id()),
|
||||
None,
|
||||
Some(sc_authority_discovery::WorkerConfig {
|
||||
query_interval: Duration::from_secs(1),
|
||||
query_start_delay: Duration::from_secs(0),
|
||||
..Default::default()
|
||||
}),
|
||||
)?;
|
||||
let mut overseer_handler = full_node.overseer_handler
|
||||
.expect("Overseer handler should be initialized for collators");
|
||||
|
||||
let genesis_head_hex = format!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
|
||||
let validation_code_hex = format!("0x{:?}", HexDisplay::from(&collator.validation_code()));
|
||||
|
||||
log::info!("Running adder collator for parachain id: {}", PARA_ID);
|
||||
log::info!("Genesis state: {}", genesis_head_hex);
|
||||
log::info!("Validation code: {}", validation_code_hex);
|
||||
|
||||
let config = CollationGenerationConfig {
|
||||
key: collator.collator_key(),
|
||||
collator: collator.create_collation_function(),
|
||||
para_id: PARA_ID,
|
||||
};
|
||||
overseer_handler
|
||||
.send_msg(CollationGenerationMessage::Initialize(config))
|
||||
.await
|
||||
.expect("Registers collator");
|
||||
|
||||
overseer_handler
|
||||
.send_msg(CollatorProtocolMessage::CollateOn(PARA_ID))
|
||||
.await
|
||||
.expect("Collates on");
|
||||
|
||||
Ok(full_node.task_manager)
|
||||
},
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
Some(cli::Subcommand::ExportGenesisWasm(_params)) => {
|
||||
let collator = Collator::new();
|
||||
println!("0x{:?}", HexDisplay::from(&collator.validation_code()));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
None => {
|
||||
let runner = cli.create_runner(&cli.run.base)?;
|
||||
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
let role = config.role.clone();
|
||||
|
||||
match role {
|
||||
Role::Light => Err("Light client not supported".into()),
|
||||
_ => {
|
||||
let collator = Collator::new();
|
||||
|
||||
let full_node = polkadot_service::build_full(
|
||||
config,
|
||||
polkadot_service::IsCollator::Yes(collator.collator_id()),
|
||||
None,
|
||||
Some(sc_authority_discovery::WorkerConfig {
|
||||
query_interval: Duration::from_secs(1),
|
||||
query_start_delay: Duration::from_secs(0),
|
||||
..Default::default()
|
||||
}),
|
||||
)?;
|
||||
let mut overseer_handler = full_node
|
||||
.overseer_handler
|
||||
.expect("Overseer handler should be initialized for collators");
|
||||
|
||||
let genesis_head_hex =
|
||||
format!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
|
||||
let validation_code_hex =
|
||||
format!("0x{:?}", HexDisplay::from(&collator.validation_code()));
|
||||
|
||||
log::info!("Running adder collator for parachain id: {}", PARA_ID);
|
||||
log::info!("Genesis state: {}", genesis_head_hex);
|
||||
log::info!("Validation code: {}", validation_code_hex);
|
||||
|
||||
let config = CollationGenerationConfig {
|
||||
key: collator.collator_key(),
|
||||
collator: collator.create_collation_function(),
|
||||
para_id: PARA_ID,
|
||||
};
|
||||
overseer_handler
|
||||
.send_msg(CollationGenerationMessage::Initialize(config))
|
||||
.await
|
||||
.expect("Registers collator");
|
||||
|
||||
overseer_handler
|
||||
.send_msg(CollatorProtocolMessage::CollateOn(PARA_ID))
|
||||
.await
|
||||
.expect("Collates on");
|
||||
|
||||
Ok(full_node.task_manager)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user