Skip to content

Commit

Permalink
Add block production metrics to prometheus (#140)
Browse files Browse the repository at this point in the history
* Avail Metrics integration
* RPC & node metrics are separated
* Remove some clippy warnings
  • Loading branch information
MiguelDD1 authored Mar 13, 2023
1 parent ce4e9aa commit 65138fe
Show file tree
Hide file tree
Showing 58 changed files with 2,292 additions and 2,037 deletions.
1,512 changes: 793 additions & 719 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ frame-system-rpc-runtime-api = { path = "pallets/system/rpc/runtime-api" }
frame-system-benchmarking = { path = "pallets/system/benchmarking" }

# Polygon Primitives
da-primitives = { git="https://github.com/maticnetwork/avail-core", version = "0.4.2", tag = "da-primitives/v0.4.3" }
kate = { git="https://github.com/maticnetwork/avail-core", version = "0.6.0", tag = "da-primitives/v0.4.3" }
kate-recovery = { git="https://github.com/maticnetwork/avail-core", version = "0.8.0", tag = "da-primitives/v0.4.3" }

da-primitives = { version = "0.4", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }
kate = { version = "0.7", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }
kate-recovery = { version = "0.8", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }

# Nomad
nomad-signature = { git="https://github.com/maticnetwork/avail-core", version = "0.1.0", tag = "da-primitives/v0.4.3" }
nomad-merkle = { git="https://github.com/maticnetwork/avail-core", version = "0.1.0", tag = "da-primitives/v0.4.3" }
nomad-base = { git="https://github.com/maticnetwork/avail-core", version = "0.1.2", tag = "da-primitives/v0.4.3" }
nomad-core = { git="https://github.com/maticnetwork/avail-core", version = "0.1.2", tag = "da-primitives/v0.4.3" }
nomad-signature = { version = "0.1", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }
nomad-merkle = { version = "0.1", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }
nomad-base = { version = "0.1", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }
nomad-core = { version = "0.1", git="https://github.com/maticnetwork/avail-core", tag = "da-primitives/v0.4.4" }

# Other stuff
uint = { git = "https://github.com/paritytech/parity-common.git", tag="rlp-v0.5.2" }
Expand Down
21 changes: 14 additions & 7 deletions avail-subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ name = "e2e"
path = "src/e2e.rs"

[dependencies]
subxt = "0.24.0"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
serde = { version = "1.0", features = ["derive"] }
parity-util-mem = "0.11.0"
scale-info = { version = "2.0.0", features = ["bit-vec"] }
# Other
derive_more = "0.99.17"
structopt = "0.3.25"
anyhow = "1.0.66"
Expand All @@ -26,20 +22,31 @@ futures = "0.3.25"
jsonrpsee = { version ="0.16.2", features = ["client", "async-client", "macros"]}
num_enum = "0.5.9"

# Substrate
subxt = "0.27"
sp-core = { version = "16.0.0", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
serde = { version = "1.0", features = ["derive"] }
scale-info = { version = "2.0.0", features = ["bit-vec"] }


[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
sp-keyring = "6.0.0"
futures = "0.3.13"
hex-literal = "0.3.4"
test-case = "1.2.3"
log = "0.4.14"
pretty_env_logger = "0.4.0"
derive_more = "0.99.17"
serde_json = "1.0"

# Substrate
sp-keyring = "18.0.0"

[features]
default = ["api-dev"]
default = ["api-dev", "std"]
api-dev = []
api-main = []
std = [ "sp-core/std"]

[workspace]
2 changes: 1 addition & 1 deletion avail-subxt/build_api.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
cargo install --git https://github.com/fmiguelgarcia/subxt --branch cli_derives_for_type_2
cargo install --git https://github.com/paritytech/subxt --tag v0.27.1
subxt codegen \
--derive Clone \
--derive PartialEq \
Expand Down
8 changes: 3 additions & 5 deletions avail-subxt/examples/accounts_from_mnemonics.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use anyhow::Result;
use avail_subxt::{api, build_client, primitives::AvailExtrinsicParams, AvailConfig, Opts};
use sp_keyring::sr25519::sr25519;
use sp_core::crypto::Pair as _;
use sp_keyring::sr25519::sr25519::{self, Pair};
use structopt::StructOpt;
use subxt::{
ext::{sp_core::Pair, sp_runtime::MultiAddress},
tx::PairSigner,
};
use subxt::{tx::PairSigner, utils::MultiAddress};

/// This example demonstrates using mnemonic seed for generating signer pairs. It creates Alice and Bob
/// from seeds, but could also be used for an arbitrary account.
Expand Down
13 changes: 7 additions & 6 deletions avail-subxt/examples/da_bridge_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use avail_subxt::{
},
build_client, Opts,
};
use sp_keyring::AccountKeyring;
use sp_keyring::AccountKeyring::Alice;
use structopt::StructOpt;
use subxt::{
ext::sp_core::H160,
tx::{PairSigner, StaticTxPayload},
utils::H160,
};

const DESTINATION_DOMAIN: u32 = 1000;
Expand All @@ -27,11 +27,12 @@ async fn main() -> Result<()> {
let args = Opts::from_args();
let client = build_client(args.ws).await?;

let signer = PairSigner::new(AccountKeyring::Alice.pair());
let mut finalized_blocks = client.rpc().subscribe_finalized_blocks().await?;
let signer = PairSigner::new(Alice.pair());
let mut finalized_headers_subscription =
client.rpc().subscribe_finalized_block_headers().await?;

if let Some(finalized_block) = finalized_blocks.next().await {
let header = finalized_block?;
if let Some(header) = finalized_headers_subscription.next().await {
let header = header?;
if let Some(_block_hash) = client.rpc().block_hash(Some(header.number.into())).await? {
// 1. Send some data.
let block_hash = client
Expand Down
93 changes: 35 additions & 58 deletions avail-subxt/examples/democracy_external.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use anyhow::{ensure, Result};
use anyhow::{bail, ensure, Result};
use avail_subxt::{
api::{
self,
Expand All @@ -16,18 +16,19 @@ use avail_subxt::{
system::events as SystemEvent,
technical_committee::events as TechComEvent,
},
avail::{Bounded, Client, TxProgress},
build_client, tx_asend, tx_send, AvailConfig, Call, Opts,
avail::{Bounded, Client, PairSigner, TxProgress},
build_client, tx_asend, tx_send, Call, Opts,
};
use codec::Encode;
use derive_more::Constructor;
use futures::stream::{self, StreamExt as _, TryStreamExt as _};
use sp_keyring::AccountKeyring::{Alice, Bob, Charlie, Dave, Eve, Ferdie};
use structopt::StructOpt;
use subxt::{
ext::sp_core::{sr25519::Pair, Pair as _, H256},
tx::{PairSigner, Signer},
use sp_core::crypto::Pair as _;
use sp_keyring::{
sr25519::sr25519::Pair,
AccountKeyring::{Alice, Bob, Charlie, Dave, Eve, Ferdie},
};
use structopt::StructOpt;
use subxt::utils::H256;

#[rustfmt::skip]
pub mod constants {
Expand All @@ -45,11 +46,12 @@ pub struct IndexedProposalContext {
#[derive(Debug, Default, Constructor)]
pub struct ProposalContext {
hash: H256,
#[allow(dead_code)]
len: u32,
}

/// Builds a signer from `seed`.
fn signer_from_seed(seed: &str) -> PairSigner<AvailConfig, Pair> {
fn signer_from_seed(seed: &str) -> PairSigner {
let pair = Pair::from_string(&format!("//{}", seed), None).expect("Valid seed .qed");
PairSigner::new(pair)
}
Expand Down Expand Up @@ -102,7 +104,7 @@ mod council {

async fn vote_yes(
client: &Client,
signer: &(dyn Signer<AvailConfig> + Send + Sync),
signer: &PairSigner,
proposal: &IndexedProposalContext,
) -> Result<TxProgress> {
let vote = api::tx()
Expand Down Expand Up @@ -208,7 +210,7 @@ mod techies {

async fn vote_yes(
client: &Client,
signer: &(dyn Signer<AvailConfig> + Send + Sync),
signer: &PairSigner,
proposal: &IndexedProposalContext,
) -> Result<TxProgress> {
let vote = api::tx()
Expand Down Expand Up @@ -278,7 +280,6 @@ mod techies {

mod democracy {

use anyhow::anyhow;
use async_std::future;
use avail_subxt::{
avail::AVL,
Expand All @@ -305,13 +306,6 @@ mod democracy {
Ok(())
}

type EventFilter = (
SystemEvent::RemarkedByRoot,
DemocracyEvent::Passed,
SchedulerEvent::Scheduled,
SchedulerEvent::Dispatched,
);

pub async fn wait_passed_and_dispatch_or_timeout(
client: &Client,
referendum: u32,
Expand All @@ -326,49 +320,32 @@ mod democracy {
}

pub async fn wait_passed_and_dispatch(client: &Client, referendum: u32) -> Result<()> {
let mut events = client
.events()
.subscribe()
.await?
.filter_events::<EventFilter>();

loop {
let event = events
.next()
.await
.ok_or(anyhow!("Empty filtered event"))??
.event;
match event {
(Some(SystemEvent::RemarkedByRoot { hash }), ..) => {
log::info!("Remarked by Root with hash {}", hash);
let mut block_sub = client.blocks().subscribe_finalized().await?;

while let Some(block) = block_sub.next().await {
let events = block?.events().await?;

for event in events.iter() {
let event = event?;

if let Some(event) = event.as_event::<SystemEvent::RemarkedByRoot>()? {
log::info!("Remarked by Root with hash {}", event.hash);
return Ok(());
},
(None, Some(DemocracyEvent::Passed { ref_index }), ..) => {
log::trace!("Democracy Referendum {} passed", ref_index)
},
(None, None, Some(SchedulerEvent::Scheduled { when, index }), ..) => {
log::trace!("Referendum {} was scheduled on {}", index, when)
},
(
None,
None,
None,
Some(SchedulerEvent::Dispatched {
task,
id: _,
result,
}),
) => {
} else if let Some(event) = event.as_event::<DemocracyEvent::Passed>()? {
log::trace!("Democracy Referendum {} passed", event.ref_index);
} else if let Some(event) = event.as_event::<SchedulerEvent::Scheduled>()? {
log::trace!("Referendum {} was scheduled on {}", event.index, event.when);
} else if let Some(event) = event.as_event::<SchedulerEvent::Dispatched>()? {
log::trace!(
"Referendum {} was dispatched at {}: {:?}",
referendum,
task.0,
result
)
},
_ => {},
"Referendum {referendum} was dispatched at {}: {:?}",
event.task.0,
event.result
);
}
}
}

bail!("Block subscription fails")
}
}

Expand Down
2 changes: 1 addition & 1 deletion avail-subxt/examples/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use avail_subxt::{build_client, Opts};
use futures::future::{join_all, TryFutureExt};
use structopt::StructOpt;
use subxt::{ext::sp_runtime::traits::Header as XtHeader, rpc::BlockNumber};
use subxt::{config::Header as XtHeader, rpc::types::BlockNumber};

/// This example gets all the headers from testnet. It requests them in concurrently in batches of BATCH_NUM.
/// Fetching headers one by one is too slow for a large number of blocks.
Expand Down
8 changes: 7 additions & 1 deletion avail-subxt/examples/submit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use avail_subxt::{
da_control::pallet::Call as DaCall, sp_core::bounded::bounded_vec::BoundedVec,
},
},
avail::AppUncheckedExtrinsic,
build_client,
primitives::AvailExtrinsicParams,
Call, Opts,
Expand Down Expand Up @@ -42,7 +43,12 @@ async fn main() -> Result<()> {
.block
.extrinsics
.into_iter()
.find(|ext| match &ext.function {
.filter_map(|chain_block_ext| {
AppUncheckedExtrinsic::try_from(chain_block_ext)
.map(|ext| ext.function)
.ok()
})
.find(|call| match call {
Call::DataAvailability(da_call) => match da_call {
DaCall::submit_data { data } => data.0 == example_data,
_ => false,
Expand Down
2 changes: 1 addition & 1 deletion avail-subxt/examples/submit_data_and_dispatch_data_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use avail_subxt::{
};
use sp_keyring::AccountKeyring;
use structopt::StructOpt;
use subxt::{ext::sp_core::H160, tx::PairSigner};
use subxt::{tx::PairSigner, utils::H160};

const DESTINATION_DOMAIN: u32 = 1000;
const DA_BRIDGE_ROUTER_ADDRESS: &str = "0x3f28a3e66326c3aa494d4f8e9477d1397ee94432";
Expand Down
Loading

0 comments on commit 65138fe

Please sign in to comment.