Skip to content

Commit

Permalink
Fix constants stuff after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur authored and claravanstaden committed Feb 5, 2024
1 parent 2d08e1b commit 2fc3300
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 35 deletions.
1 change: 0 additions & 1 deletion relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ rustc-hex = { version = "2.1.0", default-features = false }
serde = { version = "1.0.195", default-features = false }
serde_derive = { version = "1.0.195", optional = true }
static_assertions = "1.1.0"
smallvec = "1.11.2"

authority-discovery-primitives = { package = "sp-authority-discovery", default-features = false , version = "25.0.0" }
babe-primitives = { package = "sp-consensus-babe", default-features = false , version = "0.31.0" }
Expand Down
2 changes: 1 addition & 1 deletion relay/kusama/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true
license.workspace = true

[dependencies]
smallvec = "1.11.2"
smallvec = "1.13.1"

frame-support = { default-features = false , version = "27.0.0" }
primitives = { package = "polkadot-primitives", default-features = false , version = "6.0.0" }
Expand Down
1 change: 0 additions & 1 deletion relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rustc-hex = { version = "2.1.0", default-features = false }
serde = { version = "1.0.195", default-features = false }
serde_derive = { version = "1.0.195", optional = true }
static_assertions = "1.1.0"
smallvec = "1.11.2"

authority-discovery-primitives = { package = "sp-authority-discovery", default-features = false , version = "25.0.0" }
babe-primitives = { package = "sp-consensus-babe", default-features = false , version = "0.31.0" }
Expand Down
2 changes: 1 addition & 1 deletion relay/polkadot/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true
license.workspace = true

[dependencies]
smallvec = "1.11.2"
smallvec = "1.13.1"

frame-support = { default-features = false , version = "27.0.0" }
primitives = { package = "polkadot-primitives", default-features = false , version = "6.0.0" }
Expand Down
8 changes: 4 additions & 4 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ impl_runtime_apis! {
// Relay/native token can be teleported between AH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
},
Parent.into(),
Expand All @@ -1338,7 +1338,7 @@ impl_runtime_apis! {
);
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
},
ParentThen(Parachain(random_para_id).into()).into(),
Expand All @@ -1352,12 +1352,12 @@ impl_runtime_apis! {
// (We don't care that Relay doesn't accept incoming unknown AH local asset)
let dest = Parent.into();

let fee_amount = EXISTENTIAL_DEPOSIT;
let fee_amount = ExistentialDeposit::get();
let fee_asset: MultiAsset = (MultiLocation::parent(), fee_amount).into();

let who = frame_benchmarking::whitelisted_caller();
// Give some multiple of the existential deposit
let balance = fee_amount + EXISTENTIAL_DEPOSIT * 1000;
let balance = fee_amount + ExistentialDeposit::get() * 1000;
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
&who, balance,
);
Expand Down
8 changes: 4 additions & 4 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ impl_runtime_apis! {
// Relay/native token can be teleported between AH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
},
Parent.into(),
Expand All @@ -1231,7 +1231,7 @@ impl_runtime_apis! {
);
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
},
ParentThen(Parachain(random_para_id).into()).into(),
Expand All @@ -1245,12 +1245,12 @@ impl_runtime_apis! {
// (We don't care that Relay doesn't accept incoming unknown AH local asset)
let dest = Parent.into();

let fee_amount = EXISTENTIAL_DEPOSIT;
let fee_amount = ExistentialDeposit::get();
let fee_asset: MultiAsset = (MultiLocation::parent(), fee_amount).into();

let who = frame_benchmarking::whitelisted_caller();
// Give some multiple of the existential deposit
let balance = fee_amount + EXISTENTIAL_DEPOSIT * 1000;
let balance = fee_amount + ExistentialDeposit::get() * 1000;
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
&who, balance,
);
Expand Down
2 changes: 1 addition & 1 deletion system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ impl_runtime_apis! {
// Relay/native token can be teleported between BH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
},
Parent.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ impl_runtime_apis! {
// Relay/native token can be teleported between BH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
},
Parent.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl_runtime_apis! {
// Relay/native token can be teleported between Collectives and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
fun: Fungible(ExistentialDeposit::get()),
id: Concrete(Parent.into())
}.into(),
Parent.into(),
Expand Down
2 changes: 1 addition & 1 deletion system-parachains/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition.workspace = true
license.workspace = true

[dependencies]
smallvec = "1.11.2"
smallvec = "1.13.1"

frame-support = { default-features = false , version = "27.0.0" }
kusama-runtime-constants = { path = "../../relay/kusama/constants", default-features = false}
Expand Down
14 changes: 11 additions & 3 deletions system-parachains/encointer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }
smallvec = "1.13.1"

# encointer deps
encointer-balances-tx-payment = { default-features = false, version = "3.0.2" }
Expand Down Expand Up @@ -88,10 +89,13 @@ cumulus-primitives-timestamp = { default-features = false, version = "0.4.0" }
cumulus-primitives-utility = { default-features = false, version = "0.4.0" }
parachain-info = { package = "staging-parachain-info", default-features = false, version = "0.4.0" }
parachains-common = { default-features = false, version = "4.0.0" }
system-parachains-constants = { path = "../constants", default-features = false }

# Used for runtime benchmarking

# TODO:(PR#137) - Encointer pallets do not have compatible `polkadot-sdk` versions with the rest,
# so we need to copy all the stuff from `system-parachains-constants`.
# system-parachains-constants = { path = "../constants", default-features = false }
polkadot-core-primitives = { default-features = false, version = "4.0.0"}
polkadot-primitives = { default-features = false , version = "4.0.0" }
kusama-runtime-constants = { path = "../../relay/kusama/constants", default-features = false}

[build-dependencies]
substrate-wasm-builder = { optional = true, version = "14.0.0" }
Expand Down Expand Up @@ -148,6 +152,7 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-try-runtime/std",
"kusama-runtime-constants/std",
"log/std",
"pallet-asset-tx-payment/std",
"pallet-aura/std",
Expand All @@ -174,6 +179,8 @@ std = [
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
"polkadot-core-primitives/std",
"polkadot-primitives/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand All @@ -187,6 +194,7 @@ std = [
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
# "system-parachains-constants/std",
"substrate-wasm-builder",
"xcm-builder/std",
"xcm-executor/std",
Expand Down
165 changes: 149 additions & 16 deletions system-parachains/encointer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ use sp_version::RuntimeVersion;
use system_parachains_constants::{
kusama::{consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
SLOT_DURATION,
};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use xcm::{
Expand All @@ -105,22 +106,6 @@ use xcm_executor::XcmExecutor;

/// A type to hold UTC unix epoch [ms]
pub type Moment = u64;
pub const ONE_DAY: Moment = 86_400_000;

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 12000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;

pub type AssetId = AssetIdOf<Runtime>;
pub type AssetBalance = AssetBalanceOf<Runtime>;
Expand Down Expand Up @@ -1022,3 +1007,151 @@ fn test_ed_is_one_tenth_of_relay() {
let encointer_ed = ExistentialDeposit::get();
assert_eq!(relay_ed / 10, encointer_ed);
}

// TODO:(PR#137) - encointer pallets does not have compatible `polkadot-sdk` versions,
// so we cannot easily reuse `system-parachains-constants` module.
mod system_parachains_constants {
use super::*;
use frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND;

/// This determines the average expected block time that we are targeting. Blocks will be
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
/// slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 12000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;

// Time is measured by 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;

/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
/// Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 0.5 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
polkadot_primitives::MAX_POV_SIZE as u64,
);

pub(crate) mod kusama {
/// Consensus-related.
pub mod consensus {
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
}

/// Constants relating to KSM.
pub mod currency {
use polkadot_core_primitives::Balance;

/// The default existential deposit for system chains. 1/10th of the Relay Chain's
/// existential deposit. Individual system parachains may modify this in special cases.
pub const SYSTEM_PARA_EXISTENTIAL_DEPOSIT: Balance =
kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10;

/// One "KSM" that a UI would show a user.
pub const UNITS: Balance = 1_000_000_000_000;
pub const QUID: Balance = UNITS / 30;
pub const CENTS: Balance = QUID / 100;
pub const MILLICENTS: Balance = CENTS / 1_000;

/// Deposit rate for stored data. 1/100th of the Relay Chain's deposit rate. `items` is
/// the number of keys in storage and `bytes` is the size of the value.
pub const fn system_para_deposit(items: u32, bytes: u32) -> Balance {
kusama_runtime_constants::currency::deposit(items, bytes) / 100
}
}

/// Constants related to Kusama fee payment.
pub mod fee {
use frame_support::{
pallet_prelude::Weight,
weights::{
constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
},
};
use polkadot_core_primitives::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

/// 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, MAXIMUM_BLOCK_WEIGHT]
/// - [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 frame_support::weights::WeightToFee for WeightToFee {
type Balance = Balance;

fn weight_to_fee(weight: &Weight) -> Self::Balance {
let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();

// Take the maximum instead of the sum to charge by the more scarce resource.
time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
}
}

/// Maps the reference time component of `Weight` to a fee.
pub struct RefTimeToFee;

impl WeightToFeePolynomial for RefTimeToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// In Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10
// CENT: The standard system parachain configuration is 1/10 of that, as in
// 1/100 CENT.
let p = super::currency::CENTS;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());

smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}

/// Maps the proof size component of `Weight` to a fee.
pub struct ProofSizeToFee;

impl WeightToFeePolynomial for ProofSizeToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// Map 10kb proof to 1 CENT.
let p = super::currency::CENTS;
let q = 10_000;

smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
}
}
}

0 comments on commit 2fc3300

Please sign in to comment.