difftreelog
feat add frontier pallets to runtime
in: master
1 file changed
runtime/src/lib.rsdiffbeforeafterboth17use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};17use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};18use sp_api::impl_runtime_apis;18use sp_api::impl_runtime_apis;19use sp_consensus_aura::sr25519::AuthorityId as AuraId;19use sp_consensus_aura::sr25519::AuthorityId as AuraId;20use sp_core::{ crypto::KeyTypeId, crypto::Public, OpaqueMetadata };20use sp_core::{ crypto::KeyTypeId, crypto::Public, OpaqueMetadata, H160, U256 };21use sp_runtime::{21use sp_runtime::{22 Permill, Perbill, Percent,22 Permill, Perbill, Percent,23 ModuleId,23 ModuleId,35pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, CurrencyAdapter, FeeDetails, RuntimeDispatchInfo};35pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, CurrencyAdapter, FeeDetails, RuntimeDispatchInfo};36// A few exports that help ease life for downstream crates.36// A few exports that help ease life for downstream crates.37pub use pallet_balances::Call as BalancesCall;37pub use pallet_balances::Call as BalancesCall;38pub use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping, Runner};38pub use pallet_contracts::{Schedule as ContractsSchedule };39pub use pallet_contracts::{Schedule as ContractsSchedule };39pub use frame_support::{40pub use frame_support::{40 construct_runtime,41 construct_runtime,43 StorageValue,44 StorageValue,44 traits::{45 traits::{45 Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness,46 Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness,46 LockIdentifier,47 LockIdentifier, FindAuthor,47 },48 },48 weights::{49 weights::{49 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},50 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},50 DispatchClass, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, Weight,51 DispatchClass, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, Weight,51 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients52 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients52 },53 },54 ConsensusEngineId,53};55};54use pallet_contracts::weights::WeightInfo;56use pallet_contracts::weights::WeightInfo;55// #[cfg(any(feature = "std", test))]57// #[cfg(any(feature = "std", test))]61use sp_std::{prelude::*, marker::PhantomData};63use sp_std::{prelude::*, marker::PhantomData};62use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};64use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};63use smallvec::smallvec;65use smallvec::smallvec;66use codec::{Encode, Decode};67use pallet_evm::{Account as EVMAccount, FeeCalculator};68use fp_rpc::TransactionStatus;69use sp_core::H256;647065pub use pallet_timestamp::Call as TimestampCall;71pub use pallet_timestamp::Call as TimestampCall;6672333 type AuthorityId = AuraId;339 type AuthorityId = AuraId;334}340}341342parameter_types! {343 pub const ChainId: u64 = 8888;344}345346impl pallet_evm::Config for Runtime {347 type FeeCalculator = ();348 type GasWeightMapping = ();349 type CallOrigin = EnsureAddressTruncated;350 type WithdrawOrigin = EnsureAddressTruncated;351 type AddressMapping = HashedAddressMapping<BlakeTwo256>;352 type Currency = Balances;353 type Event = Event;354 type Precompiles = ();355 type ChainId = ChainId;356 type Runner = pallet_evm::runner::stack::Runner<Self>;357 type OnChargeTransaction = ();358}359360pub struct EthereumFindAuthor<F>(PhantomData<F>);361impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F>362{363 fn find_author<'a, I>(digests: I) -> Option<H160> where364 I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>365 {366 if let Some(author_index) = F::find_author(digests) {367 let authority_id = Aura::authorities()[author_index as usize].clone();368 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));369 }370 None371 }372}373374parameter_types! {375 pub BlockGasLimit: U256 = U256::from(u32::max_value());376}377378impl pallet_ethereum::Config for Runtime {379 type Event = Event;380 type FindAuthor = EthereumFindAuthor<Aura>;381 type StateRoot = pallet_ethereum::IntermediateStateRoot;382 type BlockGasLimit = BlockGasLimit;383}335384336impl pallet_grandpa::Config for Runtime {385impl pallet_grandpa::Config for Runtime {337 type Event = Event;386 type Event = Event;404 pub const SignedClaimHandicap: u32 = 2;453 pub const SignedClaimHandicap: u32 = 2;405 pub const MaxDepth: u32 = 32;454 pub const MaxDepth: u32 = 32;406 pub const MaxValueSize: u32 = 16 * 1024;455 pub const MaxValueSize: u32 = 16 * 1024;407 pub const MaxCodeSize: u32 = 1024 * 1024 * 25; // 25 Mb 456 pub const MaxCodeSize: u32 = 1024 * 1024 * 25; // 25 Mb408 // The lazy deletion runs inside on_initialize.457 // The lazy deletion runs inside on_initialize.409 pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *458 pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *410 RuntimeBlockWeights::get().max_block;459 RuntimeBlockWeights::get().max_block;441}490}442491443parameter_types! {492parameter_types! {444 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; // Targeting 0.1 Unique per NFT transfer 493 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; // Targeting 0.1 Unique per NFT transfer445}494}446495447/// Linear implementor of `WeightToFeePolynomial` 496/// Linear implementor of `WeightToFeePolynomial`448pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);497pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);449498450impl<T> WeightToFeePolynomial for LinearFee<T> where499impl<T> WeightToFeePolynomial for LinearFee<T> where545 Contracts: pallet_contracts::{Module, Call, Config<T>, Storage, Event<T>},594 Contracts: pallet_contracts::{Module, Call, Config<T>, Storage, Event<T>},546 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},595 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},547 Aura: pallet_aura::{Module, Config<T> },596 Aura: pallet_aura::{Module, Config<T> },597 EVM: pallet_evm::{Module, Config, Call, Storage, Event<T>},598 Ethereum: pallet_ethereum::{Module, Config, Call, Storage, Event},548 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},599 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},549 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},600 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},550 TransactionPayment: pallet_transaction_payment::{Module, Storage},601 TransactionPayment: pallet_transaction_payment::{Module, Storage},555 }606 }556);607);608609pub struct TransactionConverter;610611impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {612 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {613 UncheckedExtrinsic::new_unsigned(pallet_ethereum::Call::<Runtime>::transact(transaction).into())614 }615}616617impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {618 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> opaque::UncheckedExtrinsic {619 let extrinsic = UncheckedExtrinsic::new_unsigned(pallet_ethereum::Call::<Runtime>::transact(transaction).into());620 let encoded = extrinsic.encode();621 opaque::UncheckedExtrinsic::decode(&mut &encoded[..]).expect("Encoded extrinsic is always valid")622 }623}557624558/// The address format for describing accounts.625/// The address format for describing accounts.559pub type Address = AccountId;626pub type Address = AccountId;653 }720 }654721655 fn random_seed() -> <Block as BlockT>::Hash {722 fn random_seed() -> <Block as BlockT>::Hash {656 RandomnessCollectiveFlip::random_seed()723 RandomnessCollectiveFlip::random_seed().0657 }724 }658 }725 }659726682 }749 }683 }750 }751752 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {753 fn chain_id() -> u64 {754 <Runtime as pallet_evm::Config>::ChainId::get()755 }756757 fn account_basic(address: H160) -> EVMAccount {758 EVM::account_basic(&address)759 }760761 fn gas_price() -> U256 {762 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()763 }764765 fn account_code_at(address: H160) -> Vec<u8> {766 EVM::account_codes(address)767 }768769 fn author() -> H160 {770 <pallet_ethereum::Module<Runtime>>::find_author()771 }772773 fn storage_at(address: H160, index: U256) -> H256 {774 let mut tmp = [0u8; 32];775 index.to_big_endian(&mut tmp);776 EVM::account_storages(address, H256::from_slice(&tmp[..]))777 }778779 fn call(780 from: H160,781 to: H160,782 data: Vec<u8>,783 value: U256,784 gas_limit: U256,785 gas_price: Option<U256>,786 nonce: Option<U256>,787 estimate: bool,788 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {789 let config = if estimate {790 let mut config = <Runtime as pallet_evm::Config>::config().clone();791 config.estimate = true;792 Some(config)793 } else {794 None795 };796797 <Runtime as pallet_evm::Config>::Runner::call(798 from,799 to,800 data,801 value,802 gas_limit.low_u64(),803 gas_price,804 nonce,805 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),806 ).map_err(|err| err.into())807 }808809 fn create(810 from: H160,811 data: Vec<u8>,812 value: U256,813 gas_limit: U256,814 gas_price: Option<U256>,815 nonce: Option<U256>,816 estimate: bool,817 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {818 let config = if estimate {819 let mut config = <Runtime as pallet_evm::Config>::config().clone();820 config.estimate = true;821 Some(config)822 } else {823 None824 };825826 <Runtime as pallet_evm::Config>::Runner::create(827 from,828 data,829 value,830 gas_limit.low_u64(),831 gas_price,832 nonce,833 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),834 ).map_err(|err| err.into())835 }836837 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {838 Ethereum::current_transaction_statuses()839 }840841 fn current_block() -> Option<pallet_ethereum::Block> {842 Ethereum::current_block()843 }844845 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {846 Ethereum::current_receipts()847 }848849 fn current_all() -> (850 Option<pallet_ethereum::Block>,851 Option<Vec<pallet_ethereum::Receipt>>,852 Option<Vec<TransactionStatus>>853 ) {854 (855 Ethereum::current_block(),856 Ethereum::current_receipts(),857 Ethereum::current_transaction_statuses()858 )859 }860 }684861685 impl sp_session::SessionKeys<Block> for Runtime {862 impl sp_session::SessionKeys<Block> for Runtime {686 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {863 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {