Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
delegations: Default::default(),
prior: Default::default(),
});
CustomOnRuntimeUpgrade::on_runtime_upgrade();
assert_eq!(VotingOf::<Runtime>::get(a(1)), Direct {
votes: vec![(0, Standard { vote: Vote { aye: true, conviction: NoConviction }, balance: 1, })],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(2)), Direct {
votes: vec![
(0, Standard { vote: Vote { aye: true, conviction: NoConviction }, balance: 2, }),
(1, Standard { vote: Vote { aye: true, conviction: Locked2x }, balance: 2, })
],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(3)), Direct {
votes: vec![(1, Standard { vote: Vote { aye: true, conviction: Locked3x }, balance: 3, })],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(4)), Direct {
votes: vec![],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(5)), Delegating {
balance: 5,
target: a(0),
conviction: Locked1x,
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(6)), Direct {
votes: vec![(0, Split { aye: 6, nay: 6 }), (1, Split { aye: 6, nay: 6 })],
delegations: Default::default(),
prior: Default::default(),
});
});
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
parameter_types! {
pub const MaxStatementLength: usize = 1_000;
pub const UnlockedProportion: Permill = Permill::zero();
pub const MaxUnlocked: Balance = 0;
}
ord_parameter_types! {
pub const W3FValidity: AccountId = AccountId::from(
// 142wAF65SK7PxhyzzrWz5m5PXDtooehgePBd7rc2NWpfc8Wa
hex_literal::hex!("862e432e0cf75693899c62691ac0f48967f815add97ae85659dcde8332708551")
);
pub const W3FConfiguration: AccountId = AccountId::from(
// 1KvKReVmUiTc2LW2a4qyHsaJJ9eE9LRsywZkMk5hyBeyHgw
hex_literal::hex!("0e6de68b13b82479fbe988ab9ecb16bad446b67b993cdd9198cd41c7c6259c49")
);
}
type ValidityOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
EnsureSignedBy<W3FValidity, AccountId>,
>;
type ConfigurationOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
EnsureSignedBy<W3FConfiguration, AccountId>,
>;
impl purchase::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type VestingSchedule = Vesting;
type ValidityOrigin = ValidityOrigin;
type ConfigurationOrigin = ConfigurationOrigin;
type MaxStatementLength = MaxStatementLength;
type UnlockedProportion = UnlockedProportion;
type MaxUnlocked = MaxUnlocked;
}
pub enum Runtime where
UncheckedExtrinsic = UncheckedExtrinsic
// Basic stuff; balances is uncallable initially.
System: system::{Module, Call, Storage, Config, Event<T>},
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Storage},
Scheduler: scheduler::{Module, Call, Storage, Event<T>},
// Must be before session.
Babe: babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Indices: indices::{Module, Call, Storage, Config<T>, Event<T>},
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: transaction_payment::{Module, Storage},
// Consensus support.
Authorship: authorship::{Module, Call, Storage},
Staking: staking::{Module, Call, Storage, Config<T>, Event<T>, ValidateUnsigned},
Offences: offences::{Module, Call, Storage, Event},
Historical: session_historical::{Module},
Session: session::{Module, Call, Storage, Event, Config<T>},
FinalityTracker: finality_tracker::{Module, Call, Storage, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned},
ImOnline: im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
AuthorityDiscovery: authority_discovery::{Module, Call, Config},
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
ElectionsPhragmen: elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
TechnicalMembership: membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
Treasury: treasury::{Module, Call, Storage, Event<T>},
// Parachains stuff; slots are disabled (no auctions initially). The rest are safe as they
// have no public dispatchables. Disabled `Call` on all of them, but this should be
// uncommented once we're ready to start parachains.
Parachains: parachains::{Module, Call, Storage, Config, Inherent, Origin},
Attestations: attestations::{Module, Call, Storage},
Slots: slots::{Module, Call, Storage, Event<T>},
Registrar: registrar::{Module, Call, Storage, Event, Config<T>},
// Claims. Usable initially.
Claims: claims::{Module, Call, Storage, Event<T>, Config<T>, ValidateUnsigned},
// Vesting. Usable initially, but removed once all vesting is finished.
Vesting: vesting::{Module, Call, Storage, Event<T>, Config<T>},
Utility: utility::{Module, Call, Event},
// DOT Purchase module. Late addition; this is in place of Sudo.
Purchase: purchase::{Module, Call, Storage, Event<T>},
// Identity. Late addition.
Identity: identity::{Module, Call, Storage, Event<T>},
// Proxy module. Late addition.
Proxy: proxy::{Module, Call, Storage, Event<T>},
// Multisig dispatch. Late addition.
Multisig: multisig::{Module, Call, Storage, Event<T>},
/// The address format for describing accounts.
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
system::CheckSpecVersion<Runtime>,
system::CheckTxVersion<Runtime>,
system::CheckGenesis<Runtime>,
system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>,
transaction_payment::ChargeTransactionPayment<Runtime>,
registrar::LimitParathreadCommits<Runtime>,
parachains::ValidateDoubleVoteReports<Runtime>,
claims::PrevalidateAttests<Runtime>,
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<
Runtime,
Block,
system::ChainContext<Runtime>,
Runtime,
AllModules,
CustomOnRuntimeUpgrade
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block)
}
fn initialize_block(header: &<Block as BlockT>::Header) {
Executive::initialize_block(header)
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
Runtime::metadata().into()
}
impl block_builder_api::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> <Block as BlockT>::Header {
Executive::finalize_block()
fn inherent_extrinsics(data: inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
fn check_inherents(
block: Block,
data: inherents::InherentData,
) -> inherents::CheckInherentsResult {
data.check_extrinsics(&block)
fn random_seed() -> <Block as BlockT>::Hash {
impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
) -> TransactionValidity {
Executive::validate_transaction(source, tx)
impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
Executive::offchain_worker(header)
}
}
impl parachain::ParachainHost<Block> for Runtime {
fn validators() -> Vec<parachain::ValidatorId> {
}
fn duty_roster() -> parachain::DutyRoster {
Parachains::calculate_duty_roster().0
fn active_parachains() -> Vec<(parachain::Id, Option<(parachain::CollatorId, parachain::Retriable)>)> {
Registrar::active_paras()
asynchronous rob
committed
fn global_validation_data() -> parachain::GlobalValidationData {
Parachains::global_validation_data()
}
fn local_validation_data(id: parachain::Id) -> Option<parachain::LocalValidationData> {
Parachains::current_local_validation_data(&id)
asynchronous rob
committed
fn parachain_code(id: parachain::Id) -> Option<parachain::ValidationCode> {
Parachains::parachain_code(&id)
}
fn get_heads(extrinsics: Vec<<Block as BlockT>::Extrinsic>)
-> Option<Vec<AbridgedCandidateReceipt>>
{
extrinsics
.into_iter()
.find_map(|ex| match UncheckedExtrinsic::decode(&mut ex.encode().as_slice()) {
Ok(ex) => match ex.function {
Call::Parachains(ParachainsCall::set_heads(heads)) => {
Some(heads.into_iter().map(|c| c.candidate).collect())
}
_ => None,
}
Err(_) => None,
})
}
fn signing_context() -> SigningContext {
Parachains::signing_context()
}
fn downward_messages(id: parachain::Id) -> Vec<primitives::v0::DownwardMessage> {
Parachains::downward_messages(id)
}
}
impl fg_primitives::GrandpaApi<Block> for Runtime {
fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
sp_runtime::traits::NumberFor<Block>,
>,
key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;
Grandpa::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}
fn generate_key_ownership_proof(
_set_id: fg_primitives::SetId,
authority_id: fg_primitives::AuthorityId,
) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {
use codec::Encode;
Historical::prove((fg_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(fg_primitives::OpaqueKeyOwnershipProof::new)
}
impl babe_primitives::BabeApi<Block> for Runtime {
fn configuration() -> babe_primitives::BabeGenesisConfiguration {
// The choice of `c` parameter (where `1 - c` represents the
// probability of a slot being empty), is done in accordance to the
// slot duration and expected target block time, for safely
// resisting network delays of maximum two seconds.
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots,
fn current_epoch_start() -> babe_primitives::SlotNumber {
Babe::current_epoch_start()
}
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
fn generate_key_ownership_proof(
_slot_number: babe_primitives::SlotNumber,
authority_id: babe_primitives::AuthorityId,
) -> Option<babe_primitives::OpaqueKeyOwnershipProof> {
use codec::Encode;
Historical::prove((babe_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(babe_primitives::OpaqueKeyOwnershipProof::new)
}
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: babe_primitives::EquivocationProof<<Block as BlockT>::Header>,
key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;
Babe::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}
impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityDiscoveryId> {
AuthorityDiscovery::authorities()
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
}
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
SessionKeys::decode_into_raw_public_keys(&encoded)
}
impl system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
}
}
impl transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Block,
Balance,
UncheckedExtrinsic,
> for Runtime {
fn query_info(uxt: UncheckedExtrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
}
#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
pallet: Vec<u8>,
benchmark: Vec<u8>,
lowest_range_values: Vec<u32>,
highest_range_values: Vec<u32>,
steps: Vec<u32>,
repeat: u32,
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark};
// Trying to add benchmarks directly to the Session Pallet caused cyclic dependency issues.
// To get around that, we separated the Session benchmarks into its own crate, which is why
// we need these two lines below.
use pallet_session_benchmarking::Module as SessionBench;
use pallet_offences_benchmarking::Module as OffencesBench;
use frame_system_benchmarking::Module as SystemBench;
impl pallet_session_benchmarking::Trait for Runtime {}
impl pallet_offences_benchmarking::Trait for Runtime {}
impl frame_system_benchmarking::Trait for Runtime {}
let whitelist: Vec<Vec<u8>> = vec![
// Block Number
// frame_system::Number::<Runtime>::hashed_key().to_vec(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec(),
// Total Issuance
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec(),
// Execution Phase
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec(),
// Event Count
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec(),
// System Events
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec(),
// Caller 0 Account
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da946c154ffd9992e395af90b5b13cc6f295c77033fce8a9045824a6690bbf99c6db269502f0a8d1d2a008542d5690a0749").to_vec(),
// Treasury Account
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec(),
];
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (
&pallet,
&benchmark,
&lowest_range_values,
&highest_range_values,
&steps,
repeat,
&whitelist,
extra,
);
add_benchmark!(params, batches, claims, Claims);
add_benchmark!(params, batches, balances, Balances);
add_benchmark!(params, batches, collective, Council);
add_benchmark!(params, batches, democracy, Democracy);
add_benchmark!(params, batches, elections_phragmen, ElectionsPhragmen);
add_benchmark!(params, batches, im_online, ImOnline);
add_benchmark!(params, batches, offences, OffencesBench::<Runtime>);
add_benchmark!(params, batches, scheduler, Scheduler);
add_benchmark!(params, batches, session, SessionBench::<Runtime>);
add_benchmark!(params, batches, staking, Staking);
add_benchmark!(params, batches, system, SystemBench::<Runtime>);
add_benchmark!(params, batches, timestamp, Timestamp);
add_benchmark!(params, batches, treasury, Treasury);
add_benchmark!(params, batches, vesting, Vesting);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
#[cfg(test)]
mod tests {
use super::Runtime;
#[test]
fn slash_defer_less_than_bonding_duration() {
assert!(
<Runtime as staking::Trait>::SlashDeferDuration::get()
< <Runtime as staking::Trait>::BondingDuration::get()
);
}
}