Unverified Commit eca01a8c authored by Fedor Sakharov's avatar Fedor Sakharov Committed by GitHub
Browse files

Parachains-runtime (#1505)

* Initial commit

* v0 to v1 primitives and remove attestations

* Review fixes

* implement candidate_events

* remove dead code
parent d4022633
Pipeline #102410 passed with stages
in 25 minutes and 46 seconds
......@@ -5993,6 +5993,53 @@ dependencies = [
"librocksdb-sys",
]
[[package]]
name = "rococo-runtime"
version = "0.8.19"
dependencies = [
"frame-executive",
"frame-support",
"frame-system",
"frame-system-rpc-runtime-api",
"pallet-authority-discovery",
"pallet-authorship",
"pallet-babe",
"pallet-balances",
"pallet-grandpa",
"pallet-im-online",
"pallet-indices",
"pallet-offences",
"pallet-session",
"pallet-staking",
"pallet-staking-reward-curve",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"parity-scale-codec",
"polkadot-parachain",
"polkadot-primitives",
"polkadot-runtime-common",
"polkadot-runtime-parachains",
"serde",
"serde_derive",
"smallvec 1.4.1",
"sp-api",
"sp-authority-discovery",
"sp-block-builder",
"sp-consensus-babe",
"sp-core",
"sp-inherents",
"sp-io",
"sp-offchain",
"sp-runtime",
"sp-session",
"sp-staking",
"sp-std",
"sp-transaction-pool",
"sp-version",
"substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rpassword"
version = "4.0.5"
......
......@@ -35,6 +35,7 @@ members = [
"runtime/parachains",
"runtime/polkadot",
"runtime/kusama",
"runtime/rococo",
"runtime/westend",
"runtime/test-runtime",
"runtime/test-runtime/client",
......
......@@ -815,7 +815,7 @@ impl<T: Encode> EncodeAs<T> for T {
///
/// Note that the internal fields are not public; they are all accessable by immutable getters.
/// This reduces the chance that they are accidentally mutated, invalidating the signature.
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
pub struct Signed<Payload, RealPayload = Payload> {
/// The payload is part of the signed data. The rest is the signing context,
/// which is known both at signing and at validation.
......
......@@ -304,8 +304,7 @@ impl PoV {
}
/// A bitfield concerning availability of backed candidates.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct AvailabilityBitfield(pub BitVec<bitvec::order::Lsb0, u8>);
impl From<BitVec<bitvec::order::Lsb0, u8>> for AvailabilityBitfield {
......
......@@ -20,13 +20,16 @@
//! particular the `Initializer` module, as it is responsible for initializing the state
//! of the other modules.
mod configuration;
mod inclusion;
mod inclusion_inherent;
mod initializer;
mod paras;
mod scheduler;
mod validity;
#![cfg_attr(not(feature = "std"), no_std)]
pub mod configuration;
pub mod inclusion;
pub mod inclusion_inherent;
pub mod initializer;
pub mod paras;
pub mod scheduler;
pub mod validity;
pub mod runtime_api_impl;
......
......@@ -17,6 +17,7 @@
//! Runtimes implementing the v1 runtime API are recommended to forward directly to these
//! functions.
use sp_std::prelude::*;
use primitives::v1::{
ValidatorId, ValidatorIndex, GroupRotationInfo, CoreState, GlobalValidationData,
Id as ParaId, OccupiedCoreAssumption, LocalValidationData, SessionIndex, ValidationCode,
......@@ -239,9 +240,11 @@ pub fn candidate_pending_availability<T: initializer::Trait>(para_id: ParaId)
/// Implementation for the `candidate_events` function of the runtime API.
// NOTE: this runs without block initialization, as it accesses events.
// this means it can run in a different session than other runtime APIs at the same block.
pub fn candidate_events<T: initializer::Trait>(
extract_event: impl Fn(<T as system::Trait>::Event) -> Option<inclusion::Event<T>>,
) -> Vec<CandidateEvent<T::Hash>> {
pub fn candidate_events<T, F>(extract_event: F) -> Vec<CandidateEvent<T::Hash>>
where
T: initializer::Trait,
F: Fn(<T as system::Trait>::Event) -> Option<inclusion::Event<T>>,
{
use inclusion::Event as RawEvent;
<system::Module<T>>::events().into_iter()
......
[package]
name = "rococo-runtime"
version = "0.8.19"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
build = "build.rs"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
serde = { version = "1.0.102", default-features = false }
serde_derive = { version = "1.0.102", optional = true }
smallvec = "1.4.1"
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
version = { package = "sp-version", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
tx-pool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
block-builder-api = { package = "sp-block-builder", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
offchain-primitives = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
authority-discovery = { package = "pallet-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
authorship = { package = "pallet-authorship", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
session = { package = "pallet-session", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
im-online = { package = "pallet-im-online", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
indices = { package = "pallet-indices", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
transaction-payment = { package = "pallet-transaction-payment", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
transaction-payment-rpc-runtime-api = { package = "pallet-transaction-payment-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
staking = { package = "pallet-staking", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-staking-reward-curve = { package = "pallet-staking-reward-curve", git = "https://github.com/paritytech/substrate", branch = "master" }
executive = { package = "frame-executive", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
grandpa = { package = "pallet-grandpa", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
timestamp = { package = "pallet-timestamp", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
offences = { package = "pallet-offences", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
authority-discovery-primitives = { package = "sp-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
system = { package = "frame-system", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
system_rpc_runtime_api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "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 }
runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parachains", default-features = false }
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.6" }
[features]
default = ["std"]
no_std = []
std = [
"authority-discovery-primitives/std",
"authority-discovery/std",
"authorship/std",
"babe/std",
"babe-primitives/std",
"balances/std",
"codec/std",
"executive/std",
"grandpa/std",
"indices/std",
"im-online/std",
"inherents/std",
"frame-support/std",
"polkadot-parachain/std",
"primitives/std",
"runtime-common/std",
"runtime-parachains/std",
"session/std",
"sp-api/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
"sp-std/std",
"staking/std",
"system/std",
"system_rpc_runtime_api/std",
"offchain-primitives/std",
"offences/std",
"timestamp/std",
"transaction-payment/std",
"transaction-payment-rpc-runtime-api/std",
"block-builder-api/std",
"tx-pool-api/std",
"version/std",
"serde_derive",
"serde/std",
]
# When enabled, the runtime api will not be build.
#
# This is required by Cumulus to access certain types of the
# runtime without clashing with the runtime api exported functions
# in WASM.
disable-runtime-api = []
// Copyright 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("2.0.0")
.import_memory()
.export_heap_base()
.build()
}
// 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/>.
/// Money matters.
pub mod currency {
use primitives::v0::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;
pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 1 * DOLLARS + (bytes as Balance) * 5 * MILLICENTS
}
}
/// Time and blocks.
pub mod time {
use primitives::v0::{Moment, BlockNumber};
pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 1 * HOURS;
// 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::v0::Balance;
use runtime_common::ExtrinsicBaseWeight;
use frame_support::weights::{
WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,
};
use smallvec::smallvec;
/// 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 WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Westend, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = super::currency::CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational_approximation(p % q, q),
coeff_integer: p / q,
}]
}
}
}
#[cfg(test)]
mod tests {
use frame_support::weights::WeightToFeePolynomial;
use runtime_common::{MaximumBlockWeight, ExtrinsicBaseWeight};
use super::fee::WeightToFee;
use super::currency::{CENTS, DOLLARS, MILLICENTS};
#[test]
// This function tests that the fee for `MaximumBlockWeight` of weight is correct
fn full_block_fee_is_correct() {
// A full block should cost 16 DOLLARS
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&MaximumBlockWeight::get());
let y = 16 * DOLLARS;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
#[test]
// This function tests that the fee for `ExtrinsicBaseWeight` of weight is correct
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
}
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment