Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Parachains-runtime #1505

Merged
merged 5 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"runtime/parachains",
"runtime/polkadot",
"runtime/kusama",
"runtime/rococo",
"runtime/westend",
"runtime/test-runtime",
"runtime/test-runtime/client",
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions primitives/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions runtime/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 14 additions & 1 deletion runtime/parachains/src/runtime_api_impl/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,34 @@
//! 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,
CommittedCandidateReceipt, ScheduledCore, OccupiedCore, CoreOccupied, CoreIndex,
GroupIndex, CandidateEvent,
};
use sp_runtime::traits::Zero;
use frame_support::debug;
use frame_support::{
debug,
traits::Get,
};
use crate::{initializer, inclusion, scheduler, configuration, paras};

/// Implementation for the `validators` function of the runtime API.
pub fn validators<T: initializer::Trait>() -> Vec<ValidatorId> {
<inclusion::Module<T>>::validators()
}

/// Interface to the persistent (stash) identities of the current validators.
pub struct ValidatorIdentities<T>(sp_std::marker::PhantomData<T>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Contributor Author

@montekki montekki Jul 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is used by impl attestations::Trait but since this runtime does not use them, this type is not used in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's too late in the evening, now I see what you mean


impl<T: session::Trait> Get<Vec<T::ValidatorId>> for ValidatorIdentities<T> {
fn get() -> Vec<T::ValidatorId> {
<session::Module<T>>::validators()
}
}

/// Implementation for the `validator_groups` function of the runtime API.
pub fn validator_groups<T: initializer::Trait>() -> (
Vec<Vec<ValidatorIndex>>,
Expand Down
110 changes: 110 additions & 0 deletions runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[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" }
randomness-collective-flip = { package = "pallet-randomness-collective-flip", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
executive = { package = "frame-executive", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
finality-tracker = { package = "pallet-finality-tracker", 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",
"finality-tracker/std",
"grandpa/std",
"indices/std",
"im-online/std",
"inherents/std",
"frame-support/std",
"polkadot-parachain/std",
"primitives/std",
"randomness-collective-flip/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 = []
26 changes: 26 additions & 0 deletions runtime/rococo/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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()
}
113 changes: 113 additions & 0 deletions runtime/rococo/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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);
}
}
Loading