mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-26 14:37:55 +00:00
Rebrand: polkadot → pezkuwi build fixes
- Fixed TypeScript type assertion issues - Updated imports from api-augment/substrate to api-augment/bizinikiwi - Fixed imgConvert.mjs header and imports - Added @ts-expect-error for runtime-converted types - Fixed all @polkadot copyright headers to @pezkuwi
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! # State Transition Function
|
||||
//!
|
||||
//! This document briefly explains how in the context of Substrate-based blockchains, we view the
|
||||
//! This document briefly explains how in the context of Bizinikiwi-based blockchains, we view the
|
||||
//! blockchain as a **decentralized state transition function**.
|
||||
//!
|
||||
//! Recall that a blockchain's main purpose is to help a permissionless set of entities to agree on
|
||||
@@ -14,7 +14,7 @@
|
||||
//! function*.
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/stf_simple.mmd")]
|
||||
//!
|
||||
//! In Substrate-based blockchains, the state transition function is called the *Runtime*. This is
|
||||
//! In Bizinikiwi-based blockchains, the state transition function is called the *Runtime*. This is
|
||||
//! explained further in [`crate::reference_docs::wasm_meta_protocol`].
|
||||
//!
|
||||
//! With this in mind, we can paint a complete picture of a blockchain as a state machine:
|
||||
|
||||
@@ -10,52 +10,54 @@
|
||||
//! interact with the runtime in order to build the genesis state.
|
||||
//!
|
||||
//! For more information on chain specification and its properties, refer to
|
||||
//! [`sc_chain_spec#from-initial-state-to-raw-genesis`].
|
||||
//! [`pezsc_chain_spec#from-initial-state-to-raw-genesis`].
|
||||
//!
|
||||
//! The initial genesis state can be provided in the following formats:
|
||||
//! - full
|
||||
//! - patch
|
||||
//! - raw
|
||||
//!
|
||||
//! Each of the formats is explained in [_chain-spec-format_][`sc_chain_spec#chain-spec-formats`].
|
||||
//! Each of the formats is explained in
|
||||
//! [_chain-spec-format_][`pezsc_chain_spec#chain-spec-formats`].
|
||||
//!
|
||||
//!
|
||||
//! # `GenesisConfig` for `pallet`
|
||||
//! # `GenesisConfig` for `pezpallet`
|
||||
//!
|
||||
//! Every frame pallet may have its initial state which is defined by the `GenesisConfig` internal
|
||||
//! struct. It is a regular Rust struct, annotated with the [`pallet::genesis_config`] attribute.
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pallet_bar_GenesisConfig)]
|
||||
//! Every frame pezpallet may have its initial state which is defined by the `GenesisConfig`
|
||||
//! internal struct. It is a regular Rust struct, annotated with the [`pezpallet::genesis_config`]
|
||||
//! attribute.
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pezpallet_bar_GenesisConfig)]
|
||||
//!
|
||||
//! The struct shall be defined within the pallet `mod`, as in the following code:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pallet_bar)]
|
||||
//! The struct shall be defined within the pezpallet `mod`, as in the following code:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pezpallet_bar)]
|
||||
//!
|
||||
//! The initial state conveyed in the `GenesisConfig` struct is transformed into state storage
|
||||
//! items by means of the [`BuildGenesisConfig`] trait, which shall be implemented for the pallet's
|
||||
//! `GenesisConfig` struct. The [`pallet::genesis_build`] attribute shall be attached to the `impl`
|
||||
//! block:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pallet_bar_build)]
|
||||
//! items by means of the [`BuildGenesisConfig`] trait, which shall be implemented for the
|
||||
//! pezpallet's `GenesisConfig` struct. The [`pezpallet::genesis_build`] attribute shall be attached
|
||||
//! to the `impl` block:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pezpallet_bar_build)]
|
||||
//!
|
||||
//! `GenesisConfig` may also contain more complicated types, including nested structs or enums, as
|
||||
//! in the example for `pallet_foo`:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pallet_foo_GenesisConfig)]
|
||||
//! in the example for `pezpallet_foo`:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pezpallet_foo_GenesisConfig)]
|
||||
//!
|
||||
//! Note that [`serde`] attributes can be used to control how the data
|
||||
//! structures are stored into JSON. In the following example, the [`sp_core::bytes`] function is
|
||||
//! structures are stored into JSON. In the following example, the [`pezsp_core::bytes`] function is
|
||||
//! used to serialize the `values` field.
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", SomeFooData2)]
|
||||
//!
|
||||
//! Please note that fields of `GenesisConfig` may not be directly mapped to storage items. In the
|
||||
//! following example, the initial struct fields are used to compute (sum) the value that will be
|
||||
//! stored in the state as `ProcessedEnumValue`:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pallet_foo_build)]
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/pallets.rs", pezpallet_foo_build)]
|
||||
//!
|
||||
//! # `GenesisConfig` for `runtimes`
|
||||
//!
|
||||
//! The runtime genesis config struct consists of configs for every pallet. For the [_demonstration
|
||||
//! runtime_][`chain_spec_guide_runtime`] used in this guide, it consists of `SystemConfig`,
|
||||
//! `BarConfig`, and `FooConfig`. This structure was automatically generated by a macro and it can
|
||||
//! be sneak-peeked here: [`RuntimeGenesisConfig`]. For further reading on generated runtime
|
||||
//! types, refer to [`frame_runtime_types`].
|
||||
//! The runtime genesis config struct consists of configs for every pezpallet. For the
|
||||
//! [_demonstration runtime_][`pez_chain_spec_guide_runtime`] used in this guide, it consists of
|
||||
//! `SystemConfig`, `BarConfig`, and `FooConfig`. This structure was automatically generated by a
|
||||
//! macro and it can be sneak-peeked here: [`RuntimeGenesisConfig`]. For further reading on
|
||||
//! generated runtime types, refer to [`frame_runtime_types`].
|
||||
//!
|
||||
//! The macro automatically adds an attribute that renames all the fields to [`camelCase`]. It is a
|
||||
//! good practice to add it to nested structures too, to have the naming of the JSON keys consistent
|
||||
@@ -80,16 +82,16 @@
|
||||
//! ## Implementing `GenesisBuilder` for runtime
|
||||
//!
|
||||
//! The runtime exposes a dedicated runtime API for interacting with its genesis config:
|
||||
//! [`sp_genesis_builder::GenesisBuilder`]. The implementation shall be provided within
|
||||
//! the [`sp_api::impl_runtime_apis`] macro, typically making use of some helpers provided:
|
||||
//! [`pezsp_genesis_builder::GenesisBuilder`]. The implementation shall be provided within
|
||||
//! the [`pezsp_api::impl_runtime_apis`] macro, typically making use of some helpers provided:
|
||||
//! [`build_state`], [`get_preset`].
|
||||
//! A typical implementation of [`sp_genesis_builder::GenesisBuilder`] looks as follows:
|
||||
//! A typical implementation of [`pezsp_genesis_builder::GenesisBuilder`] looks as follows:
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/runtime.rs", runtime_impl)]
|
||||
//!
|
||||
//! Please note that two functions are customized: `preset_names` and `get_preset`. The first one
|
||||
//! just provides a `Vec` of the names of supported presets, while the latter delegates the call
|
||||
//! to a function that maps the name to an actual preset:
|
||||
//! [`chain_spec_guide_runtime::presets::get_builtin_preset`]
|
||||
//! [`pez_chain_spec_guide_runtime::presets::get_builtin_preset`]
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/src/presets.rs", get_builtin_preset)]
|
||||
//!
|
||||
//! ## Genesis state presets for runtime
|
||||
@@ -150,27 +152,27 @@
|
||||
//! recommended for production chains.
|
||||
//!
|
||||
//! For a detailed description of how the raw format is built, please refer to
|
||||
//! [_chain-spec-raw-genesis_][`sc_chain_spec#from-initial-state-to-raw-genesis`]. Plain and
|
||||
//! [_chain-spec-raw-genesis_][`pezsc_chain_spec#from-initial-state-to-raw-genesis`]. Plain and
|
||||
//! corresponding raw examples of chain-spec are given in
|
||||
//! [_chain-spec-examples_][`sc_chain_spec#json-chain-specification-example`].
|
||||
//! [_chain-spec-examples_][`pezsc_chain_spec#json-chain-specification-example`].
|
||||
//! The [`chain_spec_builder`] util supports building the raw storage.
|
||||
//!
|
||||
//! # Interacting with the tool
|
||||
//!
|
||||
//! The [`chain_spec_builder`] util allows interaction with the runtime in order to list or display
|
||||
//! presets and build the chain specification file. It is possible to use the tool with the
|
||||
//! [_demonstration runtime_][`chain_spec_guide_runtime`]. To build the required packages, just run
|
||||
//! the following command:
|
||||
//! [_demonstration runtime_][`pez_chain_spec_guide_runtime`]. To build the required packages, just
|
||||
//! run the following command:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! cargo build -p staging-chain-spec-builder -p chain-spec-guide-runtime --release
|
||||
//! cargo build -p pezstaging-chain-spec-builder -p pez-chain-spec-guide-runtime --release
|
||||
//! ```
|
||||
//!
|
||||
//! The `chain-spec-builder` util can also be installed with `cargo install`:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! cargo install staging-chain-spec-builder
|
||||
//! cargo build -p chain-spec-guide-runtime --release
|
||||
//! cargo install pezstaging-chain-spec-builder
|
||||
//! cargo build -p pez-chain-spec-guide-runtime --release
|
||||
//! ```
|
||||
//! Here are some examples in the form of rust tests:
|
||||
//! ## Listing available preset names:
|
||||
@@ -183,18 +185,18 @@
|
||||
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", cmd_generate_para_chain_spec)]
|
||||
//!
|
||||
//! [`RuntimeGenesisConfig`]:
|
||||
//! chain_spec_guide_runtime::runtime::RuntimeGenesisConfig
|
||||
//! pez_chain_spec_guide_runtime::runtime::RuntimeGenesisConfig
|
||||
//! [`FooStruct`]:
|
||||
//! chain_spec_guide_runtime::pallets::FooStruct
|
||||
//! [`impl_runtime_apis`]: frame::runtime::prelude::impl_runtime_apis
|
||||
//! [`build_state`]: frame_support::genesis_builder_helper::build_state
|
||||
//! [`get_preset`]: frame_support::genesis_builder_helper::get_preset
|
||||
//! [`pallet::genesis_build`]: frame_support::pallet_macros::genesis_build
|
||||
//! [`pallet::genesis_config`]: frame_support::pallet_macros::genesis_config
|
||||
//! [`build_struct_json_patch`]: frame_support::build_struct_json_patch
|
||||
//! [`BuildGenesisConfig`]: frame_support::traits::BuildGenesisConfig
|
||||
//! pez_chain_spec_guide_runtime::pallets::FooStruct
|
||||
//! [`impl_runtime_apis`]: pezframe::runtime::prelude::impl_runtime_apis
|
||||
//! [`build_state`]: pezframe_support::genesis_builder_helper::build_state
|
||||
//! [`get_preset`]: pezframe_support::genesis_builder_helper::get_preset
|
||||
//! [`pezpallet::genesis_build`]: pezframe_support::pezpallet_macros::genesis_build
|
||||
//! [`pezpallet::genesis_config`]: pezframe_support::pezpallet_macros::genesis_config
|
||||
//! [`build_struct_json_patch`]: pezframe_support::build_struct_json_patch
|
||||
//! [`BuildGenesisConfig`]: pezframe_support::traits::BuildGenesisConfig
|
||||
//! [`serde`]: https://serde.rs/field-attrs.html
|
||||
//! [`get_storage_for_patch`]: sc_chain_spec::GenesisConfigBuilderRuntimeCaller::get_storage_for_patch
|
||||
//! [`GenesisBuilder::get_preset`]: sp_genesis_builder::GenesisBuilder::get_preset
|
||||
//! [`get_storage_for_patch`]: pezsc_chain_spec::GenesisConfigBuilderRuntimeCaller::get_storage_for_patch
|
||||
//! [`GenesisBuilder::get_preset`]: pezsp_genesis_builder::GenesisBuilder::get_preset
|
||||
//! [`deny_unknown_fields`]: https://serde.rs/container-attrs.html#deny_unknown_fields
|
||||
//! [`camelCase`]: https://serde.rs/container-attrs.html#rename_all
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "chain-spec-guide-runtime"
|
||||
name = "pez-chain-spec-guide-runtime"
|
||||
description = "A minimal runtime for chain spec guide"
|
||||
version = "0.0.0"
|
||||
license = "MIT-0"
|
||||
@@ -8,57 +8,77 @@ homepage.workspace = true
|
||||
repository.workspace = true
|
||||
edition.workspace = true
|
||||
publish = false
|
||||
documentation.workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { workspace = true }
|
||||
docify = { workspace = true }
|
||||
frame-support = { workspace = true }
|
||||
pezframe-support = { workspace = true }
|
||||
pezframe-system = { workspace = true }
|
||||
scale-info = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
# this is a frame-based runtime, thus importing `frame` with runtime feature enabled.
|
||||
frame = { features = ["experimental", "runtime"], workspace = true }
|
||||
pezframe = { features = ["experimental", "runtime"], workspace = true }
|
||||
|
||||
# genesis builder that allows us to interact with runtime genesis config
|
||||
sp-application-crypto = { features = ["serde"], workspace = true }
|
||||
sp-core = { workspace = true }
|
||||
sp-genesis-builder = { workspace = true }
|
||||
sp-keyring = { workspace = true }
|
||||
sp-runtime = { features = ["serde"], workspace = true }
|
||||
pezsp-api = { workspace = true }
|
||||
pezsp-application-crypto = { features = ["serde"], workspace = true }
|
||||
pezsp-core = { workspace = true }
|
||||
pezsp-genesis-builder = { workspace = true }
|
||||
pezsp-keyring = { workspace = true }
|
||||
pezsp-runtime = { features = ["serde"], workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
cmd_lib = { workspace = true }
|
||||
sc-chain-spec = { workspace = true, default-features = true }
|
||||
pezsc-chain-spec = { workspace = true, default-features = true }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-wasm-builder = { optional = true, workspace = true, default-features = true }
|
||||
bizinikiwi-wasm-builder = { optional = true, workspace = true, default-features = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bizinikiwi-wasm-builder",
|
||||
"bizinikiwi-wasm-builder?/std",
|
||||
"codec/std",
|
||||
"pezframe-support/std",
|
||||
"pezframe-system/std",
|
||||
"pezframe/std",
|
||||
"pezsc-chain-spec/std",
|
||||
"pezsp-api/std",
|
||||
"pezsp-application-crypto/std",
|
||||
"pezsp-core/std",
|
||||
"pezsp-genesis-builder/std",
|
||||
"pezsp-keyring/std",
|
||||
"pezsp-runtime/std",
|
||||
"scale-info/std",
|
||||
|
||||
"frame-support/std",
|
||||
"frame/std",
|
||||
|
||||
"sp-application-crypto/std",
|
||||
"sp-core/std",
|
||||
"sp-genesis-builder/std",
|
||||
"sp-keyring/std",
|
||||
"sp-runtime/std",
|
||||
|
||||
"serde/std",
|
||||
"serde_json/std",
|
||||
"substrate-wasm-builder",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"frame-support/runtime-benchmarks",
|
||||
"frame/runtime-benchmarks",
|
||||
"sc-chain-spec/runtime-benchmarks",
|
||||
"sp-genesis-builder/runtime-benchmarks",
|
||||
"sp-keyring/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"substrate-wasm-builder?/runtime-benchmarks",
|
||||
"bizinikiwi-wasm-builder?/runtime-benchmarks",
|
||||
"pezframe-support/runtime-benchmarks",
|
||||
"pezframe-system/runtime-benchmarks",
|
||||
"pezframe/runtime-benchmarks",
|
||||
"pezsc-chain-spec/runtime-benchmarks",
|
||||
"pezsp-api/runtime-benchmarks",
|
||||
"pezsp-application-crypto/runtime-benchmarks",
|
||||
"pezsp-genesis-builder/runtime-benchmarks",
|
||||
"pezsp-keyring/runtime-benchmarks",
|
||||
"pezsp-runtime/runtime-benchmarks",
|
||||
]
|
||||
try-runtime = [
|
||||
"pezframe-support/try-runtime",
|
||||
"pezframe-system/try-runtime",
|
||||
"pezframe/try-runtime",
|
||||
"pezsc-chain-spec/try-runtime",
|
||||
"pezsp-api/try-runtime",
|
||||
"pezsp-genesis-builder/try-runtime",
|
||||
"pezsp-keyring/try-runtime",
|
||||
"pezsp-runtime/try-runtime",
|
||||
]
|
||||
serde = []
|
||||
experimental = []
|
||||
tuples-96 = []
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is part of Substrate.
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -18,6 +18,6 @@
|
||||
fn main() {
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
substrate_wasm_builder::WasmBuilder::build_using_defaults();
|
||||
bizinikiwi_wasm_builder::WasmBuilder::build_using_defaults();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is part of Substrate.
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is part of Substrate.
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -18,32 +18,32 @@
|
||||
//! Pallets for the chain-spec demo runtime.
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use frame::prelude::*;
|
||||
use pezframe::prelude::*;
|
||||
|
||||
#[docify::export]
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_bar {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_bar {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub(super) type InitialAccount<T: Config> = StorageValue<Value = T::AccountId>;
|
||||
|
||||
/// Simple `GenesisConfig`.
|
||||
#[pallet::genesis_config]
|
||||
#[pezpallet::genesis_config]
|
||||
#[derive(DefaultNoBound)]
|
||||
#[docify::export(pallet_bar_GenesisConfig)]
|
||||
#[docify::export(pezpallet_bar_GenesisConfig)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub initial_account: Option<T::AccountId>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
#[docify::export(pallet_bar_build)]
|
||||
#[pezpallet::genesis_build]
|
||||
#[docify::export(pezpallet_bar_build)]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
/// The storage building function that presents a direct mapping of the initial config
|
||||
/// values to the storage items.
|
||||
@@ -80,7 +80,7 @@ pub struct SomeFooData1 {
|
||||
#[docify::export]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
pub struct SomeFooData2 {
|
||||
#[serde(default, with = "sp_core::bytes")]
|
||||
#[serde(default, with = "pezsp_core::bytes")]
|
||||
pub values: Vec<u8>,
|
||||
}
|
||||
|
||||
@@ -94,24 +94,24 @@ pub enum FooEnum {
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_foo {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_foo {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type ProcessedEnumValue<T> = StorageValue<Value = u64>;
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type SomeInteger<T> = StorageValue<Value = u32>;
|
||||
|
||||
/// The more sophisticated structure for conveying initial state.
|
||||
#[docify::export(pallet_foo_GenesisConfig)]
|
||||
#[pallet::genesis_config]
|
||||
#[docify::export(pezpallet_foo_GenesisConfig)]
|
||||
#[pezpallet::genesis_config]
|
||||
#[derive(DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub some_integer: u32,
|
||||
@@ -121,8 +121,8 @@ pub mod pallet_foo {
|
||||
pub _phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
#[docify::export(pallet_foo_build)]
|
||||
#[pezpallet::genesis_build]
|
||||
#[docify::export(pezpallet_foo_build)]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
/// The build method that indirectly maps an initial config values into the storage items.
|
||||
fn build(&self) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is part of Substrate.
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -22,10 +22,10 @@ use crate::{
|
||||
runtime::{BarConfig, FooConfig, RuntimeGenesisConfig},
|
||||
};
|
||||
use alloc::vec;
|
||||
use frame_support::build_struct_json_patch;
|
||||
use pezframe_support::build_struct_json_patch;
|
||||
use pezsp_application_crypto::Ss58Codec;
|
||||
use pezsp_keyring::Sr25519Keyring;
|
||||
use serde_json::{json, to_string, Value};
|
||||
use sp_application_crypto::Ss58Codec;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
|
||||
/// A demo preset with strings only.
|
||||
pub const PRESET_1: &str = "preset_1";
|
||||
@@ -120,7 +120,7 @@ fn preset_invalid() -> Value {
|
||||
///
|
||||
/// If no preset with given `id` exits `None` is returned.
|
||||
#[docify::export]
|
||||
pub fn get_builtin_preset(id: &sp_genesis_builder::PresetId) -> Option<alloc::vec::Vec<u8>> {
|
||||
pub fn get_builtin_preset(id: &pezsp_genesis_builder::PresetId) -> Option<alloc::vec::Vec<u8>> {
|
||||
let preset = match id.as_ref() {
|
||||
PRESET_1 => preset_1(),
|
||||
PRESET_2 => preset_2(),
|
||||
@@ -140,7 +140,7 @@ pub fn get_builtin_preset(id: &sp_genesis_builder::PresetId) -> Option<alloc::ve
|
||||
#[test]
|
||||
#[docify::export]
|
||||
fn check_presets() {
|
||||
let builder = sc_chain_spec::GenesisConfigBuilderRuntimeCaller::<()>::new(
|
||||
let builder = pezsc_chain_spec::GenesisConfigBuilderRuntimeCaller::<()>::new(
|
||||
crate::WASM_BINARY.expect("wasm binary shall exists"),
|
||||
);
|
||||
assert!(builder.get_storage_for_named_preset(Some(&PRESET_1.to_string())).is_ok());
|
||||
@@ -152,7 +152,7 @@ fn check_presets() {
|
||||
#[test]
|
||||
#[docify::export]
|
||||
fn invalid_preset_works() {
|
||||
let builder = sc_chain_spec::GenesisConfigBuilderRuntimeCaller::<()>::new(
|
||||
let builder = pezsc_chain_spec::GenesisConfigBuilderRuntimeCaller::<()>::new(
|
||||
crate::WASM_BINARY.expect("wasm binary shall exists"),
|
||||
);
|
||||
// Even though a preset contains invalid_key, conversion to raw storage does not fail. This is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is part of Substrate.
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -22,25 +22,24 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
use crate::{
|
||||
pallets::{pallet_bar, pallet_foo},
|
||||
pallets::{pezpallet_bar, pezpallet_foo},
|
||||
presets::*,
|
||||
};
|
||||
use alloc::{vec, vec::Vec};
|
||||
use frame::{
|
||||
deps::frame_support::{
|
||||
genesis_builder_helper::{build_state, get_preset},
|
||||
runtime,
|
||||
},
|
||||
use pezframe::{
|
||||
deps::pezframe_support::genesis_builder_helper::{build_state, get_preset},
|
||||
prelude::*,
|
||||
runtime::{apis, prelude::*},
|
||||
runtime::prelude::*,
|
||||
};
|
||||
use sp_genesis_builder::PresetId;
|
||||
use pezsp_api::impl_runtime_apis;
|
||||
use pezsp_genesis_builder::PresetId;
|
||||
use pezsp_runtime::traits::Block as BlockT;
|
||||
|
||||
/// The runtime version.
|
||||
#[runtime_version]
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: alloc::borrow::Cow::Borrowed("minimal-template-runtime"),
|
||||
impl_name: alloc::borrow::Cow::Borrowed("minimal-template-runtime"),
|
||||
spec_name: alloc::borrow::Cow::Borrowed("pez-minimal-template-runtime"),
|
||||
impl_name: alloc::borrow::Cow::Borrowed("pez-minimal-template-runtime"),
|
||||
authoring_version: 1,
|
||||
spec_version: 0,
|
||||
impl_version: 1,
|
||||
@@ -53,7 +52,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
type SignedExtra = ();
|
||||
|
||||
// Composes the runtime by adding all the used pallets and deriving necessary types.
|
||||
#[runtime]
|
||||
#[frame_construct_runtime]
|
||||
mod runtime {
|
||||
/// The main runtime type.
|
||||
#[runtime::runtime]
|
||||
@@ -67,48 +66,48 @@ mod runtime {
|
||||
)]
|
||||
pub struct Runtime;
|
||||
|
||||
/// Mandatory system pallet that should always be included in a FRAME runtime.
|
||||
#[runtime::pallet_index(0)]
|
||||
pub type System = frame_system;
|
||||
/// Mandatory system pezpallet that should always be included in a FRAME runtime.
|
||||
#[runtime::pezpallet_index(0)]
|
||||
pub type System = pezframe_system::Pezpallet<Runtime>;
|
||||
|
||||
/// Sample pallet 1
|
||||
#[runtime::pallet_index(1)]
|
||||
pub type Bar = pallet_bar;
|
||||
/// Sample pezpallet 1
|
||||
#[runtime::pezpallet_index(1)]
|
||||
pub type Bar = pezpallet_bar::Pezpallet<Runtime>;
|
||||
|
||||
/// Sample pallet 2
|
||||
#[runtime::pallet_index(2)]
|
||||
pub type Foo = pallet_foo;
|
||||
/// Sample pezpallet 2
|
||||
#[runtime::pezpallet_index(2)]
|
||||
pub type Foo = pezpallet_foo::Pezpallet<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const Version: RuntimeVersion = VERSION;
|
||||
}
|
||||
|
||||
/// Implements the types required for the system pallet.
|
||||
#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
/// Implements the types required for the system pezpallet.
|
||||
#[derive_impl(pezframe_system::config_preludes::SolochainDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = Block;
|
||||
type Version = Version;
|
||||
}
|
||||
|
||||
impl pallet_bar::Config for Runtime {}
|
||||
impl pallet_foo::Config for Runtime {}
|
||||
impl pezpallet_bar::Config for Runtime {}
|
||||
impl pezpallet_foo::Config for Runtime {}
|
||||
|
||||
type Block = frame::runtime::types_common::BlockOf<Runtime, SignedExtra>;
|
||||
type Header = HeaderFor<Runtime>;
|
||||
type Block = pezframe::runtime::types_common::BlockOf<Runtime, SignedExtra>;
|
||||
type _Header = HeaderFor<Runtime>;
|
||||
|
||||
#[docify::export(runtime_impl)]
|
||||
impl_runtime_apis! {
|
||||
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
|
||||
fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
|
||||
impl pezsp_genesis_builder::GenesisBuilder<Block> for Runtime {
|
||||
fn build_state(config: Vec<u8>) -> pezsp_genesis_builder::Result {
|
||||
build_state::<RuntimeGenesisConfig>(config)
|
||||
}
|
||||
|
||||
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
|
||||
fn get_preset(id: &Option<pezsp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
|
||||
get_preset::<RuntimeGenesisConfig>(id, get_builtin_preset)
|
||||
}
|
||||
|
||||
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
|
||||
fn preset_names() -> Vec<pezsp_genesis_builder::PresetId> {
|
||||
vec![
|
||||
PresetId::from(PRESET_1),
|
||||
PresetId::from(PRESET_2),
|
||||
@@ -119,9 +118,9 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl apis::Core<Block> for Runtime {
|
||||
impl pezsp_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion { VERSION }
|
||||
fn execute_block(_: <Block as frame::traits::Block>::LazyBlock) { }
|
||||
fn initialize_block(_: &Header) -> ExtrinsicInclusionMode { ExtrinsicInclusionMode::default() }
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) { }
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> ExtrinsicInclusionMode { ExtrinsicInclusionMode::default() }
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -3,8 +3,8 @@ use serde_json::{json, Value};
|
||||
use std::str;
|
||||
|
||||
fn wasm_file_path() -> &'static str {
|
||||
chain_spec_guide_runtime::runtime::WASM_BINARY_PATH
|
||||
.expect("chain_spec_guide_runtime wasm should exist. qed")
|
||||
pez_chain_spec_guide_runtime::runtime::WASM_BINARY_PATH
|
||||
.expect("pez_chain_spec_guide_runtime wasm should exist. qed")
|
||||
}
|
||||
|
||||
const CHAIN_SPEC_BUILDER_PATH: &str = "../../../../../target/release/chain-spec-builder";
|
||||
@@ -24,7 +24,7 @@ macro_rules! bash(
|
||||
|
||||
fn get_chain_spec_builder_path() -> &'static str {
|
||||
run_cmd!(
|
||||
cargo build --release -p staging-chain-spec-builder --bin chain-spec-builder
|
||||
cargo build --release -p pezstaging-chain-spec-builder --bin chain-spec-builder
|
||||
)
|
||||
.expect("Failed to execute command");
|
||||
CHAIN_SPEC_BUILDER_PATH
|
||||
@@ -189,7 +189,7 @@ fn generate_para_chain_spec() {
|
||||
#[docify::export_content]
|
||||
fn preset_4_json() {
|
||||
assert_eq!(
|
||||
chain_spec_guide_runtime::presets::preset_4(),
|
||||
pez_chain_spec_guide_runtime::presets::preset_4(),
|
||||
json!({
|
||||
"foo": {
|
||||
"someEnum": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! # Substrate CLI
|
||||
//! # Bizinikiwi CLI
|
||||
//!
|
||||
//! Let's see some examples of typical CLI arguments used when setting up and running a
|
||||
//! Substrate-based blockchain. We use the [`solochain-template`](https://github.com/pezkuwichain/pezkuwi-sdk/issues/25)
|
||||
//! Bizinikiwi-based blockchain. We use the [`solochain-template`](https://github.com/pezkuwichain/pezkuwi-sdk/issues/195)
|
||||
//! on these examples.
|
||||
//!
|
||||
//! #### Checking the available CLI arguments
|
||||
@@ -10,7 +10,7 @@
|
||||
//! ```
|
||||
//! - `--help`: Displays the available CLI arguments.
|
||||
//!
|
||||
//! #### Starting a Local Substrate Node in Development Mode
|
||||
//! #### Starting a Local Bizinikiwi Node in Development Mode
|
||||
//! ```bash
|
||||
//! ./target/release/node-template \
|
||||
//! --dev
|
||||
@@ -97,8 +97,8 @@
|
||||
//! ---
|
||||
//!
|
||||
//! > If you are interested in learning how to extend the CLI with your custom arguments, you can
|
||||
//! > check out the [Customize your Substrate chain CLI](https://www.youtube.com/watch?v=IVifko1fqjw)
|
||||
//! > check out the [Customize your Bizinikiwi chain CLI](https://www.youtube.com/watch?v=IVifko1fqjw)
|
||||
//! > seminar.
|
||||
//! > Please note that the seminar is based on an older version of Substrate, and [Clap](https://docs.rs/clap/latest/clap/)
|
||||
//! > Please note that the seminar is based on an older version of Bizinikiwi, and [Clap](https://docs.rs/clap/latest/clap/)
|
||||
//! > is now used instead of [StructOpt](https://docs.rs/structopt/latest/structopt/) for parsing
|
||||
//! > CLI arguments.
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
//! ## Finding Host Functions
|
||||
//!
|
||||
//! To declare a set of functions as host functions, you need to use the `#[runtime_interface]`
|
||||
//! ([`sp_runtime_interface`]) attribute macro. The most notable set of host functions are those
|
||||
//! that allow the runtime to access the chain state, namely [`sp_io::storage`]. Some other notable
|
||||
//! host functions are also defined in [`sp_io`].
|
||||
//! ([`pezsp_runtime_interface`]) attribute macro. The most notable set of host functions are those
|
||||
//! that allow the runtime to access the chain state, namely [`pezsp_io::storage`]. Some other
|
||||
//! notable host functions are also defined in [`pezsp_io`].
|
||||
//!
|
||||
//! ## Adding New Host Functions
|
||||
//!
|
||||
@@ -20,8 +20,8 @@
|
||||
//! access to the boilerplate of building your node.
|
||||
//!
|
||||
//! A group of host functions can always be grouped to gether as a tuple:
|
||||
#![doc = docify::embed!("../../substrate/primitives/io/src/lib.rs", SubstrateHostFunctions)]
|
||||
#![doc = docify::embed!("../../bizinikiwi/primitives/io/src/lib.rs", BizinikiwiHostFunctions)]
|
||||
//!
|
||||
//! The host functions are attached to the node side's [`sc_executor::WasmExecutor`]. For example in
|
||||
//! the minimal template, the setup looks as follows:
|
||||
//! The host functions are attached to the node side's [`pezsc_executor::WasmExecutor`]. For example
|
||||
//! in the minimal template, the setup looks as follows:
|
||||
#![doc = docify::embed!("../../templates/minimal/node/src/service.rs", FullClient)]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! ## Background
|
||||
//!
|
||||
//! Pezkuwi-SDK offers the ability to query and subscribe storages directly. However what it does
|
||||
//! not have is [view functions](https://github.com/pezkuwichain/pezkuwi-sdk/issues/101). This is an
|
||||
//! not have is [view functions](https://github.com/pezkuwichain/pezkuwi-sdk/issues/247). This is an
|
||||
//! essential feature to avoid duplicated logic between runtime and the client SDK. Custom RPC was
|
||||
//! used as a solution. It allow the RPC node to expose new RPCs that clients can be used to query
|
||||
//! computed properties.
|
||||
@@ -31,7 +31,7 @@
|
||||
//!
|
||||
//! ## Alternatives
|
||||
//!
|
||||
//! Generally, [`sc_rpc::state::StateBackend::call`] aka. `state_call` should be used instead of
|
||||
//! Generally, [`pezsc_rpc::state::StateBackend::call`] aka. `state_call` should be used instead of
|
||||
//! custom RPC.
|
||||
//!
|
||||
//! Usually, each custom RPC comes with a corresponding runtime API which implements the business
|
||||
@@ -52,9 +52,9 @@
|
||||
//!
|
||||
//! For example, let's take a look at the process through which the account nonce can be queried
|
||||
//! through an RPC. First, a new runtime-api needs to be declared:
|
||||
#![doc = docify::embed!("../../substrate/frame/system/rpc/runtime-api/src/lib.rs", AccountNonceApi)]
|
||||
#![doc = docify::embed!("../../bizinikiwi/pezframe/system/rpc/runtime-api/src/lib.rs", AccountNonceApi)]
|
||||
//!
|
||||
//! This API is implemented at the runtime level, always inside [`sp_api::impl_runtime_apis!`].
|
||||
//! This API is implemented at the runtime level, always inside [`pezsp_api::impl_runtime_apis!`].
|
||||
//!
|
||||
//! As noted, this is already enough to make this API usable via `state_call`.
|
||||
//!
|
||||
@@ -62,7 +62,7 @@
|
||||
//!
|
||||
//! Should you wish to implement the legacy approach of exposing this runtime-api as a custom
|
||||
//! RPC-api, then a custom RPC server has to be defined.
|
||||
#![doc = docify::embed!("../../substrate/utils/frame/rpc/system/src/lib.rs", SystemApi)]
|
||||
#![doc = docify::embed!("../../bizinikiwi/utils/pezframe/rpc/system/src/lib.rs", SystemApi)]
|
||||
//!
|
||||
//! ## Add a new RPC to the node (Legacy)
|
||||
//!
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -24,14 +24,14 @@
|
||||
//!
|
||||
//! ## General Overview
|
||||
//!
|
||||
//! When developing within the context of the Substrate runtime, there is one golden rule:
|
||||
//! When developing within the context of the Bizinikiwi runtime, there is one golden rule:
|
||||
//!
|
||||
//! ***DO NOT PANIC***. There are some exceptions, but generally, this is the default precedent.
|
||||
//!
|
||||
//! > It’s important to differentiate between the runtime and node. The runtime refers to the core
|
||||
//! > business logic of a Substrate-based chain, whereas the node refers to the outer client, which
|
||||
//! > business logic of a Bizinikiwi-based chain, whereas the node refers to the outer client, which
|
||||
//! > deals with telemetry and gossip from other nodes. For more information, read about
|
||||
//! > [Substrate's node
|
||||
//! > [Bizinikiwi's node
|
||||
//! > architecture](crate::reference_docs::wasm_meta_protocol#node-vs-runtime). It’s also important
|
||||
//! > to note that the criticality of the node is slightly lesser
|
||||
//! > than that of the runtime, which is why you may see `unwrap()` or other “non-defensive”
|
||||
@@ -70,18 +70,18 @@
|
||||
//!
|
||||
//! ### Defensive Traits
|
||||
//!
|
||||
//! The [`Defensive`](frame::traits::Defensive) trait provides a number of functions, all of which
|
||||
//! The [`Defensive`](pezframe::traits::Defensive) trait provides a number of functions, all of which
|
||||
//! provide an alternative to 'vanilla' Rust functions, e.g.:
|
||||
//!
|
||||
//! - [`defensive_unwrap_or()`](frame::traits::Defensive::defensive_unwrap_or) instead of
|
||||
//! - [`defensive_unwrap_or()`](pezframe::traits::Defensive::defensive_unwrap_or) instead of
|
||||
//! `unwrap_or()`
|
||||
//! - [`defensive_ok_or()`](frame::traits::DefensiveOption::defensive_ok_or) instead of `ok_or()`
|
||||
//! - [`defensive_ok_or()`](pezframe::traits::DefensiveOption::defensive_ok_or) instead of `ok_or()`
|
||||
//!
|
||||
//! Defensive methods use [`debug_assertions`](https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions), which panic in development, but in
|
||||
//! production/release, they will merely log an error (i.e., `log::error`).
|
||||
//!
|
||||
//! The [`Defensive`](frame::traits::Defensive) trait and its various implementations can be found
|
||||
//! [here](frame::traits::Defensive).
|
||||
//! The [`Defensive`](pezframe::traits::Defensive) trait and its various implementations can be found
|
||||
//! [here](pezframe::traits::Defensive).
|
||||
//!
|
||||
//! ## Integer Overflow
|
||||
//!
|
||||
@@ -110,11 +110,11 @@
|
||||
//! unexpected consequences like a user balance over or underflowing.
|
||||
//!
|
||||
//! Fortunately, there are ways to both represent and handle these scenarios depending on our
|
||||
//! specific use case natively built into Rust and libraries like [`sp_arithmetic`].
|
||||
//! specific use case natively built into Rust and libraries like [`pezsp_arithmetic`].
|
||||
//!
|
||||
//! ## Infallible Arithmetic
|
||||
//!
|
||||
//! Both Rust and Substrate provide safe ways to deal with numbers and alternatives to floating
|
||||
//! Both Rust and Bizinikiwi provide safe ways to deal with numbers and alternatives to floating
|
||||
//! point arithmetic.
|
||||
//!
|
||||
//! Known scenarios that could be fallible should be avoided: i.e., avoiding the possibility of
|
||||
@@ -124,8 +124,9 @@
|
||||
//! A developer should use fixed-point instead of floating-point arithmetic to mitigate the
|
||||
//! potential for inaccuracy, rounding errors, or other unexpected behavior.
|
||||
//!
|
||||
//! - [Fixed point types](sp_arithmetic::fixed_point) and their associated usage can be found here.
|
||||
//! - [PerThing](sp_arithmetic::per_things) and its associated types can be found here.
|
||||
//! - [Fixed point types](pezsp_arithmetic::fixed_point) and their associated usage can be found
|
||||
//! here.
|
||||
//! - [PerThing](pezsp_arithmetic::per_things) and its associated types can be found here.
|
||||
//!
|
||||
//! Using floating point number types (i.e. f32, f64) in the runtime should be avoided, as a single non-deterministic result could cause chaos for blockchain consensus along with the issues above. For more on the specifics of the peculiarities of floating point calculations, [watch this video by the Computerphile](https://www.youtube.com/watch?v=PZRI1IfStY0).
|
||||
//!
|
||||
@@ -187,15 +188,15 @@
|
||||
//! to avoid introducing the notion of any potential-panic or wrapping behavior.
|
||||
//!
|
||||
//! There is also a series of defensive alternatives via
|
||||
//! [`DefensiveSaturating`](frame::traits::DefensiveSaturating), which introduces the same behavior
|
||||
//! of the [`Defensive`](frame::traits::Defensive) trait, only with saturating, mathematical
|
||||
//! [`DefensiveSaturating`](pezframe::traits::DefensiveSaturating), which introduces the same behavior
|
||||
//! of the [`Defensive`](pezframe::traits::Defensive) trait, only with saturating, mathematical
|
||||
//! operations:
|
||||
#![doc = docify::embed!(
|
||||
"./src/reference_docs/defensive_programming.rs",
|
||||
saturated_defensive_example
|
||||
)]
|
||||
//!
|
||||
//! ### Mathematical Operations in Substrate Development - Further Context
|
||||
//! ### Mathematical Operations in Bizinikiwi Development - Further Context
|
||||
//!
|
||||
//! As a recap, we covered the following concepts:
|
||||
//!
|
||||
@@ -214,9 +215,9 @@
|
||||
//!
|
||||
//! #### Bob's Overflowed Balance
|
||||
//!
|
||||
//! **Bob's** balance exceeds the `Balance` type on the `EduChain`. Because the pallet developer did
|
||||
//! not handle the calculation to add to Bob's balance with any regard to this overflow, **Bob's**
|
||||
//! balance is now essentially `0`, the operation **wrapped**.
|
||||
//! **Bob's** balance exceeds the `Balance` type on the `EduChain`. Because the pezpallet developer
|
||||
//! did not handle the calculation to add to Bob's balance with any regard to this overflow,
|
||||
//! **Bob's** balance is now essentially `0`, the operation **wrapped**.
|
||||
//!
|
||||
//! <details>
|
||||
//! <summary><b>Solution: Saturating or Checked</b></summary>
|
||||
@@ -247,7 +248,7 @@
|
||||
//!
|
||||
//! A `u8` parameter, called `proposals_count`, represents the type for counting the number of
|
||||
//! proposals on-chain. Every time a new proposal is added to the system, this number increases.
|
||||
//! With the proposal pallet's high usage, it has reached `u8::MAX`’s limit of 255, causing
|
||||
//! With the proposal pezpallet's high usage, it has reached `u8::MAX`’s limit of 255, causing
|
||||
//! `proposals_count` to go to 0. Unfortunately, this results in new proposals overwriting old ones,
|
||||
//! effectively erasing any notion of past proposals!
|
||||
//!
|
||||
@@ -267,17 +268,17 @@
|
||||
//! From the above, we can clearly see the problematic nature of seemingly simple operations in the
|
||||
//! runtime, and care should be given to ensure a defensive approach is taken.
|
||||
//!
|
||||
//! ### Edge cases of `panic!`-able instances in Substrate
|
||||
//! ### Edge cases of `panic!`-able instances in Bizinikiwi
|
||||
//!
|
||||
//! As you traverse through the codebase (particularly in `substrate/frame`, where the majority of
|
||||
//! As you traverse through the codebase (particularly in `bizinikiwi/frame`, where the majority of
|
||||
//! runtime code lives), you may notice that there (only a few!) occurrences where `panic!` is used
|
||||
//! explicitly. This is used when the runtime should stall, rather than keep running, as that is
|
||||
//! considered safer. Particularly when it comes to mission-critical components, such as block
|
||||
//! authoring, consensus, or other protocol-level dependencies, going through with an action may
|
||||
//! actually cause harm to the network, and thus stalling would be the better option.
|
||||
//!
|
||||
//! Take the example of the BABE pallet ([`pallet_babe`]), which doesn't allow for a validator to
|
||||
//! participate if it is disabled (see: [`frame::traits::DisabledValidators`]):
|
||||
//! Take the example of the BABE pezpallet ([`pezpallet_babe`]), which doesn't allow for a validator
|
||||
//! to participate if it is disabled (see: [`pezframe::traits::DisabledValidators`]):
|
||||
//!
|
||||
//! ```ignore
|
||||
//! if T::DisabledValidators::is_disabled(authority_index) {
|
||||
@@ -358,7 +359,7 @@ mod fake_runtime_types {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use frame::traits::DefensiveSaturating;
|
||||
use pezframe::traits::DefensiveSaturating;
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn checked_add_example() {
|
||||
|
||||
@@ -138,7 +138,7 @@
|
||||
//!
|
||||
//! The WASM binary is usually not needed, especially when running `check` or `test`. To skip the
|
||||
//! WASM build, set the `SKIP_WASM_BUILD` environment variable to `1`. For example:
|
||||
//! `SKIP_WASM_BUILD=1 cargo check -p frame-support`.
|
||||
//! `SKIP_WASM_BUILD=1 cargo check -p pezframe-support`.
|
||||
//!
|
||||
//! ### Cargo Remote
|
||||
//!
|
||||
|
||||
@@ -4,21 +4,21 @@
|
||||
//! of a blockchain via the [_state transition
|
||||
//! function_][crate::reference_docs::blockchain_state_machines].
|
||||
//!
|
||||
//! Substrate is configurable enough that extrinsics can take any format. In practice, runtimes
|
||||
//! tend to use our [`sp_runtime::generic::UncheckedExtrinsic`] type to represent extrinsics,
|
||||
//! Bizinikiwi is configurable enough that extrinsics can take any format. In practice, runtimes
|
||||
//! tend to use our [`pezsp_runtime::generic::UncheckedExtrinsic`] type to represent extrinsics,
|
||||
//! because it's generic enough to cater for most (if not all) use cases. In Pezkuwi, this is
|
||||
//! configured [here](https://github.com/polkadot-fellows/runtimes/blob/94b2798b69ba6779764e20a50f056e48db78ebef/relay/polkadot/src/lib.rs#L1478)
|
||||
//! at the time of writing.
|
||||
//!
|
||||
//! What follows is a description of how extrinsics based on this
|
||||
//! [`sp_runtime::generic::UncheckedExtrinsic`] type are encoded into bytes. Specifically, we are
|
||||
//! [`pezsp_runtime::generic::UncheckedExtrinsic`] type are encoded into bytes. Specifically, we are
|
||||
//! looking at how extrinsics with a format version of 5 are encoded. This version is itself a part
|
||||
//! of the payload, and if it changes, it indicates that something about the encoding may have
|
||||
//! changed.
|
||||
//!
|
||||
//! # Encoding an Extrinsic
|
||||
//!
|
||||
//! At a high level, all extrinsics compatible with [`sp_runtime::generic::UncheckedExtrinsic`]
|
||||
//! At a high level, all extrinsics compatible with [`pezsp_runtime::generic::UncheckedExtrinsic`]
|
||||
//! are formed from concatenating some details together, as in the following pseudo-code:
|
||||
//!
|
||||
//! ```text
|
||||
@@ -30,14 +30,14 @@
|
||||
//! )
|
||||
//! ```
|
||||
//!
|
||||
//! For clarity, the actual implementation in Substrate looks like this:
|
||||
#![doc = docify::embed!("../../substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs", unchecked_extrinsic_encode_impl)]
|
||||
//! For clarity, the actual implementation in Bizinikiwi looks like this:
|
||||
#![doc = docify::embed!("../../bizinikiwi/primitives/runtime/src/generic/unchecked_extrinsic.rs", unchecked_extrinsic_encode_impl)]
|
||||
//!
|
||||
//! Let's look at how each of these details is constructed:
|
||||
//!
|
||||
//! ## compact_encoded_length
|
||||
//!
|
||||
//! This is a [SCALE compact encoded][frame::deps::codec::Compact] integer which is equal to the
|
||||
//! This is a [SCALE compact encoded][pezframe::deps::codec::Compact] integer which is equal to the
|
||||
//! length, in bytes, of the rest of the extrinsic details.
|
||||
//!
|
||||
//! To obtain this value, we must encode and concatenate together the rest of the extrinsic details
|
||||
@@ -90,25 +90,26 @@
|
||||
//!
|
||||
//! #### from_address
|
||||
//!
|
||||
//! This is the [SCALE encoded][frame::deps::codec] address of the sender of the extrinsic. The
|
||||
//! address is the first generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], and so
|
||||
//! This is the [SCALE encoded][pezframe::deps::codec] address of the sender of the extrinsic. The
|
||||
//! address is the first generic parameter of [`pezsp_runtime::generic::UncheckedExtrinsic`], and so
|
||||
//! can vary from chain to chain.
|
||||
//!
|
||||
//! The address type used on the Pezkuwi relay chain is [`sp_runtime::MultiAddress<AccountId32>`],
|
||||
//! where `AccountId32` is defined [here][`sp_core::crypto::AccountId32`]. When constructing a
|
||||
//! signed extrinsic to be submitted to a Pezkuwi node, you'll always use the
|
||||
//! [`sp_runtime::MultiAddress::Id`] variant to wrap your `AccountId32`.
|
||||
//! The address type used on the Pezkuwi relay chain is
|
||||
//! [`pezsp_runtime::MultiAddress<AccountId32>`], where `AccountId32` is defined
|
||||
//! [here][`pezsp_core::crypto::AccountId32`]. When constructing a signed extrinsic to be submitted
|
||||
//! to a Pezkuwi node, you'll always use the [`pezsp_runtime::MultiAddress::Id`] variant to wrap
|
||||
//! your `AccountId32`.
|
||||
//!
|
||||
//! #### signature
|
||||
//!
|
||||
//! This is the [SCALE encoded][frame::deps::codec] signature. The signature type is configured via
|
||||
//! the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which determines the
|
||||
//! shape of the signature and signing algorithm that should be used.
|
||||
//! This is the [SCALE encoded][pezframe::deps::codec] signature. The signature type is configured via
|
||||
//! the third generic parameter of [`pezsp_runtime::generic::UncheckedExtrinsic`], which determines
|
||||
//! the shape of the signature and signing algorithm that should be used.
|
||||
//!
|
||||
//! The signature is obtained by signing the _signed payload_ bytes (see below on how this is
|
||||
//! constructed) using the private key associated with the address and correct algorithm.
|
||||
//!
|
||||
//! The signature type used on the Pezkuwi relay chain is [`sp_runtime::MultiSignature`]; the
|
||||
//! The signature type used on the Pezkuwi relay chain is [`pezsp_runtime::MultiSignature`]; the
|
||||
//! variants there are the types of signature that can be provided.
|
||||
//!
|
||||
//! ### General extrinsics
|
||||
@@ -120,12 +121,12 @@
|
||||
//!
|
||||
//! ### transaction_extensions_extra
|
||||
//!
|
||||
//! This is the concatenation of the [SCALE encoded][frame::deps::codec] bytes representing first a
|
||||
//! This is the concatenation of the [SCALE encoded][pezframe::deps::codec] bytes representing first a
|
||||
//! single byte describing the extension version (this is bumped whenever a change occurs in the
|
||||
//! transaction extension pipeline) followed by the bytes of each of the [_transaction
|
||||
//! extensions_][sp_runtime::traits::TransactionExtension], and are configured by the fourth generic
|
||||
//! parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn more about transaction
|
||||
//! extensions [here][crate::reference_docs::transaction_extensions].
|
||||
//! extensions_][pezsp_runtime::traits::TransactionExtension], and are configured by the fourth
|
||||
//! generic parameter of [`pezsp_runtime::generic::UncheckedExtrinsic`]. Learn more about
|
||||
//! transaction extensions [here][crate::reference_docs::transaction_extensions].
|
||||
//!
|
||||
//! When it comes to constructing an extrinsic, each transaction extension has two things that we
|
||||
//! are interested in here:
|
||||
@@ -141,22 +142,22 @@
|
||||
//! configuration. At the time of writing, Pezkuwi configures them
|
||||
//! [here](https://github.com/polkadot-fellows/runtimes/blob/1dc04eb954eadf8aadb5d83990b89662dbb5a074/relay/polkadot/src/lib.rs#L1432C25-L1432C25).
|
||||
//! Some of the common transaction extensions are defined
|
||||
//! [here][frame::deps::frame_system#transaction-extensions].
|
||||
//! [here][pezframe::deps::pezframe_system#transaction-extensions].
|
||||
//!
|
||||
//! Information about exactly which transaction extensions are present on a chain and in what order
|
||||
//! is also a part of the metadata for the chain. For V15 metadata, it can be [found
|
||||
//! here][frame::deps::frame_support::__private::metadata::v15::ExtrinsicMetadata].
|
||||
//! here][pezframe::deps::pezframe_support::__private::metadata::v15::ExtrinsicMetadata].
|
||||
//!
|
||||
//! ## call_data
|
||||
//!
|
||||
//! This is the main payload of the extrinsic, which is used to determine how the chain's state is
|
||||
//! altered. This is defined by the second generic parameter of
|
||||
//! [`sp_runtime::generic::UncheckedExtrinsic`].
|
||||
//! [`pezsp_runtime::generic::UncheckedExtrinsic`].
|
||||
//!
|
||||
//! A call can be anything that implements [`Encode`][frame::deps::codec::Encode]. In FRAME-based
|
||||
//! A call can be anything that implements [`Encode`][pezframe::deps::codec::Encode]. In FRAME-based
|
||||
//! runtimes, a call is represented as an enum of enums, where the outer enum represents the FRAME
|
||||
//! pallet being called, and the inner enum represents the call being made within that pallet, and
|
||||
//! any arguments to it. Read more about the call enum
|
||||
//! pezpallet being called, and the inner enum represents the call being made within that pezpallet,
|
||||
//! and any arguments to it. Read more about the call enum
|
||||
//! [here][crate::reference_docs::frame_runtime_types].
|
||||
//!
|
||||
//! FRAME `Call` enums are automatically generated, and end up looking something like this:
|
||||
@@ -166,23 +167,23 @@
|
||||
//!
|
||||
//! ```text
|
||||
//! call_data = concat(
|
||||
//! pallet_index,
|
||||
//! pezpallet_index,
|
||||
//! call_index,
|
||||
//! call_args
|
||||
//! )
|
||||
//! ```
|
||||
//!
|
||||
//! - `pallet_index` is a single byte denoting the index of the pallet that we are calling into, and
|
||||
//! is what the tag of the outermost enum will encode to.
|
||||
//! - `call_index` is a single byte denoting the index of the call that we are making the pallet,
|
||||
//! - `pezpallet_index` is a single byte denoting the index of the pezpallet that we are calling
|
||||
//! into, and is what the tag of the outermost enum will encode to.
|
||||
//! - `call_index` is a single byte denoting the index of the call that we are making the pezpallet,
|
||||
//! and is what the tag of the inner enum will encode to.
|
||||
//! - `call_args` are the SCALE encoded bytes for each of the arguments that the call expects, and
|
||||
//! are typically provided as values to the inner enum.
|
||||
//!
|
||||
//! Information about the pallets that exist for a chain (including their indexes), the calls
|
||||
//! available in each pallet (including their indexes), and the arguments required for each call can
|
||||
//! be found in the metadata for the chain. For V15 metadata, this information [is
|
||||
//! here][frame::deps::frame_support::__private::metadata::v15::PalletMetadata].
|
||||
//! available in each pezpallet (including their indexes), and the arguments required for each call
|
||||
//! can be found in the metadata for the chain. For V15 metadata, this information [is
|
||||
//! here][pezframe::deps::pezframe_support::__private::metadata::v15::PalletMetadata].
|
||||
//!
|
||||
//! # The Signed Payload Format
|
||||
//!
|
||||
@@ -202,13 +203,13 @@
|
||||
//!
|
||||
//! The bytes representing `call_data` and `transaction_extensions_extra` can be obtained as
|
||||
//! descibed above. `transaction_extensions_implicit` is constructed by SCALE encoding the
|
||||
//! ["implicit" data][sp_runtime::traits::TransactionExtension::Implicit] for each transaction
|
||||
//! ["implicit" data][pezsp_runtime::traits::TransactionExtension::Implicit] for each transaction
|
||||
//! extension that the chain is using, in order.
|
||||
//!
|
||||
//! Once we've concatenated those together, we hash the result using a Blake2 256bit hasher.
|
||||
//!
|
||||
//! The [`sp_runtime::generic::SignedPayload`] type takes care of assembling the correct payload for
|
||||
//! us, given `call_data` and a tuple of transaction extensions.
|
||||
//! The [`pezsp_runtime::generic::SignedPayload`] type takes care of assembling the correct payload
|
||||
//! for us, given `call_data` and a tuple of transaction extensions.
|
||||
//!
|
||||
//! # The General Transaction Format
|
||||
//!
|
||||
@@ -216,22 +217,22 @@
|
||||
//! extrinsic, such as a traditionally signed transaction. Instead, general transactions should have
|
||||
//! one or more extensions in the transaction extension pipeline that auhtorize origins in some way,
|
||||
//! one of which could be the traditional signature check that happens for all signed transactions
|
||||
//! in the [Checkable](sp_runtime::traits::Checkable) implementation of
|
||||
//! [UncheckedExtrinsic](sp_runtime::generic::UncheckedExtrinsic). Therefore, it is up to each
|
||||
//! in the [Checkable](pezsp_runtime::traits::Checkable) implementation of
|
||||
//! [UncheckedExtrinsic](pezsp_runtime::generic::UncheckedExtrinsic). Therefore, it is up to each
|
||||
//! extension to define the format of the payload it will try to check and authorize the right
|
||||
//! origin type. For an example, look into the [authorization example pallet
|
||||
//! extensions](pallet_example_authorization_tx_extension::extensions)
|
||||
//! origin type. For an example, look into the [authorization example pezpallet
|
||||
//! extensions](pezpallet_example_authorization_tx_extension::extensions)
|
||||
//!
|
||||
//! # Example Encoding
|
||||
//!
|
||||
//! Using [`sp_runtime::generic::UncheckedExtrinsic`], we can construct and encode an extrinsic as
|
||||
//! follows:
|
||||
//! Using [`pezsp_runtime::generic::UncheckedExtrinsic`], we can construct and encode an extrinsic
|
||||
//! as follows:
|
||||
#![doc = docify::embed!("./src/reference_docs/extrinsic_encoding.rs", encoding_example)]
|
||||
|
||||
#[docify::export]
|
||||
pub mod call_data {
|
||||
use codec::{Decode, Encode};
|
||||
use sp_runtime::{traits::Dispatchable, DispatchResultWithInfo};
|
||||
use pezsp_runtime::{traits::Dispatchable, DispatchResultWithInfo};
|
||||
|
||||
// The outer enum composes calls within
|
||||
// different pallets together. We have two
|
||||
@@ -245,7 +246,7 @@ pub mod call_data {
|
||||
}
|
||||
|
||||
// An inner enum represents the calls within
|
||||
// a specific pallet. "PalletA" has one call,
|
||||
// a specific pezpallet. "PalletA" has one call,
|
||||
// "Foo".
|
||||
#[derive(Encode, Decode, Clone)]
|
||||
pub enum PalletACall {
|
||||
@@ -275,9 +276,9 @@ pub mod encoding_example {
|
||||
use super::call_data::{Call, PalletACall};
|
||||
use crate::reference_docs::transaction_extensions::transaction_extensions_example;
|
||||
use codec::Encode;
|
||||
use sp_core::crypto::AccountId32;
|
||||
use sp_keyring::sr25519::Keyring;
|
||||
use sp_runtime::{
|
||||
use pezsp_core::crypto::AccountId32;
|
||||
use pezsp_keyring::sr25519::Keyring;
|
||||
use pezsp_runtime::{
|
||||
generic::{SignedPayload, UncheckedExtrinsic},
|
||||
MultiAddress, MultiSignature,
|
||||
};
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! within the pallet, if you want to use the standard `println!`, it needs to be wrapped in
|
||||
//! [`sp_std::if_std`]. Of course, this means that this print code is only available to you in the
|
||||
//! `std` compiler flag, and never present in a wasm build.
|
||||
//! within the pezpallet, if you want to use the standard `println!`, it needs to be wrapped in
|
||||
//! [`pezsp_std::if_std`]. Of course, this means that this print code is only available to you in
|
||||
//! the `std` compiler flag, and never present in a wasm build.
|
||||
//!
|
||||
//! ```
|
||||
//! // somewhere in your pallet. This is not a real pallet code.
|
||||
//! mod pallet {
|
||||
//! struct Pallet;
|
||||
//! impl Pallet {
|
||||
//! // somewhere in your pezpallet. This is not a real pezpallet code.
|
||||
//! mod pezpallet {
|
||||
//! struct Pezpallet;
|
||||
//! impl Pezpallet {
|
||||
//! fn print() {
|
||||
//! sp_std::if_std! {
|
||||
//! pezsp_std::if_std! {
|
||||
//! println!("Hello, world!");
|
||||
//! }
|
||||
//! }
|
||||
@@ -42,9 +42,9 @@
|
||||
//! 1. `log-level`, signifying how important it is.
|
||||
//! 2. `log-target`, signifying to which component it belongs.
|
||||
//!
|
||||
//! Add log statements to your pallet as such:
|
||||
//! Add log statements to your pezpallet as such:
|
||||
//!
|
||||
//! You can add the log crate to the `Cargo.toml` of the pallet.
|
||||
//! You can add the log crate to the `Cargo.toml` of the pezpallet.
|
||||
//!
|
||||
//! ```text
|
||||
//! #[dependencies]
|
||||
@@ -57,49 +57,49 @@
|
||||
//! ]
|
||||
//! ```
|
||||
//!
|
||||
//! More conveniently, the `frame` umbrella crate re-exports the log crate as [`frame::log`].
|
||||
//! More conveniently, the `frame` umbrella crate re-exports the log crate as [`pezframe::log`].
|
||||
//!
|
||||
//! Then, the pallet can use this crate to emit log statements. In this statement, we use the info
|
||||
//! level, and the target is `pallet-example`.
|
||||
//! Then, the pezpallet can use this crate to emit log statements. In this statement, we use the
|
||||
//! info level, and the target is `pezpallet-example`.
|
||||
//!
|
||||
//! ```
|
||||
//! mod pallet {
|
||||
//! struct Pallet;
|
||||
//! mod pezpallet {
|
||||
//! struct Pezpallet;
|
||||
//!
|
||||
//! impl Pallet {
|
||||
//! impl Pezpallet {
|
||||
//! fn logs() {
|
||||
//! frame::log::info!(target: "pallet-example", "Hello, world!");
|
||||
//! pezframe::log::info!(target: "pezpallet-example", "Hello, world!");
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! This will in itself just emit the log messages, **but unless if captured by a logger, they will
|
||||
//! not go anywhere**. [`sp_api`] provides a handy function to enable the runtime logging:
|
||||
//! not go anywhere**. [`pezsp_api`] provides a handy function to enable the runtime logging:
|
||||
//!
|
||||
//! ```
|
||||
//! // in your test
|
||||
//! fn it_also_prints() {
|
||||
//! sp_api::init_runtime_logger();
|
||||
//! // call into your pallet, and now it will print `log` statements.
|
||||
//! pezsp_api::init_runtime_logger();
|
||||
//! // call into your pezpallet, and now it will print `log` statements.
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Alternatively, you can use [`sp_tracing::try_init_simple`].
|
||||
//! Alternatively, you can use [`pezsp_tracing::try_init_simple`].
|
||||
//!
|
||||
//! `info`, `error` and `warn` logs are printed by default, but if you want lower level logs to also
|
||||
//! be printed, you must to add the following compiler flag:
|
||||
//!
|
||||
//! ```text
|
||||
//! RUST_LOG=pallet-example=trace cargo test
|
||||
//! RUST_LOG=pezpallet-example=trace cargo test
|
||||
//! ```
|
||||
//!
|
||||
//! ## Enabling Logs in Production
|
||||
//!
|
||||
//! All logs from the runtime are emitted by default, but there is a feature flag in [`sp_api`],
|
||||
//! All logs from the runtime are emitted by default, but there is a feature flag in [`pezsp_api`],
|
||||
//! called `disable-logging`, that can be used to disable all logs in the runtime. This is useful
|
||||
//! for production chains to reduce the size and overhead of the wasm runtime.
|
||||
#![doc = docify::embed!("../../substrate/primitives/api/src/lib.rs", init_runtime_logger)]
|
||||
#![doc = docify::embed!("../../bizinikiwi/primitives/api/src/lib.rs", init_runtime_logger)]
|
||||
//!
|
||||
//! Similar to the above, the proper `RUST_LOG` must also be passed to your compiler flag when
|
||||
//! compiling the runtime.
|
||||
@@ -107,7 +107,7 @@
|
||||
//! ## Log Target Prefixing
|
||||
//!
|
||||
//! Many [`crate::pezkuwi_sdk::frame_runtime`] pallets emit logs with log target `runtime::<name of
|
||||
//! pallet>`, for example `runtime::system`. This then allows one to run a node with a wasm blob
|
||||
//! pezpallet>`, for example `runtime::system`. This then allows one to run a node with a wasm blob
|
||||
//! compiled with `LOG_TARGET=runtime=debug`, which enables the log target of all pallets who's log
|
||||
//! target starts with `runtime`.
|
||||
//!
|
||||
@@ -115,8 +115,8 @@
|
||||
//!
|
||||
//! Under the hood, logging is another instance of host functions under the hood (as defined in
|
||||
//! [`crate::reference_docs::wasm_meta_protocol`]). The runtime uses a set of host functions under
|
||||
//! [`sp_io::logging`] and [`sp_io::misc`] to emit all logs and prints. You typically do not need to
|
||||
//! use these APIs directly.
|
||||
//! [`pezsp_io::logging`] and [`pezsp_io::misc`] to emit all logs and prints. You typically do not
|
||||
//! need to use these APIs directly.
|
||||
//!
|
||||
//! ## Using Logging in Production
|
||||
//!
|
||||
@@ -124,12 +124,12 @@
|
||||
//! and can lead to consensus issues. This is because with the introduction of
|
||||
//! [`crate::guides::enable_pov_reclaim`], the node side code will track the storage changes, and
|
||||
//! tries to update the onchain record of the `proof_size` weight used (stored in
|
||||
//! [`frame_system::BlockWeight`]) after the block is executed.
|
||||
//! [`pezframe_system::BlockWeight`]) after the block is executed.
|
||||
//!
|
||||
//! If one node has a different log level enabled than the rest of the network, and the extra logs
|
||||
//! impose additional storage reads, then the amount of `proof_size` weight reclaimed into
|
||||
//! [`frame_system::BlockWeight`] will be different, causing a state root mismatch, which is
|
||||
//! typically a fatal error emitted from [`frame_executive`].
|
||||
//! [`pezframe_system::BlockWeight`] will be different, causing a state root mismatch, which is
|
||||
//! typically a fatal error emitted from [`pezframe_executive`].
|
||||
//!
|
||||
//! This also can also happen in a teyrchain context, and cause discrepancies between the relay
|
||||
//! chain and the teyrchain, when execution the Teyrchain Validation Function (PVF) on the relay
|
||||
@@ -151,5 +151,5 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Please read [this issue](https://github.com/pezkuwichain/pezkuwi-sdk/issues/155) for one
|
||||
//! Please read [this issue](https://github.com/pezkuwichain/pezkuwi-sdk/issues/298) for one
|
||||
//! instance of the consensus issues caused by this mistake.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! # Offchain Workers
|
||||
//!
|
||||
//! This reference document explains how offchain workers work in Substrate and FRAME. The main
|
||||
//! This reference document explains how offchain workers work in Bizinikiwi and FRAME. The main
|
||||
//! focus is upon FRAME's implementation of this functionality. Nonetheless, offchain workers are a
|
||||
//! Substrate-provided feature and can be used with possible alternatives to [`frame`] as well.
|
||||
//! Bizinikiwi-provided feature and can be used with possible alternatives to [`frame`] as well.
|
||||
//!
|
||||
//! Offchain workers are a commonly misunderstood topic, therefore we explain them bottom-up,
|
||||
//! starting at the fundamentals and then describing the developer interface.
|
||||
@@ -11,11 +11,11 @@
|
||||
//!
|
||||
//! Recall from [`crate::reference_docs::wasm_meta_protocol`] that the node and the runtime
|
||||
//! communicate with one another via host functions and runtime APIs. Many of these interactions
|
||||
//! contribute to the actual state transition of the blockchain. For example [`sp_api::Core`] is the
|
||||
//! main runtime API that is called to execute new blocks.
|
||||
//! contribute to the actual state transition of the blockchain. For example [`pezsp_api::Core`] is
|
||||
//! the main runtime API that is called to execute new blocks.
|
||||
//!
|
||||
//! Offchain workers are in principle not different in any way: It is a runtime API exposed by the
|
||||
//! wasm blob ([`sp_offchain::OffchainWorkerApi`]), and the node software calls into it when it
|
||||
//! wasm blob ([`pezsp_offchain::OffchainWorkerApi`]), and the node software calls into it when it
|
||||
//! deems fit. But, crucially, this API call is different in that:
|
||||
//!
|
||||
//! 1. It can have no impact on the state ie. it is _OFF (the) CHAIN_. If any state is altered
|
||||
@@ -25,7 +25,7 @@
|
||||
//!
|
||||
//! > The main way through which an offchain worker can interact with the state is by submitting an
|
||||
//! > extrinsic to the chain. This is the ONLY way to alter the state from an offchain worker.
|
||||
//! > [`pallet_example_offchain_worker`] provides an example of this.
|
||||
//! > [`pezpallet_example_offchain_worker`] provides an example of this.
|
||||
//!
|
||||
//!
|
||||
//! Given the "Off Chain" nature of this API, it is important to remember that calling this API is
|
||||
@@ -33,16 +33,16 @@
|
||||
//! the execution of your blockchain because no state is altered no matter the execution of the
|
||||
//! offchain worker API.
|
||||
//!
|
||||
//! Substrate's CLI allows some degree of configuration about this, allowing node operators to
|
||||
//! Bizinikiwi's CLI allows some degree of configuration about this, allowing node operators to
|
||||
//! specify when they want to run the offchain worker API. See
|
||||
//! [`sc_cli::RunCmd::offchain_worker_params`].
|
||||
//! [`pezsc_cli::RunCmd::offchain_worker_params`].
|
||||
//!
|
||||
//! ## Nondeterministic Execution
|
||||
//!
|
||||
//! Needless to say, given the above description, the code in your offchain worker API can be
|
||||
//! nondeterministic, as it is not part of the blockchain's STF, so it can be executed at unknown
|
||||
//! times, by unknown nodes, and has no impact on the state. This is why an HTTP
|
||||
//! ([`sp_runtime::offchain::http`]) API is readily provided to the offchain worker APIs. Because
|
||||
//! ([`pezsp_runtime::offchain::http`]) API is readily provided to the offchain worker APIs. Because
|
||||
//! there is no need for determinism in this context.
|
||||
//!
|
||||
//! > A common mistake here is for novice developers to see this HTTP API, and imagine that
|
||||
@@ -54,22 +54,22 @@
|
||||
//! ## FRAME's API
|
||||
//!
|
||||
//! [`frame`] provides a simple API through which pallets can define offchain worker functions. This
|
||||
//! is part of [`frame::traits::Hooks`], which is implemented as a part of
|
||||
//! [`frame::pallet_macros::hooks`].
|
||||
//! is part of [`pezframe::traits::Hooks`], which is implemented as a part of
|
||||
//! [`pezframe::pezpallet_macros::hooks`].
|
||||
//!
|
||||
//! ```
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use frame::prelude::*;
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! use pezframe::prelude::*;
|
||||
//!
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config {}
|
||||
//! #[pezpallet::config]
|
||||
//! pub trait Config: pezframe_system::Config {}
|
||||
//!
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//! #[pezpallet::pezpallet]
|
||||
//! pub struct Pezpallet<T>(_);
|
||||
//!
|
||||
//! #[pallet::hooks]
|
||||
//! impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
//! #[pezpallet::hooks]
|
||||
//! impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
//! fn offchain_worker(block_number: BlockNumberFor<T>) {
|
||||
//! // ...
|
||||
//! }
|
||||
@@ -77,10 +77,10 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Additionally, [`sp_runtime::offchain`] provides a set of utilities that can be used to moderate
|
||||
//! the execution of offchain workers.
|
||||
//! Additionally, [`pezsp_runtime::offchain`] provides a set of utilities that can be used to
|
||||
//! moderate the execution of offchain workers.
|
||||
//!
|
||||
//! ## Think Twice: Why Use Substrate's Offchain Workers?
|
||||
//! ## Think Twice: Why Use Bizinikiwi's Offchain Workers?
|
||||
//!
|
||||
//! Consider the fact that in principle, an offchain worker code written using the above API is no
|
||||
//! different than an equivalent written with an _actual offchain interaction library_, such as
|
||||
@@ -88,16 +88,16 @@
|
||||
//!
|
||||
//! They can both read from the state, and have no means of updating the state, other than the route
|
||||
//! of submitting an extrinsic to the chain. Therefore, it is worth thinking twice before embedding
|
||||
//! a logic as a part of Substrate's offchain worker API. Does it have to be there? Can it not be a
|
||||
//! a logic as a part of Bizinikiwi's offchain worker API. Does it have to be there? Can it not be a
|
||||
//! simple, actual offchain application that lives outside of the chain's WASM blob?
|
||||
//!
|
||||
//! Some of the reasons why you might want to do the opposite, and actually embed an offchain worker
|
||||
//! API into the WASM blob are:
|
||||
//!
|
||||
//! * Accessing the state is easier within the `offchain_worker` function, as it is already a part
|
||||
//! of the runtime, and [`frame::pallet_macros::storage`] provides all the tools needed to read
|
||||
//! of the runtime, and [`pezframe::pezpallet_macros::storage`] provides all the tools needed to read
|
||||
//! the state. Other client libraries might provide varying degrees of capability here.
|
||||
//! * It will be updated in synchrony with the runtime. A Substrate's offchain application is part
|
||||
//! * It will be updated in synchrony with the runtime. A Bizinikiwi's offchain application is part
|
||||
//! of the same WASM blob, and is therefore guaranteed to be up to date.
|
||||
//!
|
||||
//! For example, imagine you have modified a storage item to have a new type. This will possibly
|
||||
@@ -111,4 +111,4 @@
|
||||
//!
|
||||
//! - <https://forum.polkadot.network/t/offchain-workers-design-assumptions-vulnerabilities/2548>
|
||||
//! - <https://exchange.pezkuwichain.app/questions/11058/how-can-i-create-ocw-that-wont-activates-every-block-but-will-activates-only-w/11060#11060>
|
||||
//! - [Offchain worker example](https://github.com/pezkuwichain/pezkuwi-sdk/tree/master/substrate/frame/examples/offchain-worker)
|
||||
//! - [Offchain worker example](https://github.com/pezkuwichain/pezkuwi-sdk/tree/master/bizinikiwi/pezframe/examples/offchain-worker)
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
//!
|
||||
//! FRAME's origin abstractions allow you to convey meanings far beyond just an account-id being the
|
||||
//! caller of an extrinsic. Nonetheless, an account-id having signed an extrinsic is one of the
|
||||
//! meanings that an origin can convey. This is the commonly used [`frame_system::ensure_signed`],
|
||||
//! where the return value happens to be an account-id.
|
||||
//! meanings that an origin can convey. This is the commonly used
|
||||
//! [`pezframe_system::ensure_signed`], where the return value happens to be an account-id.
|
||||
//!
|
||||
//! Instead, let's establish the following as the correct definition of an origin:
|
||||
//!
|
||||
@@ -21,8 +21,8 @@
|
||||
//! example:
|
||||
//!
|
||||
//! * If the majority of token holders agreed upon this. This is more or less what the
|
||||
//! [`pallet_democracy`] does under the hood ([reference](https://github.com/pezkuwichain/pezkuwi-sdk/blob/edd95b3749754d2ed0c5738588e872c87be91624/substrate/frame/democracy/src/lib.rs#L1603-L1633)).
|
||||
//! * If a specific ratio of an instance of [`pallet_collective`]/DAO agrees upon this.
|
||||
//! [`pezpallet_democracy`] does under the hood ([reference](https://github.com/pezkuwichain/pezkuwi-sdk/blob/edd95b3749754d2ed0c5738588e872c87be91624/bizinikiwi/pezframe/democracy/src/lib.rs#L1603-L1633)).
|
||||
//! * If a specific ratio of an instance of [`pezpallet_collective`]/DAO agrees upon this.
|
||||
//! * If another consensus system, for example a bridged network or a teyrchain, agrees upon this.
|
||||
//! * If the majority of validator/authority set agrees upon this[^1].
|
||||
//! * If caller holds a particular NFT.
|
||||
@@ -31,88 +31,89 @@
|
||||
//!
|
||||
//! ## Context
|
||||
//!
|
||||
//! First, let's look at where the `origin` type is encountered in a typical pallet. The `origin:
|
||||
//! First, let's look at where the `origin` type is encountered in a typical pezpallet. The `origin:
|
||||
//! OriginFor<T>` has to be the first argument of any given callable extrinsic in FRAME:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", call_simple)]
|
||||
//!
|
||||
//! Typically, the code of an extrinsic starts with an origin check, such as
|
||||
//! [`frame_system::ensure_signed`].
|
||||
//! [`pezframe_system::ensure_signed`].
|
||||
//!
|
||||
//! Note that [`OriginFor`](frame_system::pallet_prelude::OriginFor) is merely a shorthand for
|
||||
//! [`frame_system::Config::RuntimeOrigin`]. Given the name prefix `Runtime`, we can learn that
|
||||
//! Note that [`OriginFor`](pezframe_system::pezpallet_prelude::OriginFor) is merely a shorthand for
|
||||
//! [`pezframe_system::Config::RuntimeOrigin`]. Given the name prefix `Runtime`, we can learn that
|
||||
//! `RuntimeOrigin` is similar to `RuntimeCall` and others, a runtime composite enum that is
|
||||
//! amalgamated at the runtime level. Read [`crate::reference_docs::frame_runtime_types`] to
|
||||
//! familiarize yourself with these types.
|
||||
//!
|
||||
//! To understand this better, we will next create a pallet with a custom origin, which will add a
|
||||
//! new variant to `RuntimeOrigin`.
|
||||
//! To understand this better, we will next create a pezpallet with a custom origin, which will add
|
||||
//! a new variant to `RuntimeOrigin`.
|
||||
//!
|
||||
//! ## Adding Custom Pallet Origin to the Runtime
|
||||
//! ## Adding Custom Pezpallet Origin to the Runtime
|
||||
//!
|
||||
//! For example, given a pallet that defines the following custom origin:
|
||||
//! For example, given a pezpallet that defines the following custom origin:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", custom_origin)]
|
||||
//!
|
||||
//! And a runtime with the following pallets:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", runtime_exp)]
|
||||
//!
|
||||
//! The type [`crate::reference_docs::frame_origin::runtime_for_origin::RuntimeOrigin`] is expanded.
|
||||
//! This `RuntimeOrigin` contains a variant for the [`frame_system::RawOrigin`] and the custom
|
||||
//! origin of the pallet.
|
||||
//! This `RuntimeOrigin` contains a variant for the [`pezframe_system::RawOrigin`] and the custom
|
||||
//! origin of the pezpallet.
|
||||
//!
|
||||
//! > Notice how the [`frame_system::ensure_signed`] is nothing more than a `match` statement. If
|
||||
//! > Notice how the [`pezframe_system::ensure_signed`] is nothing more than a `match` statement. If
|
||||
//! > you want to know where the actual origin of an extrinsic is set (and the signature
|
||||
//! > verification happens, if any), see
|
||||
//! > [`sp_runtime::generic::CheckedExtrinsic#trait-implementations`], specifically
|
||||
//! > [`sp_runtime::traits::Applyable`]'s implementation.
|
||||
//! > [`pezsp_runtime::generic::CheckedExtrinsic#trait-implementations`], specifically
|
||||
//! > [`pezsp_runtime::traits::Applyable`]'s implementation.
|
||||
//!
|
||||
//! ## Asserting on a Custom Internal Origin
|
||||
//!
|
||||
//! In order to assert on a custom origin that is defined within your pallet, we need a way to first
|
||||
//! convert the `<T as frame_system::Config>::RuntimeOrigin` into the local `enum Origin` of the
|
||||
//! current pallet. This is a common process that is explained in
|
||||
//! In order to assert on a custom origin that is defined within your pezpallet, we need a way to
|
||||
//! first convert the `<T as pezframe_system::Config>::RuntimeOrigin` into the local `enum Origin`
|
||||
//! of the current pezpallet. This is a common process that is explained in
|
||||
//! [`crate::reference_docs::frame_runtime_types#
|
||||
//! adding-further-constraints-to-runtime-composite-enums`].
|
||||
//!
|
||||
//! We use the same process here to express that `RuntimeOrigin` has a number of additional bounds,
|
||||
//! as follows.
|
||||
//!
|
||||
//! 1. Defining a custom `RuntimeOrigin` with further bounds in the pallet.
|
||||
//! 1. Defining a custom `RuntimeOrigin` with further bounds in the pezpallet.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", custom_origin_bound)]
|
||||
//!
|
||||
//! 2. Using it in the pallet.
|
||||
//! 2. Using it in the pezpallet.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", custom_origin_usage)]
|
||||
//!
|
||||
//! ## Asserting on a Custom External Origin
|
||||
//!
|
||||
//! Very often, a pallet wants to have a parameterized origin that is **NOT** defined within the
|
||||
//! pallet. In other words, a pallet wants to delegate an origin check to something that is
|
||||
//! Very often, a pezpallet wants to have a parameterized origin that is **NOT** defined within the
|
||||
//! pezpallet. In other words, a pezpallet wants to delegate an origin check to something that is
|
||||
//! specified later at the runtime level. Like many other parameterizations in FRAME, this implies
|
||||
//! adding a new associated type to `trait Config`.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_def)]
|
||||
//!
|
||||
//! Then, within the pallet, we can simply use this "unknown" origin check type:
|
||||
//! Then, within the pezpallet, we can simply use this "unknown" origin check type:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_usage)]
|
||||
//!
|
||||
//! Finally, at the runtime, any implementation of [`frame::traits::EnsureOrigin`] can be passed.
|
||||
//! Finally, at the runtime, any implementation of [`pezframe::traits::EnsureOrigin`] can be passed.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_provide)]
|
||||
//!
|
||||
//! Indeed, some of these implementations of [`frame::traits::EnsureOrigin`] are similar to the ones
|
||||
//! that we know about: [`frame::runtime::prelude::EnsureSigned`],
|
||||
//! [`frame::runtime::prelude::EnsureSignedBy`], [`frame::runtime::prelude::EnsureRoot`],
|
||||
//! [`frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that are not known
|
||||
//! Indeed, some of these implementations of [`pezframe::traits::EnsureOrigin`] are similar to the ones
|
||||
//! that we know about: [`pezframe::runtime::prelude::EnsureSigned`],
|
||||
//! [`pezframe::runtime::prelude::EnsureSignedBy`], [`pezframe::runtime::prelude::EnsureRoot`],
|
||||
//! [`pezframe::runtime::prelude::EnsureNone`], etc. But, there are also many more that are not known
|
||||
//! to us, and are defined in other pallets.
|
||||
//!
|
||||
//! For example, [`pallet_collective`] defines [`pallet_collective::EnsureMember`] and
|
||||
//! [`pallet_collective::EnsureProportionMoreThan`] and many more, which is exactly what we alluded
|
||||
//! to earlier in this document.
|
||||
//! For example, [`pezpallet_collective`] defines [`pezpallet_collective::EnsureMember`] and
|
||||
//! [`pezpallet_collective::EnsureProportionMoreThan`] and many more, which is exactly what we
|
||||
//! alluded to earlier in this document.
|
||||
//!
|
||||
//! Make sure to check the full list of [implementors of
|
||||
//! `EnsureOrigin`](frame::traits::EnsureOrigin#implementors) for more inspiration.
|
||||
//! `EnsureOrigin`](pezframe::traits::EnsureOrigin#implementors) for more inspiration.
|
||||
//!
|
||||
//! ## Obtaining Abstract Origins
|
||||
//!
|
||||
//! So far we have learned that FRAME pallets can assert on custom and abstract origin types,
|
||||
//! whether they are defined within the pallet or not. But how can we obtain these abstract origins?
|
||||
//! whether they are defined within the pezpallet or not. But how can we obtain these abstract
|
||||
//! origins?
|
||||
//!
|
||||
//! > All extrinsics that come from the outer world can generally only be obtained as either
|
||||
//! > `signed` or `none` origin.
|
||||
@@ -125,24 +126,24 @@
|
||||
//! - [Gavin Wood's speech about FRAME features at Protocol Berg 2023.](https://youtu.be/j7b8Upipmeg?si=83_XUgYuJxMwWX4g&t=195)
|
||||
//! - [A related StackExchange question.](https://exchange.pezkuwichain.app/questions/10992/how-do-you-find-the-public-key-for-the-medium-spender-track-origin)
|
||||
//!
|
||||
//! [^1]: Inherents are essentially unsigned extrinsics that need an [`frame_system::ensure_none`]
|
||||
//! [^1]: Inherents are essentially unsigned extrinsics that need an [`pezframe_system::ensure_none`]
|
||||
//! origin check, and through the virtue of being an inherent, are agreed upon by all validators.
|
||||
|
||||
use frame::prelude::*;
|
||||
use pezframe::prelude::*;
|
||||
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_for_origin {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_for_origin {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(call_simple)]
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn do_something(_origin: OriginFor<T>) -> DispatchResult {
|
||||
// ^^^^^^^^^^^^^^^^^^^^^
|
||||
todo!();
|
||||
@@ -150,23 +151,23 @@ pub mod pallet_for_origin {
|
||||
}
|
||||
}
|
||||
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_with_custom_origin {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_with_custom_origin {
|
||||
use super::*;
|
||||
|
||||
#[docify::export(custom_origin_bound)]
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type RuntimeOrigin: From<<Self as frame_system::Config>::RuntimeOrigin>
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
type RuntimeOrigin: From<<Self as pezframe_system::Config>::RuntimeOrigin>
|
||||
+ Into<Result<Origin, <Self as Config>::RuntimeOrigin>>;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(custom_origin)]
|
||||
/// A dummy custom origin.
|
||||
#[pallet::origin]
|
||||
#[pezpallet::origin]
|
||||
#[derive(
|
||||
PartialEq,
|
||||
Eq,
|
||||
@@ -186,13 +187,13 @@ pub mod pallet_with_custom_origin {
|
||||
}
|
||||
|
||||
#[docify::export(custom_origin_usage)]
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn only_validators(origin: OriginFor<T>) -> DispatchResult {
|
||||
// first, we convert from `<T as frame_system::Config>::RuntimeOrigin` to `<T as
|
||||
// first, we convert from `<T as pezframe_system::Config>::RuntimeOrigin` to `<T as
|
||||
// Config>::RuntimeOrigin`
|
||||
let local_runtime_origin = <<T as Config>::RuntimeOrigin as From<
|
||||
<T as frame_system::Config>::RuntimeOrigin,
|
||||
<T as pezframe_system::Config>::RuntimeOrigin,
|
||||
>>::from(origin);
|
||||
// then we convert to `origin`, if possible
|
||||
let local_origin =
|
||||
@@ -204,42 +205,42 @@ pub mod pallet_with_custom_origin {
|
||||
}
|
||||
|
||||
pub mod runtime_for_origin {
|
||||
use super::pallet_with_custom_origin;
|
||||
use frame::{runtime::prelude::*, testing_prelude::*};
|
||||
use super::pezpallet_with_custom_origin;
|
||||
use pezframe::{runtime::prelude::*, testing_prelude::*};
|
||||
|
||||
#[docify::export(runtime_exp)]
|
||||
construct_runtime!(
|
||||
pub struct Runtime {
|
||||
System: frame_system,
|
||||
PalletWithCustomOrigin: pallet_with_custom_origin,
|
||||
System: pezframe_system,
|
||||
PalletWithCustomOrigin: pezpallet_with_custom_origin,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = MockBlock<Self>;
|
||||
}
|
||||
|
||||
impl pallet_with_custom_origin::Config for Runtime {
|
||||
impl pezpallet_with_custom_origin::Config for Runtime {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
}
|
||||
}
|
||||
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_with_external_origin {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_with_external_origin {
|
||||
use super::*;
|
||||
#[docify::export(external_origin_def)]
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
type ExternalOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(external_origin_usage)]
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn externally_checked_ext(origin: OriginFor<T>) -> DispatchResult {
|
||||
T::ExternalOrigin::ensure_origin(origin)?;
|
||||
todo!();
|
||||
@@ -249,22 +250,22 @@ pub mod pallet_with_external_origin {
|
||||
|
||||
pub mod runtime_for_external_origin {
|
||||
use super::*;
|
||||
use frame::{runtime::prelude::*, testing_prelude::*};
|
||||
use pezframe::{runtime::prelude::*, testing_prelude::*};
|
||||
|
||||
construct_runtime!(
|
||||
pub struct Runtime {
|
||||
System: frame_system,
|
||||
PalletWithExternalOrigin: pallet_with_external_origin,
|
||||
System: pezframe_system,
|
||||
PalletWithExternalOrigin: pezpallet_with_external_origin,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = MockBlock<Self>;
|
||||
}
|
||||
|
||||
#[docify::export(external_origin_provide)]
|
||||
impl pallet_with_external_origin::Config for Runtime {
|
||||
type ExternalOrigin = EnsureSigned<<Self as frame_system::Config>::AccountId>;
|
||||
impl pezpallet_with_external_origin::Config for Runtime {
|
||||
type ExternalOrigin = EnsureSigned<<Self as pezframe_system::Config>::AccountId>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
//! # FRAME Pallet Coupling
|
||||
//! # FRAME Pezpallet Coupling
|
||||
//!
|
||||
//! This reference document explains how FRAME pallets can be combined to interact together.
|
||||
//!
|
||||
//! It is suggested to re-read [`crate::pezkuwi_sdk::frame_runtime`], notably the information
|
||||
//! around [`frame::pallet_macros::config`]. Recall that:
|
||||
//! around [`pezframe::pezpallet_macros::config`]. Recall that:
|
||||
//!
|
||||
//! > Configuration trait of a pallet: It allows a pallet to receive types at a later
|
||||
//! > point from the runtime that wishes to contain it. It allows the pallet to be parameterized
|
||||
//! > Configuration trait of a pezpallet: It allows a pezpallet to receive types at a later
|
||||
//! > point from the runtime that wishes to contain it. It allows the pezpallet to be parameterized
|
||||
//! > over both types and values.
|
||||
//!
|
||||
//! ## Context, Background
|
||||
//!
|
||||
//! FRAME pallets, as per described in [`crate::pezkuwi_sdk::frame_runtime`] are:
|
||||
//!
|
||||
//! > A pallet is a unit of encapsulated logic. It has a clearly defined responsibility and can be
|
||||
//! > A pezpallet is a unit of encapsulated logic. It has a clearly defined responsibility and can
|
||||
//! > be
|
||||
//! linked to other pallets.
|
||||
//!
|
||||
//! That is to say:
|
||||
//!
|
||||
//! * *encapsulated*: Ideally, a FRAME pallet contains encapsulated logic which has clear
|
||||
//! boundaries. It is generally a bad idea to build a single monolithic pallet that does multiple
|
||||
//! things, such as handling currencies, identities and staking all at the same time.
|
||||
//! * *encapsulated*: Ideally, a FRAME pezpallet contains encapsulated logic which has clear
|
||||
//! boundaries. It is generally a bad idea to build a single monolithic pezpallet that does
|
||||
//! multiple things, such as handling currencies, identities and staking all at the same time.
|
||||
//! * *linked to other pallets*: But, adhering extensively to the above also hinders the ability to
|
||||
//! write useful applications. Pallets often need to work with each other, communicate and use
|
||||
//! each other's functionalities.
|
||||
//!
|
||||
//! The broad principle that allows pallets to be linked together is the same way through which a
|
||||
//! pallet uses its `Config` trait to receive types and values from the runtime that contains it.
|
||||
//! pezpallet uses its `Config` trait to receive types and values from the runtime that contains it.
|
||||
//!
|
||||
//! There are generally two ways to achieve this:
|
||||
//!
|
||||
@@ -63,52 +64,52 @@
|
||||
//!
|
||||
//! ## Example
|
||||
//!
|
||||
//! Consider the following example, in which `pallet-foo` needs another pallet to provide the block
|
||||
//! author to it, and `pallet-author` which has access to this information.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", pallet_foo)]
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", pallet_author)]
|
||||
//! Consider the following example, in which `pezpallet-foo` needs another pezpallet to provide the
|
||||
//! block author to it, and `pezpallet-author` which has access to this information.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", pezpallet_foo)]
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", pezpallet_author)]
|
||||
//!
|
||||
//! ### Tight Coupling Pallets
|
||||
//!
|
||||
//! To tightly couple `pallet-foo` and `pallet-author`, we use Rust's supertrait system. When a
|
||||
//! pallet makes its own `trait Config` be bounded by another pallet's `trait Config`, it is
|
||||
//! To tightly couple `pezpallet-foo` and `pezpallet-author`, we use Rust's supertrait system. When
|
||||
//! a pezpallet makes its own `trait Config` be bounded by another pezpallet's `trait Config`, it is
|
||||
//! expressing two things:
|
||||
//!
|
||||
//! 1. That it can only exist in a runtime if the other pallet is also present.
|
||||
//! 2. That it can use the other pallet's functionality.
|
||||
//! 1. That it can only exist in a runtime if the other pezpallet is also present.
|
||||
//! 2. That it can use the other pezpallet's functionality.
|
||||
//!
|
||||
//! `pallet-foo`'s `Config` would then look like:
|
||||
//! `pezpallet-foo`'s `Config` would then look like:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", tight_config)]
|
||||
//!
|
||||
//! And `pallet-foo` can use the method exposed by `pallet_author::Pallet` directly:
|
||||
//! And `pezpallet-foo` can use the method exposed by `pezpallet_author::Pezpallet` directly:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", tight_usage)]
|
||||
//!
|
||||
//!
|
||||
//! ### Loosely Coupling Pallets
|
||||
//!
|
||||
//! If `pallet-foo` wants to *not* rely on `pallet-author` directly, it can leverage its
|
||||
//! If `pezpallet-foo` wants to *not* rely on `pezpallet-author` directly, it can leverage its
|
||||
//! `Config`'s associated types. First, we need a trait to express the functionality that
|
||||
//! `pallet-foo` wants to obtain:
|
||||
//! `pezpallet-foo` wants to obtain:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", AuthorProvider)]
|
||||
//!
|
||||
//! > We sometimes refer to such traits that help two pallets interact as "glue traits".
|
||||
//!
|
||||
//! Next, `pallet-foo` states that it needs this trait to be provided to it, at the runtime level,
|
||||
//! via an associated type:
|
||||
//! Next, `pezpallet-foo` states that it needs this trait to be provided to it, at the runtime
|
||||
//! level, via an associated type:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", loose_config)]
|
||||
//!
|
||||
//! Then, `pallet-foo` can use this trait to obtain the block author, without knowing where it comes
|
||||
//! from:
|
||||
//! Then, `pezpallet-foo` can use this trait to obtain the block author, without knowing where it
|
||||
//! comes from:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", loose_usage)]
|
||||
//!
|
||||
//! Then, if `pallet-author` implements this glue-trait:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", pallet_author_provider)]
|
||||
//! Then, if `pezpallet-author` implements this glue-trait:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", pezpallet_author_provider)]
|
||||
//!
|
||||
//! And upon the creation of the runtime, the two pallets are linked together as such:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pallet_coupling.rs", runtime_author_provider)]
|
||||
//!
|
||||
//! Crucially, when using loose coupling, we gain the flexibility of providing different
|
||||
//! implementations of `AuthorProvider`, such that different users of a `pallet-foo` can use
|
||||
//! implementations of `AuthorProvider`, such that different users of a `pezpallet-foo` can use
|
||||
//! different ones, without any code change being needed. For example, in the code snippets of this
|
||||
//! module, you can find [`OtherAuthorProvider`], which is an alternative implementation of
|
||||
//! [`AuthorProvider`].
|
||||
@@ -120,11 +121,11 @@
|
||||
//!
|
||||
//! ## Frame System
|
||||
//!
|
||||
//! With the above information in context, we can conclude that **`frame_system` is a special pallet
|
||||
//! that is tightly coupled with every other pallet**. This is because it provides the fundamental
|
||||
//! system functionality that every pallet needs, such as some types like
|
||||
//! [`frame::prelude::frame_system::Config::AccountId`],
|
||||
//! [`frame::prelude::frame_system::Config::Hash`], and some functionality such as block number,
|
||||
//! With the above information in context, we can conclude that **`pezframe_system` is a special
|
||||
//! pezpallet that is tightly coupled with every other pezpallet**. This is because it provides the
|
||||
//! fundamental system functionality that every pezpallet needs, such as some types like
|
||||
//! [`pezframe::prelude::pezframe_system::Config::AccountId`],
|
||||
//! [`pezframe::prelude::pezframe_system::Config::Hash`], and some functionality such as block number,
|
||||
//! etc.
|
||||
//!
|
||||
//! ## Recap
|
||||
@@ -132,43 +133,44 @@
|
||||
//! To recap, consider the following rules of thumb:
|
||||
//!
|
||||
//! * In all cases, try and break down big pallets apart with clear boundaries of responsibility. In
|
||||
//! general, it is easier to argue about multiple pallet if they only communicate together via a
|
||||
//! known trait, rather than having access to all of each others public items, such as storage and
|
||||
//! dispatchables.
|
||||
//! general, it is easier to argue about multiple pezpallet if they only communicate together via
|
||||
//! a known trait, rather than having access to all of each others public items, such as storage
|
||||
//! and dispatchables.
|
||||
//! * If a group of pallets is meant to work together, but is not foreseen to be generalized, or
|
||||
//! used by others, consider tightly coupling pallets, *if it simplifies the development*.
|
||||
//! * If a pallet needs a functionality provided by another pallet, but multiple implementations can
|
||||
//! be foreseen, consider loosely coupling pallets.
|
||||
//! * If a pezpallet needs a functionality provided by another pezpallet, but multiple
|
||||
//! implementations can be foreseen, consider loosely coupling pallets.
|
||||
//!
|
||||
//! For example, all pallets in `pezkuwi-sdk` that needed to work with currencies could have been
|
||||
//! tightly coupled with [`pallet_balances`]. But, `pezkuwi-sdk` also provides [`pallet_assets`]
|
||||
//! (and more implementations by the community), therefore all pallets use traits to loosely couple
|
||||
//! with balances or assets pallet. More on this in [`crate::reference_docs::frame_tokens`].
|
||||
//! tightly coupled with [`pezpallet_balances`]. But, `pezkuwi-sdk` also provides
|
||||
//! [`pezpallet_assets`] (and more implementations by the community), therefore all pallets use
|
||||
//! traits to loosely couple with balances or assets pezpallet. More on this in
|
||||
//! [`crate::reference_docs::frame_tokens`].
|
||||
//!
|
||||
//! ## Further References
|
||||
//!
|
||||
//! - <https://www.youtube.com/watch?v=0eNGZpNkJk4>
|
||||
//! - <https://exchange.pezkuwichain.app/questions/922/pallet-loose-couplingtight-coupling-and-missing-traits>
|
||||
//! - <https://exchange.pezkuwichain.app/questions/922/pezpallet-loose-couplingtight-coupling-and-missing-traits>
|
||||
//!
|
||||
//! [`AuthorProvider`]: crate::reference_docs::frame_pallet_coupling::AuthorProvider
|
||||
//! [`OtherAuthorProvider`]: crate::reference_docs::frame_pallet_coupling::OtherAuthorProvider
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
use frame::prelude::*;
|
||||
use pezframe::prelude::*;
|
||||
|
||||
#[docify::export]
|
||||
#[frame::pallet]
|
||||
pub mod pallet_foo {
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_foo {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn do_stuff_with_author() {
|
||||
// needs block author here
|
||||
}
|
||||
@@ -176,41 +178,42 @@ pub mod pallet_foo {
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[frame::pallet]
|
||||
pub mod pallet_author {
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_author {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn author() -> T::AccountId {
|
||||
todo!("somehow has access to the block author and can return it here")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[frame::pallet]
|
||||
pub mod pallet_foo_tight {
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_foo_tight {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(tight_config)]
|
||||
/// This pallet can only live in a runtime that has both `frame_system` and `pallet_author`.
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + pallet_author::Config {}
|
||||
/// This pezpallet can only live in a runtime that has both `pezframe_system` and
|
||||
/// `pezpallet_author`.
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config + pezpallet_author::Config {}
|
||||
|
||||
#[docify::export(tight_usage)]
|
||||
impl<T: Config> Pallet<T> {
|
||||
// anywhere in `pallet-foo`, we can call into `pallet-author` directly, namely because
|
||||
// `T: pallet_author::Config`
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
// anywhere in `pezpallet-foo`, we can call into `pezpallet-author` directly, namely because
|
||||
// `T: pezpallet_author::Config`
|
||||
fn do_stuff_with_author() {
|
||||
let _ = pallet_author::Pallet::<T>::author();
|
||||
let _ = pezpallet_author::Pezpallet::<T>::author();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,33 +224,33 @@ pub trait AuthorProvider<AccountId> {
|
||||
fn author() -> AccountId;
|
||||
}
|
||||
|
||||
#[frame::pallet]
|
||||
pub mod pallet_foo_loose {
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_foo_loose {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(loose_config)]
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
/// This pallet relies on the existence of something that implements [`AuthorProvider`],
|
||||
/// which may or may not be `pallet-author`.
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
/// This pezpallet relies on the existence of something that implements [`AuthorProvider`],
|
||||
/// which may or may not be `pezpallet-author`.
|
||||
type AuthorProvider: AuthorProvider<Self::AccountId>;
|
||||
}
|
||||
|
||||
#[docify::export(loose_usage)]
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn do_stuff_with_author() {
|
||||
let _ = T::AuthorProvider::author();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(pallet_author_provider)]
|
||||
impl<T: pallet_author::Config> AuthorProvider<T::AccountId> for pallet_author::Pallet<T> {
|
||||
#[docify::export(pezpallet_author_provider)]
|
||||
impl<T: pezpallet_author::Config> AuthorProvider<T::AccountId> for pezpallet_author::Pezpallet<T> {
|
||||
fn author() -> T::AccountId {
|
||||
pallet_author::Pallet::<T>::author()
|
||||
pezpallet_author::Pezpallet::<T>::author()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,27 +272,27 @@ impl<AccountId> AuthorProvider<AccountId> for () {
|
||||
|
||||
pub mod runtime {
|
||||
use super::*;
|
||||
use cumulus_pallet_aura_ext::pallet;
|
||||
use frame::{runtime::prelude::*, testing_prelude::*};
|
||||
use pezcumulus_pezpallet_aura_ext::pezpallet;
|
||||
use pezframe::{runtime::prelude::*, testing_prelude::*};
|
||||
|
||||
construct_runtime!(
|
||||
pub struct Runtime {
|
||||
System: frame_system,
|
||||
PalletFoo: pallet_foo_loose,
|
||||
PalletAuthor: pallet_author,
|
||||
System: pezframe_system,
|
||||
PalletFoo: pezpallet_foo_loose,
|
||||
PalletAuthor: pezpallet_author,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = MockBlock<Self>;
|
||||
}
|
||||
|
||||
impl pallet_author::Config for Runtime {}
|
||||
impl pezpallet_author::Config for Runtime {}
|
||||
|
||||
#[docify::export(runtime_author_provider)]
|
||||
impl pallet_foo_loose::Config for Runtime {
|
||||
type AuthorProvider = pallet_author::Pallet<Runtime>;
|
||||
impl pezpallet_foo_loose::Config for Runtime {
|
||||
type AuthorProvider = pezpallet_author::Pezpallet<Runtime>;
|
||||
// which is also equivalent to
|
||||
// type AuthorProvider = PalletAuthor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
//! # FRAME Pezpallet Coupling
|
||||
//!
|
||||
//! This reference document explains how FRAME pezpallets can be combined to interact together.
|
||||
//!
|
||||
//! It is suggested to re-read [`crate::pezkuwi_sdk::frame_runtime`], notably the information
|
||||
//! around [`pezframe::pezpallet_macros::config`]. Recall that:
|
||||
//!
|
||||
//! > Configuration trait of a pezpallet: It allows a pezpallet to receive types at a later
|
||||
//! > point from the runtime that wishes to contain it. It allows the pezpallet to be parameterized
|
||||
//! > over both types and values.
|
||||
//!
|
||||
//! ## Context, Background
|
||||
//!
|
||||
//! FRAME pezpallets, as per described in [`crate::pezkuwi_sdk::frame_runtime`] are:
|
||||
//!
|
||||
//! > A pezpallet is a unit of encapsulated logic. It has a clearly defined responsibility and can be
|
||||
//! linked to other pezpallets.
|
||||
//!
|
||||
//! That is to say:
|
||||
//!
|
||||
//! * *encapsulated*: Ideally, a FRAME pezpallet contains encapsulated logic which has clear
|
||||
//! boundaries. It is generally a bad idea to build a single monolithic pezpallet that does multiple
|
||||
//! things, such as handling currencies, identities and staking all at the same time.
|
||||
//! * *linked to other pezpallets*: But, adhering extensively to the above also hinders the ability to
|
||||
//! write useful applications. Pezpallets often need to work with each other, communicate and use
|
||||
//! each other's functionalities.
|
||||
//!
|
||||
//! The broad principle that allows pezpallets to be linked together is the same way through which a
|
||||
//! pezpallet uses its `Config` trait to receive types and values from the runtime that contains it.
|
||||
//!
|
||||
//! There are generally two ways to achieve this:
|
||||
//!
|
||||
//! 1. Tight coupling pezpallets.
|
||||
//! 2. Loose coupling pezpallets.
|
||||
//!
|
||||
//! To explain the difference between the two, consider two pezpallets, `A` and `B`. In both cases, `A`
|
||||
//! wants to use some functionality exposed by `B`.
|
||||
//!
|
||||
//! When tightly coupling pezpallets, `A` can only exist in a runtime if `B` is also present in the
|
||||
//! same runtime. That is, `A` is expressing that can only work if `B` is present.
|
||||
//!
|
||||
//! This translates to the following Rust code:
|
||||
//!
|
||||
//! ```
|
||||
//! trait Pezpallet_B_Config {}
|
||||
//! trait Pezpallet_A_Config: Pezpallet_B_Config {}
|
||||
//! ```
|
||||
//!
|
||||
//! Contrary, when pezpallets are loosely coupled, `A` expresses that some functionality, expressed via
|
||||
//! a trait `F`, needs to be fulfilled. This trait is then implemented by `B`, and the two pezpallets
|
||||
//! are linked together at the runtime level. This means that `A` only relies on the implementation
|
||||
//! of `F`, which may be `B`, or another implementation of `F`.
|
||||
//!
|
||||
//! This translates to the following Rust code:
|
||||
//!
|
||||
//! ```
|
||||
//! trait F {}
|
||||
//! trait Pezpallet_A_Config {
|
||||
//! type F: F;
|
||||
//! }
|
||||
//! // Pezpallet_B will implement and fulfill `F`.
|
||||
//! ```
|
||||
//!
|
||||
//! ## Example
|
||||
//!
|
||||
//! Consider the following example, in which `pezpallet-foo` needs another pezpallet to provide the block
|
||||
//! author to it, and `pezpallet-author` which has access to this information.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", pezpallet_foo)]
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", pezpallet_author)]
|
||||
//!
|
||||
//! ### Tight Coupling Pezpallets
|
||||
//!
|
||||
//! To tightly couple `pezpallet-foo` and `pezpallet-author`, we use Rust's supertrait system. When a
|
||||
//! pezpallet makes its own `trait Config` be bounded by another pezpallet's `trait Config`, it is
|
||||
//! expressing two things:
|
||||
//!
|
||||
//! 1. That it can only exist in a runtime if the other pezpallet is also present.
|
||||
//! 2. That it can use the other pezpallet's functionality.
|
||||
//!
|
||||
//! `pezpallet-foo`'s `Config` would then look like:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", tight_config)]
|
||||
//!
|
||||
//! And `pezpallet-foo` can use the method exposed by `pezpallet_author::Pezpallet` directly:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", tight_usage)]
|
||||
//!
|
||||
//!
|
||||
//! ### Loosely Coupling Pezpallets
|
||||
//!
|
||||
//! If `pezpallet-foo` wants to *not* rely on `pezpallet-author` directly, it can leverage its
|
||||
//! `Config`'s associated types. First, we need a trait to express the functionality that
|
||||
//! `pezpallet-foo` wants to obtain:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", AuthorProvider)]
|
||||
//!
|
||||
//! > We sometimes refer to such traits that help two pezpallets interact as "glue traits".
|
||||
//!
|
||||
//! Next, `pezpallet-foo` states that it needs this trait to be provided to it, at the runtime level,
|
||||
//! via an associated type:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", loose_config)]
|
||||
//!
|
||||
//! Then, `pezpallet-foo` can use this trait to obtain the block author, without knowing where it comes
|
||||
//! from:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", loose_usage)]
|
||||
//!
|
||||
//! Then, if `pezpallet-author` implements this glue-trait:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", pezpallet_author_provider)]
|
||||
//!
|
||||
//! And upon the creation of the runtime, the two pezpallets are linked together as such:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", runtime_author_provider)]
|
||||
//!
|
||||
//! Crucially, when using loose coupling, we gain the flexibility of providing different
|
||||
//! implementations of `AuthorProvider`, such that different users of a `pezpallet-foo` can use
|
||||
//! different ones, without any code change being needed. For example, in the code snippets of this
|
||||
//! module, you can find [`OtherAuthorProvider`], which is an alternative implementation of
|
||||
//! [`AuthorProvider`].
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", other_author_provider)]
|
||||
//!
|
||||
//! A common pattern in pezkuwi-sdk is to provide an implementation of such glu traits for the unit
|
||||
//! type as a "default/test behavior".
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_pezpallet_coupling.rs", unit_author_provider)]
|
||||
//!
|
||||
//! ## Frame System
|
||||
//!
|
||||
//! With the above information in context, we can conclude that **`pezframe_system` is a special pezpallet
|
||||
//! that is tightly coupled with every other pezpallet**. This is because it provides the fundamental
|
||||
//! system functionality that every pezpallet needs, such as some types like
|
||||
//! [`pezframe::prelude::pezframe_system::Config::AccountId`],
|
||||
//! [`pezframe::prelude::pezframe_system::Config::Hash`], and some functionality such as block number,
|
||||
//! etc.
|
||||
//!
|
||||
//! ## Recap
|
||||
//!
|
||||
//! To recap, consider the following rules of thumb:
|
||||
//!
|
||||
//! * In all cases, try and break down big pezpallets apart with clear boundaries of responsibility. In
|
||||
//! general, it is easier to argue about multiple pezpallet if they only communicate together via a
|
||||
//! known trait, rather than having access to all of each others public items, such as storage and
|
||||
//! dispatchables.
|
||||
//! * If a group of pezpallets is meant to work together, but is not foreseen to be generalized, or
|
||||
//! used by others, consider tightly coupling pezpallets, *if it simplifies the development*.
|
||||
//! * If a pezpallet needs a functionality provided by another pezpallet, but multiple implementations can
|
||||
//! be foreseen, consider loosely coupling pezpallets.
|
||||
//!
|
||||
//! For example, all pezpallets in `pezkuwi-sdk` that needed to work with currencies could have been
|
||||
//! tightly coupled with [`pezpallet_balances`]. But, `pezkuwi-sdk` also provides [`pezpallet_assets`]
|
||||
//! (and more implementations by the community), therefore all pezpallets use traits to loosely couple
|
||||
//! with balances or assets pezpallet. More on this in [`crate::reference_docs::frame_tokens`].
|
||||
//!
|
||||
//! ## Further References
|
||||
//!
|
||||
//! - <https://www.youtube.com/watch?v=0eNGZpNkJk4>
|
||||
//! - <https://exchange.pezkuwichain.app/questions/922/pezpallet-loose-couplingtight-coupling-and-missing-traits>
|
||||
//!
|
||||
//! [`AuthorProvider`]: crate::reference_docs::frame_pezpallet_coupling::AuthorProvider
|
||||
//! [`OtherAuthorProvider`]: crate::reference_docs::frame_pezpallet_coupling::OtherAuthorProvider
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
use pezframe::prelude::*;
|
||||
|
||||
#[docify::export]
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_foo {
|
||||
use super::*;
|
||||
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn do_stuff_with_author() {
|
||||
// needs block author here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_author {
|
||||
use super::*;
|
||||
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn author() -> T::AccountId {
|
||||
todo!("somehow has access to the block author and can return it here")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_foo_tight {
|
||||
use super::*;
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(tight_config)]
|
||||
/// This pezpallet can only live in a runtime that has both `pezframe_system` and `pezpallet_author`.
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config + pezpallet_author::Config {}
|
||||
|
||||
#[docify::export(tight_usage)]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
// anywhere in `pezpallet-foo`, we can call into `pezpallet-author` directly, namely because
|
||||
// `T: pezpallet_author::Config`
|
||||
fn do_stuff_with_author() {
|
||||
let _ = pezpallet_author::Pezpallet::<T>::author();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
/// Abstraction over "something that can provide the block author".
|
||||
pub trait AuthorProvider<AccountId> {
|
||||
fn author() -> AccountId;
|
||||
}
|
||||
|
||||
#[pezframe::pezpallet]
|
||||
pub mod pezpallet_foo_loose {
|
||||
use super::*;
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[docify::export(loose_config)]
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
/// This pezpallet relies on the existence of something that implements [`AuthorProvider`],
|
||||
/// which may or may not be `pezpallet-author`.
|
||||
type AuthorProvider: AuthorProvider<Self::AccountId>;
|
||||
}
|
||||
|
||||
#[docify::export(loose_usage)]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn do_stuff_with_author() {
|
||||
let _ = T::AuthorProvider::author();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(pezpallet_author_provider)]
|
||||
impl<T: pezpallet_author::Config> AuthorProvider<T::AccountId> for pezpallet_author::Pezpallet<T> {
|
||||
fn author() -> T::AccountId {
|
||||
pezpallet_author::Pezpallet::<T>::author()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OtherAuthorProvider;
|
||||
|
||||
#[docify::export(other_author_provider)]
|
||||
impl<AccountId> AuthorProvider<AccountId> for OtherAuthorProvider {
|
||||
fn author() -> AccountId {
|
||||
todo!("somehow get the block author here")
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(unit_author_provider)]
|
||||
impl<AccountId> AuthorProvider<AccountId> for () {
|
||||
fn author() -> AccountId {
|
||||
todo!("somehow get the block author here")
|
||||
}
|
||||
}
|
||||
|
||||
pub mod runtime {
|
||||
use super::*;
|
||||
use pezcumulus_pezpallet_aura_ext::pezpallet;
|
||||
use pezframe::{runtime::prelude::*, testing_prelude::*};
|
||||
|
||||
construct_runtime!(
|
||||
pub struct Runtime {
|
||||
System: pezframe_system,
|
||||
PezpalletFoo: pezpallet_foo_loose,
|
||||
PezpalletAuthor: pezpallet_author,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = MockBlock<Self>;
|
||||
}
|
||||
|
||||
impl pezpallet_author::Config for Runtime {}
|
||||
|
||||
#[docify::export(runtime_author_provider)]
|
||||
impl pezpallet_foo_loose::Config for Runtime {
|
||||
type AuthorProvider = pezpallet_author::Pezpallet<Runtime>;
|
||||
// which is also equivalent to
|
||||
// type AuthorProvider = PezpalletAuthor;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
//!
|
||||
//! > As of now, many of these important types are generated within the internals of
|
||||
//! > [`construct_runtime`], and there is no easy way for you to visually know they exist.
|
||||
//! > [#pezkuwi-sdk#1378](https://github.com/paritytech/polkadot-sdk/pull/1378) is meant to
|
||||
//! > [#pezkuwi-sdk#1378](https://github.com/pezkuwichain/pezkuwi-sdk/issues/251) is meant to
|
||||
//! > significantly improve this. Exploring the rust-docs of a runtime, such as [`runtime`] which is
|
||||
//! > defined in this module is as of now the best way to learn about these types.
|
||||
//!
|
||||
@@ -13,7 +13,7 @@
|
||||
//!
|
||||
//! Many types within a FRAME runtime follow the following structure:
|
||||
//!
|
||||
//! * Each individual pallet defines a type, for example `Foo`.
|
||||
//! * Each individual pezpallet defines a type, for example `Foo`.
|
||||
//! * At the runtime level, these types are amalgamated into a single type, for example
|
||||
//! `RuntimeFoo`.
|
||||
//!
|
||||
@@ -29,24 +29,24 @@
|
||||
//!
|
||||
//! ### Example
|
||||
//!
|
||||
//! We provide the following two pallets: [`pallet_foo`] and [`pallet_bar`]. Each define a
|
||||
//! We provide the following two pallets: [`pezpallet_foo`] and [`pezpallet_bar`]. Each define a
|
||||
//! dispatchable, and `Foo` also defines a custom origin. Lastly, `Bar` defines an additional
|
||||
//! `GenesisConfig`.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", pallet_foo)]
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", pallet_bar)]
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", pezpallet_foo)]
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", pezpallet_bar)]
|
||||
//!
|
||||
//! Let's explore how each of these affect the [`RuntimeCall`], [`RuntimeOrigin`] and
|
||||
//! [`RuntimeGenesisConfig`] generated in [`runtime`] respectively.
|
||||
//!
|
||||
//! As observed, [`RuntimeCall`] has 3 variants, one for each pallet and one for `frame_system`. If
|
||||
//! you explore further, you will soon realize that each variant is merely a pointer to the `Call`
|
||||
//! type in each pallet, for example [`pallet_foo::Call`].
|
||||
//! As observed, [`RuntimeCall`] has 3 variants, one for each pezpallet and one for
|
||||
//! `pezframe_system`. If you explore further, you will soon realize that each variant is merely a
|
||||
//! pointer to the `Call` type in each pezpallet, for example [`pezpallet_foo::Call`].
|
||||
//!
|
||||
//! [`RuntimeOrigin`]'s [`OriginCaller`] has two variants, one for system, and one for `pallet_foo`
|
||||
//! which utilized [`frame::pallet_macros::origin`].
|
||||
//! [`RuntimeOrigin`]'s [`OriginCaller`] has two variants, one for system, and one for
|
||||
//! `pezpallet_foo` which utilized [`pezframe::pezpallet_macros::origin`].
|
||||
//!
|
||||
//! Finally, [`RuntimeGenesisConfig`] is composed of `frame_system` and a variant for `pallet_bar`'s
|
||||
//! [`pallet_bar::GenesisConfig`].
|
||||
//! Finally, [`RuntimeGenesisConfig`] is composed of `pezframe_system` and a variant for
|
||||
//! `pezpallet_bar`'s [`pezpallet_bar::GenesisConfig`].
|
||||
//!
|
||||
//! You can find other composite enums by scanning [`runtime`] for other types who's name starts
|
||||
//! with `Runtime`. Some of the more noteworthy ones are:
|
||||
@@ -57,77 +57,78 @@
|
||||
//!
|
||||
//! ### Adding Further Constraints to Runtime Composite Enums
|
||||
//!
|
||||
//! This section explores a common scenario where a pallet has access to one of these runtime
|
||||
//! This section explores a common scenario where a pezpallet has access to one of these runtime
|
||||
//! composite enums, but it wishes to further specify it by adding more trait bounds to it.
|
||||
//!
|
||||
//! Let's take the example of `RuntimeCall`. This is an associated type in
|
||||
//! [`frame_system::Config::RuntimeCall`], and all pallets have access to this type, because they
|
||||
//! have access to [`frame_system::Config`]. Finally, this type is meant to be set to outer call of
|
||||
//! the entire runtime.
|
||||
//! [`pezframe_system::Config::RuntimeCall`], and all pallets have access to this type, because they
|
||||
//! have access to [`pezframe_system::Config`]. Finally, this type is meant to be set to outer call
|
||||
//! of the entire runtime.
|
||||
//!
|
||||
//! But, let's not forget that this is information that *we know*, and the Rust compiler does not.
|
||||
//! All that the rust compiler knows about this type is *ONLY* what the trait bounds of
|
||||
//! [`frame_system::Config::RuntimeCall`] are specifying:
|
||||
#![doc = docify::embed!("../../substrate/frame/system/src/lib.rs", system_runtime_call)]
|
||||
//! [`pezframe_system::Config::RuntimeCall`] are specifying:
|
||||
#![doc = docify::embed!("../../bizinikiwi/pezframe/system/src/lib.rs", system_runtime_call)]
|
||||
//!
|
||||
//! So, when at a given pallet, one accesses `<T as frame_system::Config>::RuntimeCall`, the type is
|
||||
//! extremely opaque from the perspective of the Rust compiler.
|
||||
//! So, when at a given pezpallet, one accesses `<T as pezframe_system::Config>::RuntimeCall`, the
|
||||
//! type is extremely opaque from the perspective of the Rust compiler.
|
||||
//!
|
||||
//! How can a pallet access the `RuntimeCall` type with further constraints? For example, each
|
||||
//! pallet has its own `enum Call`, and knows that its local `Call` is a part of `RuntimeCall`,
|
||||
//! How can a pezpallet access the `RuntimeCall` type with further constraints? For example, each
|
||||
//! pezpallet has its own `enum Call`, and knows that its local `Call` is a part of `RuntimeCall`,
|
||||
//! therefore there should be a `impl From<Call<_>> for RuntimeCall`.
|
||||
//!
|
||||
//! The only way to express this using Rust's associated types is for the pallet to **define its own
|
||||
//! associated type `RuntimeCall`, and further specify what it thinks `RuntimeCall` should be**.
|
||||
//! The only way to express this using Rust's associated types is for the pezpallet to **define its
|
||||
//! own associated type `RuntimeCall`, and further specify what it thinks `RuntimeCall` should be**.
|
||||
//!
|
||||
//! In this case, we will want to assert the existence of [`frame::traits::IsSubType`], which is
|
||||
//! In this case, we will want to assert the existence of [`pezframe::traits::IsSubType`], which is
|
||||
//! very similar to [`TryFrom`].
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call)]
|
||||
//!
|
||||
//! And indeed, at the runtime level, this associated type would be the same `RuntimeCall` that is
|
||||
//! passed to `frame_system`.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", pallet_with_specific_runtime_call_impl)]
|
||||
//! passed to `pezframe_system`.
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", pezpallet_with_specific_runtime_call_impl)]
|
||||
//!
|
||||
//! > In other words, the degree of specificity that [`frame_system::Config::RuntimeCall`] has is
|
||||
//! > not enough for the pallet to work with. Therefore, the pallet has to define its own associated
|
||||
//! > In other words, the degree of specificity that [`pezframe_system::Config::RuntimeCall`] has is
|
||||
//! > not enough for the pezpallet to work with. Therefore, the pezpallet has to define its own
|
||||
//! > associated
|
||||
//! > type representing `RuntimeCall`.
|
||||
//!
|
||||
//! Another way to look at this is:
|
||||
//!
|
||||
//! `pallet_with_specific_runtime_call::Config::RuntimeCall` and `frame_system::Config::RuntimeCall`
|
||||
//! are two different representations of the same concrete type that is only known when the runtime
|
||||
//! is being constructed.
|
||||
//! `pezpallet_with_specific_runtime_call::Config::RuntimeCall` and
|
||||
//! `pezframe_system::Config::RuntimeCall` are two different representations of the same concrete
|
||||
//! type that is only known when the runtime is being constructed.
|
||||
//!
|
||||
//! Now, within this pallet, this new `RuntimeCall` can be used, and it can use its new trait
|
||||
//! bounds, such as being [`frame::traits::IsSubType`]:
|
||||
//! Now, within this pezpallet, this new `RuntimeCall` can be used, and it can use its new trait
|
||||
//! bounds, such as being [`pezframe::traits::IsSubType`]:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call_usages)]
|
||||
//!
|
||||
//! > Once Rust's "_Associated Type Bounds RFC_" is usable, this syntax can be used to
|
||||
//! > simplify the above scenario. See [this](https://github.com/pezkuwichain/pezkuwi-sdk/issues/133)
|
||||
//! > simplify the above scenario. See [this](https://github.com/pezkuwichain/pezkuwi-sdk/issues/278)
|
||||
//! > issue for more information.
|
||||
//!
|
||||
//! ### Asserting Equality of Multiple Runtime Composite Enums
|
||||
//!
|
||||
//! Recall that in the above example, `<T as Config>::RuntimeCall` and `<T as
|
||||
//! frame_system::Config>::RuntimeCall` are expected to be equal types, but at the compile-time we
|
||||
//! have to represent them with two different associated types with different bounds. Would it not
|
||||
//! be cool if we had a test to make sure they actually resolve to the same concrete type once the
|
||||
//! runtime is constructed? The following snippet exactly does that:
|
||||
//! pezframe_system::Config>::RuntimeCall` are expected to be equal types, but at the compile-time
|
||||
//! we have to represent them with two different associated types with different bounds. Would it
|
||||
//! not be cool if we had a test to make sure they actually resolve to the same concrete type once
|
||||
//! the runtime is constructed? The following snippet exactly does that:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", assert_equality)]
|
||||
//!
|
||||
//! We leave it to the reader to further explore what [`frame::traits::Hooks::integrity_test`] is,
|
||||
//! We leave it to the reader to further explore what [`pezframe::traits::Hooks::integrity_test`] is,
|
||||
//! and what [`core::any::TypeId`] is. Another way to assert this is using
|
||||
//! [`frame::traits::IsType`].
|
||||
//! [`pezframe::traits::IsType`].
|
||||
//!
|
||||
//! ## Type Aliases
|
||||
//!
|
||||
//! A number of type aliases are generated by the `construct_runtime` which are also noteworthy:
|
||||
//!
|
||||
//! * [`runtime::PalletFoo`] is an alias to [`pallet_foo::Pallet`]. Same for `PalletBar`, and
|
||||
//! * [`runtime::PalletFoo`] is an alias to [`pezpallet_foo::Pezpallet`]. Same for `PalletBar`, and
|
||||
//! `System`
|
||||
//! * [`runtime::AllPalletsWithSystem`] is an alias for a tuple of all of the above. This type is
|
||||
//! important to FRAME internals such as `executive`, as it implements traits such as
|
||||
//! [`frame::traits::Hooks`].
|
||||
//! [`pezframe::traits::Hooks`].
|
||||
//!
|
||||
//! ## Further Details
|
||||
//!
|
||||
@@ -139,15 +140,15 @@
|
||||
//! * See the corresponding lecture in the [PBA Lectures](https://www.youtube.com/watch?v=OCBC1pMYPoc&list=PL-w_i5kwVqbni1Ch2j_RwTIXiB-bwnYqq&index=11).
|
||||
//!
|
||||
//!
|
||||
//! [`construct_runtime`]: frame::runtime::prelude::construct_runtime
|
||||
//! [`construct_runtime`]: pezframe::runtime::prelude::construct_runtime
|
||||
//! [`runtime::PalletFoo`]: crate::reference_docs::frame_runtime_types::runtime::PalletFoo
|
||||
//! [`runtime::AllPalletsWithSystem`]: crate::reference_docs::frame_runtime_types::runtime::AllPalletsWithSystem
|
||||
//! [`runtime`]: crate::reference_docs::frame_runtime_types::runtime
|
||||
//! [`pallet_foo`]: crate::reference_docs::frame_runtime_types::pallet_foo
|
||||
//! [`pallet_foo::Call`]: crate::reference_docs::frame_runtime_types::pallet_foo::Call
|
||||
//! [`pallet_foo::Pallet`]: crate::reference_docs::frame_runtime_types::pallet_foo::Pallet
|
||||
//! [`pallet_bar`]: crate::reference_docs::frame_runtime_types::pallet_bar
|
||||
//! [`pallet_bar::GenesisConfig`]: crate::reference_docs::frame_runtime_types::pallet_bar::GenesisConfig
|
||||
//! [`pezpallet_foo`]: crate::reference_docs::frame_runtime_types::pezpallet_foo
|
||||
//! [`pezpallet_foo::Call`]: crate::reference_docs::frame_runtime_types::pezpallet_foo::Call
|
||||
//! [`pezpallet_foo::Pezpallet`]: crate::reference_docs::frame_runtime_types::pezpallet_foo::Pezpallet
|
||||
//! [`pezpallet_bar`]: crate::reference_docs::frame_runtime_types::pezpallet_bar
|
||||
//! [`pezpallet_bar::GenesisConfig`]: crate::reference_docs::frame_runtime_types::pezpallet_bar::GenesisConfig
|
||||
//! [`RuntimeEvent`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeEvent
|
||||
//! [`RuntimeGenesisConfig`]:
|
||||
//! crate::reference_docs::frame_runtime_types::runtime::RuntimeGenesisConfig
|
||||
@@ -157,17 +158,17 @@
|
||||
//! [`RuntimeCall`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeCall
|
||||
//! [`RuntimeHoldReason`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeHoldReason
|
||||
|
||||
use frame::prelude::*;
|
||||
use pezframe::prelude::*;
|
||||
|
||||
#[docify::export]
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_foo {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_foo {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::origin]
|
||||
#[pezpallet::origin]
|
||||
#[derive(
|
||||
PartialEq,
|
||||
Eq,
|
||||
@@ -184,11 +185,11 @@ pub mod pallet_foo {
|
||||
B,
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn foo(_origin: OriginFor<T>) -> DispatchResult {
|
||||
todo!();
|
||||
}
|
||||
@@ -200,29 +201,29 @@ pub mod pallet_foo {
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_bar {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_bar {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[pezpallet::genesis_config]
|
||||
#[derive(DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub initial_account: Option<T::AccountId>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
#[pezpallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn bar(_origin: OriginFor<T>) -> DispatchResult {
|
||||
todo!();
|
||||
}
|
||||
@@ -230,90 +231,90 @@ pub mod pallet_bar {
|
||||
}
|
||||
|
||||
pub mod runtime {
|
||||
use super::{pallet_bar, pallet_foo};
|
||||
use frame::{runtime::prelude::*, testing_prelude::*};
|
||||
use super::{pezpallet_bar, pezpallet_foo};
|
||||
use pezframe::{runtime::prelude::*, testing_prelude::*};
|
||||
|
||||
#[docify::export(runtime_exp)]
|
||||
construct_runtime!(
|
||||
pub struct Runtime {
|
||||
System: frame_system,
|
||||
PalletFoo: pallet_foo,
|
||||
PalletBar: pallet_bar,
|
||||
System: pezframe_system,
|
||||
PalletFoo: pezpallet_foo,
|
||||
PalletBar: pezpallet_bar,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = MockBlock<Self>;
|
||||
}
|
||||
|
||||
impl pallet_foo::Config for Runtime {}
|
||||
impl pallet_bar::Config for Runtime {}
|
||||
impl pezpallet_foo::Config for Runtime {}
|
||||
impl pezpallet_bar::Config for Runtime {}
|
||||
}
|
||||
|
||||
#[frame::pallet(dev_mode)]
|
||||
pub mod pallet_with_specific_runtime_call {
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
pub mod pezpallet_with_specific_runtime_call {
|
||||
use super::*;
|
||||
use frame::traits::IsSubType;
|
||||
use pezframe::traits::IsSubType;
|
||||
|
||||
#[docify::export(custom_runtime_call)]
|
||||
/// A pallet that wants to further narrow down what `RuntimeCall` is.
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
/// A pezpallet that wants to further narrow down what `RuntimeCall` is.
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
type RuntimeCall: IsSubType<Call<Self>>;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
// note that this pallet needs some `call` to have a `enum Call`.
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
// note that this pezpallet needs some `call` to have a `enum Call`.
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
pub fn foo(_origin: OriginFor<T>) -> DispatchResult {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(custom_runtime_call_usages)]
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn _do_something_useful_with_runtime_call(call: <T as Config>::RuntimeCall) {
|
||||
// check if the runtime call given is of this pallet's variant.
|
||||
// check if the runtime call given is of this pezpallet's variant.
|
||||
let _maybe_my_call: Option<&Call<T>> = call.is_sub_type();
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(assert_equality)]
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
fn integrity_test() {
|
||||
use core::any::TypeId;
|
||||
assert_eq!(
|
||||
TypeId::of::<<T as Config>::RuntimeCall>(),
|
||||
TypeId::of::<<T as frame_system::Config>::RuntimeCall>()
|
||||
TypeId::of::<<T as pezframe_system::Config>::RuntimeCall>()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod runtime_with_specific_runtime_call {
|
||||
use super::pallet_with_specific_runtime_call;
|
||||
use frame::{runtime::prelude::*, testing_prelude::*};
|
||||
use super::pezpallet_with_specific_runtime_call;
|
||||
use pezframe::{runtime::prelude::*, testing_prelude::*};
|
||||
|
||||
construct_runtime!(
|
||||
pub struct Runtime {
|
||||
System: frame_system,
|
||||
PalletWithSpecificRuntimeCall: pallet_with_specific_runtime_call,
|
||||
System: pezframe_system,
|
||||
PalletWithSpecificRuntimeCall: pezpallet_with_specific_runtime_call,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = MockBlock<Self>;
|
||||
}
|
||||
|
||||
#[docify::export(pallet_with_specific_runtime_call_impl)]
|
||||
impl pallet_with_specific_runtime_call::Config for Runtime {
|
||||
#[docify::export(pezpallet_with_specific_runtime_call_impl)]
|
||||
impl pezpallet_with_specific_runtime_call::Config for Runtime {
|
||||
// an implementation of `IsSubType` is provided by `construct_runtime`.
|
||||
type RuntimeCall = RuntimeCall;
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
//! 1. on-chain state,
|
||||
//! 2. a state transition function.
|
||||
//!
|
||||
//! In Substrate-based blockchains, state transition functions are referred to as
|
||||
//! In Bizinikiwi-based blockchains, state transition functions are referred to as
|
||||
//! [runtimes](https://docs.pezkuwichain.io/sdk/master/polkadot_sdk_docs/reference_docs/blockchain_state_machines/index.html).
|
||||
//!
|
||||
//! Traditionally, before Substrate, upgrading state transition functions required node
|
||||
//! Traditionally, before Bizinikiwi, upgrading state transition functions required node
|
||||
//! operators to download new software and restart their nodes in a process called
|
||||
//! [forking](https://en.wikipedia.org/wiki/Fork_(blockchain)).
|
||||
//!
|
||||
//! Substrate-based blockchains do not require forking, and instead upgrade runtimes
|
||||
//! Bizinikiwi-based blockchains do not require forking, and instead upgrade runtimes
|
||||
//! in a process called "Runtime Upgrades".
|
||||
//!
|
||||
//! Forkless runtime upgrades are a defining feature of the Substrate framework. Updating the
|
||||
//! Forkless runtime upgrades are a defining feature of the Bizinikiwi framework. Updating the
|
||||
//! runtime logic without forking the code base enables your blockchain to seamlessly evolve
|
||||
//! over time in a deterministic, rules-based manner. It also removes ambiguity for node operators
|
||||
//! and other participants in the network about what is the canonical runtime.
|
||||
@@ -24,26 +24,26 @@
|
||||
//!
|
||||
//! ## Performing a Runtime Upgrade
|
||||
//!
|
||||
//! To upgrade a runtime, an [`Origin`](frame_system::RawOrigin) with the necessary permissions
|
||||
//! To upgrade a runtime, an [`Origin`](pezframe_system::RawOrigin) with the necessary permissions
|
||||
//! (usually via governance) changes the `:code` storage. Usually, this is performed via a call to
|
||||
//! [`set_code`] (or [`set_code_without_checks`]) with the desired new runtime blob, scheduled
|
||||
//! using [`pallet_scheduler`].
|
||||
//! using [`pezpallet_scheduler`].
|
||||
//!
|
||||
//! Prior to building the new runtime, don't forget to update the
|
||||
//! [`RuntimeVersion`](sp_version::RuntimeVersion).
|
||||
//! [`RuntimeVersion`](pezsp_version::RuntimeVersion).
|
||||
//!
|
||||
//! # Migrations
|
||||
//!
|
||||
//! It is often desirable to define logic to execute immediately after runtime upgrades (see
|
||||
//! [this diagram](frame::traits::Hooks)).
|
||||
//! [this diagram](pezframe::traits::Hooks)).
|
||||
//!
|
||||
//! Self-contained pieces of logic that execute after a runtime upgrade are called "Migrations".
|
||||
//!
|
||||
//! The typical use case of a migration is to 'migrate' pallet storage from one layout to another,
|
||||
//! for example when the encoding of a storage item is changed. However, they can also execute
|
||||
//! arbitrary logic such as:
|
||||
//! The typical use case of a migration is to 'migrate' pezpallet storage from one layout to
|
||||
//! another, for example when the encoding of a storage item is changed. However, they can also
|
||||
//! execute arbitrary logic such as:
|
||||
//!
|
||||
//! - Calling arbitrary pallet methods.
|
||||
//! - Calling arbitrary pezpallet methods.
|
||||
//! - Mutating arbitrary on-chain state.
|
||||
//! - Cleaning up some old storage items that are no longer needed.
|
||||
//!
|
||||
@@ -54,22 +54,22 @@
|
||||
//! - Are suitable for migrations which are guaranteed to not exceed the block weight.
|
||||
//! - Are simply implementations of [`OnRuntimeUpgrade`].
|
||||
//!
|
||||
//! To learn best practices for writing single block pallet storage migrations, see the
|
||||
//! [Single Block Migration Example Pallet](pallet_example_single_block_migrations).
|
||||
//! To learn best practices for writing single block pezpallet storage migrations, see the
|
||||
//! [Single Block Migration Example Pezpallet](pezpallet_example_single_block_migrations).
|
||||
//!
|
||||
//! ### Scheduling the Single Block Migrations to Run Next Runtime Upgrade
|
||||
//!
|
||||
//! Schedule migrations to run next runtime upgrade passing them as a parameter to your
|
||||
//! [`Config`](frame_system) pallet:
|
||||
//! [`Config`](pezframe_system) pezpallet:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! /// Tuple of migrations (structs that implement `OnRuntimeUpgrade`)
|
||||
//! type Migrations = (
|
||||
//! pallet_example_storage_migration::migrations::v1::versioned::MigrateV0ToV1,
|
||||
//! pezpallet_example_storage_migration::migrations::v1::versioned::MigrateV0ToV1,
|
||||
//! MyCustomMigration,
|
||||
//! // ...more migrations here
|
||||
//! );
|
||||
//! impl frame_system::Config for Runtime {
|
||||
//! impl pezframe_system::Config for Runtime {
|
||||
//! type SingleBlockMigrations = Migrations;
|
||||
//! }
|
||||
//! ```
|
||||
@@ -114,7 +114,7 @@
|
||||
//!
|
||||
//! ### Other useful tools
|
||||
//!
|
||||
//! [`Chopsticks`](https://github.com/AcalaNetwork/chopsticks) is another tool in the Substrate
|
||||
//! [`Chopsticks`](https://github.com/AcalaNetwork/chopsticks) is another tool in the Bizinikiwi
|
||||
//! ecosystem which developers may find useful to use in addition to `try-runtime-cli` when testing
|
||||
//! their single block migrations.
|
||||
//!
|
||||
@@ -125,10 +125,10 @@
|
||||
//! Suitable for migrations which could use arbitrary amounts of block weight.
|
||||
//!
|
||||
//! See the
|
||||
//! [multi-block-migrations example](https://github.com/pezkuwichain/pezkuwi-sdk/tree/0d7d2177807ec6b3094f4491a45b0bc0d74d3c8b/substrate/frame/examples/multi-block-migrations)
|
||||
//! [multi-block-migrations example](https://github.com/pezkuwichain/pezkuwi-sdk/tree/0d7d2177807ec6b3094f4491a45b0bc0d74d3c8b/bizinikiwi/pezframe/examples/multi-block-migrations)
|
||||
//! for reference.
|
||||
//!
|
||||
//! [`OnRuntimeUpgrade`]: frame_support::traits::OnRuntimeUpgrade
|
||||
//! [`StorageVersion`]: frame_support::traits::StorageVersion
|
||||
//! [`set_code`]: frame_system::Call::set_code
|
||||
//! [`set_code_without_checks`]: frame_system::Call::set_code_without_checks
|
||||
//! [`OnRuntimeUpgrade`]: pezframe_support::traits::OnRuntimeUpgrade
|
||||
//! [`StorageVersion`]: pezframe_support::traits::StorageVersion
|
||||
//! [`set_code`]: pezframe_system::Call::set_code
|
||||
//! [`set_code_without_checks`]: pezframe_system::Call::set_code_without_checks
|
||||
|
||||
@@ -8,70 +8,70 @@
|
||||
//! Let's begin by starting to store a `NewType` in a storage item:
|
||||
//!
|
||||
//! ```compile_fail
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! # use frame::prelude::*;
|
||||
//! # #[pallet::config]
|
||||
//! # pub trait Config: frame_system::Config {}
|
||||
//! # #[pallet::pallet]
|
||||
//! # pub struct Pallet<T>(_);
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! # use pezframe::prelude::*;
|
||||
//! # #[pezpallet::config]
|
||||
//! # pub trait Config: pezframe_system::Config {}
|
||||
//! # #[pezpallet::pezpallet]
|
||||
//! # pub struct Pezpallet<T>(_);
|
||||
//! pub struct NewType(u32);
|
||||
//
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T> = StorageValue<_, NewType>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! This raises a number of compiler errors, like:
|
||||
//! ```text
|
||||
//! the trait `MaxEncodedLen` is not implemented for `NewType`, which is required by
|
||||
//! `frame::prelude::StorageValue<_GeneratedPrefixForStorageSomething<T>, NewType>:
|
||||
//! `pezframe::prelude::StorageValue<_GeneratedPrefixForStorageSomething<T>, NewType>:
|
||||
//! StorageInfoTrait`
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! This implies the following set of traits that need to be derived for a type to be stored in
|
||||
//! `frame` storage:
|
||||
//! ```rust
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! # use frame::prelude::*;
|
||||
//! # #[pallet::config]
|
||||
//! # pub trait Config: frame_system::Config {}
|
||||
//! # #[pallet::pallet]
|
||||
//! # pub struct Pallet<T>(_);
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! # use pezframe::prelude::*;
|
||||
//! # #[pezpallet::config]
|
||||
//! # pub trait Config: pezframe_system::Config {}
|
||||
//! # #[pezpallet::pezpallet]
|
||||
//! # pub struct Pezpallet<T>(_);
|
||||
//! #[derive(codec::Encode, codec::Decode, codec::MaxEncodedLen, scale_info::TypeInfo)]
|
||||
//! pub struct NewType(u32);
|
||||
//!
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T> = StorageValue<_, NewType>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! Next, let's look at how this will differ if we are to store a type that is derived from `T` in
|
||||
//! storage, such as [`frame::prelude::BlockNumberFor`]:
|
||||
//! storage, such as [`pezframe::prelude::BlockNumberFor`]:
|
||||
//! ```compile_fail
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! # use frame::prelude::*;
|
||||
//! # #[pallet::config]
|
||||
//! # pub trait Config: frame_system::Config {}
|
||||
//! # #[pallet::pallet]
|
||||
//! # pub struct Pallet<T>(_);
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! # use pezframe::prelude::*;
|
||||
//! # #[pezpallet::config]
|
||||
//! # pub trait Config: pezframe_system::Config {}
|
||||
//! # #[pezpallet::pezpallet]
|
||||
//! # pub struct Pezpallet<T>(_);
|
||||
//! #[derive(codec::Encode, codec::Decode, codec::MaxEncodedLen, scale_info::TypeInfo)]
|
||||
//! pub struct NewType<T: Config>(BlockNumberFor<T>);
|
||||
//!
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T: Config> = StorageValue<_, NewType<T>>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! Surprisingly, this will also raise a number of errors, like:
|
||||
//! ```text
|
||||
//! the trait `TypeInfo` is not implemented for `T`, which is required
|
||||
//! by`frame_support::pallet_prelude::StorageValue<pallet_2::_GeneratedPrefixForStorageSomething<T>,
|
||||
//! pallet_2::NewType<T>>:StorageEntryMetadataBuilder
|
||||
//! by`pezframe_support::pezpallet_prelude::StorageValue<pezpallet_2::_GeneratedPrefixForStorageSomething<T>,
|
||||
//! pezpallet_2::NewType<T>>:StorageEntryMetadataBuilder
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! Why is that? The underlying reason is that the `TypeInfo` `derive` macro will only work for
|
||||
//! `NewType` if all of `NewType`'s generics also implement `TypeInfo`. This is not the case for `T`
|
||||
//! in the example above.
|
||||
@@ -84,42 +84,42 @@
|
||||
//! attribute to `NewType`. This additional macro will instruct the `derive` to skip the bound on
|
||||
//! `T`.
|
||||
//! ```rust
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! # use frame::prelude::*;
|
||||
//! # #[pallet::config]
|
||||
//! # pub trait Config: frame_system::Config {}
|
||||
//! # #[pallet::pallet]
|
||||
//! # pub struct Pallet<T>(_);
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! # use pezframe::prelude::*;
|
||||
//! # #[pezpallet::config]
|
||||
//! # pub trait Config: pezframe_system::Config {}
|
||||
//! # #[pezpallet::pezpallet]
|
||||
//! # pub struct Pezpallet<T>(_);
|
||||
//! #[derive(codec::Encode, codec::Decode, codec::MaxEncodedLen, scale_info::TypeInfo)]
|
||||
//! #[scale_info(skip_type_params(T))]
|
||||
//! pub struct NewType<T: Config>(BlockNumberFor<T>);
|
||||
//!
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T: Config> = StorageValue<_, NewType<T>>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Next, let's say we wish to store `NewType` as [`frame::prelude::ValueQuery`], which means it
|
||||
//!
|
||||
//! Next, let's say we wish to store `NewType` as [`pezframe::prelude::ValueQuery`], which means it
|
||||
//! must also implement `Default`. This should be as simple as adding `derive(Default)` to it,
|
||||
//! right?
|
||||
//! ```compile_fail
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! # use frame::prelude::*;
|
||||
//! # #[pallet::config]
|
||||
//! # pub trait Config: frame_system::Config {}
|
||||
//! # #[pallet::pallet]
|
||||
//! # pub struct Pallet<T>(_);
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! # use pezframe::prelude::*;
|
||||
//! # #[pezpallet::config]
|
||||
//! # pub trait Config: pezframe_system::Config {}
|
||||
//! # #[pezpallet::pezpallet]
|
||||
//! # pub struct Pezpallet<T>(_);
|
||||
//! #[derive(codec::Encode, codec::Decode, codec::MaxEncodedLen, scale_info::TypeInfo, Default)]
|
||||
//! #[scale_info(skip_type_params(T))]
|
||||
//! pub struct NewType<T: Config>(BlockNumberFor<T>);
|
||||
//!
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T: Config> = StorageValue<_, NewType<T>, ValueQuery>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! Under the hood, the expansion of the `derive(Default)` will suffer from the same restriction as
|
||||
//! before: it will only work if `T: Default`, and `T` is not `Default`. Note that this is an
|
||||
//! expected issue: `T` is merely a wrapper of many other types, such as `BlockNumberFor<T>`.
|
||||
@@ -129,26 +129,26 @@
|
||||
//! To fix this, frame provides a set of macros that are analogous to normal rust derive macros, but
|
||||
//! work nicely on top of structs that are generic over `T: Config`. These macros are:
|
||||
//!
|
||||
//! - [`frame::prelude::DefaultNoBound`]
|
||||
//! - [`frame::prelude::DebugNoBound`]
|
||||
//! - [`frame::prelude::PartialEqNoBound`]
|
||||
//! - [`frame::prelude::EqNoBound`]
|
||||
//! - [`frame::prelude::CloneNoBound`]
|
||||
//! - [`frame::prelude::PartialOrdNoBound`]
|
||||
//! - [`frame::prelude::OrdNoBound`]
|
||||
//! - [`pezframe::prelude::DefaultNoBound`]
|
||||
//! - [`pezframe::prelude::DebugNoBound`]
|
||||
//! - [`pezframe::prelude::PartialEqNoBound`]
|
||||
//! - [`pezframe::prelude::EqNoBound`]
|
||||
//! - [`pezframe::prelude::CloneNoBound`]
|
||||
//! - [`pezframe::prelude::PartialOrdNoBound`]
|
||||
//! - [`pezframe::prelude::OrdNoBound`]
|
||||
//!
|
||||
//! The above traits are almost certainly needed for your tests - to print your type, assert equality
|
||||
//! or clone it.
|
||||
//!
|
||||
//! We can fix the following example by using [`frame::prelude::DefaultNoBound`].
|
||||
//! We can fix the following example by using [`pezframe::prelude::DefaultNoBound`].
|
||||
//! ```rust
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! # use frame::prelude::*;
|
||||
//! # #[pallet::config]
|
||||
//! # pub trait Config: frame_system::Config {}
|
||||
//! # #[pallet::pallet]
|
||||
//! # pub struct Pallet<T>(_);
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! # use pezframe::prelude::*;
|
||||
//! # #[pezpallet::config]
|
||||
//! # pub trait Config: pezframe_system::Config {}
|
||||
//! # #[pezpallet::pezpallet]
|
||||
//! # pub struct Pezpallet<T>(_);
|
||||
//! #[derive(
|
||||
//! codec::Encode,
|
||||
//! codec::Decode,
|
||||
@@ -159,44 +159,44 @@
|
||||
//! #[scale_info(skip_type_params(T))]
|
||||
//! pub struct NewType<T:Config>(BlockNumberFor<T>);
|
||||
//!
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T: Config> = StorageValue<_, NewType<T>, ValueQuery>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! Finally, if a custom type that is provided through `Config` is to be stored in the storage, it
|
||||
//! is subject to the same trait requirements. The following does not work:
|
||||
//! ```compile_fail
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use frame::prelude::*;
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config {
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! use pezframe::prelude::*;
|
||||
//! #[pezpallet::config]
|
||||
//! pub trait Config: pezframe_system::Config {
|
||||
//! type CustomType;
|
||||
//! }
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::pezpallet]
|
||||
//! pub struct Pezpallet<T>(_);
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T: Config> = StorageValue<_, T::CustomType>;
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! But adding the right trait bounds will fix it.
|
||||
//! ```rust
|
||||
//! #[frame::pallet]
|
||||
//! pub mod pallet {
|
||||
//! use frame::prelude::*;
|
||||
//! #[pallet::config]
|
||||
//! pub trait Config: frame_system::Config {
|
||||
//! #[pezframe::pezpallet]
|
||||
//! pub mod pezpallet {
|
||||
//! use pezframe::prelude::*;
|
||||
//! #[pezpallet::config]
|
||||
//! pub trait Config: pezframe_system::Config {
|
||||
//! type CustomType: codec::FullCodec
|
||||
//! + codec::MaxEncodedLen
|
||||
//! + scale_info::TypeInfo
|
||||
//! + Debug
|
||||
//! + Default;
|
||||
//! }
|
||||
//! #[pallet::pallet]
|
||||
//! pub struct Pallet<T>(_);
|
||||
//! #[pallet::storage]
|
||||
//! #[pezpallet::pezpallet]
|
||||
//! pub struct Pezpallet<T>(_);
|
||||
//! #[pezpallet::storage]
|
||||
//! pub type Something<T: Config> = StorageValue<_, T::CustomType>;
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is part of pezkuwi-sdk.
|
||||
//
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -30,13 +30,13 @@
|
||||
//!
|
||||
//! ## Getting Started
|
||||
//!
|
||||
//! The most ubiquitous way to add a token to a FRAME runtime is [`pallet_balances`]. Read
|
||||
//! The most ubiquitous way to add a token to a FRAME runtime is [`pezpallet_balances`]. Read
|
||||
//! more about pallets [here](crate::pezkuwi_sdk::frame_runtime#pallets).
|
||||
//!
|
||||
//! You may then write custom pallets that interact with [`pallet_balances`]. The fastest way to
|
||||
//! You may then write custom pallets that interact with [`pezpallet_balances`]. The fastest way to
|
||||
//! get started with that is by
|
||||
//! [tightly coupling](crate::reference_docs::frame_pallet_coupling#tight-coupling-pallets) your
|
||||
//! custom pallet to [`pallet_balances`].
|
||||
//! custom pezpallet to [`pezpallet_balances`].
|
||||
//!
|
||||
//! However, to keep pallets flexible and modular, it is often preferred to
|
||||
//! [loosely couple](crate::reference_docs::frame_pallet_coupling#loosely--coupling-pallets).
|
||||
@@ -50,80 +50,81 @@
|
||||
//! trait implementations.
|
||||
//!
|
||||
//! **Traits** define common interfaces that types of tokens should implement. For example, the
|
||||
//! [`fungible::Inspect`](`frame_support::traits::fungible::Inspect`) trait specifies an interface
|
||||
//! for *inspecting* token state such as the total issuance of the token, the balance of individual
|
||||
//! accounts, etc.
|
||||
//! [`fungible::Inspect`](`pezframe_support::traits::fungible::Inspect`) trait specifies an
|
||||
//! interface for *inspecting* token state such as the total issuance of the token, the balance of
|
||||
//! individual accounts, etc.
|
||||
//!
|
||||
//! **Trait implementations** are concrete implementations of these traits. For example, one of the
|
||||
//! many traits [`pallet_balances`] implements is
|
||||
//! [`fungible::Inspect`](`frame_support::traits::fungible::Inspect`)[^1]. It provides the concrete
|
||||
//! way of inspecting the total issuance, balance of accounts, etc. There can be many
|
||||
//! many traits [`pezpallet_balances`] implements is
|
||||
//! [`fungible::Inspect`](`pezframe_support::traits::fungible::Inspect`)[^1]. It provides the
|
||||
//! concrete way of inspecting the total issuance, balance of accounts, etc. There can be many
|
||||
//! implementations of the same traits.
|
||||
//!
|
||||
//! [^1]: Rust Advanced Tip: The knowledge that [`pallet_balances`] implements
|
||||
//! [`fungible::Inspect`](`frame_support::traits::fungible::Inspect`) is not some arcane knowledge
|
||||
//! that you have to know by heart or memorize. One can simply look at the list of the implementors
|
||||
//! of any trait in the Rust Doc to find all implementors (e.g.
|
||||
//! [Mutate trait implementors](https://docs.pezkuwichain.io/sdk/master/frame_support/traits/tokens/fungible/trait.Mutate.html#implementors)),
|
||||
//! [^1]: Rust Advanced Tip: The knowledge that [`pezpallet_balances`] implements
|
||||
//! [`fungible::Inspect`](`pezframe_support::traits::fungible::Inspect`) is not some arcane
|
||||
//! knowledge that you have to know by heart or memorize. One can simply look at the list of the
|
||||
//! implementors of any trait in the Rust Doc to find all implementors (e.g.
|
||||
//! [Mutate trait implementors](https://docs.pezkuwichain.io/sdk/master/pezframe_support/traits/tokens/fungible/trait.Mutate.html#implementors)),
|
||||
//! or use the `rust-analyzer`'s `Implementations` action.
|
||||
//!
|
||||
//! The distinction between traits and trait implementations is helpful because it allows pallets
|
||||
//! and other logic to be generic over their dependencies, avoiding tight coupling.
|
||||
//!
|
||||
//! To illustrate this with an example let's consider [`pallet_preimage`]. This pallet takes a
|
||||
//! To illustrate this with an example let's consider [`pezpallet_preimage`]. This pezpallet takes a
|
||||
//! deposit in exchange for storing a preimage for later use. A naive implementation of the
|
||||
//! pallet may use [`pallet_balances`] in a tightly coupled manner, directly calling methods
|
||||
//! on the pallet to reserve and unreserve deposits. This approach works well,
|
||||
//! until someone has a use case requiring that an asset from a different pallet such as
|
||||
//! [`pallet_assets`] is used for the deposit. Rather than tightly coupling [`pallet_preimage`] to
|
||||
//! [`pallet_balances`], [`pallet_assets`], and every other token-handling pallet, a user
|
||||
//! could possibly specify that [`pallet_preimage`] does not specify a concrete pallet as a
|
||||
//! dependency, but instead accepts any dependency which implements the
|
||||
//! [`currency::ReservableCurrency`](`frame_support::traits::tokens::currency::ReservableCurrency`)
|
||||
//! trait, namely via its [`Config::Currency`](`pallet_preimage::pallet::Config::Currency`)
|
||||
//! associated type. This allows [`pallet_preimage`] to support any arbitrary pallet implementing
|
||||
//! this trait, without needing any knowledge of what those pallets may be or requiring changes to
|
||||
//! support new pallets which may be written in the future.
|
||||
//! pezpallet may use [`pezpallet_balances`] in a tightly coupled manner, directly calling methods
|
||||
//! on the pezpallet to reserve and unreserve deposits. This approach works well,
|
||||
//! until someone has a use case requiring that an asset from a different pezpallet such as
|
||||
//! [`pezpallet_assets`] is used for the deposit. Rather than tightly coupling
|
||||
//! [`pezpallet_preimage`] to [`pezpallet_balances`], [`pezpallet_assets`], and every other
|
||||
//! token-handling pezpallet, a user could possibly specify that [`pezpallet_preimage`] does not
|
||||
//! specify a concrete pezpallet as a dependency, but instead accepts any dependency which
|
||||
//! implements the
|
||||
//! [`currency::ReservableCurrency`](`pezframe_support::traits::tokens::currency::ReservableCurrency`)
|
||||
//! trait, namely via its [`Config::Currency`](`pezpallet_preimage::pezpallet::Config::Currency`)
|
||||
//! associated type. This allows [`pezpallet_preimage`] to support any arbitrary pezpallet
|
||||
//! implementing this trait, without needing any knowledge of what those pallets may be or requiring
|
||||
//! changes to support new pallets which may be written in the future.
|
||||
//!
|
||||
//! Read more about coupling, and the benefits of loose coupling
|
||||
//! [here](crate::reference_docs::frame_pallet_coupling).
|
||||
//!
|
||||
//! ## Fungible Token Traits in FRAME
|
||||
//!
|
||||
//! The [`fungible`](`frame_support::traits::fungible`) crate contains the latest set of FRAME
|
||||
//! The [`fungible`](`pezframe_support::traits::fungible`) crate contains the latest set of FRAME
|
||||
//! fungible token traits, and is recommended to use for all new logic requiring a fungible token.
|
||||
//! See the crate documentation for more info about these fungible traits.
|
||||
//!
|
||||
//! [`fungibles`](`frame_support::traits::fungibles`) provides very similar functionality to
|
||||
//! [`fungible`](`frame_support::traits::fungible`), except it supports managing multiple tokens.
|
||||
//! [`fungibles`](`pezframe_support::traits::fungibles`) provides very similar functionality to
|
||||
//! [`fungible`](`pezframe_support::traits::fungible`), except it supports managing multiple tokens.
|
||||
//!
|
||||
//! You may notice the trait [`Currency`](`frame_support::traits::Currency`) with similar
|
||||
//! You may notice the trait [`Currency`](`pezframe_support::traits::Currency`) with similar
|
||||
//! functionality is also used in the codebase, however this trait is deprecated and existing logic
|
||||
//! is in the process of being migrated to [`fungible`](`frame_support::traits::fungible`) ([tracking issue](https://github.com/pezkuwichain/pezkuwi-sdk/issues/102)).
|
||||
//! is in the process of being migrated to [`fungible`](`pezframe_support::traits::fungible`) ([tracking issue](https://github.com/pezkuwichain/pezkuwi-sdk/issues/248)).
|
||||
//!
|
||||
//! ## Fungible Token Trait Implementations in FRAME
|
||||
//!
|
||||
//! [`pallet_balances`] implements [`fungible`](`frame_support::traits::fungible`), and is the most
|
||||
//! commonly used fungible implementation in FRAME. Most of the time, it's used for managing the
|
||||
//! native token of the blockchain network it's used in.
|
||||
//! [`pezpallet_balances`] implements [`fungible`](`pezframe_support::traits::fungible`), and is the
|
||||
//! most commonly used fungible implementation in FRAME. Most of the time, it's used for managing
|
||||
//! the native token of the blockchain network it's used in.
|
||||
//!
|
||||
//! [`pallet_assets`] implements [`fungibles`](`frame_support::traits::fungibles`), and is another
|
||||
//! popular fungible token implementation. It supports the creation and management of multiple
|
||||
//! assets in a single crate, making it a good choice when a network requires more assets in
|
||||
//! addition to its native token.
|
||||
//! [`pezpallet_assets`] implements [`fungibles`](`pezframe_support::traits::fungibles`), and is
|
||||
//! another popular fungible token implementation. It supports the creation and management of
|
||||
//! multiple assets in a single crate, making it a good choice when a network requires more assets
|
||||
//! in addition to its native token.
|
||||
//!
|
||||
//! ## Non-Fungible Tokens in FRAME
|
||||
//!
|
||||
//! [`pallet_nfts`] is recommended to use for all NFT use cases in FRAME.
|
||||
//! See the crate documentation for more info about this pallet.
|
||||
//! [`pezpallet_nfts`] is recommended to use for all NFT use cases in FRAME.
|
||||
//! See the crate documentation for more info about this pezpallet.
|
||||
//!
|
||||
//! [`pallet_uniques`] is deprecated and should not be used.
|
||||
//! [`pezpallet_uniques`] is deprecated and should not be used.
|
||||
//!
|
||||
//!
|
||||
//! # What Next?
|
||||
//!
|
||||
//! - If you are interested in implementing a single fungible token, continue reading the
|
||||
//! [`fungible`](`frame_support::traits::fungible`) and [`pallet_balances`] docs.
|
||||
//! [`fungible`](`pezframe_support::traits::fungible`) and [`pezpallet_balances`] docs.
|
||||
//! - If you are interested in implementing a set of fungible tokens, continue reading the
|
||||
//! [`fungibles`](`frame_support::traits::fungibles`) trait and [`pallet_assets`] docs.
|
||||
//! - If you are interested in implementing an NFT, continue reading the [`pallet_nfts`] docs.
|
||||
//! [`fungibles`](`pezframe_support::traits::fungibles`) trait and [`pezpallet_assets`] docs.
|
||||
//! - If you are interested in implementing an NFT, continue reading the [`pezpallet_nfts`] docs.
|
||||
|
||||
@@ -66,14 +66,14 @@
|
||||
//! included into a block and leads to some action. This includes user-initiated transactions as
|
||||
//! well as inherents which are placed into the block by the block-builder.
|
||||
//!
|
||||
//! #### Pallet
|
||||
//! #### Pezpallet
|
||||
//!
|
||||
//! Similar to software modules in traditional programming, [FRAME](frame) pallets in Substrate are
|
||||
//! Similar to software modules in traditional programming, [FRAME](frame) pallets in Bizinikiwi are
|
||||
//! modular components that encapsulate distinct functionalities or business logic. Just as
|
||||
//! libraries or modules are used to build and extend the capabilities of a software application,
|
||||
//! pallets are the foundational building blocks for constructing a blockchain's runtime with frame.
|
||||
//! They enable the creation of customizable and upgradeable networks, offering a composable
|
||||
//! framework for a Substrate-based blockchain. Each pallet can be thought of as a plug-and-play
|
||||
//! framework for a Bizinikiwi-based blockchain. Each pezpallet can be thought of as a plug-and-play
|
||||
//! module, enhancing the blockchain's functionality in a cohesive and integrated manner.
|
||||
//!
|
||||
//! #### Full Node
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! # Metadata
|
||||
//!
|
||||
//! The existence of metadata in pezkuwi-sdk goes back to the (forkless) upgrade-ability of all
|
||||
//! Substrate-based blockchains, which is achieved through
|
||||
//! Bizinikiwi-based blockchains, which is achieved through
|
||||
//! [`crate::reference_docs::wasm_meta_protocol`]. You can learn more about the details of how to
|
||||
//! deal with these upgrades in [`crate::reference_docs::frame_runtime_upgrades_and_migrations`].
|
||||
//!
|
||||
@@ -9,9 +9,9 @@
|
||||
//! it is hard to know the types internal to the runtime, specifically in light of the fact that
|
||||
//! they can change at any point in time.
|
||||
//!
|
||||
//! This is why all Substrate-based runtimes must expose a [`sp_api::Metadata`] api, which mandates
|
||||
//! the runtime to return a description of itself. The return type of this api is `Vec<u8>`, meaning
|
||||
//! that it is up to the runtime developer to decide on the format of this.
|
||||
//! This is why all Bizinikiwi-based runtimes must expose a [`pezsp_api::Metadata`] api, which
|
||||
//! mandates the runtime to return a description of itself. The return type of this api is
|
||||
//! `Vec<u8>`, meaning that it is up to the runtime developer to decide on the format of this.
|
||||
//!
|
||||
//! All [`crate::pezkuwi_sdk::frame_runtime`] based runtimes expose a specific metadata language,
|
||||
//! maintained in <https://github.com/paritytech/frame-metadata> which is adopted in the Pezkuwi
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
//! We call this class of documents "reference documents". Our goal should be to minimize the number
|
||||
//! of "reference" docs, as they incur maintenance burden.
|
||||
|
||||
/// Learn how Substrate and FRAME use traits and associated types to make modules generic in a
|
||||
/// Learn how Bizinikiwi and FRAME use traits and associated types to make modules generic in a
|
||||
/// type-safe manner.
|
||||
pub mod trait_based_programming;
|
||||
|
||||
/// Learn about the way Substrate and FRAME view their blockchains as state machines.
|
||||
/// Learn about the way Bizinikiwi and FRAME view their blockchains as state machines.
|
||||
pub mod blockchain_state_machines;
|
||||
|
||||
/// The glossary.
|
||||
pub mod glossary;
|
||||
|
||||
/// Learn about the WASM meta-protocol of all Substrate-based chains.
|
||||
/// Learn about the WASM meta-protocol of all Bizinikiwi-based chains.
|
||||
pub mod wasm_meta_protocol;
|
||||
|
||||
/// Learn about the differences between smart contracts and a FRAME-based runtime. They are both
|
||||
@@ -60,8 +60,8 @@ pub mod defensive_programming;
|
||||
/// `RuntimeCall`.
|
||||
pub mod frame_runtime_types;
|
||||
|
||||
/// Learn about how to make a pallet/runtime that is fee-less and instead uses another mechanism to
|
||||
/// control usage and sybil attacks.
|
||||
/// Learn about how to make a pezpallet/runtime that is fee-less and instead uses another mechanism
|
||||
/// to control usage and sybil attacks.
|
||||
pub mod fee_less_runtime;
|
||||
|
||||
/// Learn about metadata, the main means through which an upgradeable runtime communicates its
|
||||
@@ -71,14 +71,14 @@ pub mod metadata;
|
||||
/// Learn about how to add custom host functions to the node.
|
||||
pub mod custom_host_functions;
|
||||
|
||||
/// Learn about how frame-system handles `account-ids`, nonces, consumers and providers.
|
||||
pub mod frame_system_accounts;
|
||||
/// Learn about how pezframe-system handles `account-ids`, nonces, consumers and providers.
|
||||
pub mod pezframe_system_accounts;
|
||||
|
||||
/// Advice for configuring your development environment for Substrate development.
|
||||
/// Advice for configuring your development environment for Bizinikiwi development.
|
||||
pub mod development_environment_advice;
|
||||
|
||||
/// Learn about benchmarking and weight.
|
||||
pub mod frame_benchmarking_weight;
|
||||
pub mod pezframe_benchmarking_weight;
|
||||
|
||||
/// Learn about the token-related logic in FRAME and how to apply it to your use case.
|
||||
pub mod frame_tokens;
|
||||
@@ -86,7 +86,7 @@ pub mod frame_tokens;
|
||||
/// Learn about chain specification file and the genesis state of the blockchain.
|
||||
pub mod chain_spec_genesis;
|
||||
|
||||
/// Learn about Substrate's CLI, and how it can be extended.
|
||||
/// Learn about Bizinikiwi's CLI, and how it can be extended.
|
||||
pub mod cli;
|
||||
|
||||
/// Learn about Runtime Upgrades and best practices for writing Migrations.
|
||||
@@ -112,5 +112,5 @@ pub mod custom_runtime_api_rpc;
|
||||
/// The [`pezkuwi-omni-node`](https://crates.io/crates/polkadot-omni-node) and its related binaries.
|
||||
pub mod omni_node;
|
||||
|
||||
/// Learn about the state in Substrate.
|
||||
/// Learn about the state in Bizinikiwi.
|
||||
pub mod state;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! # (Omni) Node
|
||||
//!
|
||||
//! This reference doc elaborates on what a Pezkuwi-SDK/Substrate node software is, and what
|
||||
//! This reference doc elaborates on what a Pezkuwi-SDK/Bizinikiwi node software is, and what
|
||||
//! various ways exist to run one.
|
||||
//!
|
||||
//! The node software, as denoted in [`crate::reference_docs::wasm_meta_protocol`], is everything in
|
||||
//! a blockchain other than the WASM runtime. It contains common components such as the database,
|
||||
//! networking, RPC server and consensus. Substrate-based nodes are native binaries that are
|
||||
//! networking, RPC server and consensus. Bizinikiwi-based nodes are native binaries that are
|
||||
//! compiled down from the Rust source code. The `node` folder in any of the [`templates`] are
|
||||
//! examples of this source.
|
||||
//!
|
||||
@@ -30,7 +30,7 @@
|
||||
//!
|
||||
//! > The notorious `service.rs` in any node template is a good example of this.
|
||||
//!
|
||||
//! A [trend](https://github.com/pezkuwichain/pezkuwi-sdk/issues/97) has already been undergoing in
|
||||
//! A [trend](https://github.com/pezkuwichain/pezkuwi-sdk/issues/243) has already been undergoing in
|
||||
//! order to de-couple the node and the runtime for a long time. The north star of this effort is
|
||||
//! twofold :
|
||||
//!
|
||||
@@ -42,7 +42,7 @@
|
||||
//! is the latter.
|
||||
//!
|
||||
//! > Note: The OmniNodes are mainly focused on the development needs of **Pezkuwi
|
||||
//! > teyrchains ONLY**, not (Substrate) solo-chains. For the time being, solo-chains are not
|
||||
//! > teyrchains ONLY**, not (Bizinikiwi) solo-chains. For the time being, solo-chains are not
|
||||
//! > supported by the OmniNodes. This might change in the future.
|
||||
//!
|
||||
//! ## Types of Nodes
|
||||
@@ -95,7 +95,7 @@
|
||||
//! * [`crate::guides::your_first_runtime`]
|
||||
//! * If need be, the weights of the runtime need to be updated using `frame-omni-bencher`.
|
||||
//! References:
|
||||
//! * [`crate::reference_docs::frame_benchmarking_weight`]
|
||||
//! * [`crate::reference_docs::pezframe_benchmarking_weight`]
|
||||
//! * Next, [`chain-spec-builder`] is used to generate a `chain_spec.json`, either for development,
|
||||
//! or for production. References:
|
||||
//! * [`crate::reference_docs::chain_spec_genesis`]
|
||||
@@ -115,21 +115,21 @@
|
||||
//!
|
||||
//! ### Consensus Engine
|
||||
//!
|
||||
//! In any given substrate-based chain, both the node and the runtime will have their own
|
||||
//! In any given bizinikiwi-based chain, both the node and the runtime will have their own
|
||||
//! opinion/information about what consensus engine is going to be used.
|
||||
//!
|
||||
//! In practice, the majority of the implementation of any consensus engine is in the node side, but
|
||||
//! the runtime also typically needs to expose a custom runtime-api to enable the particular
|
||||
//! consensus engine to work, and that particular runtime-api is implemented by a pallet
|
||||
//! consensus engine to work, and that particular runtime-api is implemented by a pezpallet
|
||||
//! corresponding to that consensus engine.
|
||||
//!
|
||||
//! For example, taking a snippet from [`solochain_template_runtime`], the runtime has to provide
|
||||
//! this additional runtime-api (compared to [`minimal_template_runtime`]), if the node software is
|
||||
//! configured to use the Aura consensus engine:
|
||||
//! For example, taking a snippet from [`pez_solochain_template_runtime`], the runtime has to
|
||||
//! provide this additional runtime-api (compared to [`pez_minimal_template_runtime`]), if the node
|
||||
//! software is configured to use the Aura consensus engine:
|
||||
//!
|
||||
//! ```text
|
||||
//! impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
|
||||
//! fn slot_duration() -> sp_consensus_aura::SlotDuration {
|
||||
//! impl pezsp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
|
||||
//! fn slot_duration() -> pezsp_consensus_aura::SlotDuration {
|
||||
//! ...
|
||||
//! }
|
||||
//! fn authorities() -> Vec<AuraId> {
|
||||
@@ -145,17 +145,17 @@
|
||||
//!
|
||||
//! For block authoring, there are a number of options:
|
||||
//!
|
||||
//! * [`sc_consensus_manual_seal`]: Useful for testing, where any node can produce a block at any
|
||||
//! * [`pezsc_consensus_manual_seal`]: Useful for testing, where any node can produce a block at any
|
||||
//! time. This is often combined with a fixed interval at which a block is produced.
|
||||
//! * [`sc_consensus_aura`]/[`pallet_aura`]: A simple round-robin block authoring mechanism.
|
||||
//! * [`sc_consensus_babe`]/[`pallet_babe`]: A more advanced block authoring mechanism, capable of
|
||||
//! anonymizing the next block author.
|
||||
//! * [`sc_consensus_pow`]: Proof of Work block authoring.
|
||||
//! * [`pezsc_consensus_aura`]/[`pezpallet_aura`]: A simple round-robin block authoring mechanism.
|
||||
//! * [`pezsc_consensus_babe`]/[`pezpallet_babe`]: A more advanced block authoring mechanism,
|
||||
//! capable of anonymizing the next block author.
|
||||
//! * [`pezsc_consensus_pow`]: Proof of Work block authoring.
|
||||
//!
|
||||
//! For finality, there is one main option shipped with pezkuwi-sdk:
|
||||
//!
|
||||
//! * [`sc_consensus_grandpa`]/[`pallet_grandpa`]: A finality gadget that uses a voting mechanism to
|
||||
//! decide when a block
|
||||
//! * [`pezsc_consensus_grandpa`]/[`pezpallet_grandpa`]: A finality gadget that uses a voting
|
||||
//! mechanism to decide when a block
|
||||
//!
|
||||
//! **The most important lesson here is that the node and the runtime must have matching consensus
|
||||
//! components.**
|
||||
@@ -171,10 +171,10 @@
|
||||
//! scaling). [`pezkuwi_omni_node_lib::cli::Cli::experimental_use_slot_based`] for fixed factor
|
||||
//! scaling (a step
|
||||
//! * Ability to run any runtime with [`--dev-block-time`] flag. This uses
|
||||
//! [`sc_consensus_manual_seal`] under the hood, and has no restrictions on the runtime's
|
||||
//! [`pezsc_consensus_manual_seal`] under the hood, and has no restrictions on the runtime's
|
||||
//! consensus.
|
||||
//!
|
||||
//! [This](https://github.com/pezkuwichain/pezkuwi-sdk/issues/143) future improvement to OmniNode
|
||||
//! [This](https://github.com/pezkuwichain/pezkuwi-sdk/issues/286) future improvement to OmniNode
|
||||
//! aims to make such checks automatic.
|
||||
//!
|
||||
//! ### Runtime conventions
|
||||
@@ -185,17 +185,17 @@
|
||||
//! failure.
|
||||
//!
|
||||
//! The list of checks may evolve in the future and for now only few rules are implemented:
|
||||
//! * runtimes must define a type for [`cumulus-pallet-teyrchain-system`], which is recommended to
|
||||
//! be named as `TeyrchainSystem`.
|
||||
//! * runtimes must define a type for [`frame-system`] pallet, which is recommended to be named as
|
||||
//! `System`. The configured [`block number`] here will be used by Omni Node to configure AURA
|
||||
//! accordingly.
|
||||
//! * runtimes must define a type for [`pezcumulus-pezpallet-teyrchain-system`], which is
|
||||
//! recommended to be named as `TeyrchainSystem`.
|
||||
//! * runtimes must define a type for [`pezframe-system`] pezpallet, which is recommended to be
|
||||
//! named as `System`. The configured [`block number`] here will be used by Omni Node to configure
|
||||
//! AURA accordingly.
|
||||
//!
|
||||
//! [`templates`]: crate::pezkuwi_sdk::templates
|
||||
//! [`teyrchain-template`]: https://github.com/pezkuwichain/pezkuwi-sdk-teyrchain-template
|
||||
//! [`--dev-block-time`]: pezkuwi_omni_node_lib::cli::Cli::dev_block_time
|
||||
//! [`pezkuwi-omni-node`]: https://crates.io/crates/polkadot-omni-node
|
||||
//! [`chain-spec-builder`]: https://crates.io/crates/staging-chain-spec-builder
|
||||
//! [`cumulus-pallet-teyrchain-system`]: https://docs.rs/cumulus-pallet-parachain-system/latest/cumulus_pallet_parachain_system/
|
||||
//! [`frame-system`]: https://docs.rs/frame-system/latest/frame_system/
|
||||
//! [`chain-spec-builder`]: https://crates.io/crates/pezstaging-chain-spec-builder
|
||||
//! [`pezcumulus-pezpallet-teyrchain-system`]: https://docs.rs/cumulus-pallet-parachain-system/latest/cumulus_pallet_parachain_system/
|
||||
//! [`pezframe-system`]: https://docs.rs/frame-system/latest/frame_system/
|
||||
//! [`block number`]: https://docs.rs/frame-system/latest/frame_system/pallet/storage_types/struct.Number.html
|
||||
|
||||
+26
-26
@@ -47,13 +47,13 @@
|
||||
//! the 20ms. In a benchmarked environment, it can examine the transactions for their upper bound,
|
||||
//! and include the ones that are known to fit based on the worst case.
|
||||
//!
|
||||
//! The benchmarking code can be written as a part of FRAME pallet, using the macros provided in
|
||||
//! [`frame_benchmarking`]. See any of the existing pallets in `pezkuwi-sdk`, or the pallets in our
|
||||
//! [`crate::pezkuwi_sdk::templates`] for examples.
|
||||
//! The benchmarking code can be written as a part of FRAME pezpallet, using the macros provided in
|
||||
//! [`pezframe_benchmarking`]. See any of the existing pallets in `pezkuwi-sdk`, or the pallets in
|
||||
//! our [`crate::pezkuwi_sdk::templates`] for examples.
|
||||
//!
|
||||
//! ## Weight
|
||||
//!
|
||||
//! Finally, [`sp_weights::Weight`] is the output of the benchmarking process. It is a
|
||||
//! Finally, [`pezsp_weights::Weight`] is the output of the benchmarking process. It is a
|
||||
//! two-dimensional data structure that demonstrates the resources consumed by a given block of
|
||||
//! code (for example, a transaction). The two dimensions are:
|
||||
//!
|
||||
@@ -67,29 +67,29 @@
|
||||
//! it captures the worst case execution of any block of code.
|
||||
//!
|
||||
//! Consider:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_benchmarking_weight.rs", simple_transfer)]
|
||||
#![doc = docify::embed!("./src/reference_docs/pezframe_benchmarking_weight.rs", simple_transfer)]
|
||||
//!
|
||||
//! If this block of code is to be benchmarked, then the benchmarking code must be written such that
|
||||
//! it captures the worst case.
|
||||
//!
|
||||
//! ## Gluing Pallet Benchmarking with Runtime
|
||||
//! ## Gluing Pezpallet Benchmarking with Runtime
|
||||
//!
|
||||
//! FRAME pallets are mandated to provide their own benchmarking code. Runtimes contain the
|
||||
//! boilerplate needed to run these benchmarking (see [Running Benchmarks
|
||||
//! below](#running-benchmarks)). The outcome of running these benchmarks are meant to be fed back
|
||||
//! into the pallet via a conventional `trait WeightInfo` on `Config`:
|
||||
#![doc = docify::embed!("src/reference_docs/frame_benchmarking_weight.rs", WeightInfo)]
|
||||
//! into the pezpallet via a conventional `trait WeightInfo` on `Config`:
|
||||
#![doc = docify::embed!("src/reference_docs/pezframe_benchmarking_weight.rs", WeightInfo)]
|
||||
//!
|
||||
//! Then, individual functions of this trait are the final values that we assigned to the
|
||||
//! [`frame::pallet_macros::weight`] attribute:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_benchmarking_weight.rs", simple_transfer_2)]
|
||||
//! [`pezframe::pezpallet_macros::weight`] attribute:
|
||||
#![doc = docify::embed!("./src/reference_docs/pezframe_benchmarking_weight.rs", simple_transfer_2)]
|
||||
//!
|
||||
//! ## Manual Refund
|
||||
//!
|
||||
//! Back to the assumption of writing benchmarks for worst case: Sometimes, the pre-dispatch weight
|
||||
//! significantly differ from the post-dispatch actual weight consumed. This can be expressed with
|
||||
//! the following FRAME syntax:
|
||||
#![doc = docify::embed!("./src/reference_docs/frame_benchmarking_weight.rs", simple_transfer_3)]
|
||||
#![doc = docify::embed!("./src/reference_docs/pezframe_benchmarking_weight.rs", simple_transfer_3)]
|
||||
//!
|
||||
//! ## Running Benchmarks
|
||||
//!
|
||||
@@ -114,7 +114,7 @@
|
||||
//!
|
||||
//! Pezkuwi-SDK runtimes use a more performant VM, namely WASM, which does not have metering. In
|
||||
//! return they have to be benchmarked to provide an upper bound on the resources they consume. This
|
||||
//! upper bound is represented as [`sp_weights::Weight`].
|
||||
//! upper bound is represented as [`pezsp_weights::Weight`].
|
||||
//!
|
||||
//! ## Future: PolkaVM
|
||||
//!
|
||||
@@ -130,28 +130,28 @@
|
||||
//! [PolkaVM]: https://github.com/koute/polkavm
|
||||
//! [JAM]: https://graypaper.com
|
||||
|
||||
#[frame::pallet(dev_mode)]
|
||||
#[pezframe::pezpallet(dev_mode)]
|
||||
#[allow(unused_variables, unreachable_code, unused, clippy::diverging_sub_expression)]
|
||||
pub mod pallet {
|
||||
use frame::prelude::*;
|
||||
pub mod pezpallet {
|
||||
use pezframe::prelude::*;
|
||||
|
||||
#[docify::export]
|
||||
pub trait WeightInfo {
|
||||
fn simple_transfer() -> Weight;
|
||||
}
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
#[docify::export]
|
||||
#[pallet::weight(10_000)]
|
||||
#[pezpallet::weight(10_000)]
|
||||
pub fn simple_transfer(
|
||||
origin: OriginFor<T>,
|
||||
destination: T::AccountId,
|
||||
@@ -167,7 +167,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[pallet::weight(T::WeightInfo::simple_transfer())]
|
||||
#[pezpallet::weight(T::WeightInfo::simple_transfer())]
|
||||
pub fn simple_transfer_2(
|
||||
origin: OriginFor<T>,
|
||||
destination: T::AccountId,
|
||||
@@ -184,7 +184,7 @@ pub mod pallet {
|
||||
|
||||
#[docify::export]
|
||||
// This is the worst-case, pre-dispatch weight.
|
||||
#[pallet::weight(T::WeightInfo::simple_transfer())]
|
||||
#[pezpallet::weight(T::WeightInfo::simple_transfer())]
|
||||
pub fn simple_transfer_3(
|
||||
origin: OriginFor<T>,
|
||||
destination: T::AccountId,
|
||||
@@ -195,14 +195,14 @@ pub mod pallet {
|
||||
if destination_exists {
|
||||
// simpler code path
|
||||
// Note that need for .into(), to convert `()` to `PostDispatchInfo`
|
||||
// See: https://docs.pezkuwichain.io/sdk/master/frame_support/dispatch/struct.PostDispatchInfo.html#impl-From%3C()%3E-for-PostDispatchInfo
|
||||
// See: https://docs.pezkuwichain.io/sdk/master/pezframe_support/dispatch/struct.PostDispatchInfo.html#impl-From%3C()%3E-for-PostDispatchInfo
|
||||
Ok(().into())
|
||||
} else {
|
||||
// more complex code path
|
||||
let actual_weight =
|
||||
todo!("this can likely come from another benchmark that is NOT the worst case");
|
||||
let pays_fee = todo!("You can set this to `Pays::Yes` or `Pays::No` to change if this transaction should pay fees");
|
||||
Ok(frame::deps::frame_support::dispatch::PostDispatchInfo {
|
||||
Ok(pezframe::deps::pezframe_support::dispatch::PostDispatchInfo {
|
||||
actual_weight: Some(actual_weight),
|
||||
pays_fee,
|
||||
})
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
//!
|
||||
//! 🚧 Work In Progress 🚧
|
||||
//!
|
||||
//! How `frame_system` handles accountIds. Nonce. Consumers and Providers, reference counting.
|
||||
//! How `pezframe_system` handles accountIds. Nonce. Consumers and Providers, reference counting.
|
||||
|
||||
// - poorly understood topics, needs one great article to rul them all.
|
||||
// - https://github.com/paritytech/substrate/issues/14425
|
||||
// - https://github.com/paritytech/substrate/pull/12951
|
||||
// - https://github.com/pezkuwichain/pezkuwi-sdk/issues/17
|
||||
// - https://github.com/pezkuwichain/pezkuwi-sdk/issues/40
|
||||
// - https://exchange.pezkuwichain.app/questions/263/what-is-the-meaning-of-the-account-provider-sufficients-and-consumer
|
||||
@@ -3,7 +3,7 @@
|
||||
//! *TL;DR*: If you need to create a *Blockchain*, then write a runtime. If you need to create a
|
||||
//! *DApp*, then write a Smart Contract.
|
||||
//!
|
||||
//! This is a comparative analysis of Substrate-based Runtimes and Smart Contracts, highlighting
|
||||
//! This is a comparative analysis of Bizinikiwi-based Runtimes and Smart Contracts, highlighting
|
||||
//! their main differences. Our aim is to equip you with a clear understanding of how these two
|
||||
//! methods of deploying on-chain logic diverge in their design, usage, and implications.
|
||||
//!
|
||||
@@ -12,21 +12,21 @@
|
||||
//! decentralized applications. Understanding their differences is crucial in choosing the right
|
||||
//! approach for a specific solution.
|
||||
//!
|
||||
//! ## Substrate
|
||||
//! Substrate is a modular framework that enables the creation of purpose-specific blockchains. In
|
||||
//! ## Bizinikiwi
|
||||
//! Bizinikiwi is a modular framework that enables the creation of purpose-specific blockchains. In
|
||||
//! the Pezkuwi ecosystem you can find two distinct approaches for on-chain code execution:
|
||||
//! [Runtime Development](#runtime-in-substrate) and [Smart Contracts](#smart-contracts).
|
||||
//! [Runtime Development](#runtime-in-bizinikiwi) and [Smart Contracts](#smart-contracts).
|
||||
//!
|
||||
//! #### Smart Contracts in Substrate
|
||||
//! #### Smart Contracts in Bizinikiwi
|
||||
//! Smart Contracts are autonomous, programmable constructs deployed on the blockchain.
|
||||
//! In [FRAME](frame), Smart Contracts infrastructure is implemented by the
|
||||
//! [`pallet_contracts`] for WASM-based contracts or the
|
||||
//! [`pallet_evm`](https://github.com/polkadot-evm/frontier/tree/master/frame/evm) for EVM-compatible contracts. These pallets
|
||||
//! enable Smart Contract developers to build applications and systems on top of a Substrate-based
|
||||
//! [`pezpallet_contracts`] for WASM-based contracts or the
|
||||
//! [`pezpallet_evm`](https://github.com/polkadot-evm/frontier/tree/master/frame/evm) for EVM-compatible contracts. These pallets
|
||||
//! enable Smart Contract developers to build applications and systems on top of a Bizinikiwi-based
|
||||
//! blockchain.
|
||||
//!
|
||||
//! #### Runtime in Substrate
|
||||
//! The Runtime is the state transition function of a Substrate-based blockchain. It defines the
|
||||
//! #### Runtime in Bizinikiwi
|
||||
//! The Runtime is the state transition function of a Bizinikiwi-based blockchain. It defines the
|
||||
//! rules for processing transactions and blocks, essentially governing the behavior and
|
||||
//! capabilities of a blockchain.
|
||||
//!
|
||||
@@ -35,7 +35,7 @@
|
||||
//! | Aspect | Runtime | Smart Contracts |
|
||||
//! |-----------------------|-------------------------------------------------------------------------|----------------------------------------------------------------------|
|
||||
//! | **Design Philosophy** | Core logic of a blockchain, allowing broad and deep customization. | Designed for DApps deployed on the blockchain runtime. |
|
||||
//! | **Development Complexity** | Requires in-depth knowledge of Rust and Substrate. Suitable for complex blockchain architectures. | Easier to develop with knowledge of Smart Contract languages like Solidity or [ink!](https://use.ink/). |
|
||||
//! | **Development Complexity** | Requires in-depth knowledge of Rust and Bizinikiwi. Suitable for complex blockchain architectures. | Easier to develop with knowledge of Smart Contract languages like Solidity or [ink!](https://use.ink/). |
|
||||
//! | **Upgradeability and Flexibility** | Offers comprehensive upgradeability with migration logic and on-chain governance, allowing modifications to the entire blockchain logic without hard forks. | Less flexible in upgrade migrations but offers more straightforward deployment and iteration. |
|
||||
//! | **Performance and Efficiency** | More efficient, optimized for specific needs of the blockchain. | Can be less efficient due to its generic nature (e.g. the overhead of a virtual machine). |
|
||||
//! | **Security Considerations** | Security flaws can affect the entire blockchain. | Security risks usually localized to the individual contract. |
|
||||
@@ -70,8 +70,8 @@
|
||||
//! differing purposes and technical requirements.
|
||||
//!
|
||||
//! #### Runtime Development Complexity
|
||||
//! - **In-depth Knowledge Requirements**: Developing a Runtime in Substrate requires a
|
||||
//! comprehensive understanding of Rust, Substrate's framework, and blockchain principles.
|
||||
//! - **In-depth Knowledge Requirements**: Developing a Runtime in Bizinikiwi requires a
|
||||
//! comprehensive understanding of Rust, Bizinikiwi's framework, and blockchain principles.
|
||||
//! - **Complex Blockchain Architectures**: Runtime development is suitable for creating complex
|
||||
//! blockchain architectures. Developers must consider aspects like security, scalability, and
|
||||
//! network efficiency.
|
||||
@@ -108,7 +108,7 @@
|
||||
//! - **Deployment and Iteration**: Smart Contracts, by nature, are designed for more
|
||||
//! straightforward deployment and iteration. Developers can quickly deploy contracts.
|
||||
//! - **Contract Code Updates**: Once deployed, although typically immutable, Smart Contracts can be
|
||||
//! upgraded, but lack of migration logic. The [`pallet_contracts`]
|
||||
//! upgraded, but lack of migration logic. The [`pezpallet_contracts`]
|
||||
//! allows for contracts to be upgraded by exposing the `set_code` dispatchable. More details on this
|
||||
//! can be found in [Ink! documentation on upgradeable contracts](https://use.ink/basics/upgradeable-contracts).
|
||||
//! - **Isolated Impact**: Upgrades or changes to a smart contract generally impact only that
|
||||
@@ -123,7 +123,7 @@
|
||||
//! and optimized for specific needs, while Smart Contracts are more generic and less efficient.
|
||||
//!
|
||||
//! #### Runtime Performance and Efficiency
|
||||
//! - **Optimized for Specific Needs**: Runtime modules in Substrate are tailored to meet the
|
||||
//! - **Optimized for Specific Needs**: Runtime modules in Bizinikiwi are tailored to meet the
|
||||
//! specific needs of the blockchain. They are integrated directly into the blockchain's core,
|
||||
//! allowing them to operate with high efficiency and minimal overhead.
|
||||
//! - **Direct Access to Blockchain State**: Runtime has direct access to the blockchain's state.
|
||||
@@ -181,12 +181,12 @@
|
||||
//! #### Weighing
|
||||
//! In FRAME-based Runtimes, operations are *weighed*. This means that each operation in the Runtime
|
||||
//! has a fixed upper cost, known in advance, determined through
|
||||
//! [benchmarking](crate::reference_docs::frame_benchmarking_weight). Weighing is practical here
|
||||
//! [benchmarking](crate::reference_docs::pezframe_benchmarking_weight). Weighing is practical here
|
||||
//! because:
|
||||
//!
|
||||
//! - *Predictability*: Runtime operations are part of the blockchain's core logic, which is static
|
||||
//! until an upgrade occurs. This predictability allows for precise
|
||||
//! [benchmarking](crate::reference_docs::frame_benchmarking_weight).
|
||||
//! [benchmarking](crate::reference_docs::pezframe_benchmarking_weight).
|
||||
//! - *Prevention of Abuse*: By having a fixed upper cost that corresponds to the worst-case
|
||||
//! complexity scenario of its execution (and a mechanism to refund unused weight), it becomes
|
||||
//! infeasible for an attacker to create transactions that could unpredictably consume excessive
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
//! The key-value pairs in the state are represented as byte sequences. The node
|
||||
//! doesn't know how to interpret most the key-value pairs. However, there exist some
|
||||
//! special keys and its values that are known to the node, the so-called
|
||||
//! [`well-known-keys`](sp_storage::well_known_keys).
|
||||
//! [`well-known-keys`](pezsp_storage::well_known_keys).
|
||||
|
||||
@@ -7,29 +7,29 @@
|
||||
//! The rest of this document assumes familiarity with the
|
||||
//! [Rust book's Advanced Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html)
|
||||
//! section.
|
||||
//! Moreover, we use the [`frame::traits::Get`].
|
||||
//! Moreover, we use the [`pezframe::traits::Get`].
|
||||
//!
|
||||
//! First, imagine we are writing a FRAME pallet. We represent this pallet with a `struct Pallet`,
|
||||
//! and this pallet wants to implement the functionalities of that pallet, for example a simple
|
||||
//! `transfer` function. For the sake of education, we are interested in having a `MinTransfer`
|
||||
//! amount, expressed as a [`frame::traits::Get`], which will dictate what is the minimum amount
|
||||
//! that can be transferred.
|
||||
//! First, imagine we are writing a FRAME pezpallet. We represent this pezpallet with a `struct
|
||||
//! Pezpallet`, and this pezpallet wants to implement the functionalities of that pezpallet, for
|
||||
//! example a simple `transfer` function. For the sake of education, we are interested in having a
|
||||
//! `MinTransfer` amount, expressed as a [`pezframe::traits::Get`], which will dictate what is the
|
||||
//! minimum amount that can be transferred.
|
||||
//!
|
||||
//! We can foremost write this as simple as the following snippet:
|
||||
#![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", basic)]
|
||||
//!
|
||||
//!
|
||||
//! In this example, we use arbitrary choices for `AccountId`, `Balance` and the `MinTransfer` type.
|
||||
//! This works great for **one team's purposes** but we have to remember that Substrate and FRAME
|
||||
//! This works great for **one team's purposes** but we have to remember that Bizinikiwi and FRAME
|
||||
//! are written as generic frameworks, intended to be highly configurable.
|
||||
//!
|
||||
//! In a broad sense, there are two avenues in exposing configurability:
|
||||
//!
|
||||
//! 1. For *values* that need to be generic, for example `MinTransfer`, we attach them to the
|
||||
//! `Pallet` struct as fields:
|
||||
//! `Pezpallet` struct as fields:
|
||||
//!
|
||||
//! ```
|
||||
//! struct Pallet {
|
||||
//! struct Pezpallet {
|
||||
//! min_transfer: u128,
|
||||
//! }
|
||||
//! ```
|
||||
@@ -38,23 +38,23 @@
|
||||
//! as:
|
||||
//!
|
||||
//! ```
|
||||
//! struct Pallet<AccountId> {
|
||||
//! struct Pezpallet<AccountId> {
|
||||
//! min_transfer: u128,
|
||||
//! _marker: std::marker::PhantomData<AccountId>,
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Substrate and FRAME, for various reasons (performance, correctness, type safety) has opted to
|
||||
//! Bizinikiwi and FRAME, for various reasons (performance, correctness, type safety) has opted to
|
||||
//! use *types* to declare both *values* and *types* as generic. This is the essence of why the
|
||||
//! `Get` trait exists.
|
||||
//!
|
||||
//! This would bring us to the second iteration of the pallet, which would look like:
|
||||
//! This would bring us to the second iteration of the pezpallet, which would look like:
|
||||
#![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", generic)]
|
||||
//!
|
||||
//! In this example, we managed to make all 3 of our types generic. Taking the example of the
|
||||
//! `AccountId`, one should read the above as following:
|
||||
//!
|
||||
//! > The `Pallet` does not know what type `AccountId` concretely is, but it knows that it is
|
||||
//! > The `Pezpallet` does not know what type `AccountId` concretely is, but it knows that it is
|
||||
//! > something that adheres to being `From<[u8; 32]>`.
|
||||
//!
|
||||
//! This method would work, but it suffers from two downsides:
|
||||
@@ -72,7 +72,7 @@
|
||||
//!
|
||||
//! > Interestingly, one downside of associated types is that declaring defaults on them is not
|
||||
//! > stable yet. In the meantime, we have built our own custom mechanics around declaring defaults
|
||||
//! for associated types, see [`pallet_default_config_example`].
|
||||
//! for associated types, see [`pezpallet_default_config_example`].
|
||||
//!
|
||||
//! The last iteration of our code would look like this:
|
||||
#![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", trait_based)]
|
||||
@@ -84,7 +84,7 @@
|
||||
//! having individual `trait Configs` declare a shared `trait SystemConfig` as their
|
||||
//! [supertrait](https://doc.rust-lang.org/rust-by-example/trait/supertraits.html).
|
||||
#![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", with_system)]
|
||||
//! In FRAME, this shared supertrait is [`frame::prelude::frame_system`].
|
||||
//! In FRAME, this shared supertrait is [`pezframe::prelude::pezframe_system`].
|
||||
//!
|
||||
//! Notice how this made no difference in the syntax of the rest of the code. `T::AccountId` is
|
||||
//! still a valid type, since `T` implements `Config` and `Config` implies `SystemConfig`, which
|
||||
@@ -103,27 +103,27 @@
|
||||
//! length of fully qualified syntax is a common pattern in FRAME.
|
||||
//!
|
||||
//! The above example is almost identical to the well-known (and somewhat notorious) `type
|
||||
//! BalanceOf` that is often used in the context of [`frame::traits::fungible`].
|
||||
#![doc = docify::embed!("../../substrate/frame/fast-unstake/src/types.rs", BalanceOf)]
|
||||
//! BalanceOf` that is often used in the context of [`pezframe::traits::fungible`].
|
||||
#![doc = docify::embed!("../../bizinikiwi/pezframe/fast-unstake/src/types.rs", BalanceOf)]
|
||||
//!
|
||||
//! ## Additional Resources
|
||||
//!
|
||||
//! - <https://github.com/paritytech/substrate/issues/13836>
|
||||
//! - [Substrate Seminar - Traits and Generic Types](https://www.youtube.com/watch?v=6cp10jVWNl4)
|
||||
//! - <https://github.com/pezkuwichain/pezkuwi-sdk/issues/326>
|
||||
//! - [Bizinikiwi Seminar - Traits and Generic Types](https://www.youtube.com/watch?v=6cp10jVWNl4)
|
||||
//! - <https://exchange.pezkuwichain.app/questions/2228/type-casting-to-trait-t-as-config>
|
||||
#![allow(unused)]
|
||||
|
||||
use frame::traits::Get;
|
||||
use pezframe::traits::Get;
|
||||
|
||||
#[docify::export]
|
||||
mod basic {
|
||||
struct Pallet;
|
||||
struct Pezpallet;
|
||||
|
||||
type AccountId = frame::deps::sp_runtime::AccountId32;
|
||||
type AccountId = pezframe::deps::pezsp_runtime::AccountId32;
|
||||
type Balance = u128;
|
||||
type MinTransfer = frame::traits::ConstU128<10>;
|
||||
type MinTransfer = pezframe::traits::ConstU128<10>;
|
||||
|
||||
impl Pallet {
|
||||
impl Pezpallet {
|
||||
fn transfer(_from: AccountId, _to: AccountId, _amount: Balance) {
|
||||
todo!()
|
||||
}
|
||||
@@ -134,14 +134,14 @@ mod basic {
|
||||
mod generic {
|
||||
use super::*;
|
||||
|
||||
struct Pallet<AccountId, Balance, MinTransfer> {
|
||||
struct Pezpallet<AccountId, Balance, MinTransfer> {
|
||||
_marker: std::marker::PhantomData<(AccountId, Balance, MinTransfer)>,
|
||||
}
|
||||
|
||||
impl<AccountId, Balance, MinTransfer> Pallet<AccountId, Balance, MinTransfer>
|
||||
impl<AccountId, Balance, MinTransfer> Pezpallet<AccountId, Balance, MinTransfer>
|
||||
where
|
||||
Balance: frame::traits::AtLeast32BitUnsigned,
|
||||
MinTransfer: frame::traits::Get<Balance>,
|
||||
Balance: pezframe::traits::AtLeast32BitUnsigned,
|
||||
MinTransfer: pezframe::traits::Get<Balance>,
|
||||
AccountId: From<[u8; 32]>,
|
||||
{
|
||||
fn transfer(_from: AccountId, _to: AccountId, amount: Balance) {
|
||||
@@ -157,12 +157,12 @@ mod trait_based {
|
||||
|
||||
trait Config {
|
||||
type AccountId: From<[u8; 32]>;
|
||||
type Balance: frame::traits::AtLeast32BitUnsigned;
|
||||
type MinTransfer: frame::traits::Get<Self::Balance>;
|
||||
type Balance: pezframe::traits::AtLeast32BitUnsigned;
|
||||
type MinTransfer: pezframe::traits::Get<Self::Balance>;
|
||||
}
|
||||
|
||||
struct Pallet<T: Config>(std::marker::PhantomData<T>);
|
||||
impl<T: Config> Pallet<T> {
|
||||
struct Pezpallet<T: Config>(std::marker::PhantomData<T>);
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn transfer(_from: T::AccountId, _to: T::AccountId, amount: T::Balance) {
|
||||
assert!(amount >= T::MinTransfer::get());
|
||||
unimplemented!();
|
||||
@@ -179,12 +179,12 @@ mod with_system {
|
||||
}
|
||||
|
||||
pub trait Config: SystemConfig {
|
||||
type Balance: frame::traits::AtLeast32BitUnsigned;
|
||||
type MinTransfer: frame::traits::Get<Self::Balance>;
|
||||
type Balance: pezframe::traits::AtLeast32BitUnsigned;
|
||||
type MinTransfer: pezframe::traits::Get<Self::Balance>;
|
||||
}
|
||||
|
||||
pub struct Pallet<T: Config>(std::marker::PhantomData<T>);
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub struct Pezpallet<T: Config>(std::marker::PhantomData<T>);
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn transfer(_from: T::AccountId, _to: T::AccountId, amount: T::Balance) {
|
||||
assert!(amount >= T::MinTransfer::get());
|
||||
unimplemented!();
|
||||
@@ -205,7 +205,7 @@ mod fully_qualified_complicated {
|
||||
use super::with_system::*;
|
||||
|
||||
trait CurrencyTrait {
|
||||
type Balance: frame::traits::AtLeast32BitUnsigned;
|
||||
type Balance: pezframe::traits::AtLeast32BitUnsigned;
|
||||
fn more_stuff() {}
|
||||
}
|
||||
|
||||
@@ -213,8 +213,8 @@ mod fully_qualified_complicated {
|
||||
type Currency: CurrencyTrait;
|
||||
}
|
||||
|
||||
struct Pallet<T: Config>(std::marker::PhantomData<T>);
|
||||
impl<T: Config> Pallet<T> {
|
||||
struct Pezpallet<T: Config>(std::marker::PhantomData<T>);
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn transfer(
|
||||
_from: T::AccountId,
|
||||
_to: T::AccountId,
|
||||
|
||||
@@ -5,53 +5,54 @@
|
||||
//!
|
||||
//! FRAME by default already provides the following transaction extensions:
|
||||
//!
|
||||
//! - [`CheckGenesis`](frame_system::CheckGenesis): Ensures that a transaction was sent for the same
|
||||
//! network. Determined based on genesis.
|
||||
//! - [`CheckGenesis`](pezframe_system::CheckGenesis): Ensures that a transaction was sent for the
|
||||
//! same network. Determined based on genesis.
|
||||
//!
|
||||
//! - [`CheckMortality`](frame_system::CheckMortality): Extends a transaction with a configurable
|
||||
//! - [`CheckMortality`](pezframe_system::CheckMortality): Extends a transaction with a configurable
|
||||
//! mortality.
|
||||
//!
|
||||
//! - [`CheckNonZeroSender`](frame_system::CheckNonZeroSender): Ensures that the sender of a
|
||||
//! - [`CheckNonZeroSender`](pezframe_system::CheckNonZeroSender): Ensures that the sender of a
|
||||
//! transaction is not the *all zero account* (all bytes of the accountid are zero).
|
||||
//!
|
||||
//! - [`CheckNonce`](frame_system::CheckNonce): Extends a transaction with a nonce to prevent replay
|
||||
//! of transactions and to provide ordering of transactions.
|
||||
//! - [`CheckNonce`](pezframe_system::CheckNonce): Extends a transaction with a nonce to prevent
|
||||
//! replay of transactions and to provide ordering of transactions.
|
||||
//!
|
||||
//! - [`CheckSpecVersion`](frame_system::CheckSpecVersion): Ensures that a transaction was built for
|
||||
//! the currently active runtime.
|
||||
//! - [`CheckSpecVersion`](pezframe_system::CheckSpecVersion): Ensures that a transaction was built
|
||||
//! for the currently active runtime.
|
||||
//!
|
||||
//! - [`CheckTxVersion`](frame_system::CheckTxVersion): Ensures that the transaction signer used the
|
||||
//! correct encoding of the call.
|
||||
//! - [`CheckTxVersion`](pezframe_system::CheckTxVersion): Ensures that the transaction signer used
|
||||
//! the correct encoding of the call.
|
||||
//!
|
||||
//! - [`CheckWeight`](frame_system::CheckWeight): Ensures that the transaction fits into the block
|
||||
//! before dispatching it.
|
||||
//! - [`CheckWeight`](pezframe_system::CheckWeight): Ensures that the transaction fits into the
|
||||
//! block before dispatching it.
|
||||
//!
|
||||
//! - [`ChargeTransactionPayment`](pallet_transaction_payment::ChargeTransactionPayment): Charges
|
||||
//! - [`ChargeTransactionPayment`](pezpallet_transaction_payment::ChargeTransactionPayment): Charges
|
||||
//! transaction fees from the signer based on the weight of the call using the native token.
|
||||
//!
|
||||
//! - [`ChargeAssetTxPayment`](pallet_asset_tx_payment::ChargeAssetTxPayment): Charges transaction
|
||||
//! fees from the signer based on the weight of the call using any supported asset (including the
|
||||
//! native token).
|
||||
//! - [`ChargeAssetTxPayment`](pezpallet_asset_tx_payment::ChargeAssetTxPayment): Charges
|
||||
//! transaction fees from the signer based on the weight of the call using any supported asset
|
||||
//! (including the native token).
|
||||
//!
|
||||
//! - [`ChargeAssetTxPayment`(using
|
||||
//! conversion)](pallet_asset_conversion_tx_payment::ChargeAssetTxPayment): Charges transaction
|
||||
//! conversion)](pezpallet_asset_conversion_tx_payment::ChargeAssetTxPayment): Charges transaction
|
||||
//! fees from the signer based on the weight of the call using any supported asset (including the
|
||||
//! native token). The asset is converted to the native token using a pool.
|
||||
//!
|
||||
//! - [`SkipCheckIfFeeless`](pallet_skip_feeless_payment::SkipCheckIfFeeless): Allows transactions
|
||||
//! to be processed without paying any fee. This requires that the `call` that should be
|
||||
//! dispatched is augmented with the [`feeless_if`](frame_support::pallet_macros::feeless_if)
|
||||
//! attribute.
|
||||
//! - [`SkipCheckIfFeeless`](pezpallet_skip_feeless_payment::SkipCheckIfFeeless): Allows
|
||||
//! transactions to be processed without paying any fee. This requires that the `call` that should
|
||||
//! be dispatched is augmented with the
|
||||
//! [`feeless_if`](pezframe_support::pezpallet_macros::feeless_if) attribute.
|
||||
//!
|
||||
//! - [`CheckMetadataHash`](frame_metadata_hash_extension::CheckMetadataHash): Extends transactions
|
||||
//! to include the so-called metadata hash. This is required by chains to support the generic
|
||||
//! Ledger application and other similar offline wallets.
|
||||
//! - [`CheckMetadataHash`](pezframe_metadata_hash_extension::CheckMetadataHash): Extends
|
||||
//! transactions to include the so-called metadata hash. This is required by chains to support the
|
||||
//! generic Ledger application and other similar offline wallets.
|
||||
//!
|
||||
//! - [`WeightReclaim`](frame_system::WeightReclaim): A transaction extension for the relay chain
|
||||
//! - [`WeightReclaim`](pezframe_system::WeightReclaim): A transaction extension for the relay chain
|
||||
//! that reclaims unused weight after executing a transaction.
|
||||
//!
|
||||
//! - [`StorageWeightReclaim`](cumulus_pallet_weight_reclaim::StorageWeightReclaim): A transaction
|
||||
//! extension for teyrchains that reclaims unused storage weight after executing a transaction.
|
||||
//! - [`StorageWeightReclaim`](pezcumulus_pezpallet_weight_reclaim::StorageWeightReclaim): A
|
||||
//! transaction extension for teyrchains that reclaims unused storage weight after executing a
|
||||
//! transaction.
|
||||
//!
|
||||
//! For more information about these extensions, follow the link to the type documentation.
|
||||
//!
|
||||
@@ -63,12 +64,12 @@
|
||||
#[docify::export]
|
||||
pub mod transaction_extensions_example {
|
||||
use codec::{Decode, DecodeWithMemTracking, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
use pezsp_runtime::{
|
||||
impl_tx_ext_default,
|
||||
traits::{Dispatchable, TransactionExtension},
|
||||
transaction_validity::TransactionValidityError,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
// This doesn't actually check anything, but simply allows
|
||||
// some arbitrary `u32` to be added to the extrinsic payload
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
//! crate in the repo, with `default-features = false`.
|
||||
//!
|
||||
//! For more fine-grained control, additionally, each crate can be enabled selectively. The umbrella
|
||||
//! exposes one feature per dependency. For example, if you only want to use the `frame-support`
|
||||
//! crate, you can enable the `frame-support` feature.
|
||||
//! exposes one feature per dependency. For example, if you only want to use the `pezframe-support`
|
||||
//! crate, you can enable the `pezframe-support` feature.
|
||||
//!
|
||||
//! The umbrella exposes a few more general features:
|
||||
//! - `tuples-96`: Needs to be enabled for runtimes that have more than 64 pallets.
|
||||
@@ -43,7 +43,8 @@
|
||||
//!
|
||||
//! ## Usage
|
||||
//!
|
||||
//! > Note: You can see a live example in the `staging-node-cli` and `kitchensink-runtime` crates.
|
||||
//! > Note: You can see a live example in the `pezstaging-node-cli` and `pez-kitchensink-runtime`
|
||||
//! > crates.
|
||||
//!
|
||||
//! The umbrella crate can be added to your runtime crate like this:
|
||||
//!
|
||||
@@ -70,10 +71,10 @@
|
||||
//!
|
||||
//! mod foo {
|
||||
//! // This does sadly not compile:
|
||||
//! frame_support::parameter_types! { }
|
||||
//! pezframe_support::parameter_types! { }
|
||||
//!
|
||||
//! // Instead, we need to do this (or add an equivalent `use` statement):
|
||||
//! pezkuwi_sdk::frame_support::parameter_types! { }
|
||||
//! pezkuwi_sdk::pezframe_support::parameter_types! { }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! # WASM Meta Protocol
|
||||
//!
|
||||
//! All Substrate based chains adhere to a unique architectural design novel to the Pezkuwi
|
||||
//! All Bizinikiwi based chains adhere to a unique architectural design novel to the Pezkuwi
|
||||
//! ecosystem. We refer to this design as the "**WASM Meta Protocol**".
|
||||
//!
|
||||
//! Consider the fact that a traditional blockchain software is usually a monolithic artifact.
|
||||
@@ -12,12 +12,12 @@
|
||||
//! Moreover, the idea of "storing code in the state" is explored in the context of smart contracts
|
||||
//! platforms, but has not been expanded further.
|
||||
//!
|
||||
//! Substrate mixes these two ideas together, and takes the novel approach of storing the
|
||||
//! Bizinikiwi mixes these two ideas together, and takes the novel approach of storing the
|
||||
//! blockchain's main "state transition function" in the main blockchain state, in the same fashion
|
||||
//! that a smart contract platform stores the code of individual contracts in its state. As noted in
|
||||
//! [`crate::reference_docs::blockchain_state_machines`], this state transition function is called
|
||||
//! the **Runtime**, and WASM is chosen as the bytecode. The Runtime is stored under a special key
|
||||
//! in the state (see [`sp_core::storage::well_known_keys`]) and can be updated as a part of the
|
||||
//! in the state (see [`pezsp_core::storage::well_known_keys`]) and can be updated as a part of the
|
||||
//! state transition function's execution, just like a user's account balance can be updated.
|
||||
//!
|
||||
//! > Note that while we drew an analogy between smart contracts and runtimes in the above, there
|
||||
@@ -28,24 +28,24 @@
|
||||
//! [**Node**](crate::reference_docs::glossary#node), and is a normal binary that is compiled from
|
||||
//! Rust to different hardware targets.
|
||||
//!
|
||||
//! This design enables all Substrate-based chains to be fork-less-ly upgradeable, because the
|
||||
//! This design enables all Bizinikiwi-based chains to be fork-less-ly upgradeable, because the
|
||||
//! Runtime can be updated on the fly, within the execution of a block, and the node is (for the
|
||||
//! most part) oblivious to the change that is happening.
|
||||
//!
|
||||
//! Therefore, the high-level architecture of a any Substrate-based chain can be demonstrated as
|
||||
//! Therefore, the high-level architecture of a any Bizinikiwi-based chain can be demonstrated as
|
||||
//! follows:
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/substrate_simple.mmd")]
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/bizinikiwi_simple.mmd")]
|
||||
//!
|
||||
//! The node and the runtime need to communicate. This is done through two concepts:
|
||||
//!
|
||||
//! 1. **Host functions**: a way for the (WASM) runtime to talk to the node. All host functions are
|
||||
//! defined in [`sp_io`]. For example, [`sp_io::storage`] are the set of host functions that
|
||||
//! allow the runtime to read and write data to the on-chain state.
|
||||
//! defined in [`pezsp_io`]. For example, [`pezsp_io::storage`] are the set of host functions
|
||||
//! that allow the runtime to read and write data to the on-chain state.
|
||||
//! 2. **Runtime APIs**: a way for the node to talk to the WASM runtime. Runtime APIs are defined
|
||||
//! using macros and utilities in [`sp_api`]. For example, [`sp_api::Core`] is the most
|
||||
//! using macros and utilities in [`pezsp_api`]. For example, [`pezsp_api::Core`] is the most
|
||||
//! fundamental runtime API that any blockchain must implement in order to be able to (re)
|
||||
//! execute blocks.
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/substrate_client_runtime.mmd")]
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/bizinikiwi_client_runtime.mmd")]
|
||||
//!
|
||||
//! A runtime must have a set of runtime APIs in order to have any meaningful blockchain
|
||||
//! functionality, but it can also expose more APIs. See
|
||||
@@ -78,12 +78,12 @@
|
||||
//! > The consensus is to your runtime what HTTP is to a web-application. It is the underlying
|
||||
//! > engine that enables trustless execution of the runtime in a distributed manner whilst
|
||||
//! > maintaining a canonical outcome of that execution.
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/substrate_with_frame.mmd")]
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/bizinikiwi_with_frame.mmd")]
|
||||
//!
|
||||
//! ## State
|
||||
//!
|
||||
//! From the previous sections, we know that the database component is part of the node, not the
|
||||
//! runtime. We also hinted that a set of host functions ([`sp_io::storage`]) are how the runtime
|
||||
//! runtime. We also hinted that a set of host functions ([`pezsp_io::storage`]) are how the runtime
|
||||
//! issues commands to the node to read/write to the state. Let's dive deeper into this.
|
||||
//!
|
||||
//! The state of the blockchain, what we seek to come to consensus about, is indeed *kept* in the
|
||||
@@ -92,7 +92,7 @@
|
||||
//! 1. Can update the state.
|
||||
//! 2. Can fully interpret the state.
|
||||
//!
|
||||
//! In fact, [`sp_core::storage::well_known_keys`] are the only state keys that the node side is
|
||||
//! In fact, [`pezsp_core::storage::well_known_keys`] are the only state keys that the node side is
|
||||
//! aware of. The rest of the state, including what logic the runtime has, what balance each user
|
||||
//! has and such, are all only comprehensible to the runtime.
|
||||
#![doc = simple_mermaid::mermaid!("../../../mermaid/state.mmd")]
|
||||
@@ -102,7 +102,7 @@
|
||||
//! (e.g. if it is a number of a vector). Contrary, the runtime knows both the meaning of their
|
||||
//! keys, and the type of the values.
|
||||
//!
|
||||
//! This opaque-ness is the fundamental reason why Substrate-based chains can fork-less-ly upgrade:
|
||||
//! This opaque-ness is the fundamental reason why Bizinikiwi-based chains can fork-less-ly upgrade:
|
||||
//! because the node side code is kept oblivious to all of the details of the state transition
|
||||
//! function. Therefore, the state transition function can freely upgrade without the node needing
|
||||
//! to know.
|
||||
@@ -115,10 +115,10 @@
|
||||
//! infrastructure of native code. However, neither of the two arguments strongly hold and the
|
||||
//! native runtime is being fully removed from the node-sdk.
|
||||
//!
|
||||
//! See: <https://github.com/pezkuwichain/pezkuwi-sdk/issues/97>
|
||||
//! See: <https://github.com/pezkuwichain/pezkuwi-sdk/issues/243>
|
||||
//!
|
||||
//! > Also, note that the flags [`sc_cli::ExecutionStrategy::Native`] is already a noop and all
|
||||
//! > chains built with Substrate only use WASM execution.
|
||||
//! > Also, note that the flags [`pezsc_cli::ExecutionStrategy::Native`] is already a noop and all
|
||||
//! > chains built with Bizinikiwi only use WASM execution.
|
||||
//!
|
||||
//! ### Runtime Versions
|
||||
//!
|
||||
@@ -126,18 +126,18 @@
|
||||
//! obviously, only uses the native runtime if it is the same code as with the wasm blob stored
|
||||
//! onchain. Else, nodes who run the native runtime will come to a different state transition. How
|
||||
//! do nodes determine if two runtimes are the same? Through the very important
|
||||
//! [`sp_version::RuntimeVersion`]. All runtimes expose their version via a runtime api
|
||||
//! ([`sp_api::Core::version`]) that returns this struct. The node software, or other applications,
|
||||
//! inspect this struct to examine the identity of a runtime, and to determine if two runtimes are
|
||||
//! the same. Namely, [`sp_version::RuntimeVersion::spec_version`] is the main key that implies two
|
||||
//! runtimes are the same.
|
||||
//! [`pezsp_version::RuntimeVersion`]. All runtimes expose their version via a runtime api
|
||||
//! ([`pezsp_api::Core::version`]) that returns this struct. The node software, or other
|
||||
//! applications, inspect this struct to examine the identity of a runtime, and to determine if two
|
||||
//! runtimes are the same. Namely, [`pezsp_version::RuntimeVersion::spec_version`] is the main key
|
||||
//! that implies two runtimes are the same.
|
||||
//!
|
||||
//! Therefore, it is utmost important to make sure before any runtime upgrade, the spec version is
|
||||
//! updated.
|
||||
//!
|
||||
//! ## Example: Block Execution.
|
||||
//!
|
||||
//! As a final example to recap, let's look at how Substrate-based nodes execute blocks. Blocks are
|
||||
//! As a final example to recap, let's look at how Bizinikiwi-based nodes execute blocks. Blocks are
|
||||
//! received in the node side software as opaque blobs and in the networking layer.
|
||||
//!
|
||||
//! At some point, based on the consensus algorithm's rules, the node decides to import (aka.
|
||||
@@ -146,10 +146,10 @@
|
||||
//! * First, the node will fetch the state of the parent hash of the block that wishes to be
|
||||
//! imported.
|
||||
//! * The runtime is fetched from this state, and placed into a WASM execution environment.
|
||||
//! * The [`sp_api::Core::execute_block`] runtime API is called and the block is passed in as an
|
||||
//! * The [`pezsp_api::Core::execute_block`] runtime API is called and the block is passed in as an
|
||||
//! argument.
|
||||
//! * The runtime will then execute the block, and update the state accordingly. Any state update is
|
||||
//! issued via the [`sp_io::storage`] host functions.
|
||||
//! issued via the [`pezsp_io::storage`] host functions.
|
||||
//! * Both the runtime and node will check the state-root of the state after the block execution to
|
||||
//! match the one claimed in the block header.
|
||||
//!
|
||||
|
||||
Reference in New Issue
Block a user