git.delta.rocks / unique-network / refs/commits / e04c397d4e37

difftreelog

source

runtime/common/config/substrate.rs8.4 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	traits::{Everything, ConstU32},19	weights::{20		constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},21		DispatchClass, WeightToFeePolynomial, WeightToFeeCoefficients,22		ConstantMultiplier, WeightToFeeCoefficient,23	},24	parameter_types,25	PalletId,26};27use sp_runtime::{28	generic,29	traits::{BlakeTwo256, AccountIdLookup},30	Perbill, Permill, Percent,31};32use frame_system::{33	limits::{BlockLength, BlockWeights},34	EnsureRoot,35};36use sp_arithmetic::traits::{BaseArithmetic, Unsigned};37use smallvec::smallvec;38use crate::{39    runtime_common::{40        DealWithFees,41        constants::*,42    },43	Runtime,44	Event,45	Call,46	Origin,47	PalletInfo,48	System,49	Balances,50	Treasury,51	SS58Prefix,52	Version,53};54use common_types::*;5556parameter_types! {57	pub const BlockHashCount: BlockNumber = 2400;58	pub RuntimeBlockLength: BlockLength =59		BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);60	pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);61	pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;62	pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()63		.base_block(BlockExecutionWeight::get())64		.for_class(DispatchClass::all(), |weights| {65			weights.base_extrinsic = ExtrinsicBaseWeight::get();66		})67		.for_class(DispatchClass::Normal, |weights| {68			weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);69		})70		.for_class(DispatchClass::Operational, |weights| {71			weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);72			// Operational transactions have some extra reserved space, so that they73			// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.74			weights.reserved = Some(75				MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT76			);77		})78		.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)79		.build_or_panic();80}8182impl frame_system::Config for Runtime {83	/// The data to be stored in an account.84	type AccountData = pallet_balances::AccountData<Balance>;85	/// The identifier used to distinguish between accounts.86	type AccountId = AccountId;87	/// The basic call filter to use in dispatchable.88	type BaseCallFilter = Everything;89	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).90	type BlockHashCount = BlockHashCount;91	/// The maximum length of a block (in bytes).92	type BlockLength = RuntimeBlockLength;93	/// The index type for blocks.94	type BlockNumber = BlockNumber;95	/// The weight of the overhead invoked on the block import process, independent of the extrinsics included in that block.96	type BlockWeights = RuntimeBlockWeights;97	/// The aggregated dispatch type that is available for extrinsics.98	type Call = Call;99	/// The weight of database operations that the runtime can invoke.100	type DbWeight = RocksDbWeight;101	/// The ubiquitous event type.102	type Event = Event;103	/// The type for hashing blocks and tries.104	type Hash = Hash;105	/// The hashing algorithm used.106	type Hashing = BlakeTwo256;107	/// The header type.108	type Header = generic::Header<BlockNumber, BlakeTwo256>;109	/// The index type for storing how many extrinsics an account has signed.110	type Index = Index;111	/// The lookup mechanism to get account ID from whatever is passed in dispatchers.112	type Lookup = AccountIdLookup<AccountId, ()>;113	/// What to do if an account is fully reaped from the system.114	type OnKilledAccount = ();115	/// What to do if a new account is created.116	type OnNewAccount = ();117	type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;118	/// The ubiquitous origin type.119	type Origin = Origin;120	/// This type is being generated by `construct_runtime!`.121	type PalletInfo = PalletInfo;122	/// This is used as an identifier of the chain. 42 is the generic substrate prefix.123	type SS58Prefix = SS58Prefix;124	/// Weight information for the extrinsics of this pallet.125	type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;126	/// Version of the runtime.127	type Version = Version;128	type MaxConsumers = ConstU32<16>;129}130131impl pallet_randomness_collective_flip::Config for Runtime {}132133parameter_types! {134	pub const MinimumPeriod: u64 = SLOT_DURATION / 2;135}136137impl pallet_timestamp::Config for Runtime {138	/// A timestamp: milliseconds since the unix epoch.139	type Moment = u64;140	type OnTimestampSet = ();141	type MinimumPeriod = MinimumPeriod;142	type WeightInfo = ();143}144145parameter_types! {146	// pub const ExistentialDeposit: u128 = 500;147	pub const ExistentialDeposit: u128 = 0;148	pub const MaxLocks: u32 = 50;149	pub const MaxReserves: u32 = 50;150}151152impl pallet_balances::Config for Runtime {153	type MaxLocks = MaxLocks;154	type MaxReserves = MaxReserves;155	type ReserveIdentifier = [u8; 16];156	/// The type for recording an account's balance.157	type Balance = Balance;158	/// The ubiquitous event type.159	type Event = Event;160	type DustRemoval = Treasury;161	type ExistentialDeposit = ExistentialDeposit;162	type AccountStore = System;163	type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;164}165166parameter_types! {167	/// This value increases the priority of `Operational` transactions by adding168	/// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.169	pub const OperationalFeeMultiplier: u8 = 5;170}171172/// Linear implementor of `WeightToFeePolynomial`173pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);174175impl<T> WeightToFeePolynomial for LinearFee<T>176where177	T: BaseArithmetic + From<u32> + Copy + Unsigned,178{179	type Balance = T;180181	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {182		smallvec!(WeightToFeeCoefficient {183			coeff_integer: WEIGHT_TO_FEE_COEFF.into(),184			coeff_frac: Perbill::zero(),185			negative: false,186			degree: 1,187		})188	}189}190191impl pallet_transaction_payment::Config for Runtime {192	type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;193	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;194	type OperationalFeeMultiplier = OperationalFeeMultiplier;195	type WeightToFee = LinearFee<Balance>;196	type FeeMultiplierUpdate = ();197}198199parameter_types! {200	pub const ProposalBond: Permill = Permill::from_percent(5);201	pub const ProposalBondMinimum: Balance = 1 * UNIQUE;202	pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;203	pub const SpendPeriod: BlockNumber = 5 * MINUTES;204	pub const Burn: Permill = Permill::from_percent(0);205	pub const TipCountdown: BlockNumber = 1 * DAYS;206	pub const TipFindersFee: Percent = Percent::from_percent(20);207	pub const TipReportDepositBase: Balance = 1 * UNIQUE;208	pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;209	pub const BountyDepositBase: Balance = 1 * UNIQUE;210	pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;211	pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");212	pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;213	pub const MaximumReasonLength: u32 = 16384;214	pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);215	pub const BountyValueMinimum: Balance = 5 * UNIQUE;216	pub const MaxApprovals: u32 = 100;217}218219impl pallet_treasury::Config for Runtime {220	type PalletId = TreasuryModuleId;221	type Currency = Balances;222	type ApproveOrigin = EnsureRoot<AccountId>;223	type RejectOrigin = EnsureRoot<AccountId>;224	type Event = Event;225	type OnSlash = ();226	type ProposalBond = ProposalBond;227	type ProposalBondMinimum = ProposalBondMinimum;228	type ProposalBondMaximum = ProposalBondMaximum;229	type SpendPeriod = SpendPeriod;230	type Burn = Burn;231	type BurnDestination = ();232	type SpendFunds = ();233	type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;234	type MaxApprovals = MaxApprovals;235}236237impl pallet_sudo::Config for Runtime {238	type Event = Event;239	type Call = Call;240}241242parameter_types! {243	pub const MaxAuthorities: u32 = 100_000;244}245246impl pallet_aura::Config for Runtime {247	type AuthorityId = AuraId;248	type DisabledValidators = ();249	type MaxAuthorities = MaxAuthorities;250}