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,44 @@
|
||||
[package]
|
||||
name = "pezsc-sync-state-rpc"
|
||||
version = "0.34.0"
|
||||
authors.workspace = true
|
||||
description = "A RPC handler to create sync states for light clients."
|
||||
edition.workspace = true
|
||||
license = "Apache-2.0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { workspace = true, default-features = true }
|
||||
jsonrpsee = { features = [
|
||||
"client-core",
|
||||
"macros",
|
||||
"server-core",
|
||||
], workspace = true }
|
||||
pezsc-chain-spec = { workspace = true, default-features = true }
|
||||
pezsc-client-api = { workspace = true, default-features = true }
|
||||
pezsc-consensus-babe = { workspace = true, default-features = true }
|
||||
pezsc-consensus-epochs = { workspace = true, default-features = true }
|
||||
pezsc-consensus-grandpa = { workspace = true, default-features = true }
|
||||
serde = { features = ["derive"], workspace = true, default-features = true }
|
||||
serde_json = { workspace = true, default-features = true }
|
||||
pezsp-blockchain = { workspace = true, default-features = true }
|
||||
pezsp-runtime = { workspace = true, default-features = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[features]
|
||||
runtime-benchmarks = [
|
||||
"pezsc-chain-spec/runtime-benchmarks",
|
||||
"pezsc-client-api/runtime-benchmarks",
|
||||
"pezsc-consensus-babe/runtime-benchmarks",
|
||||
"pezsc-consensus-epochs/runtime-benchmarks",
|
||||
"pezsc-consensus-grandpa/runtime-benchmarks",
|
||||
"pezsp-blockchain/runtime-benchmarks",
|
||||
"pezsp-runtime/runtime-benchmarks",
|
||||
]
|
||||
@@ -0,0 +1,211 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! A RPC handler to create sync states for light clients.
|
||||
//!
|
||||
//! Currently only usable with BABE + GRANDPA.
|
||||
//!
|
||||
//! # Usage
|
||||
//!
|
||||
//! To use the light sync state, it needs to be added as an extension to the chain spec:
|
||||
//!
|
||||
//! ```
|
||||
//! use pezsc_sync_state_rpc::LightSyncStateExtension;
|
||||
//!
|
||||
//! #[derive(Default, Clone, serde::Serialize, serde::Deserialize, pezsc_chain_spec::ChainSpecExtension)]
|
||||
//! #[serde(rename_all = "camelCase")]
|
||||
//! pub struct Extensions {
|
||||
//! light_sync_state: LightSyncStateExtension,
|
||||
//! }
|
||||
//!
|
||||
//! type ChainSpec = pezsc_chain_spec::GenericChainSpec<(), Extensions>;
|
||||
//! ```
|
||||
//!
|
||||
//! If the [`LightSyncStateExtension`] is not added as an extension to the chain spec,
|
||||
//! the [`SyncState`] will fail at instantiation.
|
||||
|
||||
#![deny(unused_crate_dependencies)]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use jsonrpsee::{
|
||||
core::async_trait,
|
||||
proc_macros::rpc,
|
||||
types::{ErrorObject, ErrorObjectOwned},
|
||||
};
|
||||
|
||||
use pezsc_client_api::StorageData;
|
||||
use pezsc_consensus_babe::{BabeWorkerHandle, Error as BabeError};
|
||||
use pezsp_blockchain::HeaderBackend;
|
||||
use pezsp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
|
||||
type SharedAuthoritySet<TBl> =
|
||||
pezsc_consensus_grandpa::SharedAuthoritySet<<TBl as BlockT>::Hash, NumberFor<TBl>>;
|
||||
|
||||
/// Error type used by this crate.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum Error<Block: BlockT> {
|
||||
#[error(transparent)]
|
||||
Blockchain(#[from] pezsp_blockchain::Error),
|
||||
|
||||
#[error("Failed to load the block weight for block {0:?}")]
|
||||
LoadingBlockWeightFailed(Block::Hash),
|
||||
|
||||
#[error("Failed to load the BABE epoch data: {0}")]
|
||||
LoadingEpochDataFailed(BabeError<Block>),
|
||||
|
||||
#[error("JsonRpc error: {0}")]
|
||||
JsonRpc(String),
|
||||
|
||||
#[error(
|
||||
"The light sync state extension is not provided by the chain spec. \
|
||||
Read the `sc-sync-state-rpc` crate docs on how to do this!"
|
||||
)]
|
||||
LightSyncStateExtensionNotFound,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> From<Error<Block>> for ErrorObjectOwned {
|
||||
fn from(error: Error<Block>) -> Self {
|
||||
let message = match error {
|
||||
Error::JsonRpc(s) => s,
|
||||
_ => error.to_string(),
|
||||
};
|
||||
ErrorObject::owned(1, message, None::<()>)
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize the given `val` by encoding it with SCALE codec and serializing it as hex.
|
||||
fn serialize_encoded<S: serde::Serializer, T: codec::Encode>(
|
||||
val: &T,
|
||||
s: S,
|
||||
) -> Result<S::Ok, S::Error> {
|
||||
let encoded = StorageData(val.encode());
|
||||
serde::Serialize::serialize(&encoded, s)
|
||||
}
|
||||
|
||||
/// The light sync state extension.
|
||||
///
|
||||
/// This represents a JSON serialized [`LightSyncState`]. It is required to be added to the
|
||||
/// chain-spec as an extension.
|
||||
pub type LightSyncStateExtension = Option<serde_json::Value>;
|
||||
|
||||
/// Hardcoded information that allows light clients to sync quickly.
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct LightSyncState<Block: BlockT> {
|
||||
/// The header of the best finalized block.
|
||||
#[serde(serialize_with = "serialize_encoded")]
|
||||
pub finalized_block_header: <Block as BlockT>::Header,
|
||||
/// The epoch changes tree for babe.
|
||||
#[serde(serialize_with = "serialize_encoded")]
|
||||
pub babe_epoch_changes: pezsc_consensus_epochs::EpochChangesFor<Block, pezsc_consensus_babe::Epoch>,
|
||||
/// The babe weight of the finalized block.
|
||||
pub babe_finalized_block_weight: pezsc_consensus_babe::BabeBlockWeight,
|
||||
/// The authority set for grandpa.
|
||||
#[serde(serialize_with = "serialize_encoded")]
|
||||
pub grandpa_authority_set:
|
||||
pezsc_consensus_grandpa::AuthoritySet<<Block as BlockT>::Hash, NumberFor<Block>>,
|
||||
}
|
||||
|
||||
/// An api for sync state RPC calls.
|
||||
#[rpc(client, server)]
|
||||
pub trait SyncStateApi<B: BlockT> {
|
||||
/// Returns the JSON serialized chainspec running the node, with a sync state.
|
||||
#[method(name = "sync_state_genSyncSpec")]
|
||||
async fn system_gen_sync_spec(&self, raw: bool) -> Result<serde_json::Value, Error<B>>;
|
||||
}
|
||||
|
||||
/// An api for sync state RPC calls.
|
||||
pub struct SyncState<Block: BlockT, Client> {
|
||||
chain_spec: Box<dyn pezsc_chain_spec::ChainSpec>,
|
||||
client: Arc<Client>,
|
||||
shared_authority_set: SharedAuthoritySet<Block>,
|
||||
babe_worker_handle: BabeWorkerHandle<Block>,
|
||||
}
|
||||
|
||||
impl<Block, Client> SyncState<Block, Client>
|
||||
where
|
||||
Block: BlockT,
|
||||
Client: HeaderBackend<Block> + pezsc_client_api::AuxStore + 'static,
|
||||
{
|
||||
/// Create a new sync state RPC helper.
|
||||
pub fn new(
|
||||
chain_spec: Box<dyn pezsc_chain_spec::ChainSpec>,
|
||||
client: Arc<Client>,
|
||||
shared_authority_set: SharedAuthoritySet<Block>,
|
||||
babe_worker_handle: BabeWorkerHandle<Block>,
|
||||
) -> Result<Self, Error<Block>> {
|
||||
if pezsc_chain_spec::get_extension::<LightSyncStateExtension>(chain_spec.extensions())
|
||||
.is_some()
|
||||
{
|
||||
Ok(Self { chain_spec, client, shared_authority_set, babe_worker_handle })
|
||||
} else {
|
||||
Err(Error::<Block>::LightSyncStateExtensionNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
async fn build_sync_state(&self) -> Result<LightSyncState<Block>, Error<Block>> {
|
||||
let epoch_changes = self
|
||||
.babe_worker_handle
|
||||
.epoch_data()
|
||||
.await
|
||||
.map_err(Error::LoadingEpochDataFailed)?;
|
||||
|
||||
let finalized_hash = self.client.info().finalized_hash;
|
||||
let finalized_header = self
|
||||
.client
|
||||
.header(finalized_hash)?
|
||||
.ok_or_else(|| pezsp_blockchain::Error::MissingHeader(finalized_hash.to_string()))?;
|
||||
|
||||
let finalized_block_weight =
|
||||
pezsc_consensus_babe::aux_schema::load_block_weight(&*self.client, finalized_hash)?
|
||||
.ok_or(Error::LoadingBlockWeightFailed(finalized_hash))?;
|
||||
|
||||
Ok(LightSyncState {
|
||||
finalized_block_header: finalized_header,
|
||||
babe_epoch_changes: epoch_changes,
|
||||
babe_finalized_block_weight: finalized_block_weight,
|
||||
grandpa_authority_set: self.shared_authority_set.clone_inner(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<Block, Backend> SyncStateApiServer<Block> for SyncState<Block, Backend>
|
||||
where
|
||||
Block: BlockT,
|
||||
Backend: HeaderBackend<Block> + pezsc_client_api::AuxStore + 'static,
|
||||
{
|
||||
async fn system_gen_sync_spec(&self, raw: bool) -> Result<serde_json::Value, Error<Block>> {
|
||||
let current_sync_state = self.build_sync_state().await?;
|
||||
let mut chain_spec = self.chain_spec.cloned_box();
|
||||
|
||||
let extension = pezsc_chain_spec::get_extension_mut::<LightSyncStateExtension>(
|
||||
chain_spec.extensions_mut(),
|
||||
)
|
||||
.ok_or(Error::<Block>::LightSyncStateExtensionNotFound)?;
|
||||
|
||||
let val = serde_json::to_value(¤t_sync_state)
|
||||
.map_err(|e| Error::<Block>::JsonRpc(e.to_string()))?;
|
||||
*extension = Some(val);
|
||||
|
||||
let json_str = chain_spec.as_json(raw).map_err(|e| Error::<Block>::JsonRpc(e))?;
|
||||
serde_json::from_str(&json_str).map_err(|e| Error::<Block>::JsonRpc(e.to_string()))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user