git.delta.rocks / unique-network / refs/commits / 448629b28a12

difftreelog

source

runtime/common/config/ethereum.rs5.6 KiBsourcehistory
1use sp_core::{U256, H160};2use frame_support::{3	weights::{Weight, constants::WEIGHT_REF_TIME_PER_SECOND},4	traits::{FindAuthor},5	parameter_types, ConsensusEngineId,6};7use sp_runtime::{RuntimeAppPublic, Perbill, traits::ConstU32};8use crate::{9	runtime_common::{10		config::sponsoring::DefaultSponsoringRateLimit,11		DealWithFees,12		dispatch::CollectionDispatchT,13		ethereum::{precompiles::UniquePrecompiles, sponsoring::EvmSponsorshipHandler},14	},15	Runtime, Aura, Balances, RuntimeEvent, ChainId,16};17use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};18use pallet_ethereum::PostLogContent;19use up_common::constants::*;2021pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;2223// Assuming PoV size per read is 96 bytes: 16 for twox128(Evm), 16 for twox128(Storage), 32 for storage key, and 32 for storage value24const EVM_SLOAD_PROOF_SIZE: u64 = 96;2526// ~~Assuming slowest ethereum opcode is SSTORE, with gas price of 20000 as our worst case~~27// ~~(contract, which only writes a lot of data),~~28// ~~approximating on top of our real store write weight~~29//30// The above approach is very wrong, and the reason is described there:31// https://forum.polkadot.network/t/frontier-support-for-evm-weight-v2/2470/5#problem-232parameter_types! {33	pub const ReadsPerSecond: u64 = WEIGHT_REF_TIME_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().read;34	pub const GasPerSecond: u64 = ReadsPerSecond::get() * 2100;35	pub const WeightTimePerGas: u64 = WEIGHT_REF_TIME_PER_SECOND / GasPerSecond::get();3637	pub const BytesReadPerSecond: u64 = ReadsPerSecond::get() * EVM_SLOAD_PROOF_SIZE;38	pub const ProofSizePerGas: u64 = 0; //WEIGHT_REF_TIME_PER_SECOND / GasPerSecond::get();3940	pub const WeightPerGas: Weight = Weight::from_parts(WeightTimePerGas::get(), ProofSizePerGas::get());41}4243/// Limiting EVM execution to 50% of block for substrate users and management tasks44/// EVM transaction consumes more weight than substrate's, so we can't rely on them being45/// scheduled fairly46const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);47parameter_types! {48	pub BlockGasLimit: U256 = U256::from((NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightTimePerGas::get()).ref_time());49	pub PrecompilesValue: UniquePrecompiles<Runtime> = UniquePrecompiles::<_>::new();50}5152pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);53impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {54	fn find_author<'a, I>(digests: I) -> Option<H160>55	where56		I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,57	{58		if let Some(author_index) = F::find_author(digests) {59			let authority_id = Aura::authorities()[author_index as usize].clone();60			return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));61		}62		None63	}64}6566impl pallet_evm::Config for Runtime {67	type CrossAccountId = CrossAccountId;68	type AddressMapping = HashedAddressMapping<Self::Hashing>;69	type BackwardsAddressMapping = HashedAddressMapping<Self::Hashing>;70	type BlockGasLimit = BlockGasLimit;71	type FeeCalculator = pallet_configuration::FeeCalculator<Self>;72	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;73	type WeightPerGas = WeightPerGas;74	type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;75	type CallOrigin = EnsureAddressTruncated<Self>;76	type WithdrawOrigin = EnsureAddressTruncated<Self>;77	type PrecompilesType = UniquePrecompiles<Self>;78	type PrecompilesValue = PrecompilesValue;79	type Currency = Balances;80	type RuntimeEvent = RuntimeEvent;81	type OnMethodCall = (82		pallet_evm_migration::OnMethodCall<Self>,83		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,84		CollectionDispatchT<Self>,85		pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,86	);87	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;88	type ChainId = ChainId;89	type Runner = pallet_evm::runner::stack::Runner<Self>;90	type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;91	type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;92	type FindAuthor = EthereumFindAuthor<Aura>;93	type Timestamp = crate::Timestamp;94	type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;95	type GasLimitPovSizeRatio = ProofSizePerGas;96}9798impl pallet_evm_migration::Config for Runtime {99	type RuntimeEvent = RuntimeEvent;100	type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;101}102103parameter_types! {104	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;105}106107impl pallet_ethereum::Config for Runtime {108	type RuntimeEvent = RuntimeEvent;109	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;110	type PostLogContent = PostBlockAndTxnHashes;111	// Space for revert reason. Ethereum transactions are not cheap, and overall size is much less112	// than the substrate tx size, so we can afford this113	type ExtraDataLength = ConstU32<32>;114}115116parameter_types! {117	// 0x842899ECF380553E8a4de75bF534cdf6fBF64049118	pub const HelpersContractAddress: H160 = H160([119		0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,120	]);121122	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f123	pub const EvmCollectionHelpersAddress: H160 = H160([124		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,125	]);126}127128impl pallet_evm_contract_helpers::Config for Runtime {129	type RuntimeEvent = RuntimeEvent;130	type ContractAddress = HelpersContractAddress;131	type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;132}133134impl pallet_evm_coder_substrate::Config for Runtime {}135136impl pallet_evm_transaction_payment::Config for Runtime {137	type EvmSponsorshipHandler = EvmSponsorshipHandler;138}