mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-05-09 21:27:54 +00:00
Transition into monorepo (#180)
* evm template integrated * workflows modified per template * workflow fixes
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
pub mod currency {
|
||||
use crate::Balance;
|
||||
|
||||
pub const MICROCENTS: Balance = 1_000_000;
|
||||
pub const MILLICENTS: Balance = 1_000_000_000;
|
||||
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
|
||||
pub const DOLLARS: Balance = 100 * CENTS;
|
||||
pub const GRAND: Balance = 1_000 * DOLLARS;
|
||||
|
||||
pub const EXISTENTIAL_DEPOSIT: Balance = 0;
|
||||
|
||||
pub const fn deposit(items: u32, bytes: u32) -> Balance {
|
||||
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
//! OpenGov governance config
|
||||
|
||||
pub mod origins;
|
||||
pub use origins::{
|
||||
pallet_custom_origins, ReferendumCanceller, ReferendumKiller, Spender, Treasurer,
|
||||
WhitelistedCaller,
|
||||
};
|
||||
mod tracks;
|
||||
|
||||
use frame_support::traits::EitherOf;
|
||||
use frame_system::EnsureRootWithSuccess;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
constants::currency::{CENTS, GRAND},
|
||||
Balance,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
|
||||
}
|
||||
|
||||
impl pallet_conviction_voting::Config for Runtime {
|
||||
type Currency = Balances;
|
||||
type MaxTurnout =
|
||||
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
|
||||
type MaxVotes = ConstU32<512>;
|
||||
type Polls = Referenda;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type VoteLockingPeriod = VoteLockingPeriod;
|
||||
type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxBalance: Balance = Balance::max_value();
|
||||
}
|
||||
pub type TreasurySpender = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, Spender>;
|
||||
|
||||
impl origins::pallet_custom_origins::Config for Runtime {}
|
||||
|
||||
impl pallet_whitelist::Config for Runtime {
|
||||
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
|
||||
type Preimages = Preimage;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
|
||||
type WhitelistOrigin = EnsureRoot<Self::AccountId>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AlarmInterval: BlockNumber = 1;
|
||||
pub const SubmissionDeposit: Balance = 3 * CENTS;
|
||||
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
|
||||
}
|
||||
|
||||
impl pallet_referenda::Config for Runtime {
|
||||
type AlarmInterval = AlarmInterval;
|
||||
type CancelOrigin = EnsureRoot<AccountId>;
|
||||
type Currency = Balances;
|
||||
type KillOrigin = EnsureRoot<AccountId>;
|
||||
type MaxQueued = ConstU32<20>;
|
||||
type Preimages = Preimage;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Scheduler = Scheduler;
|
||||
type Slash = Treasury;
|
||||
type SubmissionDeposit = SubmissionDeposit;
|
||||
type SubmitOrigin = EnsureSigned<AccountId>;
|
||||
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
|
||||
type Tracks = tracks::TracksInfo;
|
||||
type UndecidingTimeout = UndecidingTimeout;
|
||||
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
|
||||
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
//! Custom origins for governance interventions.
|
||||
|
||||
pub use pallet_custom_origins::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet_custom_origins {
|
||||
use frame_support::pallet_prelude::*;
|
||||
|
||||
use crate::governance::{Balance, CENTS, GRAND};
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
|
||||
#[pallet::origin]
|
||||
pub enum Origin {
|
||||
/// Origin for spending (any amount of) funds.
|
||||
Treasurer,
|
||||
/// Origin able to cancel referenda.
|
||||
ReferendumCanceller,
|
||||
/// Origin able to kill referenda.
|
||||
ReferendumKiller,
|
||||
/// Origin able to spend the amount specified in Spender.
|
||||
SmallTipper,
|
||||
/// Origin able to spend the amount specified in Spender.
|
||||
BigTipper,
|
||||
/// Origin able to spend the amount specified in Spender.
|
||||
SmallSpender,
|
||||
/// Origin able to spend the amount specified in Spender.
|
||||
MediumSpender,
|
||||
/// Origin able to spend the amount specified in Spender.
|
||||
BigSpender,
|
||||
/// Origin able to dispatch a whitelisted call.
|
||||
WhitelistedCaller,
|
||||
}
|
||||
|
||||
macro_rules! decl_unit_ensures {
|
||||
( $name:ident: $success_type:ty = $success:expr ) => {
|
||||
pub struct $name;
|
||||
impl<O: Into<Result<Origin, O>> + From<Origin>>
|
||||
EnsureOrigin<O> for $name
|
||||
{
|
||||
type Success = $success_type;
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
o.into().and_then(|o| match o {
|
||||
Origin::$name => Ok($success),
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin() -> Result<O, ()> {
|
||||
Ok(O::from(Origin::$name))
|
||||
}
|
||||
}
|
||||
};
|
||||
( $name:ident ) => { decl_unit_ensures! { $name : () = () } };
|
||||
( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => {
|
||||
decl_unit_ensures! { $name: $success_type = $success }
|
||||
decl_unit_ensures! { $( $rest )* }
|
||||
};
|
||||
( $name:ident, $( $rest:tt )* ) => {
|
||||
decl_unit_ensures! { $name }
|
||||
decl_unit_ensures! { $( $rest )* }
|
||||
};
|
||||
() => {}
|
||||
}
|
||||
decl_unit_ensures!(Treasurer, ReferendumCanceller, ReferendumKiller, WhitelistedCaller,);
|
||||
|
||||
macro_rules! decl_ensure {
|
||||
(
|
||||
$vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
|
||||
$( $item:ident = $success:expr, )*
|
||||
}
|
||||
) => {
|
||||
$vis struct $name;
|
||||
impl<O: Into<Result<Origin, O>> + From<Origin>>
|
||||
EnsureOrigin<O> for $name
|
||||
{
|
||||
type Success = $success_type;
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
o.into().and_then(|o| match o {
|
||||
$(
|
||||
Origin::$item => Ok($success),
|
||||
)*
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin() -> Result<O, ()> {
|
||||
// By convention the more privileged origins go later, so for greatest chance
|
||||
// of success, we want the last one.
|
||||
let _result: Result<O, ()> = Err(());
|
||||
$(
|
||||
let _result: Result<O, ()> = Ok(O::from(Origin::$item));
|
||||
)*
|
||||
_result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_ensure! {
|
||||
pub type Spender: EnsureOrigin<Success = Balance> {
|
||||
SmallTipper = 250 * 3 * CENTS,
|
||||
BigTipper = GRAND,
|
||||
SmallSpender = 10 * GRAND,
|
||||
MediumSpender = 100 * GRAND,
|
||||
BigSpender = 1_000 * GRAND,
|
||||
Treasurer = 10_000 * GRAND,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
//! Track configurations for governance.
|
||||
|
||||
use super::*;
|
||||
|
||||
const fn percent(x: i32) -> sp_arithmetic::FixedI64 {
|
||||
sp_arithmetic::FixedI64::from_rational(x as u128, 100)
|
||||
}
|
||||
use pallet_referenda::Curve;
|
||||
const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
|
||||
const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
|
||||
const APP_TREASURER: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
|
||||
const SUP_TREASURER: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
|
||||
const APP_REFERENDUM_CANCELLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_REFERENDUM_CANCELLER: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_REFERENDUM_KILLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_REFERENDUM_KILLER: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_SMALL_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
|
||||
const SUP_SMALL_TIPPER: Curve = Curve::make_reciprocal(1, 28, percent(4), percent(0), percent(50));
|
||||
const APP_BIG_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
|
||||
const SUP_BIG_TIPPER: Curve = Curve::make_reciprocal(8, 28, percent(1), percent(0), percent(50));
|
||||
const APP_SMALL_SPENDER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_SMALL_SPENDER: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_MEDIUM_SPENDER: Curve = Curve::make_linear(23, 28, percent(50), percent(100));
|
||||
const SUP_MEDIUM_SPENDER: Curve =
|
||||
Curve::make_reciprocal(16, 28, percent(1), percent(0), percent(50));
|
||||
const APP_BIG_SPENDER: Curve = Curve::make_linear(28, 28, percent(50), percent(100));
|
||||
const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percent(0), percent(50));
|
||||
const APP_WHITELISTED_CALLER: Curve =
|
||||
Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100));
|
||||
const SUP_WHITELISTED_CALLER: Curve =
|
||||
Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50));
|
||||
|
||||
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 10] = [
|
||||
(
|
||||
0,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "root",
|
||||
max_deciding: 1,
|
||||
decision_deposit: 100 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 12 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_ROOT,
|
||||
min_support: SUP_ROOT,
|
||||
},
|
||||
),
|
||||
(
|
||||
1,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "whitelisted_caller",
|
||||
max_deciding: 100,
|
||||
decision_deposit: 10 * GRAND,
|
||||
prepare_period: 6 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 4 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_WHITELISTED_CALLER,
|
||||
min_support: SUP_WHITELISTED_CALLER,
|
||||
},
|
||||
),
|
||||
(
|
||||
11,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "treasurer",
|
||||
max_deciding: 10,
|
||||
decision_deposit: GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_TREASURER,
|
||||
min_support: SUP_TREASURER,
|
||||
},
|
||||
),
|
||||
(
|
||||
20,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "referendum_canceller",
|
||||
max_deciding: 1_000,
|
||||
decision_deposit: 10 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 14 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_REFERENDUM_CANCELLER,
|
||||
min_support: SUP_REFERENDUM_CANCELLER,
|
||||
},
|
||||
),
|
||||
(
|
||||
21,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "referendum_killer",
|
||||
max_deciding: 1_000,
|
||||
decision_deposit: 50 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_REFERENDUM_KILLER,
|
||||
min_support: SUP_REFERENDUM_KILLER,
|
||||
},
|
||||
),
|
||||
(
|
||||
30,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "small_tipper",
|
||||
max_deciding: 200,
|
||||
decision_deposit: 3 * CENTS,
|
||||
prepare_period: MINUTES,
|
||||
decision_period: 14 * MINUTES,
|
||||
confirm_period: 4 * MINUTES,
|
||||
min_enactment_period: MINUTES,
|
||||
min_approval: APP_SMALL_TIPPER,
|
||||
min_support: SUP_SMALL_TIPPER,
|
||||
},
|
||||
),
|
||||
(
|
||||
31,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "big_tipper",
|
||||
max_deciding: 100,
|
||||
decision_deposit: 10 * 3 * CENTS,
|
||||
prepare_period: 4 * MINUTES,
|
||||
decision_period: 14 * MINUTES,
|
||||
confirm_period: 12 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_BIG_TIPPER,
|
||||
min_support: SUP_BIG_TIPPER,
|
||||
},
|
||||
),
|
||||
(
|
||||
32,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "small_spender",
|
||||
max_deciding: 50,
|
||||
decision_deposit: 100 * 3 * CENTS,
|
||||
prepare_period: 10 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 10 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_SMALL_SPENDER,
|
||||
min_support: SUP_SMALL_SPENDER,
|
||||
},
|
||||
),
|
||||
(
|
||||
33,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "medium_spender",
|
||||
max_deciding: 50,
|
||||
decision_deposit: 200 * 3 * CENTS,
|
||||
prepare_period: 10 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 12 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_MEDIUM_SPENDER,
|
||||
min_support: SUP_MEDIUM_SPENDER,
|
||||
},
|
||||
),
|
||||
(
|
||||
34,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "big_spender",
|
||||
max_deciding: 50,
|
||||
decision_deposit: 400 * 3 * CENTS,
|
||||
prepare_period: 10 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 14 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_BIG_SPENDER,
|
||||
min_support: SUP_BIG_SPENDER,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
pub struct TracksInfo;
|
||||
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
|
||||
type Id = u16;
|
||||
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
|
||||
|
||||
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
|
||||
&TRACKS_DATA[..]
|
||||
}
|
||||
|
||||
fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
|
||||
if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
|
||||
match system_origin {
|
||||
frame_system::RawOrigin::Root => Ok(0),
|
||||
_ => Err(()),
|
||||
}
|
||||
} else if let Ok(custom_origin) = origins::Origin::try_from(id.clone()) {
|
||||
match custom_origin {
|
||||
origins::Origin::WhitelistedCaller => Ok(1),
|
||||
origins::Origin::Treasurer => Ok(11),
|
||||
// Referendum admins
|
||||
origins::Origin::ReferendumCanceller => Ok(20),
|
||||
origins::Origin::ReferendumKiller => Ok(21),
|
||||
// Limited treasury spenders
|
||||
origins::Origin::SmallTipper => Ok(30),
|
||||
origins::Origin::BigTipper => Ok(31),
|
||||
origins::Origin::SmallSpender => Ok(32),
|
||||
origins::Origin::MediumSpender => Ok(33),
|
||||
origins::Origin::BigSpender => Ok(34),
|
||||
}
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// 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 constants {
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
weights::{constants, Weight},
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
/// Importing a block with 0 Extrinsics.
|
||||
pub const BlockExecutionWeight: Weight =
|
||||
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_weights {
|
||||
use frame_support::weights::constants;
|
||||
|
||||
/// Checks that the weight exists and is sane.
|
||||
// NOTE: If this test fails but you are sure that the generated values are fine,
|
||||
// you can delete it.
|
||||
#[test]
|
||||
fn sane() {
|
||||
let w = super::constants::BlockExecutionWeight::get();
|
||||
|
||||
// At least 100 µs.
|
||||
assert!(
|
||||
w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
|
||||
"Weight should be at least 100 µs."
|
||||
);
|
||||
// At most 50 ms.
|
||||
assert!(
|
||||
w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS,
|
||||
"Weight should be at most 50 ms."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// 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 constants {
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
weights::{constants, Weight},
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
/// Executing a NO-OP `System::remarks` Extrinsic.
|
||||
pub const ExtrinsicBaseWeight: Weight =
|
||||
Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_weights {
|
||||
use frame_support::weights::constants;
|
||||
|
||||
/// Checks that the weight exists and is sane.
|
||||
// NOTE: If this test fails but you are sure that the generated values are fine,
|
||||
// you can delete it.
|
||||
#[test]
|
||||
fn sane() {
|
||||
let w = super::constants::ExtrinsicBaseWeight::get();
|
||||
|
||||
// At least 10 µs.
|
||||
assert!(
|
||||
w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
|
||||
"Weight should be at least 10 µs."
|
||||
);
|
||||
// At most 1 ms.
|
||||
assert!(
|
||||
w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
|
||||
"Weight should be at most 1 ms."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// 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.
|
||||
|
||||
//! Expose the auto generated weight files.
|
||||
|
||||
pub mod block_weights;
|
||||
pub mod extrinsic_weights;
|
||||
pub mod paritydb_weights;
|
||||
pub mod rocksdb_weights;
|
||||
|
||||
pub use block_weights::constants::BlockExecutionWeight;
|
||||
pub use extrinsic_weights::constants::ExtrinsicBaseWeight;
|
||||
pub use rocksdb_weights::constants::RocksDbWeight;
|
||||
@@ -0,0 +1,64 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// 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 constants {
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
weights::{constants, RuntimeDbWeight},
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
/// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights
|
||||
/// are available for brave runtime engineers who may want to try this out as default.
|
||||
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
|
||||
read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
|
||||
write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_db_weights {
|
||||
use frame_support::weights::constants;
|
||||
|
||||
use super::constants::ParityDbWeight as W;
|
||||
|
||||
/// Checks that all weights exist and have sane values.
|
||||
// NOTE: If this test fails but you are sure that the generated values are fine,
|
||||
// you can delete it.
|
||||
#[test]
|
||||
fn sane() {
|
||||
// At least 1 µs.
|
||||
assert!(
|
||||
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
|
||||
"Read weight should be at least 1 µs."
|
||||
);
|
||||
assert!(
|
||||
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
|
||||
"Write weight should be at least 1 µs."
|
||||
);
|
||||
// At most 1 ms.
|
||||
assert!(
|
||||
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
|
||||
"Read weight should be at most 1 ms."
|
||||
);
|
||||
assert!(
|
||||
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
|
||||
"Write weight should be at most 1 ms."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// 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 constants {
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
weights::{constants, RuntimeDbWeight},
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
/// By default, Substrate uses `RocksDB`, so this will be the weight used throughout
|
||||
/// the runtime.
|
||||
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
|
||||
read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
|
||||
write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_db_weights {
|
||||
use frame_support::weights::constants;
|
||||
|
||||
use super::constants::RocksDbWeight as W;
|
||||
|
||||
/// Checks that all weights exist and have sane values.
|
||||
// NOTE: If this test fails but you are sure that the generated values are fine,
|
||||
// you can delete it.
|
||||
#[test]
|
||||
fn sane() {
|
||||
// At least 1 µs.
|
||||
assert!(
|
||||
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
|
||||
"Read weight should be at least 1 µs."
|
||||
);
|
||||
assert!(
|
||||
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
|
||||
"Write weight should be at least 1 µs."
|
||||
);
|
||||
// At most 1 ms.
|
||||
assert!(
|
||||
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
|
||||
"Read weight should be at most 1 ms."
|
||||
);
|
||||
assert!(
|
||||
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
|
||||
"Write weight should be at most 1 ms."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
use pallet_xcm::XcmPassthrough;
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
|
||||
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
|
||||
FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, NativeAsset,
|
||||
NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
|
||||
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
|
||||
TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
|
||||
};
|
||||
use xcm_executor::XcmExecutor;
|
||||
|
||||
use super::{
|
||||
AccountId, AllPalletsWithSystem, Assets, Balance, Balances, ParachainInfo, ParachainSystem,
|
||||
PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: Location = Location::parent();
|
||||
pub const RelayNetwork: Option<NetworkId> = None;
|
||||
pub PlaceholderAccount: AccountId = PolkadotXcm::check_account();
|
||||
pub AssetsPalletLocation: Location =
|
||||
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
|
||||
}
|
||||
|
||||
/// `AssetId/Balancer` converter for `TrustBackedAssets`
|
||||
pub type TrustBackedAssetsConvertedConcreteId =
|
||||
assets_common::TrustBackedAssetsConvertedConcreteId<AssetsPalletLocation, Balance>;
|
||||
|
||||
/// Type for specifying how a `Location` can be converted into an
|
||||
/// `AccountId`. This is used when determining ownership of accounts for asset
|
||||
/// transacting and when attempting to use XCM `Transact` in order to determine
|
||||
/// the dispatch Origin.
|
||||
pub type LocationToAccountId = (
|
||||
// The parent (Relay-chain) origin converts to the parent `AccountId`.
|
||||
ParentIsPreset<AccountId>,
|
||||
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
|
||||
SiblingParachainConvertsVia<Sibling, AccountId>,
|
||||
// If we receive a Location of type AccountKey20, just generate a native account
|
||||
AccountKey20Aliases<RelayNetwork, AccountId>,
|
||||
);
|
||||
|
||||
/// Means for transacting assets on this chain.
|
||||
pub type LocalAssetTransactor = FungibleAdapter<
|
||||
// Use this currency:
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<RelayLocation>,
|
||||
// Do a simple punn to convert an AccountId20 Location into a native chain account ID:
|
||||
LocationToAccountId,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
// We don't track any teleports.
|
||||
(),
|
||||
>;
|
||||
|
||||
/// Means for transacting assets besides the native currency on this chain.
|
||||
pub type LocalFungiblesTransactor = FungiblesAdapter<
|
||||
// Use this fungibles implementation:
|
||||
Assets,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
TrustBackedAssetsConvertedConcreteId,
|
||||
// Convert an XCM MultiLocation into a local account id:
|
||||
LocationToAccountId,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
// We don't track any teleports of `Assets`.
|
||||
NoChecking,
|
||||
// We don't track any teleports of `Assets`, but a placeholder account is provided due to trait
|
||||
// bounds.
|
||||
PlaceholderAccount,
|
||||
>;
|
||||
|
||||
/// Means for transacting assets on this chain.
|
||||
pub type AssetTransactors = (LocalAssetTransactor, LocalFungiblesTransactor);
|
||||
|
||||
/// This is the type we use to convert an (incoming) XCM origin into a local
|
||||
/// `Origin` instance, ready for dispatching a transaction with Xcm's
|
||||
/// `Transact`. There is an `OriginKind` which can biases the kind of local
|
||||
/// `Origin` it will become.
|
||||
pub type XcmOriginToTransactDispatchOrigin = (
|
||||
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
|
||||
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
|
||||
// foreign chains who want to have a local sovereign account on this chain which they control.
|
||||
SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
|
||||
// Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when
|
||||
// recognized.
|
||||
RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
|
||||
// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
|
||||
// recognized.
|
||||
SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
|
||||
// Xcm Origins defined by a Multilocation of type AccountKey20 can be converted to a 20 byte-
|
||||
// account local origin
|
||||
SignedAccountKey20AsNative<RelayNetwork, RuntimeOrigin>,
|
||||
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
|
||||
XcmPassthrough<RuntimeOrigin>,
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
|
||||
pub const UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
}
|
||||
|
||||
pub struct ParentOrParentsExecutivePlurality;
|
||||
impl Contains<Location> for ParentOrParentsExecutivePlurality {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
|
||||
}
|
||||
}
|
||||
|
||||
pub type Barrier = TrailingSetTopicAsId<
|
||||
DenyThenTry<
|
||||
DenyReserveTransferToRelayChain,
|
||||
(
|
||||
TakeWeightCredit,
|
||||
WithComputedOrigin<
|
||||
(
|
||||
AllowTopLevelPaidExecutionFrom<Everything>,
|
||||
AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
|
||||
// ^^^ Parent and its exec plurality get free execution
|
||||
),
|
||||
UniversalLocation,
|
||||
ConstU32<8>,
|
||||
>,
|
||||
),
|
||||
>,
|
||||
>;
|
||||
|
||||
pub struct XcmConfig;
|
||||
impl xcm_executor::Config for XcmConfig {
|
||||
type Aliasers = Nothing;
|
||||
type AssetClaims = PolkadotXcm;
|
||||
type AssetExchanger = ();
|
||||
type AssetLocker = ();
|
||||
// How to withdraw and deposit an asset.
|
||||
type AssetTransactor = AssetTransactors;
|
||||
type AssetTrap = PolkadotXcm;
|
||||
type Barrier = Barrier;
|
||||
type CallDispatcher = RuntimeCall;
|
||||
type FeeManager = ();
|
||||
type IsReserve = NativeAsset;
|
||||
type IsTeleporter = ();
|
||||
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
|
||||
type MessageExporter = ();
|
||||
type OriginConverter = XcmOriginToTransactDispatchOrigin;
|
||||
type PalletInstancesInfo = AllPalletsWithSystem;
|
||||
type ResponseHandler = PolkadotXcm;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type SafeCallFilter = Everything;
|
||||
type SubscriptionService = PolkadotXcm;
|
||||
type Trader = UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ()>;
|
||||
type TransactionalProcessor = FrameTransactionalProcessor;
|
||||
type UniversalAliases = Nothing;
|
||||
// Teleporting is disabled.
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
|
||||
type XcmSender = XcmRouter;
|
||||
}
|
||||
|
||||
use frame_support::{pallet_prelude::Get, traits::OriginTrait};
|
||||
use sp_runtime::traits::TryConvert;
|
||||
|
||||
// Convert a local Origin (i.e., a signed 20 byte account Origin) to a Multilocation
|
||||
pub struct SignedToAccountId20<Origin, AccountId, Network>(
|
||||
sp_std::marker::PhantomData<(Origin, AccountId, Network)>,
|
||||
);
|
||||
impl<Origin: OriginTrait + Clone, AccountId: Into<[u8; 20]>, Network: Get<Option<NetworkId>>>
|
||||
TryConvert<Origin, Location> for SignedToAccountId20<Origin, AccountId, Network>
|
||||
where
|
||||
Origin::PalletsOrigin: From<frame_system::RawOrigin<AccountId>>
|
||||
+ TryInto<frame_system::RawOrigin<AccountId>, Error = Origin::PalletsOrigin>,
|
||||
{
|
||||
fn try_convert(o: Origin) -> Result<Location, Origin> {
|
||||
o.try_with_caller(|caller| match caller.try_into() {
|
||||
Ok(frame_system::RawOrigin::Signed(who)) =>
|
||||
Ok(AccountKey20 { key: who.into(), network: Network::get() }.into()),
|
||||
Ok(other) => Err(other.into()),
|
||||
Err(other) => Err(other),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Converts a Signed Local Origin into a Location
|
||||
pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, RelayNetwork>;
|
||||
|
||||
/// The means for routing XCM messages which are not for local execution into
|
||||
/// the right message queues.
|
||||
pub type XcmRouter = WithUniqueTopic<(
|
||||
// Two routers - use UMP to communicate with the relay chain:
|
||||
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, (), ()>,
|
||||
// ..and XCMP to communicate with the sibling chains.
|
||||
XcmpQueue,
|
||||
)>;
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxLockers: u32 = 8;
|
||||
pub const MaxRemoteLockConsumers: u32 = 0;
|
||||
}
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type AdminOrigin = EnsureRoot<AccountId>;
|
||||
// ^ Override for AdvertisedXcmVersion default
|
||||
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
|
||||
type Currency = Balances;
|
||||
type CurrencyMatcher = ();
|
||||
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
|
||||
type MaxLockers = MaxLockers;
|
||||
type MaxRemoteLockConsumers = MaxLockers;
|
||||
type RemoteLockConsumerIdentifier = ();
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
|
||||
type SovereignAccountOf = LocationToAccountId;
|
||||
type TrustedLockers = ();
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
|
||||
type WeightInfo = pallet_xcm::TestWeightInfo;
|
||||
type XcmExecuteFilter = Nothing;
|
||||
// ^ Disable dispatchable execute on the XCM pallet.
|
||||
// Needs to be `Everything` for local testing.
|
||||
type XcmExecutor = XcmExecutor<XcmConfig>;
|
||||
type XcmReserveTransferFilter = Nothing;
|
||||
type XcmRouter = XcmRouter;
|
||||
type XcmTeleportFilter = Everything;
|
||||
|
||||
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
|
||||
}
|
||||
|
||||
impl cumulus_pallet_xcm::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type XcmExecutor = XcmExecutor<XcmConfig>;
|
||||
}
|
||||
Reference in New Issue
Block a user