mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 20:05:49 +00:00
Add a testnet similar to sc_network_test. (#852)
* Copy over files * Most network tests work * Fix copyrights * Strip out unneeded pallets * Update test-runtime and remove unused network test things * Upgrade test runtime * Strip more things out of the test runtime * Bump kusama impl version
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
[package]
|
||||
name = "polkadot-test-runtime"
|
||||
version = "0.7.21"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
bitvec = { version = "0.15.2", default-features = false, features = ["alloc"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = ["derive"] }
|
||||
log = { version = "0.3.9", optional = true }
|
||||
rustc-hex = { version = "2.0.1", default-features = false }
|
||||
serde = { version = "1.0.102", default-features = false }
|
||||
serde_derive = { version = "1.0.102", optional = true }
|
||||
|
||||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
version = { package = "sp-version", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
tx-pool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
block-builder-api = { package = "sp-block-builder", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
|
||||
authorship = { package = "pallet-authorship", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
transaction-payment = { package = "pallet-transaction-payment", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
executive = { package = "frame-executive", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
finality-tracker = { package = "pallet-finality-tracker", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
grandpa = { package = "pallet-grandpa", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false, features = ["migrate-authorities"] }
|
||||
indices = { package = "pallet-indices", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
nicks = { package = "pallet-nicks", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
randomness-collective-flip = { package = "pallet-randomness-collective-flip", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
session = { package = "pallet-session", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
staking = { package = "pallet-staking", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
system = { package = "frame-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
system_rpc_runtime_api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
timestamp = { package = "pallet-timestamp", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
vesting = { package = "pallet-vesting", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
|
||||
|
||||
runtime-common = { package = "polkadot-runtime-common", path = "../common", default-features = false }
|
||||
primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false }
|
||||
polkadot-parachain = { path = "../../parachain", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.2.1"
|
||||
libsecp256k1 = "0.3.2"
|
||||
tiny-keccak = "1.5.0"
|
||||
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
trie-db = "0.20.0"
|
||||
serde_json = "1.0.41"
|
||||
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.5" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
no_std = []
|
||||
only-staking = []
|
||||
std = [
|
||||
"bitvec/std",
|
||||
"primitives/std",
|
||||
"rustc-hex/std",
|
||||
"codec/std",
|
||||
"inherents/std",
|
||||
"sp-core/std",
|
||||
"polkadot-parachain/std",
|
||||
"sp-api/std",
|
||||
"tx-pool-api/std",
|
||||
"block-builder-api/std",
|
||||
"rstd/std",
|
||||
"sp-io/std",
|
||||
"frame-support/std",
|
||||
"authorship/std",
|
||||
"balances/std",
|
||||
"transaction-payment/std",
|
||||
"pallet-transaction-payment-rpc-runtime-api/std",
|
||||
"executive/std",
|
||||
"finality-tracker/std",
|
||||
"grandpa/std",
|
||||
"indices/std",
|
||||
"nicks/std",
|
||||
"sp-runtime/std",
|
||||
"sp-staking/std",
|
||||
"session/std",
|
||||
"staking/std",
|
||||
"system/std",
|
||||
"system_rpc_runtime_api/std",
|
||||
"timestamp/std",
|
||||
"version/std",
|
||||
"vesting/std",
|
||||
"serde_derive",
|
||||
"serde/std",
|
||||
"log",
|
||||
"babe/std",
|
||||
"babe-primitives/std",
|
||||
"sp-session/std",
|
||||
"randomness-collective-flip/std",
|
||||
"runtime-common/std",
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use wasm_builder_runner::WasmBuilder;
|
||||
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.with_current_project()
|
||||
.with_wasm_builder_from_crates("1.0.9")
|
||||
.import_memory()
|
||||
.export_heap_base()
|
||||
.build()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "polkadot-test-runtime-client"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
polkadot-test-runtime = { path = ".." }
|
||||
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sc-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
futures = "0.3.1"
|
||||
@@ -0,0 +1,323 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Client testing utilities.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::collections::BTreeMap;
|
||||
pub use substrate_test_client::*;
|
||||
pub use polkadot_test_runtime as runtime;
|
||||
pub use sc_client::LongestChain;
|
||||
|
||||
use sp_core::{sr25519, ChangesTrieConfiguration, map, twox_128};
|
||||
use sp_core::storage::{ChildInfo, Storage, StorageChild};
|
||||
use substrate_test_runtime::genesismap::{GenesisConfig};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, HashFor};
|
||||
use sc_client::{
|
||||
light::fetcher::{
|
||||
RemoteCallRequest, RemoteBodyRequest,
|
||||
},
|
||||
};
|
||||
|
||||
/// A prelude to import in tests.
|
||||
pub mod prelude {
|
||||
// Trait extensions
|
||||
pub use super::{ClientExt, ClientBlockImportExt};
|
||||
// Client structs
|
||||
pub use super::{
|
||||
TestClient, TestClientBuilder, Backend, LightBackend,
|
||||
Executor, LightExecutor, LocalExecutor, NativeExecutor, WasmExecutionMethod,
|
||||
};
|
||||
// Keyring
|
||||
pub use super::{AccountKeyring, Sr25519Keyring};
|
||||
}
|
||||
|
||||
sc_executor::native_executor_instance! {
|
||||
pub LocalExecutor,
|
||||
polkadot_test_runtime::api::dispatch,
|
||||
polkadot_test_runtime::native_version,
|
||||
}
|
||||
|
||||
/// Test client database backend.
|
||||
pub type Backend = substrate_test_client::Backend<polkadot_test_runtime::Block>;
|
||||
|
||||
/// Test client executor.
|
||||
pub type Executor = sc_client::LocalCallExecutor<
|
||||
Backend,
|
||||
NativeExecutor<LocalExecutor>,
|
||||
>;
|
||||
|
||||
/// Test client light database backend.
|
||||
pub type LightBackend = substrate_test_client::LightBackend<polkadot_test_runtime::Block>;
|
||||
|
||||
/// Test client light executor.
|
||||
pub type LightExecutor = sc_client::light::call_executor::GenesisCallExecutor<
|
||||
LightBackend,
|
||||
sc_client::LocalCallExecutor<
|
||||
sc_client::light::backend::Backend<
|
||||
sc_client_db::light::LightStorage<polkadot_test_runtime::Block>,
|
||||
HashFor<polkadot_test_runtime::Block>
|
||||
>,
|
||||
NativeExecutor<LocalExecutor>
|
||||
>
|
||||
>;
|
||||
|
||||
/// Parameters of test-client builder with test-runtime.
|
||||
#[derive(Default)]
|
||||
pub struct GenesisParameters {
|
||||
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||
heap_pages_override: Option<u64>,
|
||||
extra_storage: Storage,
|
||||
}
|
||||
|
||||
impl GenesisParameters {
|
||||
fn genesis_config(&self) -> GenesisConfig {
|
||||
GenesisConfig::new(
|
||||
self.changes_trie_config.clone(),
|
||||
vec![
|
||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
||||
],
|
||||
vec![
|
||||
AccountKeyring::Alice.into(),
|
||||
AccountKeyring::Bob.into(),
|
||||
AccountKeyring::Charlie.into(),
|
||||
],
|
||||
1000,
|
||||
self.heap_pages_override,
|
||||
self.extra_storage.clone(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn additional_storage_with_genesis(genesis_block: &polkadot_test_runtime::Block) -> BTreeMap<Vec<u8>, Vec<u8>> {
|
||||
map![
|
||||
twox_128(&b"latest"[..]).to_vec() => genesis_block.hash().as_fixed_bytes().to_vec()
|
||||
]
|
||||
}
|
||||
|
||||
impl substrate_test_client::GenesisInit for GenesisParameters {
|
||||
fn genesis_storage(&self) -> Storage {
|
||||
use codec::Encode;
|
||||
|
||||
let mut storage = self.genesis_config().genesis_map();
|
||||
|
||||
let child_roots = storage.children.iter().map(|(sk, child_content)| {
|
||||
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect()
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
});
|
||||
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().chain(child_roots).collect()
|
||||
);
|
||||
let block: runtime::Block = sc_client::genesis::construct_genesis_block(state_root);
|
||||
storage.top.extend(additional_storage_with_genesis(&block));
|
||||
|
||||
storage
|
||||
}
|
||||
}
|
||||
|
||||
/// A `TestClient` with `test-runtime` builder.
|
||||
pub type TestClientBuilder<E, B> = substrate_test_client::TestClientBuilder<
|
||||
polkadot_test_runtime::Block,
|
||||
E,
|
||||
B,
|
||||
GenesisParameters,
|
||||
>;
|
||||
|
||||
/// Test client type with `LocalExecutor` and generic Backend.
|
||||
pub type Client<B> = sc_client::Client<
|
||||
B,
|
||||
sc_client::LocalCallExecutor<B, sc_executor::NativeExecutor<LocalExecutor>>,
|
||||
polkadot_test_runtime::Block,
|
||||
polkadot_test_runtime::RuntimeApi,
|
||||
>;
|
||||
|
||||
/// A test client with default backend.
|
||||
pub type TestClient = Client<Backend>;
|
||||
|
||||
/// A `TestClientBuilder` with default backend and executor.
|
||||
pub trait DefaultTestClientBuilderExt: Sized {
|
||||
/// Create new `TestClientBuilder`
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
impl DefaultTestClientBuilderExt for TestClientBuilder<Executor, Backend> {
|
||||
fn new() -> Self {
|
||||
Self::with_default_backend()
|
||||
}
|
||||
}
|
||||
|
||||
/// A `test-runtime` extensions to `TestClientBuilder`.
|
||||
pub trait TestClientBuilderExt<B>: Sized {
|
||||
/// Returns a mutable reference to the genesis parameters.
|
||||
fn genesis_init_mut(&mut self) -> &mut GenesisParameters;
|
||||
|
||||
/// Set changes trie configuration for genesis.
|
||||
fn changes_trie_config(mut self, config: Option<ChangesTrieConfiguration>) -> Self {
|
||||
self.genesis_init_mut().changes_trie_config = config;
|
||||
self
|
||||
}
|
||||
|
||||
/// Override the default value for Wasm heap pages.
|
||||
fn set_heap_pages(mut self, heap_pages: u64) -> Self {
|
||||
self.genesis_init_mut().heap_pages_override = Some(heap_pages);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add an extra value into the genesis storage.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the key is empty.
|
||||
fn add_extra_child_storage<SK: Into<Vec<u8>>, K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
|
||||
mut self,
|
||||
storage_key: SK,
|
||||
child_info: ChildInfo,
|
||||
key: K,
|
||||
value: V,
|
||||
) -> Self {
|
||||
let storage_key = storage_key.into();
|
||||
let key = key.into();
|
||||
assert!(!storage_key.is_empty());
|
||||
assert!(!key.is_empty());
|
||||
self.genesis_init_mut().extra_storage.children
|
||||
.entry(storage_key)
|
||||
.or_insert_with(|| StorageChild {
|
||||
data: Default::default(),
|
||||
child_info: child_info.to_owned(),
|
||||
}).data.insert(key, value.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add an extra child value into the genesis storage.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the key is empty.
|
||||
fn add_extra_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(mut self, key: K, value: V) -> Self {
|
||||
let key = key.into();
|
||||
assert!(!key.is_empty());
|
||||
self.genesis_init_mut().extra_storage.top.insert(key, value.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the test client.
|
||||
fn build(self) -> Client<B> {
|
||||
self.build_with_longest_chain().0
|
||||
}
|
||||
|
||||
/// Build the test client and longest chain selector.
|
||||
fn build_with_longest_chain(self) -> (Client<B>, sc_client::LongestChain<B, polkadot_test_runtime::Block>);
|
||||
|
||||
/// Build the test client and the backend.
|
||||
fn build_with_backend(self) -> (Client<B>, Arc<B>);
|
||||
}
|
||||
|
||||
impl TestClientBuilderExt<Backend> for TestClientBuilder<
|
||||
sc_client::LocalCallExecutor<Backend, sc_executor::NativeExecutor<LocalExecutor>>,
|
||||
Backend
|
||||
> {
|
||||
fn genesis_init_mut(&mut self) -> &mut GenesisParameters {
|
||||
Self::genesis_init_mut(self)
|
||||
}
|
||||
|
||||
fn build_with_longest_chain(self) -> (Client<Backend>, sc_client::LongestChain<Backend, polkadot_test_runtime::Block>) {
|
||||
self.build_with_native_executor(None)
|
||||
}
|
||||
|
||||
fn build_with_backend(self) -> (Client<Backend>, Arc<Backend>) {
|
||||
let backend = self.backend();
|
||||
(self.build_with_native_executor(None).0, backend)
|
||||
}
|
||||
}
|
||||
|
||||
/// Type of optional fetch callback.
|
||||
type MaybeFetcherCallback<Req, Resp> = Option<Box<dyn Fn(Req) -> Result<Resp, sp_blockchain::Error> + Send + Sync>>;
|
||||
|
||||
/// Implementation of light client fetcher used in tests.
|
||||
#[derive(Default)]
|
||||
pub struct LightFetcher {
|
||||
call: MaybeFetcherCallback<RemoteCallRequest<polkadot_test_runtime::Header>, Vec<u8>>,
|
||||
body: MaybeFetcherCallback<RemoteBodyRequest<polkadot_test_runtime::Header>, Vec<substrate_test_runtime::Extrinsic>>,
|
||||
}
|
||||
|
||||
impl LightFetcher {
|
||||
/// Sets remote call callback.
|
||||
pub fn with_remote_call(
|
||||
self,
|
||||
call: MaybeFetcherCallback<RemoteCallRequest<polkadot_test_runtime::Header>, Vec<u8>>,
|
||||
) -> Self {
|
||||
LightFetcher {
|
||||
call,
|
||||
body: self.body,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets remote body callback.
|
||||
pub fn with_remote_body(
|
||||
self,
|
||||
body: MaybeFetcherCallback<RemoteBodyRequest<polkadot_test_runtime::Header>, Vec<substrate_test_runtime::Extrinsic>>,
|
||||
) -> Self {
|
||||
LightFetcher {
|
||||
call: self.call,
|
||||
body,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates new client instance used for tests.
|
||||
pub fn new() -> Client<Backend> {
|
||||
TestClientBuilder::new().build()
|
||||
}
|
||||
|
||||
/// Creates new light client instance used for tests.
|
||||
pub fn new_light() -> (
|
||||
sc_client::Client<LightBackend, LightExecutor, polkadot_test_runtime::Block, polkadot_test_runtime::RuntimeApi>,
|
||||
Arc<LightBackend>,
|
||||
) {
|
||||
|
||||
let storage = sc_client_db::light::LightStorage::new_test();
|
||||
let blockchain = Arc::new(sc_client::light::blockchain::Blockchain::new(storage));
|
||||
let backend = Arc::new(LightBackend::new(blockchain.clone()));
|
||||
let executor = new_native_executor();
|
||||
let local_call_executor = sc_client::LocalCallExecutor::new(backend.clone(), executor);
|
||||
let call_executor = LightExecutor::new(
|
||||
backend.clone(),
|
||||
local_call_executor,
|
||||
);
|
||||
|
||||
(
|
||||
TestClientBuilder::with_backend(backend.clone())
|
||||
.build_with_executor(call_executor)
|
||||
.0,
|
||||
backend,
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates new light client fetcher used for tests.
|
||||
pub fn new_light_fetcher() -> LightFetcher {
|
||||
LightFetcher::default()
|
||||
}
|
||||
|
||||
/// Create a new native executor.
|
||||
pub fn new_native_executor() -> sc_executor::NativeExecutor<LocalExecutor> {
|
||||
sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/// Money matters.
|
||||
pub mod currency {
|
||||
use primitives::Balance;
|
||||
|
||||
pub const DOTS: Balance = 1_000_000_000_000;
|
||||
pub const DOLLARS: Balance = DOTS;
|
||||
pub const CENTS: Balance = DOLLARS / 100;
|
||||
pub const MILLICENTS: Balance = CENTS / 1_000;
|
||||
}
|
||||
|
||||
/// Time and blocks.
|
||||
pub mod time {
|
||||
use primitives::{Moment, BlockNumber};
|
||||
// Testnet
|
||||
pub const MILLISECS_PER_BLOCK: Moment = 1000;
|
||||
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
|
||||
// Testnet
|
||||
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
|
||||
|
||||
// These time units are defined in number of blocks.
|
||||
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
|
||||
pub const HOURS: BlockNumber = MINUTES * 60;
|
||||
pub const DAYS: BlockNumber = HOURS * 24;
|
||||
|
||||
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
|
||||
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
||||
}
|
||||
|
||||
/// Fee-related.
|
||||
pub mod fee {
|
||||
pub use sp_runtime::Perbill;
|
||||
use primitives::Balance;
|
||||
use frame_support::weights::Weight;
|
||||
use sp_runtime::traits::Convert;
|
||||
|
||||
/// The block saturation level. Fees will be updates based on this value.
|
||||
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
|
||||
|
||||
/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
|
||||
/// node's balance type.
|
||||
///
|
||||
/// This should typically create a mapping between the following ranges:
|
||||
/// - [0, system::MaximumBlockWeight]
|
||||
/// - [Balance::min, Balance::max]
|
||||
///
|
||||
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
|
||||
/// - Setting it to `0` will essentially disable the weight fee.
|
||||
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
|
||||
pub struct WeightToFee;
|
||||
impl Convert<Weight, Balance> for WeightToFee {
|
||||
fn convert(x: Weight) -> Balance {
|
||||
// in Kusama a weight of 10_000 (smallest non-zero weight) is mapped to 1/10 CENT:
|
||||
Balance::from(x).saturating_mul(super::currency::CENTS / (10 * 10_000))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,580 @@
|
||||
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The Polkadot runtime. This can be compiled with `#[no_std]`, ready for Wasm.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
||||
#![recursion_limit="256"]
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::{Encode, Decode};
|
||||
use primitives::{
|
||||
AccountId, AccountIndex, Balance, BlockNumber, Hash as HashT, Nonce, Signature, Moment,
|
||||
parachain::{self, ActiveParas, AbridgedCandidateReceipt}, ValidityError,
|
||||
};
|
||||
use runtime_common::{attestations, claims, parachains, registrar, slots,
|
||||
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment},
|
||||
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
|
||||
MaximumBlockLength,
|
||||
};
|
||||
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
ApplyExtrinsicResult, Perbill, RuntimeDebug,
|
||||
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
|
||||
curve::PiecewiseLinear,
|
||||
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto},
|
||||
};
|
||||
use version::RuntimeVersion;
|
||||
use grandpa::{AuthorityId as GrandpaId, fg_primitives};
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use version::NativeVersion;
|
||||
use sp_core::OpaqueMetadata;
|
||||
use sp_staking::SessionIndex;
|
||||
use frame_support::{
|
||||
parameter_types, construct_runtime, traits::Randomness,
|
||||
weights::DispatchInfo,
|
||||
};
|
||||
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use staking::StakerStatus;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub use sp_runtime::BuildStorage;
|
||||
pub use timestamp::Call as TimestampCall;
|
||||
pub use balances::Call as BalancesCall;
|
||||
pub use attestations::{Call as AttestationsCall, MORE_ATTESTATIONS_IDENTIFIER};
|
||||
pub use parachains::Call as ParachainsCall;
|
||||
|
||||
/// Constant values used within the runtime.
|
||||
pub mod constants;
|
||||
use constants::{time::*, currency::*, fee::*};
|
||||
|
||||
// Make the WASM binary available.
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
/// Runtime version (Kusama).
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("polkadot-test-runtime"),
|
||||
impl_name: create_runtime_str!("parity-polkadot-test-runtime"),
|
||||
authoring_version: 2,
|
||||
spec_version: 1048,
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
/// Native version.
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub fn native_version() -> NativeVersion {
|
||||
NativeVersion {
|
||||
runtime_version: VERSION,
|
||||
can_author_with: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Avoid processing transactions from slots and parachain registrar.
|
||||
#[derive(Default, Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug)]
|
||||
pub struct RestrictFunctionality;
|
||||
impl SignedExtension for RestrictFunctionality {
|
||||
const IDENTIFIER: &'static str = "RestrictFunctionality";
|
||||
type AccountId = AccountId;
|
||||
type Call = Call;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
type DispatchInfo = DispatchInfo;
|
||||
|
||||
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
|
||||
|
||||
fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
|
||||
-> TransactionValidity
|
||||
{
|
||||
match call {
|
||||
Call::Slots(_) | Call::Registrar(_)
|
||||
=> Err(InvalidTransaction::Custom(ValidityError::NoPermission.into()).into()),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const Version: RuntimeVersion = VERSION;
|
||||
}
|
||||
|
||||
impl system::Trait for Runtime {
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = Nonce;
|
||||
type BlockNumber = BlockNumber;
|
||||
type Hash = HashT;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = AccountId;
|
||||
type Lookup = Indices;
|
||||
type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type MaximumBlockWeight = MaximumBlockWeight;
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = Version;
|
||||
type ModuleToIndex = ModuleToIndex;
|
||||
type AccountData = balances::AccountData<Balance>;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
|
||||
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
|
||||
}
|
||||
|
||||
impl babe::Trait for Runtime {
|
||||
type EpochDuration = EpochDuration;
|
||||
type ExpectedBlockTime = ExpectedBlockTime;
|
||||
|
||||
// session module is the trigger
|
||||
type EpochChangeTrigger = babe::ExternalTrigger;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const IndexDeposit: Balance = 1 * DOLLARS;
|
||||
}
|
||||
|
||||
impl indices::Trait for Runtime {
|
||||
type AccountIndex = AccountIndex;
|
||||
type Currency = Balances;
|
||||
type Deposit = IndexDeposit;
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: Balance = 1 * CENTS;
|
||||
}
|
||||
|
||||
impl balances::Trait for Runtime {
|
||||
type Balance = Balance;
|
||||
type DustRemoval = ();
|
||||
type Event = Event;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const TransactionBaseFee: Balance = 1 * CENTS;
|
||||
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
|
||||
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
|
||||
pub const TargetBlockFullness: Perbill = Perbill::from_percent(25);
|
||||
}
|
||||
|
||||
impl transaction_payment::Trait for Runtime {
|
||||
type Currency = Balances;
|
||||
type OnTransactionPayment = ();
|
||||
type TransactionBaseFee = TransactionBaseFee;
|
||||
type TransactionByteFee = TransactionByteFee;
|
||||
type WeightToFee = WeightToFee;
|
||||
type FeeMultiplierUpdate = TargetedFeeAdjustment<TargetBlockFullness, Self>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
||||
}
|
||||
impl timestamp::Trait for Runtime {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Babe;
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const UncleGenerations: u32 = 0;
|
||||
}
|
||||
|
||||
// TODO: substrate#2986 implement this properly
|
||||
impl authorship::Trait for Runtime {
|
||||
type FindAuthor = session::FindAccountFromAuthorIndex<Self, Babe>;
|
||||
type UncleGenerations = UncleGenerations;
|
||||
type FilterUncle = ();
|
||||
type EventHandler = Staking;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const Period: BlockNumber = 10 * MINUTES;
|
||||
pub const Offset: BlockNumber = 0;
|
||||
}
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub grandpa: Grandpa,
|
||||
pub babe: Babe,
|
||||
pub parachain_validator: Parachains,
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
|
||||
}
|
||||
|
||||
impl session::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type ValidatorId = AccountId;
|
||||
type ValidatorIdOf = staking::StashOf<Self>;
|
||||
type ShouldEndSession = Babe;
|
||||
type SessionManager = Staking;
|
||||
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = SessionKeys;
|
||||
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
|
||||
}
|
||||
|
||||
impl session::historical::Trait for Runtime {
|
||||
type FullIdentification = staking::Exposure<AccountId, Balance>;
|
||||
type FullIdentificationOf = staking::ExposureOf<Runtime>;
|
||||
}
|
||||
|
||||
pallet_staking_reward_curve::build! {
|
||||
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
|
||||
min_inflation: 0_025_000,
|
||||
max_inflation: 0_100_000,
|
||||
ideal_stake: 0_500_000,
|
||||
falloff: 0_050_000,
|
||||
max_piece_count: 40,
|
||||
test_precision: 0_005_000,
|
||||
);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
// Six sessions in an era (6 hours).
|
||||
pub const SessionsPerEra: SessionIndex = 6;
|
||||
// 28 eras for unbonding (7 days).
|
||||
pub const BondingDuration: staking::EraIndex = 28;
|
||||
// 28 eras in which slashes can be cancelled (7 days).
|
||||
pub const SlashDeferDuration: staking::EraIndex = 28;
|
||||
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
|
||||
pub const MaxNominatorRewardedPerValidator: u32 = 64;
|
||||
}
|
||||
|
||||
impl staking::Trait for Runtime {
|
||||
type Currency = Balances;
|
||||
type Time = Timestamp;
|
||||
type CurrencyToVote = CurrencyToVoteHandler<Self>;
|
||||
type RewardRemainder = ();
|
||||
type Event = Event;
|
||||
type Slash = ();
|
||||
type Reward = ();
|
||||
type SessionsPerEra = SessionsPerEra;
|
||||
type BondingDuration = BondingDuration;
|
||||
type SlashDeferDuration = SlashDeferDuration;
|
||||
// A majority of the council can cancel the slash.
|
||||
type SlashCancelOrigin = system::EnsureNever<()>;
|
||||
type SessionInterface = Self;
|
||||
type RewardCurve = RewardCurve;
|
||||
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
|
||||
}
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AttestationPeriod: BlockNumber = 50;
|
||||
}
|
||||
|
||||
impl attestations::Trait for Runtime {
|
||||
type AttestationPeriod = AttestationPeriod;
|
||||
type ValidatorIdentities = parachains::ValidatorIdentities<Runtime>;
|
||||
type RewardAttestation = Staking;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxCodeSize: u32 = 10 * 1024 * 1024; // 10 MB
|
||||
pub const MaxHeadDataSize: u32 = 20 * 1024; // 20 KB
|
||||
}
|
||||
|
||||
impl parachains::Trait for Runtime {
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type ParachainCurrency = Balances;
|
||||
type Randomness = RandomnessCollectiveFlip;
|
||||
type ActiveParachains = Registrar;
|
||||
type Registrar = Registrar;
|
||||
type MaxCodeSize = MaxCodeSize;
|
||||
type MaxHeadDataSize = MaxHeadDataSize;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ParathreadDeposit: Balance = 5 * DOLLARS;
|
||||
pub const QueueSize: usize = 2;
|
||||
pub const MaxRetries: u32 = 3;
|
||||
}
|
||||
|
||||
impl registrar::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Origin = Origin;
|
||||
type Currency = Balances;
|
||||
type ParathreadDeposit = ParathreadDeposit;
|
||||
type SwapAux = Slots;
|
||||
type QueueSize = QueueSize;
|
||||
type MaxRetries = MaxRetries;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const LeasePeriod: BlockNumber = 100_000;
|
||||
pub const EndingPeriod: BlockNumber = 1000;
|
||||
}
|
||||
|
||||
impl slots::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Currency = Balances;
|
||||
type Parachains = Registrar;
|
||||
type LeasePeriod = LeasePeriod;
|
||||
type EndingPeriod = EndingPeriod;
|
||||
type Randomness = RandomnessCollectiveFlip;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const Prefix: &'static [u8] = b"Pay KSMs to the Kusama account:";
|
||||
}
|
||||
|
||||
impl claims::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type VestingSchedule = Vesting;
|
||||
type Prefix = Prefix;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinVestedTransfer: Balance = 100 * DOLLARS;
|
||||
}
|
||||
|
||||
impl vesting::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Currency = Balances;
|
||||
type BlockNumberToBalance = ConvertInto;
|
||||
type MinVestedTransfer = MinVestedTransfer;
|
||||
}
|
||||
|
||||
construct_runtime! {
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
NodeBlock = primitives::Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
// Basic stuff; balances is uncallable initially.
|
||||
System: system::{Module, Call, Storage, Config, Event<T>},
|
||||
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Storage},
|
||||
|
||||
// Must be before session.
|
||||
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
|
||||
|
||||
Timestamp: timestamp::{Module, Call, Storage, Inherent},
|
||||
Indices: indices::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: transaction_payment::{Module, Storage},
|
||||
|
||||
// Consensus support.
|
||||
Authorship: authorship::{Module, Call, Storage},
|
||||
Staking: staking::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
Session: session::{Module, Call, Storage, Event, Config<T>},
|
||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||
|
||||
// Claims. Usable initially.
|
||||
Claims: claims::{Module, Call, Storage, Event<T>, Config<T>, ValidateUnsigned},
|
||||
|
||||
// Parachains stuff; slots are disabled (no auctions initially). The rest are safe as they
|
||||
// have no public dispatchables.
|
||||
Parachains: parachains::{Module, Call, Storage, Config, Inherent, Origin},
|
||||
Attestations: attestations::{Module, Call, Storage},
|
||||
Slots: slots::{Module, Call, Storage, Event<T>},
|
||||
Registrar: registrar::{Module, Call, Storage, Event, Config<T>},
|
||||
|
||||
// Vesting. Usable initially, but removed once all vesting is finished.
|
||||
Vesting: vesting::{Module, Call, Storage, Event<T>, Config<T>},
|
||||
}
|
||||
}
|
||||
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = <Indices as StaticLookup>::Source;
|
||||
/// Block header type as expected by this runtime.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
/// Block type as expected by this runtime.
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
/// A Block signed with a Justification
|
||||
pub type SignedBlock = generic::SignedBlock<Block>;
|
||||
/// BlockId type as expected by this runtime.
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
/// The SignedExtension to the basic transaction logic.
|
||||
pub type SignedExtra = (
|
||||
RestrictFunctionality,
|
||||
system::CheckVersion<Runtime>,
|
||||
system::CheckGenesis<Runtime>,
|
||||
system::CheckEra<Runtime>,
|
||||
system::CheckNonce<Runtime>,
|
||||
system::CheckWeight<Runtime>,
|
||||
transaction_payment::ChargeTransactionPayment::<Runtime>,
|
||||
registrar::LimitParathreadCommits<Runtime>
|
||||
);
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
|
||||
/// Extrinsic type that has already been checked.
|
||||
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
|
||||
/// Executive: handles dispatch to the various modules.
|
||||
pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;
|
||||
|
||||
pub type Hash = <Block as BlockT>::Hash;
|
||||
pub type Extrinsic = <Block as BlockT>::Extrinsic;
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion {
|
||||
VERSION
|
||||
}
|
||||
|
||||
fn execute_block(block: Block) {
|
||||
Executive::execute_block(block)
|
||||
}
|
||||
|
||||
fn initialize_block(header: &<Block as BlockT>::Header) {
|
||||
Executive::initialize_block(header)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_api::Metadata<Block> for Runtime {
|
||||
fn metadata() -> OpaqueMetadata {
|
||||
Runtime::metadata().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl block_builder_api::BlockBuilder<Block> for Runtime {
|
||||
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
|
||||
Executive::apply_extrinsic(extrinsic)
|
||||
}
|
||||
|
||||
fn finalize_block() -> <Block as BlockT>::Header {
|
||||
Executive::finalize_block()
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(data: inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||
data.create_extrinsics()
|
||||
}
|
||||
|
||||
fn check_inherents(
|
||||
block: Block,
|
||||
data: inherents::InherentData,
|
||||
) -> inherents::CheckInherentsResult {
|
||||
data.check_extrinsics(&block)
|
||||
}
|
||||
|
||||
fn random_seed() -> <Block as BlockT>::Hash {
|
||||
RandomnessCollectiveFlip::random_seed()
|
||||
}
|
||||
}
|
||||
|
||||
impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
|
||||
Executive::validate_transaction(tx)
|
||||
}
|
||||
}
|
||||
|
||||
impl parachain::ParachainHost<Block> for Runtime {
|
||||
fn validators() -> Vec<parachain::ValidatorId> {
|
||||
Parachains::authorities()
|
||||
}
|
||||
fn duty_roster() -> parachain::DutyRoster {
|
||||
Parachains::calculate_duty_roster().0
|
||||
}
|
||||
fn active_parachains() -> Vec<(parachain::Id, Option<(parachain::CollatorId, parachain::Retriable)>)> {
|
||||
Registrar::active_paras()
|
||||
}
|
||||
fn global_validation_schedule() -> parachain::GlobalValidationSchedule {
|
||||
Parachains::global_validation_schedule()
|
||||
}
|
||||
fn local_validation_data(id: parachain::Id) -> Option<parachain::LocalValidationData> {
|
||||
Parachains::local_validation_data(&id)
|
||||
}
|
||||
fn parachain_code(id: parachain::Id) -> Option<Vec<u8>> {
|
||||
Parachains::parachain_code(&id)
|
||||
}
|
||||
fn get_heads(extrinsics: Vec<<Block as BlockT>::Extrinsic>)
|
||||
-> Option<Vec<AbridgedCandidateReceipt>>
|
||||
{
|
||||
extrinsics
|
||||
.into_iter()
|
||||
.find_map(|ex| match UncheckedExtrinsic::decode(&mut ex.encode().as_slice()) {
|
||||
Ok(ex) => match ex.function {
|
||||
Call::Parachains(ParachainsCall::set_heads(heads)) => {
|
||||
Some(heads.into_iter().map(|c| c.candidate).collect())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
Err(_) => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fg_primitives::GrandpaApi<Block> for Runtime {
|
||||
fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
}
|
||||
|
||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
||||
fn configuration() -> babe_primitives::BabeConfiguration {
|
||||
// The choice of `c` parameter (where `1 - c` represents the
|
||||
// probability of a slot being empty), is done in accordance to the
|
||||
// slot duration and expected target block time, for safely
|
||||
// resisting network delays of maximum two seconds.
|
||||
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
|
||||
babe_primitives::BabeConfiguration {
|
||||
slot_duration: Babe::slot_duration(),
|
||||
epoch_length: EpochDuration::get(),
|
||||
c: PRIMARY_PROBABILITY,
|
||||
genesis_authorities: Babe::authorities(),
|
||||
randomness: Babe::randomness(),
|
||||
secondary_slots: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn current_epoch_start() -> babe_primitives::SlotNumber {
|
||||
Babe::current_epoch_start()
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_session::SessionKeys<Block> for Runtime {
|
||||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
SessionKeys::generate(seed)
|
||||
}
|
||||
|
||||
fn decode_session_keys(
|
||||
encoded: Vec<u8>,
|
||||
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
|
||||
SessionKeys::decode_into_raw_public_keys(&encoded)
|
||||
}
|
||||
}
|
||||
|
||||
impl system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
|
||||
fn account_nonce(account: AccountId) -> Nonce {
|
||||
System::account_nonce(account)
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
|
||||
Block,
|
||||
Balance,
|
||||
UncheckedExtrinsic,
|
||||
> for Runtime {
|
||||
fn query_info(uxt: UncheckedExtrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
|
||||
TransactionPayment::query_info(uxt, len)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user