This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Parachains-runtime #1505
Merged
+1,036
−13
Merged
Parachains-runtime #1505
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
There was a problem hiding this comment.
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 PRThere was a problem hiding this comment.
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