Transition into monorepo (#180)

* evm template integrated

* workflows modified per template

* workflow fixes
This commit is contained in:
Özgün Özerk
2024-05-17 12:00:25 +03:00
committed by GitHub
parent 9cd76d29f0
commit 1bb2e96501
103 changed files with 20153 additions and 581 deletions
@@ -0,0 +1,19 @@
name: 🏗️ Core Implementation
description: Create a report to help us improve
title: "🏗️ [Core Feature]: "
labels: ["core"]
body:
- type: textarea
id: feature
attributes:
label: What is the key feature we're aiming to implement?
validations:
required: true
- type: checkboxes
id: terms
attributes:
label: Contribution Guidelines
description: By submitting this issue, you agree to follow our [Contribution Guidelines](https://github.com/OpenZeppelin/substrate-runtime-template/blob/main/CONTRIBUTING.md)
options:
- label: I agree to follow this project's Contribution Guidelines
required: true
@@ -1,15 +1,16 @@
name: "cargo tests"
name: "evm template cargo tests"
on:
push:
branches:
- main
- plain-cumulus-template
paths-ignore:
- "generic-template/**"
- "**.md"
- "**.adoc"
pull_request:
paths-ignore:
- "generic-template/**"
- "**.md"
- "**.adoc"
workflow_dispatch:
@@ -30,7 +31,7 @@ env:
RUSTFLAGS: -C strip=symbols -C opt-level=s
jobs:
clippy-fmt-test:
evm-clippy-fmt-test:
strategy:
fail-fast: false
matrix:
@@ -44,6 +45,9 @@ jobs:
os: macos-12
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./evm-template
steps:
- name: git checkout
uses: actions/checkout@v4
@@ -70,7 +74,7 @@ jobs:
- name: Run tests
run: cargo test --release
- name: Check benchmarking compilation
run: cargo check --release --features runtime-benchmarks
+98
View File
@@ -0,0 +1,98 @@
name: "cargo tests"
on:
push:
branches:
- main
paths-ignore:
- "evm-template/**"
- "**.md"
- "**.adoc"
pull_request:
paths-ignore:
- "evm-template/**"
- "**.md"
- "**.adoc"
workflow_dispatch:
inputs:
test-macos:
description: "run tests on macOS"
required: true
default: false
type: boolean
env:
# Not needed in CI, should make things a bit faster
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
# Remove unnecessary WASM build artifacts
WASM_BUILD_CLEAN_TARGET: 1
# stripping symbols and optimizing for binary size
RUSTFLAGS: -C strip=symbols -C opt-level=s
jobs:
clippy-fmt-test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- macos-12
run-all:
- ${{ inputs.test-macos == true || github.ref == 'refs/heads/main' }}
exclude: # exclude macos-12 when the condition is false
- run-all: false
os: macos-12
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./generic-template
steps:
- name: git checkout
uses: actions/checkout@v4
- name: cd to `generic` template
run: cd generic-template
- name: Install Protoc
uses: arduino/setup-protoc@9b1ee5b22b0a3f1feb8c2ff99b32c89b3c3191e9 # v2.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install toml-sort
run: cargo install --git https://github.com/4meta5/toml_sort
- name: Add file permissions for toml-sort
run: chmod +x ./scripts/toml-sort.sh
- name: Add file permissions for check-toml-sorted
run: chmod +x ./scripts/check-toml-sorted.sh
- name: Check Cargo.toml files are formatted using toml_sort
run: ./scripts/check-toml-sorted.sh
- name: Check format
run: cargo fmt --all -- --check
- name: Run tests
run: cargo test --release
- name: Check benchmarking compilation
run: cargo check --release --features runtime-benchmarks
- name: Run tests with async backing
run: cargo test --release --features="async-backing"
- name: Check clippy
run: cargo clippy --release --locked --all-targets -- -D warnings
- name: Check Documentation
run: cargo doc --release --locked --all --no-deps
env:
RUSTDOCFLAGS: "-D rustdoc::broken-intra-doc-links -D rustdoc::private_intra_doc_links"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
+4 -8
View File
@@ -1,23 +1,19 @@
# OpenZeppelin Runtime Template for Substrate
Substrate has a steep learning curve. In order to make it easier for newcomers to get started, OpenZeppelin is providing a generic template that can be used to quickly bootstrap a Substrate project.
Substrate has a steep learning curve. In order to make it easier for newcomers to get started, OpenZeppelin is providing runtime templates that can be used to quickly bootstrap a Substrate project.
Along with the templates, OpenZeppelin also provides a documentation website that explains how to add or deduct all the common pallets to your Runtime project (including this template).
### Usage
to be filled
Along with the templates, OpenZeppelin also provides a documentation website that explains the templates and the niche details.
## Security
Past audits can be found in [`/audits`](/audits/) directory.
Past audits can be found in `/audits` directory in the respective template.
Refer to [SECURITY.md](SECURITY.md) for more details.
## License
OpenZeppelin Runtime Template for Substrate is released under the [GNU v3 License](LICENSE).
OpenZeppelin Runtime Templates are released under the [GNU v3 License](LICENSE).
+8
View File
@@ -0,0 +1,8 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+14700
View File
File diff suppressed because it is too large Load Diff
+152
View File
@@ -0,0 +1,152 @@
[workspace]
members = [ "node", "runtime", "template-fuzzer" ]
resolver = "2"
[workspace.package]
authors = [ "OpenZeppelin" ]
description = "Runtime template(s) for Polkadot Para{chains, cores}"
edition = "2021"
license = "GPL-3.0-only"
repository = "https://github.com/OpenZeppelin/polkadot-runtime-template"
[workspace.dependencies]
clap = { version = "4.4.6", features = [ "derive" ] }
color-print = "0.3.4"
futures = "0.3.28"
hex-literal = "0.4.1"
jsonrpsee = { version = "0.20.3", features = [ "server" ] }
log = { version = "0.4.20", default-features = false }
parity-scale-codec = { version = "3.0.0", default-features = false, features = [
"derive",
"max-encoded-len",
] }
scale-info = { version = "2.10.0", default-features = false }
serde = { version = "1.0.188", default-features = false }
serde_json = "1.0.108"
smallvec = "1.11.0"
# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-executive = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-referenda = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-session = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-whitelist = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-chain-spec = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-network = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-service = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-sysinfo = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-telemetry = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-tracing = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.7.0" }
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-offchain = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-session = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.7.0" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.7.0" }
# Polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", features = [
"rococo-native",
], tag = "polkadot-v1.7.0" }
polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
# Cumulus
assets-common = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-client-cli = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-client-collator = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-client-consensus-common = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-client-consensus-proposer = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-client-service = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-primitives-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-relay-chain-interface = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
parachain-info = { package = "staging-parachain-info", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.7.0" }
# Frontier
fp-account = { git = "https://github.com/OpenZeppelin/frontier", branch = "polkadot-v1.7.0", default-features = false, features = [ "serde" ] }
# Fuzzer
substrate-runtime-fuzzer = { git = "https://github.com/srlabs/substrate-runtime-fuzzer.git", default-features = false }
ziggy = { version = "0.8", default-features = false }
[workspace.lints.clippy]
large_enum_variant = "allow"
too_many_arguments = "allow"
type_complexity = "allow"
[profile.production]
codegen-units = 1
inherits = "release"
lto = true
[profile.release]
opt-level = 3
panic = "unwind"
+96
View File
@@ -0,0 +1,96 @@
[package]
name = "parachain-template-node"
authors = { workspace = true }
build = "build.rs"
description = "Node compatible with parachain runtime template."
edition = { workspace = true }
license = { workspace = true }
publish = false
repository = { workspace = true }
version = "0.1.2"
[dependencies]
clap = { workspace = true }
futures = { workspace = true }
jsonrpsee = { workspace = true, features = [ "server" ] }
log = { workspace = true }
parity-scale-codec = { workspace = true }
serde = { workspace = true, features = [ "derive" ] }
serde_json = { workspace = true }
# Local
parachain-template-runtime = { path = "../runtime" }
# Substrate
frame-benchmarking = { workspace = true }
frame-benchmarking-cli = { workspace = true }
pallet-transaction-payment-rpc = { workspace = true }
sc-basic-authorship = { workspace = true }
sc-chain-spec = { workspace = true }
sc-cli = { workspace = true }
sc-client-api = { workspace = true }
sc-consensus = { workspace = true }
sc-executor = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-offchain = { workspace = true }
sc-rpc = { workspace = true }
sc-service = { workspace = true }
sc-sysinfo = { workspace = true }
sc-telemetry = { workspace = true }
sc-tracing = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-keystore = { workspace = true }
sp-runtime = { workspace = true }
sp-timestamp = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }
# Polkadot
polkadot-cli = { workspace = true, features = [ "rococo-native" ] }
polkadot-primitives = { workspace = true }
xcm = { workspace = true }
# Cumulus
color-print = { workspace = true }
cumulus-client-cli = { workspace = true }
cumulus-client-collator = { workspace = true }
cumulus-client-consensus-aura = { workspace = true }
cumulus-client-consensus-common = { workspace = true }
cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }
[build-dependencies]
substrate-build-script-utils = { workspace = true }
[features]
default = []
async-backing = []
experimental = []
runtime-benchmarks = [
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"parachain-template-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"parachain-template-runtime/try-runtime",
"polkadot-cli/try-runtime",
"sp-runtime/try-runtime",
]
[lints]
workspace = true
+202
View File
@@ -0,0 +1,202 @@
use cumulus_primitives_core::ParaId;
use parachain_template_runtime::{
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AuraId, Signature,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{ecdsa, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec =
sc_service::GenericChainSpec<parachain_template_runtime::RuntimeGenesisConfig, Extensions>;
/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}
/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
/// The relay chain of the Parachain.
pub relay_chain: String,
/// The id of the Parachain.
pub para_id: u32,
}
impl Extensions {
/// Try to get the extension from the given `ChainSpec`.
pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
sc_chain_spec::get_extension(chain_spec.extensions())
}
}
type AccountPublic = <Signature as Verify>::Signer;
/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain
/// in tuple format.
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}
/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we
/// have just one key).
pub fn template_session_keys(keys: AuraId) -> parachain_template_runtime::SessionKeys {
parachain_template_runtime::SessionKeys { aura: keys }
}
pub fn development_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
ChainSpec::builder(
parachain_template_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
para_id: 1000,
},
)
.with_name("Development")
.with_id("dev")
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis(
// initial collators.
vec![
(
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(get_account_id_from_seed::<ecdsa::Public>("Bob"), get_collator_keys_from_seed("Bob")),
],
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Charlie"),
get_account_id_from_seed::<ecdsa::Public>("Dave"),
get_account_id_from_seed::<ecdsa::Public>("Eve"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
get_account_id_from_seed::<ecdsa::Public>("Charlie//stash"),
get_account_id_from_seed::<ecdsa::Public>("Dave//stash"),
get_account_id_from_seed::<ecdsa::Public>("Eve//stash"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<ecdsa::Public>("Alice"),
1000.into(),
))
.build()
}
pub fn local_testnet_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
#[allow(deprecated)]
ChainSpec::builder(
parachain_template_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
para_id: 1000,
},
)
.with_name("Local Testnet")
.with_id("local_testnet")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(testnet_genesis(
// initial collators.
vec![
(
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(get_account_id_from_seed::<ecdsa::Public>("Bob"), get_collator_keys_from_seed("Bob")),
],
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Charlie"),
get_account_id_from_seed::<ecdsa::Public>("Dave"),
get_account_id_from_seed::<ecdsa::Public>("Eve"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
get_account_id_from_seed::<ecdsa::Public>("Charlie//stash"),
get_account_id_from_seed::<ecdsa::Public>("Dave//stash"),
get_account_id_from_seed::<ecdsa::Public>("Eve//stash"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<ecdsa::Public>("Alice"),
1000.into(),
))
.with_protocol_id("template-local")
.with_properties(properties)
.build()
}
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root: AccountId,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
},
"parachainInfo": {
"parachainId": id,
},
"collatorSelection": {
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
},
"session": {
"keys": invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc, // account id
acc, // validator id
template_session_keys(aura), // session keys
)
})
.collect::<Vec<_>>(),
},
"treasury": {},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": { "key": Some(root) }
})
}
+388
View File
@@ -0,0 +1,388 @@
use std::net::SocketAddr;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::info;
use parachain_template_runtime::Block;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, SharedParams, SubstrateCli,
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_runtime::traits::AccountIdConversion;
use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::new_partial,
};
fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"template-rococo" => Box::new(chain_spec::local_testnet_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
impl SubstrateCli for Cli {
fn impl_name() -> String {
"Parachain Collator Template".into()
}
fn impl_version() -> String {
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
}
fn description() -> String {
format!(
"Parachain Collator Template\n\nThe command-line arguments provided first will be \
passed to the parachain node, while the arguments provided after -- will be passed \
to the relay chain node.\n\n{} <parachain-args> -- <relay-chain-args>",
Self::executable_name()
)
}
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}
fn support_url() -> String {
"https://github.com/paritytech/polkadot-sdk/issues/new".into()
}
fn copyright_start_year() -> i32 {
2020
}
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
load_spec(id)
}
}
impl SubstrateCli for RelayChainCli {
fn impl_name() -> String {
"Parachain Collator Template".into()
}
fn impl_version() -> String {
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
}
fn description() -> String {
format!(
"Parachain Collator Template\n\nThe command-line arguments provided first will be \
passed to the parachain node, while the arguments provided after -- will be passed \
to the relay chain node.\n\n{} <parachain-args> -- <relay-chain-args>",
Self::executable_name()
)
}
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}
fn support_url() -> String {
"https://github.com/paritytech/polkadot-sdk/issues/new".into()
}
fn copyright_start_year() -> i32 {
2020
}
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}
}
macro_rules! construct_async_run {
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
let runner = $cli.create_runner($cmd)?;
runner.async_run(|$config| {
let $components = new_partial(&$config)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
}}
}
/// Parse command line arguments into service configuration.
pub fn run() -> Result<()> {
let cli = Cli::from_args();
match &cli.subcommand {
Some(Subcommand::BuildSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
},
Some(Subcommand::CheckBlock(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.import_queue))
})
},
Some(Subcommand::ExportBlocks(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, config.database))
})
},
Some(Subcommand::ExportState(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, config.chain_spec))
})
},
Some(Subcommand::ImportBlocks(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.import_queue))
})
},
Some(Subcommand::Revert(cmd)) => {
construct_async_run!(|components, cli, cmd, config| {
Ok(cmd.run(components.client, components.backend, None))
})
},
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()),
);
let polkadot_config = SubstrateCli::create_configuration(
&polkadot_cli,
&polkadot_cli,
config.tokio_handle.clone(),
)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
cmd.run(config, polkadot_config)
})
},
Some(Subcommand::ExportGenesisHead(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
let partials = new_partial(&config)?;
cmd.run(partials.client)
})
},
Some(Subcommand::ExportGenesisWasm(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|_config| {
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
cmd.run(&*spec)
})
},
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
// Switch on the concrete benchmark sub-command-
match cmd {
BenchmarkCmd::Pallet(cmd) =>
if cfg!(feature = "runtime-benchmarks") {
runner.sync_run(|config| cmd.run::<Block, ()>(config))
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into())
},
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
let partials = new_partial(&config)?;
cmd.run(partials.client)
}),
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) =>
Err(sc_cli::Error::Input(
"Compile with --features=runtime-benchmarks \
to enable storage benchmarks."
.into(),
)),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials = new_partial(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
cmd.run(config, partials.client.clone(), db, storage)
}),
BenchmarkCmd::Machine(cmd) =>
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())),
// NOTE: this allows the Client to leniently implement
// new benchmark commands without requiring a companion MR.
#[allow(unreachable_patterns)]
_ => Err("Benchmarking sub-command unsupported".into()),
}
},
Some(Subcommand::TryRuntime) => Err("The `try-runtime` subcommand has been migrated to a standalone CLI (https://github.com/paritytech/try-runtime-cli). It is no longer being maintained here and will be removed entirely some time after January 2024. Please remove this subcommand from your runtime and use the standalone CLI.".into()),
None => {
let runner = cli.create_runner(&cli.run.normalize())?;
let collator_options = cli.run.collator_options();
runner.run_node_until_exit(|config| async move {
let hwbench = (!cli.no_hardware_benchmarks)
.then_some(config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
}))
.flatten();
let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or("Could not find parachain ID in chain-spec.")?;
let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()),
);
let id = ParaId::from(para_id);
let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(
&id,
);
let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
info!("Parachain Account: {parachain_account}");
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });
crate::service::start_parachain_node(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into)
})
},
}
}
impl DefaultConfigurationValues for RelayChainCli {
fn p2p_listen_port() -> u16 {
30334
}
fn rpc_listen_port() -> u16 {
9945
}
fn prometheus_listen_port() -> u16 {
9616
}
}
impl CliConfiguration<Self> for RelayChainCli {
fn shared_params(&self) -> &SharedParams {
self.base.base.shared_params()
}
fn import_params(&self) -> Option<&ImportParams> {
self.base.base.import_params()
}
fn network_params(&self) -> Option<&NetworkParams> {
self.base.base.network_params()
}
fn keystore_params(&self) -> Option<&KeystoreParams> {
self.base.base.keystore_params()
}
fn base_path(&self) -> Result<Option<BasePath>> {
Ok(self.shared_params().base_path()?.or_else(|| self.base_path.clone().map(Into::into)))
}
fn rpc_addr(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {
self.base.base.rpc_addr(default_listen_port)
}
fn prometheus_config(
&self,
default_listen_port: u16,
chain_spec: &Box<dyn ChainSpec>,
) -> Result<Option<PrometheusConfig>> {
self.base.base.prometheus_config(default_listen_port, chain_spec)
}
fn init<F>(
&self,
_support_url: &String,
_impl_version: &String,
_logger_hook: F,
_config: &sc_service::Configuration,
) -> Result<()>
where
F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration),
{
unreachable!("PolkadotCli is never initialized; qed");
}
fn chain_id(&self, is_dev: bool) -> Result<String> {
let chain_id = self.base.base.chain_id(is_dev)?;
Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id })
}
fn role(&self, is_dev: bool) -> Result<sc_service::Role> {
self.base.base.role(is_dev)
}
fn transaction_pool(&self, is_dev: bool) -> Result<sc_service::config::TransactionPoolOptions> {
self.base.base.transaction_pool(is_dev)
}
fn trie_cache_maximum_size(&self) -> Result<Option<usize>> {
self.base.base.trie_cache_maximum_size()
}
fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {
self.base.base.rpc_methods()
}
fn rpc_max_connections(&self) -> Result<u32> {
self.base.base.rpc_max_connections()
}
fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {
self.base.base.rpc_cors(is_dev)
}
fn default_heap_pages(&self) -> Result<Option<u64>> {
self.base.base.default_heap_pages()
}
fn force_authoring(&self) -> Result<bool> {
self.base.base.force_authoring()
}
fn disable_grandpa(&self) -> Result<bool> {
self.base.base.disable_grandpa()
}
fn max_runtime_instances(&self) -> Result<Option<usize>> {
self.base.base.max_runtime_instances()
}
fn announce_block(&self) -> Result<bool> {
self.base.base.announce_block()
}
fn telemetry_endpoints(
&self,
chain_spec: &Box<dyn ChainSpec>,
) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {
self.base.base.telemetry_endpoints(chain_spec)
}
fn node_name(&self) -> Result<String> {
self.base.base.node_name()
}
}
+471
View File
@@ -0,0 +1,471 @@
//! Service and ServiceFactory implementation. Specialized wrapper over
//! substrate service.
// std
use std::{sync::Arc, time::Duration};
use cumulus_client_cli::CollatorOptions;
// Cumulus Imports
use cumulus_client_collator::service::CollatorService;
use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
use cumulus_client_consensus_proposer::Proposer;
use cumulus_client_service::{
build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks,
BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
};
#[cfg(feature = "async-backing")]
use cumulus_primitives_core::relay_chain::ValidationCode;
use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
// Substrate Imports
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
// Local Runtime Types
use parachain_template_runtime::{
opaque::{Block, Hash},
RuntimeApi,
};
use sc_client_api::Backend;
use sc_consensus::ImportQueue;
use sc_executor::{
HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
};
use sc_network::NetworkBlock;
use sc_network_sync::SyncingService;
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_keystore::KeystorePtr;
use substrate_prometheus_endpoint::Registry;
/// Native executor type.
pub struct ParachainNativeExecutor;
impl sc_executor::NativeExecutionDispatch for ParachainNativeExecutor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
parachain_template_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
parachain_template_runtime::native_version()
}
}
type ParachainExecutor = NativeElseWasmExecutor<ParachainNativeExecutor>;
type ParachainClient = TFullClient<Block, RuntimeApi, ParachainExecutor>;
type ParachainBackend = TFullBackend<Block>;
type ParachainBlockImport = TParachainBlockImport<Block, Arc<ParachainClient>, ParachainBackend>;
/// Starts a `ServiceBuilder` for a full service.
///
/// Use this macro if you don't actually need the full service, but just the
/// builder in order to be able to perform chain operations.
pub fn new_partial(
config: &Configuration,
) -> Result<
PartialComponents<
ParachainClient,
ParachainBackend,
(),
sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, ParachainClient>,
(ParachainBlockImport, Option<Telemetry>, Option<TelemetryWorkerHandle>),
>,
sc_service::Error,
> {
let telemetry = config
.telemetry_endpoints
.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;
let heap_pages = config
.default_heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ });
let wasm = WasmExecutor::builder()
.with_execution_method(config.wasm_method)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(config.max_runtime_instances)
.with_runtime_cache_size(config.runtime_cache_size)
.build();
let executor = ParachainExecutor::new_with_wasm_executor(wasm);
let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
let client = Arc::new(client);
let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());
let telemetry = telemetry.map(|(worker, telemetry)| {
task_manager.spawn_handle().spawn("telemetry", None, worker.run());
telemetry
});
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);
let block_import = ParachainBlockImport::new(client.clone(), backend.clone());
let import_queue = build_import_queue(
client.clone(),
block_import.clone(),
config,
telemetry.as_ref().map(|telemetry| telemetry.handle()),
&task_manager,
)?;
Ok(PartialComponents {
backend,
client,
import_queue,
keystore_container,
task_manager,
transaction_pool,
select_chain: (),
other: (block_import, telemetry, telemetry_worker_handle),
})
}
/// Start a node with the given parachain `Configuration` and relay chain
/// `Configuration`.
///
/// This is the actual implementation that is abstract over the executor and the
/// runtime api.
#[sc_tracing::logging::prefix_logs_with("Parachain")]
async fn start_node_impl(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
para_id: ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
let parachain_config = prepare_node_config(parachain_config);
let params = new_partial(&parachain_config)?;
let (block_import, mut telemetry, telemetry_worker_handle) = params.other;
let net_config = sc_network::config::FullNetworkConfiguration::new(&parachain_config.network);
let client = params.client.clone();
let backend = params.backend.clone();
let mut task_manager = params.task_manager;
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
&parachain_config,
telemetry_worker_handle,
&mut task_manager,
collator_options.clone(),
hwbench.clone(),
)
.await
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;
let validator = parachain_config.role.is_authority();
let prometheus_registry = parachain_config.prometheus_registry().cloned();
let transaction_pool = params.transaction_pool.clone();
let import_queue_service = params.import_queue.service();
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
build_network(BuildNetworkParams {
parachain_config: &parachain_config,
net_config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
para_id,
spawn_handle: task_manager.spawn_handle(),
relay_chain_interface: relay_chain_interface.clone(),
import_queue: params.import_queue,
sybil_resistance_level: CollatorSybilResistance::Resistant, // because of Aura
})
.await?;
if parachain_config.offchain_worker.enabled {
use futures::FutureExt;
task_manager.spawn_handle().spawn(
"offchain-workers-runner",
"offchain-work",
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(),
keystore: Some(params.keystore_container.keystore()),
offchain_db: backend.offchain_storage(),
transaction_pool: Some(OffchainTransactionPoolFactory::new(
transaction_pool.clone(),
)),
network_provider: network.clone(),
is_validator: parachain_config.role.is_authority(),
enable_http_requests: false,
custom_extensions: move |_| vec![],
})
.run(client.clone(), task_manager.spawn_handle())
.boxed(),
);
}
let rpc_builder = {
let client = client.clone();
let transaction_pool = transaction_pool.clone();
Box::new(move |deny_unsafe, _| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
deny_unsafe,
};
crate::rpc::create_full(deps).map_err(Into::into)
})
};
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_builder,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
config: parachain_config,
keystore: params.keystore_container.keystore(),
#[cfg(not(feature = "async-backing"))]
backend,
#[cfg(feature = "async-backing")]
backend: backend.clone(),
network: network.clone(),
sync_service: sync_service.clone(),
system_rpc_tx,
tx_handler_controller,
telemetry: telemetry.as_mut(),
})?;
if let Some(hwbench) = hwbench {
sc_sysinfo::print_hwbench(&hwbench);
// Here you can check whether the hardware meets your chains' requirements.
// Putting a link in there and swapping out the requirements for your
// own are probably a good idea. The requirements for a para-chain are
// dictated by its relay-chain.
match SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench) {
Err(err) if validator => {
log::warn!(
"⚠️ The hardware does not meet the minimal requirements {} for role \
'Authority'.",
err
);
}
_ => {}
}
if let Some(ref mut telemetry) = telemetry {
let telemetry_handle = telemetry.handle();
task_manager.spawn_handle().spawn(
"telemetry_hwbench",
None,
sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
);
}
}
let announce_block = {
let sync_service = sync_service.clone();
Arc::new(move |hash, data| sync_service.announce_block(hash, data))
};
let relay_chain_slot_duration = Duration::from_secs(6);
let overseer_handle = relay_chain_interface
.overseer_handle()
.map_err(|e| sc_service::Error::Application(Box::new(e)))?;
start_relay_chain_tasks(StartRelayChainTasksParams {
client: client.clone(),
announce_block: announce_block.clone(),
para_id,
relay_chain_interface: relay_chain_interface.clone(),
task_manager: &mut task_manager,
da_recovery_profile: if validator {
DARecoveryProfile::Collator
} else {
DARecoveryProfile::FullNode
},
import_queue: import_queue_service,
relay_chain_slot_duration,
recovery_handle: Box::new(overseer_handle.clone()),
sync_service: sync_service.clone(),
})?;
if validator {
start_consensus(
client.clone(),
#[cfg(feature = "async-backing")]
backend.clone(),
block_import,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
&task_manager,
relay_chain_interface.clone(),
transaction_pool,
sync_service.clone(),
params.keystore_container.keystore(),
relay_chain_slot_duration,
para_id,
collator_key.expect("Command line arguments do not allow this. qed"),
overseer_handle,
announce_block,
)?;
}
start_network.start_network();
Ok((task_manager, client))
}
/// Build the import queue for the parachain runtime.
fn build_import_queue(
client: Arc<ParachainClient>,
block_import: ParachainBlockImport,
config: &Configuration,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error> {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
Ok(cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::<
sp_consensus_aura::sr25519::AuthorityPair,
_,
_,
_,
_,
>(
client,
block_import,
move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Ok(timestamp)
},
slot_duration,
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
telemetry,
))
}
fn start_consensus(
client: Arc<ParachainClient>,
#[cfg(feature = "async-backing")] backend: Arc<ParachainBackend>,
block_import: ParachainBlockImport,
prometheus_registry: Option<&Registry>,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
relay_chain_interface: Arc<dyn RelayChainInterface>,
transaction_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient>>,
sync_oracle: Arc<SyncingService<Block>>,
keystore: KeystorePtr,
relay_chain_slot_duration: Duration,
para_id: ParaId,
collator_key: CollatorPair,
overseer_handle: OverseerHandle,
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
) -> Result<(), sc_service::Error> {
#[cfg(not(feature = "async-backing"))]
use cumulus_client_consensus_aura::collators::basic::{self as basic_aura, Params};
#[cfg(feature = "async-backing")]
use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params};
// NOTE: because we use Aura here explicitly, we can use
// `CollatorSybilResistance::Resistant` when starting the network.
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
);
let proposer = Proposer::new(proposer_factory);
let collator_service = CollatorService::new(
client.clone(),
Arc::new(task_manager.spawn_handle()),
announce_block,
client.clone(),
);
let params = Params {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
#[cfg(not(feature = "async-backing"))]
para_client: client,
#[cfg(feature = "async-backing")]
para_client: client.clone(),
#[cfg(feature = "async-backing")]
para_backend: backend,
relay_client: relay_chain_interface,
#[cfg(feature = "async-backing")]
code_hash_provider: move |block_hash| {
client.code_at(block_hash).ok().map(ValidationCode).map(|c| c.hash())
},
sync_oracle,
keystore,
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
#[cfg(not(feature = "async-backing"))]
authoring_duration: Duration::from_millis(500),
#[cfg(feature = "async-backing")]
authoring_duration: Duration::from_millis(1500),
#[cfg(not(feature = "async-backing"))]
collation_request_receiver: None,
#[cfg(feature = "async-backing")]
reinitialize: false,
};
#[cfg(not(feature = "async-backing"))]
let fut =
basic_aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _>(
params,
);
#[cfg(feature = "async-backing")]
let fut =
aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _, _, _>(
params,
);
task_manager.spawn_essential_handle().spawn("aura", None, fut);
Ok(())
}
/// Start a parachain node.
pub async fn start_parachain_node(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
para_id: ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
start_node_impl(parachain_config, polkadot_config, collator_options, para_id, hwbench).await
}
+39
View File
@@ -0,0 +1,39 @@
{
"relaychain": {
"bin": "../../polkadot/target/release/polkadot",
"chain": "rococo-local",
"nodes": [
{
"name": "alice",
"wsPort": 9944,
"port": 30444
},
{
"name": "bob",
"wsPort": 9955,
"port": 30555
}
]
},
"parachains": [
{
"bin": "../target/release/polkadot-parachain",
"id": "200",
"balance": "1000000000000000000000",
"nodes": [
{
"wsPort": 9988,
"name": "alice",
"port": 31200,
"flags": [
"--force-authoring",
"--",
"--execution=wasm"
]
}
]
}
],
"types": {
}
}
+229
View File
@@ -0,0 +1,229 @@
[package]
name = "parachain-template-runtime"
authors = { workspace = true }
description = "A generic parachain runtime template"
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
version = "0.1.2"
[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]
[dependencies]
hex-literal = { workspace = true, optional = true }
log = { workspace = true }
parity-scale-codec = { workspace = true, features = [ "derive" ] }
scale-info = { workspace = true, features = [ "derive" ] }
smallvec = { workspace = true }
# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
frame-system-rpc-runtime-api = { workspace = true }
frame-try-runtime = { workspace = true, optional = true }
pallet-assets = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true, features = [ "insecure_zero_ed" ] }
pallet-conviction-voting = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-treasury = { workspace = true }
pallet-utility = { workspace = true }
pallet-whitelist = { workspace = true }
sp-api = { workspace = true }
sp-arithmetic = { workspace = true }
sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-genesis-builder = { workspace = true }
sp-inherents = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
sp-std = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
# Polkadot
pallet-xcm = { workspace = true }
polkadot-parachain-primitives = { workspace = true }
polkadot-runtime-common = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
# Cumulus
assets-common = { workspace = true }
cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true, features = [
"parameterized-consensus-hook",
] }
cumulus-pallet-session-benchmarking = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
cumulus-primitives-aura = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-utility = { workspace = true }
pallet-collator-selection = { workspace = true }
parachain-info = { workspace = true }
parachains-common = { workspace = true }
# Frontier
fp-account = { workspace = true }
[dev-dependencies]
sp-io = { workspace = true }
[build-dependencies]
substrate-wasm-builder = { workspace = true }
[features]
default = [ "std" ]
std = [
"assets-common/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-session-benchmarking/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
"fp-account/std",
"frame-benchmarking?/std",
"frame-executive/std",
"frame-support/std",
"frame-system-benchmarking?/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-conviction-voting/std",
"pallet-message-queue/std",
"pallet-multisig/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-referenda/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-utility/std",
"pallet-whitelist/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
"parity-scale-codec/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"scale-info/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
]
async-backing = []
runtime-benchmarks = [
"assets-common/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"cumulus-primitives-utility/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-multisig/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-referenda/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-whitelist/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
"sp-runtime/try-runtime",
]
experimental = [ "pallet-aura/experimental" ]
+15
View File
@@ -0,0 +1,15 @@
pub mod currency {
use crate::Balance;
pub const MICROCENTS: Balance = 1_000_000;
pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;
pub const GRAND: Balance = 1_000 * DOLLARS;
pub const EXISTENTIAL_DEPOSIT: Balance = 0;
pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
}
}
File diff suppressed because it is too large Load Diff
+27
View File
@@ -0,0 +1,27 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Expose the auto generated weight files.
pub mod block_weights;
pub mod extrinsic_weights;
pub mod paritydb_weights;
pub mod rocksdb_weights;
pub use block_weights::constants::BlockExecutionWeight;
pub use extrinsic_weights::constants::ExtrinsicBaseWeight;
pub use rocksdb_weights::constants::RocksDbWeight;
+244
View File
@@ -0,0 +1,244 @@
use frame_support::{
parameter_types,
traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess},
weights::Weight,
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain_primitives::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, NativeAsset,
NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::XcmExecutor;
use super::{
AccountId, AllPalletsWithSystem, Assets, Balance, Balances, ParachainInfo, ParachainSystem,
PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
};
parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = None;
pub PlaceholderAccount: AccountId = PolkadotXcm::check_account();
pub AssetsPalletLocation: Location =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}
/// `AssetId/Balancer` converter for `TrustBackedAssets`
pub type TrustBackedAssetsConvertedConcreteId =
assets_common::TrustBackedAssetsConvertedConcreteId<AssetsPalletLocation, Balance>;
/// Type for specifying how a `Location` can be converted into an
/// `AccountId`. This is used when determining ownership of accounts for asset
/// transacting and when attempting to use XCM `Transact` in order to determine
/// the dispatch Origin.
pub type LocationToAccountId = (
// The parent (Relay-chain) origin converts to the parent `AccountId`.
ParentIsPreset<AccountId>,
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
SiblingParachainConvertsVia<Sibling, AccountId>,
// If we receive a Location of type AccountKey20, just generate a native account
AccountKey20Aliases<RelayNetwork, AccountId>,
);
/// Means for transacting assets on this chain.
pub type LocalAssetTransactor = FungibleAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<RelayLocation>,
// Do a simple punn to convert an AccountId20 Location into a native chain account ID:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We don't track any teleports.
(),
>;
/// Means for transacting assets besides the native currency on this chain.
pub type LocalFungiblesTransactor = FungiblesAdapter<
// Use this fungibles implementation:
Assets,
// Use this currency when it is a fungible asset matching the given location or name:
TrustBackedAssetsConvertedConcreteId,
// Convert an XCM MultiLocation into a local account id:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We don't track any teleports of `Assets`.
NoChecking,
// We don't track any teleports of `Assets`, but a placeholder account is provided due to trait
// bounds.
PlaceholderAccount,
>;
/// Means for transacting assets on this chain.
pub type AssetTransactors = (LocalAssetTransactor, LocalFungiblesTransactor);
/// This is the type we use to convert an (incoming) XCM origin into a local
/// `Origin` instance, ready for dispatching a transaction with Xcm's
/// `Transact`. There is an `OriginKind` which can biases the kind of local
/// `Origin` it will become.
pub type XcmOriginToTransactDispatchOrigin = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
// Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when
// recognized.
RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
// recognized.
SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
// Xcm Origins defined by a Multilocation of type AccountKey20 can be converted to a 20 byte-
// account local origin
SignedAccountKey20AsNative<RelayNetwork, RuntimeOrigin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<RuntimeOrigin>,
);
parameter_types! {
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub const UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
}
pub struct ParentOrParentsExecutivePlurality;
impl Contains<Location> for ParentOrParentsExecutivePlurality {
fn contains(location: &Location) -> bool {
matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
}
}
pub type Barrier = TrailingSetTopicAsId<
DenyThenTry<
DenyReserveTransferToRelayChain,
(
TakeWeightCredit,
WithComputedOrigin<
(
AllowTopLevelPaidExecutionFrom<Everything>,
AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// ^^^ Parent and its exec plurality get free execution
),
UniversalLocation,
ConstU32<8>,
>,
),
>,
>;
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Aliasers = Nothing;
type AssetClaims = PolkadotXcm;
type AssetExchanger = ();
type AssetLocker = ();
// How to withdraw and deposit an asset.
type AssetTransactor = AssetTransactors;
type AssetTrap = PolkadotXcm;
type Barrier = Barrier;
type CallDispatcher = RuntimeCall;
type FeeManager = ();
type IsReserve = NativeAsset;
type IsTeleporter = ();
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type MessageExporter = ();
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type PalletInstancesInfo = AllPalletsWithSystem;
type ResponseHandler = PolkadotXcm;
type RuntimeCall = RuntimeCall;
type SafeCallFilter = Everything;
type SubscriptionService = PolkadotXcm;
type Trader = UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ()>;
type TransactionalProcessor = FrameTransactionalProcessor;
type UniversalAliases = Nothing;
// Teleporting is disabled.
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmSender = XcmRouter;
}
use frame_support::{pallet_prelude::Get, traits::OriginTrait};
use sp_runtime::traits::TryConvert;
// Convert a local Origin (i.e., a signed 20 byte account Origin) to a Multilocation
pub struct SignedToAccountId20<Origin, AccountId, Network>(
sp_std::marker::PhantomData<(Origin, AccountId, Network)>,
);
impl<Origin: OriginTrait + Clone, AccountId: Into<[u8; 20]>, Network: Get<Option<NetworkId>>>
TryConvert<Origin, Location> for SignedToAccountId20<Origin, AccountId, Network>
where
Origin::PalletsOrigin: From<frame_system::RawOrigin<AccountId>>
+ TryInto<frame_system::RawOrigin<AccountId>, Error = Origin::PalletsOrigin>,
{
fn try_convert(o: Origin) -> Result<Location, Origin> {
o.try_with_caller(|caller| match caller.try_into() {
Ok(frame_system::RawOrigin::Signed(who)) =>
Ok(AccountKey20 { key: who.into(), network: Network::get() }.into()),
Ok(other) => Err(other.into()),
Err(other) => Err(other),
})
}
}
// Converts a Signed Local Origin into a Location
pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, RelayNetwork>;
/// The means for routing XCM messages which are not for local execution into
/// the right message queues.
pub type XcmRouter = WithUniqueTopic<(
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, (), ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
)>;
parameter_types! {
pub const MaxLockers: u32 = 8;
pub const MaxRemoteLockConsumers: u32 = 0;
}
impl pallet_xcm::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
// ^ Override for AdvertisedXcmVersion default
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type MaxLockers = MaxLockers;
type MaxRemoteLockConsumers = MaxLockers;
type RemoteLockConsumerIdentifier = ();
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type WeightInfo = pallet_xcm::TestWeightInfo;
type XcmExecuteFilter = Nothing;
// ^ Disable dispatchable execute on the XCM pallet.
// Needs to be `Everything` for local testing.
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmReserveTransferFilter = Nothing;
type XcmRouter = XcmRouter;
type XcmTeleportFilter = Everything;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
}
impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
@@ -0,0 +1,217 @@
mod constant_tests {
use parachain_template_runtime::constants::currency::*;
#[test]
fn test_constants() {
assert_eq!(MICROCENTS, 1_000_000);
assert_eq!(MILLICENTS, 1_000_000_000);
assert_eq!(CENTS, 1_000 * MILLICENTS);
assert_eq!(DOLLARS, 100 * CENTS);
assert_eq!(EXISTENTIAL_DEPOSIT, 0);
// Ensure deposit function behavior remains constant
assert_eq!(deposit(2, 3), 2 * 15 * CENTS + 3 * 6 * CENTS);
}
}
mod runtime_tests {
use frame_support::{pallet_prelude::Weight, traits::TypedGet, PalletId};
use parachain_template_runtime::{constants::currency::*, *};
use xcm::latest::prelude::BodyId;
#[test]
fn weight_to_fee_constants() {
assert_eq!(P_FACTOR, 10);
assert_eq!(Q_FACTOR, 100);
assert_eq!(POLY_DEGREE, 1);
}
#[test]
fn frame_system_constants() {
#[cfg(not(feature = "async-backing"))]
assert_eq!(
MAXIMUM_BLOCK_WEIGHT,
Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64
)
);
#[cfg(feature = "async-backing")]
assert_eq!(
MAXIMUM_BLOCK_WEIGHT,
Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64
)
);
assert_eq!(AVERAGE_ON_INITIALIZE_RATIO, Perbill::from_percent(5));
assert_eq!(NORMAL_DISPATCH_RATIO, Perbill::from_percent(75));
#[cfg(not(feature = "async-backing"))]
assert_eq!(UNINCLUDED_SEGMENT_CAPACITY, 1);
#[cfg(feature = "async-backing")]
assert_eq!(UNINCLUDED_SEGMENT_CAPACITY, 3);
assert_eq!(BLOCK_PROCESSING_VELOCITY, 1);
assert_eq!(RELAY_CHAIN_SLOT_DURATION_MILLIS, 6000);
#[cfg(not(feature = "async-backing"))]
assert_eq!(MILLISECS_PER_BLOCK, 12000);
#[cfg(feature = "async-backing")]
assert_eq!(MILLISECS_PER_BLOCK, 6000);
assert_eq!(SLOT_DURATION, MILLISECS_PER_BLOCK);
assert_eq!(MINUTES, 60_000 / (MILLISECS_PER_BLOCK as BlockNumber));
assert_eq!(HOURS, MINUTES * 60);
assert_eq!(DAYS, HOURS * 24);
assert_eq!(MAX_BLOCK_LENGTH, 5 * 1024 * 1024);
assert_eq!(SS58Prefix::get(), 42);
assert_eq!(<Runtime as frame_system::Config>::MaxConsumers::get(), 16);
}
#[test]
fn proxy_constants() {
assert_eq!(MaxProxies::get(), 32);
assert_eq!(MaxPending::get(), 32);
assert_eq!(ProxyDepositBase::get(), deposit(1, 40));
assert_eq!(AnnouncementDepositBase::get(), deposit(1, 48));
assert_eq!(ProxyDepositFactor::get(), deposit(0, 33));
assert_eq!(AnnouncementDepositFactor::get(), deposit(0, 66));
}
#[test]
fn balances_constants() {
assert_eq!(MaxFreezes::get(), 0);
assert_eq!(MaxLocks::get(), 50);
assert_eq!(MaxReserves::get(), 50);
}
#[test]
fn assets_constants() {
assert_eq!(AssetDeposit::get(), 10 * CENTS);
assert_eq!(AssetAccountDeposit::get(), deposit(1, 16));
assert_eq!(ApprovalDeposit::get(), MILLICENTS);
assert_eq!(StringLimit::get(), 50);
assert_eq!(MetadataDepositBase::get(), deposit(1, 68));
assert_eq!(MetadataDepositPerByte::get(), deposit(0, 1));
assert_eq!(RemoveItemsLimit::get(), 1000);
}
#[test]
fn transaction_payment_constants() {
assert_eq!(TransactionByteFee::get(), 10 * MICROCENTS);
assert_eq!(OperationalFeeMultiplier::get(), 5);
}
#[test]
fn cumulus_pallet_parachain_system_constants() {
assert_eq!(ReservedXcmpWeight::get(), MAXIMUM_BLOCK_WEIGHT.saturating_div(4));
assert_eq!(ReservedDmpWeight::get(), MAXIMUM_BLOCK_WEIGHT.saturating_div(4));
}
#[test]
fn message_queue_constants() {
assert_eq!(HeapSize::get(), 64 * 1024);
assert_eq!(MaxStale::get(), 8);
}
#[test]
fn cumulus_pallet_xcmp_queue_constants() {
assert_eq!(MaxInboundSuspended::get(), 1000);
}
#[test]
fn multisig_constants() {
assert_eq!(DepositBase::get(), deposit(1, 88));
assert_eq!(DepositFactor::get(), deposit(0, 32));
assert_eq!(MaxSignatories::get(), 100);
}
#[test]
fn session_constants() {
assert_eq!(Period::get(), 6 * HOURS);
assert_eq!(Offset::get(), 0);
}
#[test]
#[allow(clippy::assertions_on_constants)]
fn aura_constants() {
#[cfg(not(feature = "async-backing"))]
assert!(!AllowMultipleBlocksPerSlot::get());
#[cfg(feature = "async-backing")]
assert!(AllowMultipleBlocksPerSlot::get());
assert_eq!(MaxAuthorities::get(), 100_000);
}
#[test]
fn collator_selection_constants() {
let pallet_id_to_string = |id: PalletId| -> String {
core::str::from_utf8(&id.0).unwrap_or_default().to_string()
};
assert_eq!(pallet_id_to_string(PotId::get()), pallet_id_to_string(PalletId(*b"PotStake")));
assert_eq!(SessionLength::get(), 6 * HOURS);
assert_eq!(StakingAdminBodyId::get(), BodyId::Defense);
assert_eq!(MaxCandidates::get(), 100);
assert_eq!(MaxInvulnerables::get(), 20);
assert_eq!(MinEligibleCollators::get(), 4);
}
}
mod xcm_tests {
use frame_support::weights::Weight;
use parachain_template_runtime::xcm_config::*;
#[test]
fn xcm_executor_constants() {
assert_eq!(UnitWeightCost::get(), Weight::from_parts(1_000_000_000, 64 * 1024));
assert_eq!(MaxInstructions::get(), 100);
assert_eq!(MaxAssetsIntoHolding::get(), 64);
}
#[test]
fn pallet_xcm_constants() {
assert_eq!(MaxLockers::get(), 8);
assert_eq!(MaxRemoteLockConsumers::get(), 0);
assert_eq!(<parachain_template_runtime::Runtime as pallet_xcm::Config>::VERSION_DISCOVERY_QUEUE_SIZE, 100);
}
}
+288
View File
@@ -0,0 +1,288 @@
use std::time::{Duration, Instant};
use cumulus_primitives_core::relay_chain::Slot;
use frame_support::{
dispatch::GetDispatchInfo,
pallet_prelude::Encode,
traits::{IntegrityTest, TryState, TryStateSelect},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use parachain_template_runtime::{
AccountId, AllPalletsWithSystem, Balance, Balances, BlockNumber, Executive, Runtime,
RuntimeCall, RuntimeOrigin, SudoConfig, UncheckedExtrinsic, SLOT_DURATION,
};
use sp_consensus_aura::AURA_ENGINE_ID;
use sp_runtime::{
traits::{Dispatchable, Header},
Digest, DigestItem, Storage,
};
use substrate_runtime_fuzzer::{Data, INITIAL_TIMESTAMP, MAX_TIME_FOR_BLOCK};
pub type Externalities = sp_state_machine::BasicExternalities;
fn main() {
let endowed_accounts: Vec<AccountId> = (0..5).map(|i| [i; 32].into()).collect();
let genesis_storage: Storage = {
use parachain_template_runtime::{
BalancesConfig, CollatorSelectionConfig, RuntimeGenesisConfig, SessionConfig,
SessionKeys,
};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_runtime::{app_crypto::ByteArray, BuildStorage};
let initial_authorities: Vec<(AccountId, AuraId)> =
vec![([0; 32].into(), AuraId::from_slice(&[0; 32]).unwrap())];
let root: AccountId = [0; 32].into();
RuntimeGenesisConfig {
system: Default::default(),
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
aura: Default::default(),
session: SessionConfig {
keys: initial_authorities
.iter()
.map(|x| (x.0, x.0, SessionKeys { aura: x.1.clone() }))
.collect::<Vec<_>>(),
},
collator_selection: CollatorSelectionConfig {
invulnerables: initial_authorities.iter().map(|x| x.0).collect(),
candidacy_bond: 1 << 57,
desired_candidates: 1,
},
aura_ext: Default::default(),
parachain_info: Default::default(),
parachain_system: Default::default(),
polkadot_xcm: Default::default(),
assets: Default::default(),
transaction_payment: Default::default(),
sudo: SudoConfig { key: Some(root) },
treasury: Default::default(),
}
.build_storage()
.unwrap()
};
ziggy::fuzz!(|data: &[u8]| {
let mut iteratable = Data::from_data(data);
// Max weight for a block.
let max_weight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND * 2, 0);
let extrinsics: Vec<(Option<u32>, usize, RuntimeCall)> =
iteratable.extract_extrinsics::<RuntimeCall>();
if extrinsics.is_empty() {
return;
}
// `externalities` represents the state of our mock chain.
let mut externalities = Externalities::new(genesis_storage.clone());
let mut current_block: u32 = 1;
let mut current_weight: Weight = Weight::zero();
// let mut already_seen = 0; // This must be uncommented if you want to print events
let mut elapsed: Duration = Duration::ZERO;
let start_block = |block: u32, lapse: u32| {
#[cfg(not(fuzzing))]
println!("\ninitializing block {}", block + lapse);
let next_block = block + lapse;
let current_timestamp = INITIAL_TIMESTAMP + u64::from(next_block) * SLOT_DURATION;
let pre_digest = match current_timestamp {
INITIAL_TIMESTAMP => Default::default(),
_ => Digest {
logs: vec![DigestItem::PreRuntime(
AURA_ENGINE_ID,
Slot::from(current_timestamp / SLOT_DURATION).encode(),
)],
},
};
let prev_header = match next_block {
1 => None,
_ => Some(Executive::finalize_block()),
};
let parent_header = &Header::new(
next_block + 1,
Default::default(),
Default::default(),
prev_header.clone().map(|x| x.hash()).unwrap_or_default(),
pre_digest,
);
Executive::initialize_block(parent_header);
// We apply the timestamp extrinsic for the current block.
Executive::apply_extrinsic(UncheckedExtrinsic::new_unsigned(RuntimeCall::Timestamp(
pallet_timestamp::Call::set { now: current_timestamp },
)))
.unwrap()
.unwrap();
let parachain_validation_data = {
use cumulus_primitives_core::{relay_chain::HeadData, PersistedValidationData};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
let parent_head =
HeadData(prev_header.clone().unwrap_or(parent_header.clone()).encode());
let sproof_builder = RelayStateSproofBuilder {
para_id: 100.into(),
current_slot: Slot::from(2 * current_timestamp / SLOT_DURATION),
included_para_head: Some(parent_head.clone()),
..Default::default()
};
let (relay_parent_storage_root, relay_chain_state) =
sproof_builder.into_state_root_and_proof();
let data = ParachainInherentData {
validation_data: PersistedValidationData {
parent_head,
relay_parent_number: next_block,
relay_parent_storage_root,
max_pov_size: 1000,
},
relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
};
cumulus_pallet_parachain_system::Call::set_validation_data { data }
};
Executive::apply_extrinsic(UncheckedExtrinsic::new_unsigned(
RuntimeCall::ParachainSystem(parachain_validation_data),
))
.unwrap()
.unwrap();
// Calls that need to be called before each block starts (init_calls) go here
};
externalities.execute_with(|| start_block(current_block, 0));
for (maybe_lapse, origin, extrinsic) in extrinsics {
// If the lapse is in the range [0, MAX_BLOCK_LAPSE] we finalize the block and initialize
// a new one.
if let Some(lapse) = maybe_lapse {
// We update our state variables
current_weight = Weight::zero();
elapsed = Duration::ZERO;
// We start the next block
externalities.execute_with(|| start_block(current_block, lapse));
current_block += lapse;
}
// We get the current time for timing purposes.
let now = Instant::now();
let mut call_weight = Weight::zero();
// We compute the weight to avoid overweight blocks.
externalities.execute_with(|| {
call_weight = extrinsic.get_dispatch_info().weight;
});
current_weight = current_weight.saturating_add(call_weight);
if current_weight.ref_time() >= max_weight.ref_time() {
#[cfg(not(fuzzing))]
println!("Skipping because of max weight {max_weight}");
continue;
}
externalities.execute_with(|| {
let origin_account = endowed_accounts[origin % endowed_accounts.len()];
#[cfg(not(fuzzing))]
{
println!("\n origin: {origin_account:?}");
println!(" call: {extrinsic:?}");
}
let _res = extrinsic.clone().dispatch(RuntimeOrigin::signed(origin_account));
#[cfg(not(fuzzing))]
println!(" result: {_res:?}");
// Uncomment to print events for debugging purposes
/*
#[cfg(not(fuzzing))]
{
let all_events = statemine_runtime::System::events();
let events: Vec<_> = all_events.clone().into_iter().skip(already_seen).collect();
already_seen = all_events.len();
println!(" events: {:?}\n", events);
}
*/
});
elapsed += now.elapsed();
}
#[cfg(not(fuzzing))]
println!("\n time spent: {elapsed:?}");
assert!(elapsed.as_secs() <= MAX_TIME_FOR_BLOCK, "block execution took too much time");
// We end the final block
externalities.execute_with(|| {
// Finilization
Executive::finalize_block();
// Invariants
#[cfg(not(fuzzing))]
println!("\ntesting invariants for block {current_block}");
<AllPalletsWithSystem as TryState<BlockNumber>>::try_state(
current_block,
TryStateSelect::All,
)
.unwrap();
});
// After execution of all blocks.
externalities.execute_with(|| {
// We keep track of the sum of balance of accounts
let mut counted_free = 0;
let mut counted_reserved = 0;
for acc in frame_system::Account::<Runtime>::iter() {
// Check that the consumer/provider state is valid.
let acc_consumers = acc.1.consumers;
let acc_providers = acc.1.providers;
assert!(!(acc_consumers > 0 && acc_providers == 0), "Invalid state");
// Increment our balance counts
counted_free += acc.1.data.free;
counted_reserved += acc.1.data.reserved;
// Check that locks and holds are valid.
let max_lock: Balance =
Balances::locks(acc.0).iter().map(|l| l.amount).max().unwrap_or_default();
assert_eq!(
max_lock, acc.1.data.frozen,
"Max lock should be equal to frozen balance"
);
let sum_holds: Balance =
pallet_balances::Holds::<Runtime>::get(acc.0).iter().map(|l| l.amount).sum();
assert!(
sum_holds <= acc.1.data.reserved,
"Sum of all holds ({sum_holds}) should be less than or equal to reserved \
balance {}",
acc.1.data.reserved
);
}
let total_issuance = pallet_balances::TotalIssuance::<Runtime>::get();
let counted_issuance = counted_free + counted_reserved;
// The reason we do not simply use `!=` here is that some balance might be transfered to another chain via XCM.
// If we find some kind of workaround for this, we could replace `<` by `!=` here and make the check stronger.
assert!(
total_issuance <= counted_issuance,
"Inconsistent total issuance: {total_issuance} but counted {counted_issuance}"
);
#[cfg(not(fuzzing))]
println!("running integrity tests");
// We run all developer-defined integrity tests
<AllPalletsWithSystem as IntegrityTest>::integrity_test();
});
});
}
+31
View File
@@ -0,0 +1,31 @@
[relaychain]
chain = "rococo-local"
default_command = "./bin-v1.6.0/polkadot"
[[relaychain.nodes]]
name = "alice"
validator = true
[[relaychain.nodes]]
name = "bob"
validator = true
[[parachains]]
id = 1000
addToGenesis = true
cumulus_based = true
chain = "dev"
[[parachains.collators]]
name = "collator01"
command = "./target/release/parachain-template-node"
ws_port = 9933
rpc_port = 8833
args = ["--rpc-max-connections 10000"]
[[parachains.collators]]
name = "collator02"
ws_port = 9822
rpc_port = 8822
command = "./target/release/parachain-template-node"
args = ["--rpc-max-connections 10000"]
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
allow-unwrap-in-tests = true
+7
View File
@@ -0,0 +1,7 @@
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
fn main() {
generate_cargo_keys();
rerun_if_git_head_changed();
}
+117
View File
@@ -0,0 +1,117 @@
use std::path::PathBuf;
/// Sub-commands supported by the collator.
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Build a chain specification.
BuildSpec(sc_cli::BuildSpecCmd),
/// Validate blocks.
CheckBlock(sc_cli::CheckBlockCmd),
/// Export blocks.
ExportBlocks(sc_cli::ExportBlocksCmd),
/// Export the state of a given block into a chain spec.
ExportState(sc_cli::ExportStateCmd),
/// Import blocks.
ImportBlocks(sc_cli::ImportBlocksCmd),
/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),
/// Remove the whole chain.
PurgeChain(cumulus_client_cli::PurgeChainCmd),
/// Export the genesis head data of the parachain.
///
/// Head data is the encoded block header.
#[command(alias = "export-genesis-state")]
ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),
/// Export the genesis wasm of the parachain.
ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
/// Sub-commands concerned with benchmarking.
/// The pallet benchmarking moved to the `pallet` sub-command.
#[command(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
/// Try-runtime has migrated to a standalone
/// [CLI](<https://github.com/paritytech/try-runtime-cli>). The subcommand exists as a stub and
/// deprecation notice. It will be removed entirely some time after Janurary
/// 2024.
TryRuntime,
}
const AFTER_HELP_EXAMPLE: &str = color_print::cstr!(
r#"<bold><underline>Examples:</></>
<bold>parachain-template-node build-spec --disable-default-bootnode > plain-parachain-chainspec.json</>
Export a chainspec for a local testnet in json format.
<bold>parachain-template-node --chain plain-parachain-chainspec.json --tmp -- --chain rococo-local</>
Launch a full node with chain specification loaded from plain-parachain-chainspec.json.
<bold>parachain-template-node</>
Launch a full node with default parachain <italic>local-testnet</> and relay chain <italic>rococo-local</>.
<bold>parachain-template-node --collator</>
Launch a collator with default parachain <italic>local-testnet</> and relay chain <italic>rococo-local</>.
"#
);
#[derive(Debug, clap::Parser)]
#[command(
propagate_version = true,
args_conflicts_with_subcommands = true,
subcommand_negates_reqs = true
)]
#[clap(after_help = AFTER_HELP_EXAMPLE)]
pub struct Cli {
#[command(subcommand)]
pub subcommand: Option<Subcommand>,
#[command(flatten)]
pub run: cumulus_client_cli::RunCmd,
/// Disable automatic hardware benchmarks.
///
/// By default these benchmarks are automatically ran at startup and measure
/// the CPU speed, the memory bandwidth and the disk speed.
///
/// The results are then printed out in the logs, and also sent as part of
/// telemetry, if telemetry is enabled.
#[arg(long)]
pub no_hardware_benchmarks: bool,
/// Relay chain arguments
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,
}
#[derive(Debug)]
pub struct RelayChainCli {
/// The actual relay chain cli object.
pub base: polkadot_cli::RunCmd,
/// Optional chain id that should be passed to the relay chain.
pub chain_id: Option<String>,
/// The base path that should be used by the relay chain.
pub base_path: Option<PathBuf>,
}
impl RelayChainCli {
/// Parse the relay chain CLI parameters using the para chain
/// `Configuration`.
pub fn new<'a>(
para_config: &sc_service::Configuration,
relay_chain_args: impl Iterator<Item = &'a String>,
) -> Self {
let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec);
let chain_id = extension.map(|e| e.relay_chain.clone());
let base_path = para_config.base_path.path().join("polkadot");
Self {
base_path: Some(base_path),
chain_id,
base: clap::Parser::parse_from(relay_chain_args),
}
}
}
+14
View File
@@ -0,0 +1,14 @@
//! Substrate Parachain Node Template CLI
#![warn(missing_docs)]
mod chain_spec;
#[macro_use]
mod service;
mod cli;
mod command;
mod rpc;
fn main() -> sc_cli::Result<()> {
command::run()
}
+57
View File
@@ -0,0 +1,57 @@
//! A collection of node-specific RPC methods.
//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer
//! used by Substrate nodes. This file extends those RPC definitions with
//! capabilities that are specific to this project's runtime configuration.
#![warn(missing_docs)]
use std::sync::Arc;
use parachain_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
use sc_client_api::AuxStore;
pub use sc_rpc::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpsee::RpcModule<()>;
/// Full client dependencies
pub struct FullDeps<C, P> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
}
/// Instantiate all RPC extensions.
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client).into_rpc())?;
Ok(module)
}
+13
View File
@@ -0,0 +1,13 @@
#[cfg(feature = "std")]
fn main() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
}
/// The wasm builder is deactivated when compiling
/// this crate for wasm to speed up the compilation.
#[cfg(not(feature = "std"))]
fn main() {}
@@ -0,0 +1,74 @@
//! OpenGov governance config
pub mod origins;
pub use origins::{
pallet_custom_origins, ReferendumCanceller, ReferendumKiller, Spender, Treasurer,
WhitelistedCaller,
};
mod tracks;
use frame_support::traits::EitherOf;
use frame_system::EnsureRootWithSuccess;
use super::*;
use crate::{
constants::currency::{CENTS, GRAND},
Balance,
};
parameter_types! {
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
}
impl pallet_conviction_voting::Config for Runtime {
type Currency = Balances;
type MaxTurnout =
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
type MaxVotes = ConstU32<512>;
type Polls = Referenda;
type RuntimeEvent = RuntimeEvent;
type VoteLockingPeriod = VoteLockingPeriod;
type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
pub const MaxBalance: Balance = Balance::max_value();
}
pub type TreasurySpender = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, Spender>;
impl origins::pallet_custom_origins::Config for Runtime {}
impl pallet_whitelist::Config for Runtime {
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
type Preimages = Preimage;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
type WhitelistOrigin = EnsureRoot<Self::AccountId>;
}
parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 3 * CENTS;
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
}
impl pallet_referenda::Config for Runtime {
type AlarmInterval = AlarmInterval;
type CancelOrigin = EnsureRoot<AccountId>;
type Currency = Balances;
type KillOrigin = EnsureRoot<AccountId>;
type MaxQueued = ConstU32<20>;
type Preimages = Preimage;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Slash = Treasury;
type SubmissionDeposit = SubmissionDeposit;
type SubmitOrigin = EnsureSigned<AccountId>;
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
type Tracks = tracks::TracksInfo;
type UndecidingTimeout = UndecidingTimeout;
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Runtime>;
}
@@ -0,0 +1,115 @@
//! Custom origins for governance interventions.
pub use pallet_custom_origins::*;
#[frame_support::pallet]
pub mod pallet_custom_origins {
use frame_support::pallet_prelude::*;
use crate::governance::{Balance, CENTS, GRAND};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[pallet::origin]
pub enum Origin {
/// Origin for spending (any amount of) funds.
Treasurer,
/// Origin able to cancel referenda.
ReferendumCanceller,
/// Origin able to kill referenda.
ReferendumKiller,
/// Origin able to spend the amount specified in Spender.
SmallTipper,
/// Origin able to spend the amount specified in Spender.
BigTipper,
/// Origin able to spend the amount specified in Spender.
SmallSpender,
/// Origin able to spend the amount specified in Spender.
MediumSpender,
/// Origin able to spend the amount specified in Spender.
BigSpender,
/// Origin able to dispatch a whitelisted call.
WhitelistedCaller,
}
macro_rules! decl_unit_ensures {
( $name:ident: $success_type:ty = $success:expr ) => {
pub struct $name;
impl<O: Into<Result<Origin, O>> + From<Origin>>
EnsureOrigin<O> for $name
{
type Success = $success_type;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
Origin::$name => Ok($success),
r => Err(O::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(Origin::$name))
}
}
};
( $name:ident ) => { decl_unit_ensures! { $name : () = () } };
( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => {
decl_unit_ensures! { $name: $success_type = $success }
decl_unit_ensures! { $( $rest )* }
};
( $name:ident, $( $rest:tt )* ) => {
decl_unit_ensures! { $name }
decl_unit_ensures! { $( $rest )* }
};
() => {}
}
decl_unit_ensures!(Treasurer, ReferendumCanceller, ReferendumKiller, WhitelistedCaller,);
macro_rules! decl_ensure {
(
$vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
$( $item:ident = $success:expr, )*
}
) => {
$vis struct $name;
impl<O: Into<Result<Origin, O>> + From<Origin>>
EnsureOrigin<O> for $name
{
type Success = $success_type;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
$(
Origin::$item => Ok($success),
)*
r => Err(O::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
// By convention the more privileged origins go later, so for greatest chance
// of success, we want the last one.
let _result: Result<O, ()> = Err(());
$(
let _result: Result<O, ()> = Ok(O::from(Origin::$item));
)*
_result
}
}
}
}
decl_ensure! {
pub type Spender: EnsureOrigin<Success = Balance> {
SmallTipper = 250 * 3 * CENTS,
BigTipper = GRAND,
SmallSpender = 10 * GRAND,
MediumSpender = 100 * GRAND,
BigSpender = 1_000 * GRAND,
Treasurer = 10_000 * GRAND,
}
}
}
@@ -0,0 +1,213 @@
//! Track configurations for governance.
use super::*;
const fn percent(x: i32) -> sp_arithmetic::FixedI64 {
sp_arithmetic::FixedI64::from_rational(x as u128, 100)
}
use pallet_referenda::Curve;
const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
const APP_TREASURER: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
const SUP_TREASURER: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
const APP_REFERENDUM_CANCELLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
const SUP_REFERENDUM_CANCELLER: Curve =
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
const APP_REFERENDUM_KILLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
const SUP_REFERENDUM_KILLER: Curve =
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
const APP_SMALL_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
const SUP_SMALL_TIPPER: Curve = Curve::make_reciprocal(1, 28, percent(4), percent(0), percent(50));
const APP_BIG_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
const SUP_BIG_TIPPER: Curve = Curve::make_reciprocal(8, 28, percent(1), percent(0), percent(50));
const APP_SMALL_SPENDER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
const SUP_SMALL_SPENDER: Curve =
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
const APP_MEDIUM_SPENDER: Curve = Curve::make_linear(23, 28, percent(50), percent(100));
const SUP_MEDIUM_SPENDER: Curve =
Curve::make_reciprocal(16, 28, percent(1), percent(0), percent(50));
const APP_BIG_SPENDER: Curve = Curve::make_linear(28, 28, percent(50), percent(100));
const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percent(0), percent(50));
const APP_WHITELISTED_CALLER: Curve =
Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100));
const SUP_WHITELISTED_CALLER: Curve =
Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50));
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 10] = [
(
0,
pallet_referenda::TrackInfo {
name: "root",
max_deciding: 1,
decision_deposit: 100 * GRAND,
prepare_period: 8 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 12 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: APP_ROOT,
min_support: SUP_ROOT,
},
),
(
1,
pallet_referenda::TrackInfo {
name: "whitelisted_caller",
max_deciding: 100,
decision_deposit: 10 * GRAND,
prepare_period: 6 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 4 * MINUTES,
min_enactment_period: 3 * MINUTES,
min_approval: APP_WHITELISTED_CALLER,
min_support: SUP_WHITELISTED_CALLER,
},
),
(
11,
pallet_referenda::TrackInfo {
name: "treasurer",
max_deciding: 10,
decision_deposit: GRAND,
prepare_period: 8 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 8 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: APP_TREASURER,
min_support: SUP_TREASURER,
},
),
(
20,
pallet_referenda::TrackInfo {
name: "referendum_canceller",
max_deciding: 1_000,
decision_deposit: 10 * GRAND,
prepare_period: 8 * MINUTES,
decision_period: 14 * MINUTES,
confirm_period: 8 * MINUTES,
min_enactment_period: 3 * MINUTES,
min_approval: APP_REFERENDUM_CANCELLER,
min_support: SUP_REFERENDUM_CANCELLER,
},
),
(
21,
pallet_referenda::TrackInfo {
name: "referendum_killer",
max_deciding: 1_000,
decision_deposit: 50 * GRAND,
prepare_period: 8 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 8 * MINUTES,
min_enactment_period: 3 * MINUTES,
min_approval: APP_REFERENDUM_KILLER,
min_support: SUP_REFERENDUM_KILLER,
},
),
(
30,
pallet_referenda::TrackInfo {
name: "small_tipper",
max_deciding: 200,
decision_deposit: 3 * CENTS,
prepare_period: MINUTES,
decision_period: 14 * MINUTES,
confirm_period: 4 * MINUTES,
min_enactment_period: MINUTES,
min_approval: APP_SMALL_TIPPER,
min_support: SUP_SMALL_TIPPER,
},
),
(
31,
pallet_referenda::TrackInfo {
name: "big_tipper",
max_deciding: 100,
decision_deposit: 10 * 3 * CENTS,
prepare_period: 4 * MINUTES,
decision_period: 14 * MINUTES,
confirm_period: 12 * MINUTES,
min_enactment_period: 3 * MINUTES,
min_approval: APP_BIG_TIPPER,
min_support: SUP_BIG_TIPPER,
},
),
(
32,
pallet_referenda::TrackInfo {
name: "small_spender",
max_deciding: 50,
decision_deposit: 100 * 3 * CENTS,
prepare_period: 10 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 10 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: APP_SMALL_SPENDER,
min_support: SUP_SMALL_SPENDER,
},
),
(
33,
pallet_referenda::TrackInfo {
name: "medium_spender",
max_deciding: 50,
decision_deposit: 200 * 3 * CENTS,
prepare_period: 10 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 12 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: APP_MEDIUM_SPENDER,
min_support: SUP_MEDIUM_SPENDER,
},
),
(
34,
pallet_referenda::TrackInfo {
name: "big_spender",
max_deciding: 50,
decision_deposit: 400 * 3 * CENTS,
prepare_period: 10 * MINUTES,
decision_period: 20 * MINUTES,
confirm_period: 14 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: APP_BIG_SPENDER,
min_support: SUP_BIG_SPENDER,
},
),
];
pub struct TracksInfo;
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
type Id = u16;
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
&TRACKS_DATA[..]
}
fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
match system_origin {
frame_system::RawOrigin::Root => Ok(0),
_ => Err(()),
}
} else if let Ok(custom_origin) = origins::Origin::try_from(id.clone()) {
match custom_origin {
origins::Origin::WhitelistedCaller => Ok(1),
origins::Origin::Treasurer => Ok(11),
// Referendum admins
origins::Origin::ReferendumCanceller => Ok(20),
origins::Origin::ReferendumKiller => Ok(21),
// Limited treasury spenders
origins::Origin::SmallTipper => Ok(30),
origins::Origin::BigTipper => Ok(31),
origins::Origin::SmallSpender => Ok(32),
origins::Origin::MediumSpender => Ok(33),
origins::Origin::BigSpender => Ok(34),
}
} else {
Err(())
}
}
}
pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
@@ -0,0 +1,53 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, Weight},
};
parameter_types! {
/// Importing a block with 0 Extrinsics.
pub const BlockExecutionWeight: Weight =
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0);
}
#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::constants::BlockExecutionWeight::get();
// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 50 ms."
);
}
}
}
@@ -0,0 +1,53 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, Weight},
};
parameter_types! {
/// Executing a NO-OP `System::remarks` Extrinsic.
pub const ExtrinsicBaseWeight: Weight =
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0);
}
#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::constants::ExtrinsicBaseWeight::get();
// At least 10 µs.
assert!(
w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 10 µs."
);
// At most 1 ms.
assert!(
w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 1 ms."
);
}
}
}
@@ -0,0 +1,64 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, RuntimeDbWeight},
};
parameter_types! {
/// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights
/// are available for brave runtime engineers who may want to try this out as default.
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}
#[cfg(test)]
mod test_db_weights {
use frame_support::weights::constants;
use super::constants::ParityDbWeight as W;
/// Checks that all weights exist and have sane values.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}
}
}
@@ -0,0 +1,64 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, RuntimeDbWeight},
};
parameter_types! {
/// By default, Substrate uses `RocksDB`, so this will be the weight used throughout
/// the runtime.
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}
#[cfg(test)]
mod test_db_weights {
use frame_support::weights::constants;
use super::constants::RocksDbWeight as W;
/// Checks that all weights exist and have sane values.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}
}
}
@@ -0,0 +1,12 @@
// ExtBuilder impl for all runtime integration tests
use frame_support::weights::Weight;
use parachain_template_runtime::{BuildStorage, Runtime, System};
pub fn run_with_system_weight<F: FnMut()>(w: Weight, mut assertions: F) {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap().into();
t.execute_with(|| {
System::set_block_consumed_resources(w, 0);
assertions()
});
}
@@ -0,0 +1,46 @@
// Integration transaction weight-fee tests
mod common;
use common::*;
use frame_support::pallet_prelude::*;
use pallet_transaction_payment::Multiplier;
use parachain_template_runtime::{Runtime, RuntimeBlockWeights};
use polkadot_runtime_common::MinimumMultiplier;
use sp_runtime::{traits::Convert, Perquintill};
fn min_multiplier() -> Multiplier {
MinimumMultiplier::get()
}
fn target() -> Weight {
Perquintill::from_percent(25)
* RuntimeBlockWeights::get().get(DispatchClass::Normal).max_total.unwrap()
}
fn runtime_multiplier_update(fm: Multiplier) -> Multiplier {
<Runtime as pallet_transaction_payment::Config>::FeeMultiplierUpdate::convert(fm)
}
#[test]
fn multiplier_can_grow_from_zero() {
// if the min is too small, then this will not change, and we are doomed forever.
// the block ref time is 1/100th bigger than target.
run_with_system_weight(target().set_ref_time(target().ref_time() * 101 / 100), || {
let next = runtime_multiplier_update(min_multiplier());
assert!(next > min_multiplier(), "{:?} !> {:?}", next, min_multiplier());
});
// the block proof size is 1/100th bigger than target.
run_with_system_weight(target().set_proof_size((target().proof_size() / 100) * 101), || {
let next = runtime_multiplier_update(min_multiplier());
assert!(next > min_multiplier(), "{:?} !> {:?}", next, min_multiplier());
})
}
#[test]
fn multiplier_cannot_go_below_limit() {
// will not go any further below even if block is empty.
run_with_system_weight(Weight::zero(), || {
let next = runtime_multiplier_update(min_multiplier());
assert_eq!(next, min_multiplier());
})
}
+33
View File
@@ -0,0 +1,33 @@
// Storage indices integration checks
use frame_support::traits::PalletInfo;
use parachain_template_runtime::{
Aura, AuraExt, Authorship, Balances, CollatorSelection, CumulusXcm, MessageQueue, Multisig,
ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, Runtime, Session, Sudo, System, Timestamp,
TransactionPayment, XcmpQueue,
};
fn assert_pallet_prefix<P: 'static>(name: &str) {
assert_eq!(<Runtime as frame_system::Config>::PalletInfo::name::<P>(), Some(name));
}
#[test]
fn verify_pallet_prefixes() {
assert_pallet_prefix::<System>("System");
assert_pallet_prefix::<ParachainSystem>("ParachainSystem");
assert_pallet_prefix::<Timestamp>("Timestamp");
assert_pallet_prefix::<ParachainInfo>("ParachainInfo");
assert_pallet_prefix::<Proxy>("Proxy");
assert_pallet_prefix::<Balances>("Balances");
assert_pallet_prefix::<TransactionPayment>("TransactionPayment");
assert_pallet_prefix::<Sudo>("Sudo");
assert_pallet_prefix::<Multisig>("Multisig");
assert_pallet_prefix::<Authorship>("Authorship");
assert_pallet_prefix::<CollatorSelection>("CollatorSelection");
assert_pallet_prefix::<Session>("Session");
assert_pallet_prefix::<Aura>("Aura");
assert_pallet_prefix::<AuraExt>("AuraExt");
assert_pallet_prefix::<XcmpQueue>("XcmpQueue");
assert_pallet_prefix::<PolkadotXcm>("PolkadotXcm");
assert_pallet_prefix::<CumulusXcm>("CumulusXcm");
assert_pallet_prefix::<MessageQueue>("MessageQueue");
}
+4
View File
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2024-02-17"
targets = ["wasm32-unknown-unknown"]
components = ["rustfmt", "clippy", "rust-src"]
+18
View File
@@ -0,0 +1,18 @@
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
imports_granularity = "Crate"
match_arm_blocks = false
reorder_impl_items = true
group_imports = "StdExternalCrate"
use_field_init_shorthand = true
use_small_heuristics = "Max"
# most of these are unstable, so we enable them
unstable_features = true
# wanted to enable below, but they are removing the documentation comments if there is an empty line in between
# wrap_comments = true
# format_code_in_doc_comments = true
@@ -0,0 +1,16 @@
#!/bin/bash
find . -name "Cargo.toml" -not -path "*/target/*" -exec toml-sort {} \;
CMD="git diff --name-only"
stdbuf -oL $CMD | {
while IFS= read -r line; do
echo$line
if [[ "$line" == *"Cargo.toml" ]]; then
echo "Check fails: $line"
echo "Please run './scripts/toml-sort.sh' to format Cargo.toml files properly."
exit 1
fi
done
}
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
# From the workspace directory, run :
# ./scripts/toml-sort.sh
# to format all Cargo.toml files, and
# ./scripts/toml-sort.sh --check
# to only check the formatting.
if ! type "toml-sort" > /dev/null; then
echo "Run 'cargo install --git https://github.com/4meta5/toml_sort'"
else
find . -name "Cargo.toml" -not -path "*/target/*" -exec toml-sort {} $@ \;
fi
+102
View File
@@ -0,0 +1,102 @@
#!/bin/bash
ZOMBIENET_V=v1.3.91
POLKADOT_V=v1.6.0
case "$(uname -s)" in
Linux*) MACHINE=Linux;;
Darwin*) MACHINE=Mac;;
*) exit 1
esac
if [ $MACHINE = "Linux" ]; then
ZOMBIENET_BIN=zombienet-linux-x64
elif [ $MACHINE = "Mac" ]; then
ZOMBIENET_BIN=zombienet-macos
fi
BIN_DIR=bin-$POLKADOT_V
build_polkadot() {
echo "cloning polkadot repository..."
CWD=$(pwd)
mkdir -p "$BIN_DIR"
pushd /tmp
git clone https://github.com/paritytech/polkadot-sdk.git
pushd polkadot-sdk
git checkout release-polkadot-$POLKADOT_V
echo "building polkadot executable..."
cargo build --release --features fast-runtime
cp target/release/polkadot "$CWD/$BIN_DIR"
cp target/release/polkadot-execute-worker "$CWD/$BIN_DIR"
cp target/release/polkadot-prepare-worker "$CWD/$BIN_DIR"
popd
popd
}
fetch_polkadot() {
echo "fetching from polkadot repository..."
echo $BIN_DIR
mkdir -p "$BIN_DIR"
pushd "$BIN_DIR"
wget https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-$POLKADOT_V/polkadot
wget https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-$POLKADOT_V/polkadot-execute-worker
wget https://github.com/paritytech/polkadot-sdk/releases/download/polkadot-$POLKADOT_V/polkadot-prepare-worker
chmod +x *
popd
}
zombienet_init() {
if [ ! -f $ZOMBIENET_BIN ]; then
echo "fetching zombienet executable..."
curl -LO https://github.com/paritytech/zombienet/releases/download/$ZOMBIENET_V/$ZOMBIENET_BIN
chmod +x $ZOMBIENET_BIN
fi
if [ ! -f $BIN_DIR/polkadot ]; then
fetch_polkadot
fi
}
zombienet_build() {
if [ ! -f $ZOMBIENET_BIN ]; then
echo "fetching zombienet executable..."
curl -LO https://github.com/paritytech/zombienet/releases/download/$ZOMBIENET_V/$ZOMBIENET_BIN
chmod +x $ZOMBIENET_BIN
fi
if [ ! -f $BIN_DIR/polkadot ]; then
build_polkadot
fi
}
zombienet_devnet() {
zombienet_init
cargo build --release
echo "spawning rococo-local relay chain plus devnet as a parachain..."
local dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
./$ZOMBIENET_BIN spawn "$dir/../zombienet-config/devnet.toml" -p native
}
print_help() {
echo "This is a shell script to automate the execution of zombienet."
echo ""
echo "$ ./zombienet.sh init # fetches zombienet and polkadot executables"
echo "$ ./zombienet.sh build # builds polkadot executables from source"
echo "$ ./zombienet.sh devnet # spawns a rococo-local relay chain plus parachain devnet-local as a parachain"
}
SUBCOMMAND=$1
case $SUBCOMMAND in
"" | "-h" | "--help")
print_help
;;
*)
shift
zombienet_${SUBCOMMAND} $@
if [ $? = 127 ]; then
echo "Error: '$SUBCOMMAND' is not a known SUBCOMMAND." >&2
echo "Run './zombienet.sh --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac
@@ -0,0 +1,60 @@
[package]
name = "template-fuzzer"
version = "0.1.0"
[package.authors]
workspace = true
[package.description]
workspace = true
[package.edition]
workspace = true
[package.license]
workspace = true
[package.repository]
workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
substrate-runtime-fuzzer = { workspace = true }
ziggy = { workspace = true }
parachain-template-runtime = { path = "../runtime" }
parachains-common = { workspace = true }
parity-scale-codec = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-runtime = { workspace = true }
sp-state-machine = { workspace = true }
pallet-balances = { workspace = true }
pallet-timestamp = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-test-relay-sproof-builder = { workspace = true }
[features]
default = [ "std", "try-runtime" ]
std = [
"frame-support/std",
"pallet-timestamp/std",
"parachain-template-runtime/std",
"parity-scale-codec/std",
"sp-consensus-aura/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp/try-runtime",
"parachain-template-runtime/try-runtime",
"sp-runtime/try-runtime",
]
[lints]
workspace = true
@@ -0,0 +1,12 @@
FROM rust:1-buster
USER root
RUN apt-get update && apt-get -y install protobuf-compiler libclang-dev clang binutils-dev libunwind-dev
RUN mkdir -p /fuzztest
ADD . /fuzztest/
WORKDIR /fuzztest/template-fuzzer
CMD ["/bin/bash", "/fuzztest/template-fuzzer/run-fuzzer.sh"]
@@ -0,0 +1,13 @@
## Template Fuzzer
This a fuzzer implementation for OpenZeppelin's runtime templates. Currently there is a single runtime (generic one) and a single fuzzer setup.
This code is highly experimental, if you notice any flaws consider creating an issue or a pull request.
### How to run the fuzzer
We have provided a docker packaging for the fuzzer, so that you can run it like this from the **repository root directory**
```bash
docker build -t fuzzer -f template-fuzzer/Dockerfile .
docker run --mount source=output,target=/fuzztest/template-fuzzer/output fuzzer
```
@@ -0,0 +1,5 @@
#!/bin/bash
rustup target add wasm32-unknown-unknown
rustup component add rust-src
cargo install ziggy cargo-afl honggfuzz grcov
AFL_SKIP_CPUFREQ=true AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=true cargo ziggy fuzz -t 20 -j 5

Some files were not shown because too many files have changed in this diff Show More