feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
[package]
|
||||
name = "pezsc-informant"
|
||||
version = "0.33.0"
|
||||
authors.workspace = true
|
||||
description = "Bizinikiwi informant."
|
||||
edition.workspace = true
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
readme = "README.md"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
console = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
futures-timer = { workspace = true }
|
||||
log = { workspace = true, default-features = true }
|
||||
pezsc-client-api = { workspace = true, default-features = true }
|
||||
pezsc-network = { workspace = true, default-features = true }
|
||||
pezsc-network-sync = { workspace = true, default-features = true }
|
||||
pezsp-blockchain = { workspace = true, default-features = true }
|
||||
pezsp-runtime = { workspace = true, default-features = true }
|
||||
|
||||
[features]
|
||||
runtime-benchmarks = [
|
||||
"pezsc-client-api/runtime-benchmarks",
|
||||
"pezsc-network-sync/runtime-benchmarks",
|
||||
"pezsc-network/runtime-benchmarks",
|
||||
"pezsp-blockchain/runtime-benchmarks",
|
||||
"pezsp-runtime/runtime-benchmarks",
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
Console informant. Prints sync progress and block events. Runs on the calling thread.
|
||||
|
||||
License: GPL-3.0-or-later WITH Classpath-exception-2.0
|
||||
@@ -0,0 +1,219 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
||||
|
||||
// This program 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.
|
||||
|
||||
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use console::style;
|
||||
use log::info;
|
||||
use pezsc_client_api::ClientInfo;
|
||||
use pezsc_network::NetworkStatus;
|
||||
use pezsc_network_sync::{SyncState, SyncStatus, WarpSyncPhase, WarpSyncProgress};
|
||||
use pezsp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Saturating, Zero};
|
||||
use std::{fmt, time::Instant};
|
||||
|
||||
use crate::PrintFullHashOnDebugLogging;
|
||||
|
||||
/// State of the informant display system.
|
||||
///
|
||||
/// This is the system that handles the line that gets regularly printed and that looks something
|
||||
/// like:
|
||||
///
|
||||
/// > Syncing 5.4 bps, target=#531028 (4 peers), best: #90683 (0x4ca8…51b8),
|
||||
/// > finalized #360 (0x6f24…a38b), ⬇ 5.5kiB/s ⬆ 0.9kiB/s
|
||||
///
|
||||
/// # Usage
|
||||
///
|
||||
/// Call `InformantDisplay::new` to initialize the state, then regularly call `display` with the
|
||||
/// information to display.
|
||||
pub struct InformantDisplay<B: BlockT> {
|
||||
/// Head of chain block number from the last time `display` has been called.
|
||||
/// `None` if `display` has never been called.
|
||||
last_number: Option<NumberFor<B>>,
|
||||
/// The last time `display` or `new` has been called.
|
||||
last_update: Instant,
|
||||
/// The last seen total of bytes received.
|
||||
last_total_bytes_inbound: u64,
|
||||
/// The last seen total of bytes sent.
|
||||
last_total_bytes_outbound: u64,
|
||||
}
|
||||
|
||||
impl<B: BlockT> InformantDisplay<B> {
|
||||
/// Builds a new informant display system.
|
||||
pub fn new() -> InformantDisplay<B> {
|
||||
InformantDisplay {
|
||||
last_number: None,
|
||||
last_update: Instant::now(),
|
||||
last_total_bytes_inbound: 0,
|
||||
last_total_bytes_outbound: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Displays the informant by calling `info!`.
|
||||
pub fn display(
|
||||
&mut self,
|
||||
info: &ClientInfo<B>,
|
||||
net_status: NetworkStatus,
|
||||
sync_status: SyncStatus<B>,
|
||||
num_connected_peers: usize,
|
||||
) {
|
||||
let best_number = info.chain.best_number;
|
||||
let best_hash = info.chain.best_hash;
|
||||
let finalized_number = info.chain.finalized_number;
|
||||
let speed = speed::<B>(best_number, self.last_number, self.last_update);
|
||||
let total_bytes_inbound = net_status.total_bytes_inbound;
|
||||
let total_bytes_outbound = net_status.total_bytes_outbound;
|
||||
|
||||
let now = Instant::now();
|
||||
let elapsed = (now - self.last_update).as_secs();
|
||||
self.last_update = now;
|
||||
self.last_number = Some(best_number);
|
||||
|
||||
let diff_bytes_inbound = total_bytes_inbound - self.last_total_bytes_inbound;
|
||||
let diff_bytes_outbound = total_bytes_outbound - self.last_total_bytes_outbound;
|
||||
let (avg_bytes_per_sec_inbound, avg_bytes_per_sec_outbound) = if elapsed > 0 {
|
||||
self.last_total_bytes_inbound = total_bytes_inbound;
|
||||
self.last_total_bytes_outbound = total_bytes_outbound;
|
||||
(diff_bytes_inbound / elapsed, diff_bytes_outbound / elapsed)
|
||||
} else {
|
||||
(diff_bytes_inbound, diff_bytes_outbound)
|
||||
};
|
||||
|
||||
let (level, status, target) =
|
||||
match (sync_status.state, sync_status.state_sync, sync_status.warp_sync) {
|
||||
// Do not set status to "Block history" when we are doing a major sync.
|
||||
//
|
||||
// A node could for example have been warp synced to the tip of the chain and
|
||||
// shutdown. At the next start we still need to download the block history, but
|
||||
// first will sync to the tip of the chain.
|
||||
(
|
||||
sync_status,
|
||||
_,
|
||||
Some(WarpSyncProgress { phase: WarpSyncPhase::DownloadingBlocks(n), .. }),
|
||||
) if !sync_status.is_major_syncing() => ("⏩", "Block history".into(), format!(", #{}", n)),
|
||||
// Handle all phases besides the two phases we already handle above.
|
||||
(_, _, Some(warp))
|
||||
if !matches!(warp.phase, WarpSyncPhase::DownloadingBlocks(_)) =>
|
||||
(
|
||||
"⏩",
|
||||
"Warping".into(),
|
||||
format!(
|
||||
", {}, {:.2} Mib",
|
||||
warp.phase,
|
||||
(warp.total_bytes as f32) / (1024f32 * 1024f32)
|
||||
),
|
||||
),
|
||||
(_, Some(state), _) => (
|
||||
"⚙️ ",
|
||||
"State sync".into(),
|
||||
format!(
|
||||
", {}, {}%, {:.2} Mib",
|
||||
state.phase,
|
||||
state.percentage,
|
||||
(state.size as f32) / (1024f32 * 1024f32)
|
||||
),
|
||||
),
|
||||
(SyncState::Idle, _, _) => ("💤", "Idle".into(), "".into()),
|
||||
(SyncState::Downloading { target }, _, _) =>
|
||||
("⚙️ ", format!("Syncing{}", speed), format!(", target=#{target}")),
|
||||
(SyncState::Importing { target }, _, _) =>
|
||||
("⚙️ ", format!("Preparing{}", speed), format!(", target=#{target}")),
|
||||
};
|
||||
|
||||
info!(
|
||||
target: "bizinikiwi",
|
||||
"{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}",
|
||||
level,
|
||||
style(&status).white().bold(),
|
||||
target,
|
||||
style(num_connected_peers).white().bold(),
|
||||
style(best_number).white().bold(),
|
||||
PrintFullHashOnDebugLogging(&best_hash),
|
||||
style(finalized_number).white().bold(),
|
||||
PrintFullHashOnDebugLogging(&info.chain.finalized_hash),
|
||||
style(TransferRateFormat(avg_bytes_per_sec_inbound)).green(),
|
||||
style(TransferRateFormat(avg_bytes_per_sec_outbound)).red(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates `(best_number - last_number) / (now - last_update)` and returns a `String`
|
||||
/// representing the speed of import.
|
||||
fn speed<B: BlockT>(
|
||||
best_number: NumberFor<B>,
|
||||
last_number: Option<NumberFor<B>>,
|
||||
last_update: Instant,
|
||||
) -> String {
|
||||
// Number of milliseconds elapsed since last time.
|
||||
let elapsed_ms = {
|
||||
let elapsed = last_update.elapsed();
|
||||
let since_last_millis = elapsed.as_secs() * 1000;
|
||||
let since_last_subsec_millis = elapsed.subsec_millis() as u64;
|
||||
since_last_millis + since_last_subsec_millis
|
||||
};
|
||||
|
||||
// Number of blocks that have been imported since last time.
|
||||
let diff = match last_number {
|
||||
None => return String::new(),
|
||||
Some(n) => best_number.saturating_sub(n),
|
||||
};
|
||||
|
||||
if let Ok(diff) = TryInto::<u128>::try_into(diff) {
|
||||
// If the number of blocks can be converted to a regular integer, then it's easy: just
|
||||
// do the math and turn it into a `f64`.
|
||||
let speed = diff
|
||||
.saturating_mul(10_000)
|
||||
.checked_div(u128::from(elapsed_ms))
|
||||
.map_or(0.0, |s| s as f64) /
|
||||
10.0;
|
||||
format!(" {:4.1} bps", speed)
|
||||
} else {
|
||||
// If the number of blocks can't be converted to a regular integer, then we need a more
|
||||
// algebraic approach and we stay within the realm of integers.
|
||||
let one_thousand = NumberFor::<B>::from(1_000u32);
|
||||
let elapsed =
|
||||
NumberFor::<B>::from(<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::MAX));
|
||||
|
||||
let speed = diff
|
||||
.saturating_mul(one_thousand)
|
||||
.checked_div(&elapsed)
|
||||
.unwrap_or_else(Zero::zero);
|
||||
format!(" {} bps", speed)
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains a number of bytes per second. Implements `fmt::Display` and shows this number of bytes
|
||||
/// per second in a nice way.
|
||||
struct TransferRateFormat(u64);
|
||||
impl fmt::Display for TransferRateFormat {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// Special case 0.
|
||||
if self.0 == 0 {
|
||||
return write!(f, "0");
|
||||
}
|
||||
|
||||
// Under 0.1 kiB, display plain bytes.
|
||||
if self.0 < 100 {
|
||||
return write!(f, "{} B/s", self.0);
|
||||
}
|
||||
|
||||
// Under 1.0 MiB/sec, display the value in kiB/sec.
|
||||
if self.0 < 1024 * 1024 {
|
||||
return write!(f, "{:.1}kiB/s", self.0 as f64 / 1024.0);
|
||||
}
|
||||
|
||||
write!(f, "{:.1}MiB/s", self.0 as f64 / (1024.0 * 1024.0))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
||||
|
||||
// This program 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.
|
||||
|
||||
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
//! Console informant. Prints sync progress and block events. Runs on the calling thread.
|
||||
|
||||
use console::style;
|
||||
use futures::prelude::*;
|
||||
use futures_timer::Delay;
|
||||
use log::{debug, info, log_enabled, trace};
|
||||
use pezsc_client_api::{BlockchainEvents, UsageProvider};
|
||||
use pezsc_network::NetworkStatusProvider;
|
||||
use pezsc_network_sync::{SyncStatusProvider, SyncingService};
|
||||
use pezsp_blockchain::HeaderMetadata;
|
||||
use pezsp_runtime::traits::{Block as BlockT, Header};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
fmt::{Debug, Display},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
mod display;
|
||||
|
||||
/// Creates a stream that returns a new value every `duration`.
|
||||
fn interval(duration: Duration) -> impl Stream<Item = ()> + Unpin {
|
||||
futures::stream::unfold((), move |_| Delay::new(duration).map(|_| Some(((), ())))).map(drop)
|
||||
}
|
||||
|
||||
/// Builds the informant and returns a `Future` that drives the informant.
|
||||
pub async fn build<B: BlockT, C, N>(client: Arc<C>, network: N, syncing: Arc<SyncingService<B>>)
|
||||
where
|
||||
N: NetworkStatusProvider,
|
||||
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
|
||||
<C as HeaderMetadata<B>>::Error: Display,
|
||||
{
|
||||
let mut display = display::InformantDisplay::new();
|
||||
|
||||
let client_1 = client.clone();
|
||||
|
||||
let display_notifications = interval(Duration::from_millis(5000))
|
||||
.filter_map(|_| async {
|
||||
let net_status = network.status().await;
|
||||
let sync_status = syncing.status().await;
|
||||
let num_connected_peers = syncing.num_connected_peers();
|
||||
|
||||
match (net_status, sync_status) {
|
||||
(Ok(net), Ok(sync)) => Some((net, sync, num_connected_peers)),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.for_each(move |(net_status, sync_status, num_connected_peers)| {
|
||||
let info = client_1.usage_info();
|
||||
if let Some(ref usage) = info.usage {
|
||||
trace!(target: "usage", "Usage statistics: {}", usage);
|
||||
} else {
|
||||
trace!(
|
||||
target: "usage",
|
||||
"Usage statistics not displayed as backend does not provide it",
|
||||
)
|
||||
}
|
||||
display.display(&info, net_status, sync_status, num_connected_peers);
|
||||
future::ready(())
|
||||
});
|
||||
|
||||
futures::select! {
|
||||
() = display_notifications.fuse() => (),
|
||||
() = display_block_import(client).fuse() => (),
|
||||
};
|
||||
}
|
||||
|
||||
/// Print the full hash when debug logging is enabled.
|
||||
struct PrintFullHashOnDebugLogging<'a, H>(&'a H);
|
||||
|
||||
impl<H: Debug + Display> Display for PrintFullHashOnDebugLogging<'_, H> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if log_enabled!(log::Level::Debug) {
|
||||
Debug::fmt(&self.0, f)
|
||||
} else {
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn display_block_import<B: BlockT, C>(client: Arc<C>)
|
||||
where
|
||||
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
|
||||
<C as HeaderMetadata<B>>::Error: Display,
|
||||
{
|
||||
let mut last_best = {
|
||||
let info = client.usage_info();
|
||||
Some((info.chain.best_number, info.chain.best_hash))
|
||||
};
|
||||
|
||||
// Hashes of the last blocks we have seen at import.
|
||||
let mut last_blocks = VecDeque::new();
|
||||
let max_blocks_to_track = 100;
|
||||
let mut notifications = client.import_notification_stream();
|
||||
|
||||
while let Some(n) = notifications.next().await {
|
||||
// detect and log reorganizations.
|
||||
if let Some((ref last_num, ref last_hash)) = last_best {
|
||||
if n.header.parent_hash() != last_hash && n.is_new_best {
|
||||
let maybe_ancestor =
|
||||
pezsp_blockchain::lowest_common_ancestor(&*client, *last_hash, n.hash);
|
||||
|
||||
match maybe_ancestor {
|
||||
Ok(ref ancestor) if ancestor.hash != *last_hash => info!(
|
||||
"♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}",
|
||||
style(last_num).red().bold(),
|
||||
PrintFullHashOnDebugLogging(&last_hash),
|
||||
style(n.header.number()).green().bold(),
|
||||
PrintFullHashOnDebugLogging(&n.hash),
|
||||
style(ancestor.number).white().bold(),
|
||||
ancestor.hash,
|
||||
),
|
||||
Ok(_) => {},
|
||||
Err(e) => debug!("Error computing tree route: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if n.is_new_best {
|
||||
last_best = Some((*n.header.number(), n.hash));
|
||||
}
|
||||
|
||||
// If we already printed a message for a given block recently,
|
||||
// we should not print it again.
|
||||
if !last_blocks.contains(&n.hash) {
|
||||
last_blocks.push_back(n.hash);
|
||||
|
||||
if last_blocks.len() > max_blocks_to_track {
|
||||
last_blocks.pop_front();
|
||||
}
|
||||
|
||||
let best_indicator = if n.is_new_best { "🏆" } else { "🆕" };
|
||||
info!(
|
||||
target: "bizinikiwi",
|
||||
"{best_indicator} Imported #{} ({} → {})",
|
||||
style(n.header.number()).white().bold(),
|
||||
PrintFullHashOnDebugLogging(n.header.parent_hash()),
|
||||
PrintFullHashOnDebugLogging(&n.hash),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user