123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- use frame_support::inherent::{CheckInherentsResult, InherentData};
- use frame_support::traits::{KeyOwnerProofSystem, Randomness};
- use frame_support::unsigned::{TransactionSource, TransactionValidity};
- use pallet_grandpa::fg_primitives;
- use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
- use sp_api::impl_runtime_apis;
- use sp_core::crypto::KeyTypeId;
- use sp_core::OpaqueMetadata;
- use sp_runtime::traits::{BlakeTwo256, Block as BlockT, NumberFor};
- use sp_runtime::{generic, ApplyExtrinsicResult};
- use sp_std::vec::Vec;
- use crate::constants::PRIMARY_PROBABILITY;
- use crate::{
- AccountId, AuthorityDiscoveryId, Balance, BlockNumber, EpochDuration, GrandpaAuthorityList,
- GrandpaId, Hash, Index, RuntimeVersion, Signature, VERSION,
- };
- use crate::{
- AllModules, AuthorityDiscovery, Babe, Call, Grandpa, Historical, InherentDataExt,
- RandomnessCollectiveFlip, Runtime, SessionKeys, System, TransactionPayment,
- };
- /// The SignedExtension to the basic transaction logic.
- pub type SignedExtra = (
- system::CheckSpecVersion<Runtime>,
- system::CheckTxVersion<Runtime>,
- system::CheckGenesis<Runtime>,
- system::CheckEra<Runtime>,
- system::CheckNonce<Runtime>,
- system::CheckWeight<Runtime>,
- pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
- pallet_grandpa::ValidateEquivocationReport<Runtime>,
- );
- /// Digest item type.
- pub type DigestItem = generic::DigestItem<Hash>;
- /// 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>;
- /// Unchecked extrinsic type as expected by this runtime.
- pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<AccountId, Call, Signature, SignedExtra>;
- /// Executive: handles dispatch to the various modules.
- pub type Executive =
- frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;
- /// Export of the private const generated within the macro.
- pub const EXPORTED_RUNTIME_API_VERSIONS: sp_version::ApisVec = RUNTIME_API_VERSIONS;
- 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 sp_block_builder::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: InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
- data.create_extrinsics()
- }
- fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult {
- data.check_extrinsics(&block)
- }
- fn random_seed() -> <Block as BlockT>::Hash {
- RandomnessCollectiveFlip::random_seed()
- }
- }
- impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
- fn validate_transaction(
- source: TransactionSource,
- tx: <Block as BlockT>::Extrinsic,
- ) -> TransactionValidity {
- Executive::validate_transaction(source, tx)
- }
- }
- impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
- fn offchain_worker(header: &<Block as BlockT>::Header) {
- Executive::offchain_worker(header)
- }
- }
- impl fg_primitives::GrandpaApi<Block> for Runtime {
- fn grandpa_authorities() -> GrandpaAuthorityList {
- Grandpa::grandpa_authorities()
- }
- fn submit_report_equivocation_extrinsic(
- equivocation_proof: fg_primitives::EquivocationProof<
- <Block as BlockT>::Hash,
- NumberFor<Block>,
- >,
- key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
- ) -> Option<()> {
- let key_owner_proof = key_owner_proof.decode()?;
- Grandpa::submit_report_equivocation_extrinsic(
- equivocation_proof,
- key_owner_proof,
- )
- }
- fn generate_key_ownership_proof(
- _set_id: fg_primitives::SetId,
- authority_id: GrandpaId,
- ) -> 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 sp_consensus_babe::BabeApi<Block> for Runtime {
- fn configuration() -> sp_consensus_babe::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>
- sp_consensus_babe::BabeGenesisConfiguration {
- slot_duration: Babe::slot_duration(),
- epoch_length: EpochDuration::get(),
- c: PRIMARY_PROBABILITY,
- genesis_authorities: Babe::authorities(),
- randomness: Babe::randomness(),
- allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
- }
- }
- fn current_epoch_start() -> sp_consensus_babe::SlotNumber {
- Babe::current_epoch_start()
- }
- }
- impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
- fn authorities() -> Vec<AuthorityDiscoveryId> {
- AuthorityDiscovery::authorities()
- }
- }
- impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
- fn account_nonce(account: AccountId) -> Index {
- System::account_nonce(account)
- }
- }
- impl pallet_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)
- }
- }
- 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>, KeyTypeId)>> {
- SessionKeys::decode_into_raw_public_keys(&encoded)
- }
- }
- #[cfg(feature = "runtime-benchmarks")]
- impl frame_benchmarking::Benchmark<Block> for Runtime {
- fn dispatch_benchmark(
- 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>, sp_runtime::RuntimeString> {
- use sp_std::vec;
- use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark};
- use frame_system_benchmarking::Module as SystemBench;
- impl frame_system_benchmarking::Trait for Runtime {}
- let whitelist: Vec<Vec<u8>> = vec![
- // Block Number
- 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);
- add_benchmark!(params, batches, b"system", SystemBench::<Runtime>);
- if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
- Ok(batches)
- }
- }
- }
|