mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Move Relay-Specific Shared Code to One Place (#1193)
* add common libs * asset hubs * add westend * bridge hubs * collectives * contracts * emulated tests * parachain bin * delete collectives constants and update docs * integration tests should have apache license (some missing, some needed changing) * propagate features * fmt
This commit is contained in:
@@ -1,136 +0,0 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub mod account {
|
||||
use frame_support::PalletId;
|
||||
|
||||
/// Polkadot treasury pallet id, used to convert into AccountId
|
||||
pub const POLKADOT_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");
|
||||
/// Alliance pallet ID.
|
||||
/// It is used as a temporarily place to deposit a slashed imbalance
|
||||
/// before the teleport to the Treasury.
|
||||
pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia");
|
||||
/// Referenda pallet ID.
|
||||
/// It is used as a temporarily place to deposit a slashed imbalance
|
||||
/// before the teleport to the Treasury.
|
||||
pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer");
|
||||
}
|
||||
|
||||
pub mod currency {
|
||||
use polkadot_core_primitives::Balance;
|
||||
use polkadot_runtime_constants as constants;
|
||||
|
||||
/// The existential deposit. Set to 1/10 of its parent Relay Chain.
|
||||
pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10;
|
||||
|
||||
pub const UNITS: Balance = constants::currency::UNITS;
|
||||
pub const DOLLARS: Balance = constants::currency::DOLLARS;
|
||||
pub const CENTS: Balance = constants::currency::CENTS;
|
||||
pub const MILLICENTS: Balance = constants::currency::MILLICENTS;
|
||||
|
||||
pub const fn deposit(items: u32, bytes: u32) -> Balance {
|
||||
// 1/100 of Polkadot.
|
||||
constants::currency::deposit(items, bytes) / 100
|
||||
}
|
||||
}
|
||||
|
||||
/// Fee-related.
|
||||
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;
|
||||
|
||||
/// 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, 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 Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
|
||||
// in a parachain, we map to 1/10 of that, or 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,
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ pub(crate) mod migration;
|
||||
mod origins;
|
||||
mod tracks;
|
||||
use crate::{
|
||||
constants, impls::ToParentTreasury, weights, AccountId, Balance, Balances, FellowshipReferenda,
|
||||
impls::ToParentTreasury, weights, AccountId, Balance, Balances, FellowshipReferenda,
|
||||
GovernanceLocation, PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent,
|
||||
RuntimeOrigin, Scheduler, DAYS,
|
||||
};
|
||||
@@ -36,6 +36,7 @@ pub use origins::{
|
||||
};
|
||||
use pallet_ranked_collective::EnsureOfRank;
|
||||
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
|
||||
use parachains_common::polkadot::account;
|
||||
use polkadot_runtime_constants::{time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX};
|
||||
use sp_core::{ConstU128, ConstU32};
|
||||
use sp_runtime::traits::{AccountIdConversion, ConstU16, ConvertToValue, Replace, TakeFirst};
|
||||
@@ -62,7 +63,7 @@ pub mod ranks {
|
||||
|
||||
parameter_types! {
|
||||
// Referenda pallet account, used to temporarily deposit slashed imbalance before teleporting.
|
||||
pub ReferendaPalletAccount: AccountId = constants::account::REFERENDA_PALLET_ID.into_account_truncating();
|
||||
pub ReferendaPalletAccount: AccountId = account::REFERENDA_PALLET_ID.into_account_truncating();
|
||||
pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
pub mod constants;
|
||||
pub mod impls;
|
||||
mod weights;
|
||||
pub mod xcm_config;
|
||||
@@ -64,7 +63,6 @@ use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use constants::{consensus::*, currency::*, fee::WeightToFee};
|
||||
use frame_support::{
|
||||
construct_runtime,
|
||||
dispatch::DispatchClass,
|
||||
@@ -79,7 +77,9 @@ use frame_system::{
|
||||
};
|
||||
pub use parachains_common as common;
|
||||
use parachains_common::{
|
||||
impls::DealWithFees, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature,
|
||||
impls::DealWithFees,
|
||||
polkadot::{account::*, consensus::*, currency::*, fee::WeightToFee},
|
||||
AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature,
|
||||
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO,
|
||||
SLOT_DURATION,
|
||||
};
|
||||
@@ -484,8 +484,8 @@ parameter_types! {
|
||||
pub const AllyDeposit: Balance = 1_000 * UNITS; // 1,000 DOT bond to join as an Ally
|
||||
// The Alliance pallet account, used as a temporary place to deposit a slashed imbalance
|
||||
// before the teleport to the Treasury.
|
||||
pub AlliancePalletAccount: AccountId = constants::account::ALLIANCE_PALLET_ID.into_account_truncating();
|
||||
pub PolkadotTreasuryAccount: AccountId = constants::account::POLKADOT_TREASURY_PALLET_ID.into_account_truncating();
|
||||
pub AlliancePalletAccount: AccountId = ALLIANCE_PALLET_ID.into_account_truncating();
|
||||
pub PolkadotTreasuryAccount: AccountId = POLKADOT_TREASURY_PALLET_ID.into_account_truncating();
|
||||
// The number of blocks a member must wait between giving a retirement notice and retiring.
|
||||
// Supposed to be greater than time required to `kick_member` with alliance motion.
|
||||
pub const AllianceRetirementPeriod: BlockNumber = (90 * DAYS) + ALLIANCE_MOTION_DURATION;
|
||||
|
||||
Reference in New Issue
Block a user