From e58599f47c6197b41f2d026c5d609abc6c84599b Mon Sep 17 00:00:00 2001 From: Dino Pacandi Date: Fri, 14 Jul 2023 17:08:28 +0200 Subject: [PATCH] Progress 4 --- pallets/pallet-xcm/src/weights.rs | 24 +++++ runtime/astar/src/lib.rs | 141 ++++++++++++++++++++++++---- runtime/local/src/lib.rs | 139 ++++++++++++++++++++++++---- runtime/shibuya/src/lib.rs | 139 ++++++++++++++++++++++++---- runtime/shiden/src/lib.rs | 149 ++++++++++++++++++++++++------ 5 files changed, 509 insertions(+), 83 deletions(-) diff --git a/pallets/pallet-xcm/src/weights.rs b/pallets/pallet-xcm/src/weights.rs index bc5c452d85..a2f4e4cdb6 100644 --- a/pallets/pallet-xcm/src/weights.rs +++ b/pallets/pallet-xcm/src/weights.rs @@ -242,6 +242,18 @@ impl WeightInfo for SubstrateWeight { .saturating_add(Weight::from_parts(0, 3102)) .saturating_add(T::DbWeight::get().reads(2_u64)) } + /// C/P from PolkadotXcm, should be measured independently. + /// Storage: XcmPallet XcmExecutionSuspended (r:0 w:1) + /// Proof Skipped: XcmPallet XcmExecutionSuspended (max_values: Some(1), max_size: None, mode: Measured) + fn force_suspension() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_849_000 picoseconds. + Weight::from_parts(3_018_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } } // For backwards compatibility and tests @@ -438,4 +450,16 @@ impl WeightInfo for () { .saturating_add(Weight::from_parts(0, 3102)) .saturating_add(RocksDbWeight::get().reads(2_u64)) } + /// C/P from PolkadotXcm, should be measured independently. + /// Storage: XcmPallet XcmExecutionSuspended (r:0 w:1) + /// Proof Skipped: XcmPallet XcmExecutionSuspended (max_values: Some(1), max_size: None, mode: Measured) + fn force_suspension() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_849_000 picoseconds. + Weight::from_parts(3_018_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(RocksDbWeight::get().writes(1)) + } } diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 082ace47b9..b14b509e6e 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -48,7 +48,7 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_ethereum::PostLogContent; -use pallet_evm::{FeeCalculator, Runner}; +use pallet_evm::{FeeCalculator, GasWeightMapping, Runner}; use pallet_transaction_payment::{ FeeDetails, Multiplier, RuntimeDispatchInfo, TargetedFeeAdjustment, }; @@ -607,9 +607,8 @@ impl pallet_vesting::Config for Runtime { parameter_types! { pub const DepositPerItem: Balance = contracts_deposit(1, 0); pub const DepositPerByte: Balance = contracts_deposit(0, 1); - // The lazy deletion runs inside on_initialize. - pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * - RuntimeBlockWeights::get().max_block; + // Fallback value if storage deposit limit not set by the user + pub const DefaultDepositLimit: Balance = contracts_deposit(1024, 1024 * 1024); pub Schedule: pallet_contracts::Schedule = Default::default(); } @@ -639,12 +638,11 @@ impl pallet_contracts::Config for Runtime { type CallFilter = Nothing; type DepositPerItem = DepositPerItem; type DepositPerByte = DepositPerByte; + type DefaultDepositLimit = DefaultDepositLimit; type CallStack = [pallet_contracts::Frame; 5]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; type ChainExtension = (); - type DeletionQueueDepth = ConstU32<128>; - type DeletionWeightLimit = DeletionWeightLimit; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type MaxCodeLen = ConstU32<{ 123 * 1024 }>; @@ -786,6 +784,13 @@ parameter_types! { ); pub PrecompilesValue: Precompiles = AstarNetworkPrecompiles::<_, _>::new(); pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per PoV size. Value is calculated as: + /// + /// max_gas_limit = max_tx_ref_time / WEIGHT_PER_GAS = max_pov_size * gas_limit_pov_size_ratio + /// gas_limit_pov_size_ratio = ceil((max_tx_ref_time / WEIGHT_PER_GAS) / max_pov_size) + /// + /// Equals 4 for values used by Astar runtime. + pub const GasLimitPovSizeRatio: u64 = 4; } impl pallet_evm::Config for Runtime { @@ -807,6 +812,7 @@ impl pallet_evm::Config for Runtime { type Timestamp = Timestamp; type OnCreate = (); type FindAuthor = FindAuthorTruncated; + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type WeightInfo = pallet_evm::weights::SubstrateWeight; } @@ -825,6 +831,7 @@ impl pallet_ethereum::Config for Runtime { impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; + type WeightInfo = pallet_sudo::weights::SubstrateWeight; } pub struct EvmRevertCodeHandler; @@ -1082,6 +1089,11 @@ parameter_types! { pub type Migrations = (frame_support::migrations::RemovePallet,); +type EventRecord = frame_system::EventRecord< + ::RuntimeEvent, + ::Hash, +>; + use frame_support::pallet_prelude::*; pub struct PalletContractsV9(PhantomData); impl frame_support::traits::OnRuntimeUpgrade for PalletContractsV9 { @@ -1361,7 +1373,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1373,6 +1385,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + ::Runner::call( from, to, @@ -1385,6 +1433,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or_else(|| ::config()), @@ -1401,7 +1451,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1413,6 +1463,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + #[allow(clippy::or_fun_call)] // suggestion not helpful here ::Runner::create( from, @@ -1425,6 +1511,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or(::config()), @@ -1473,7 +1561,7 @@ impl_runtime_apis! { fn pending_block( xts: Vec<::Extrinsic>, - ) -> (Option, Option>) { + ) -> (Option, Option>) { for ext in xts.into_iter() { let _ = Executive::apply_extrinsic(ext); } @@ -1497,11 +1585,7 @@ impl_runtime_apis! { } } - impl pallet_contracts::ContractsApi< - Block, AccountId, Balance, BlockNumber, Hash, - > - for Runtime - { + impl pallet_contracts::ContractsApi for Runtime { fn call( origin: AccountId, dest: AccountId, @@ -1509,9 +1593,19 @@ impl_runtime_apis! { gas_limit: Option, storage_deposit_limit: Option, input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { + ) -> pallet_contracts_primitives::ContractExecResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, true, pallet_contracts::Determinism::Enforced) + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + pallet_contracts::Determinism::Enforced, + ) } fn instantiate( @@ -1522,10 +1616,19 @@ impl_runtime_apis! { code: pallet_contracts_primitives::Code, data: Vec, salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult - { + ) -> pallet_contracts_primitives::ContractInstantiateResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, true) + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + ) } fn upload_code( diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index 9b22e6147e..56cd9777a9 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -41,7 +41,7 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_ethereum::PostLogContent; -use pallet_evm::{FeeCalculator, Runner}; +use pallet_evm::{FeeCalculator, GasWeightMapping, Runner}; use pallet_evm_precompile_assets_erc20::AddressToAssetId; use pallet_grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList}; use parity_scale_codec::{Compact, Decode, Encode, MaxEncodedLen}; @@ -521,6 +521,13 @@ parameter_types! { ); pub PrecompilesValue: Precompiles = LocalNetworkPrecompiles::<_>::new(); pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per PoV size. Value is calculated as: + /// + /// max_gas_limit = max_tx_ref_time / WEIGHT_PER_GAS = max_pov_size * gas_limit_pov_size_ratio + /// gas_limit_pov_size_ratio = ceil((max_tx_ref_time / WEIGHT_PER_GAS) / max_pov_size) + /// + /// Local runtime has no strict bounds as parachain, but we keep the value set to 4 for consistency. + pub const GasLimitPovSizeRatio: u64 = 4; } impl pallet_evm::Config for Runtime { @@ -542,6 +549,7 @@ impl pallet_evm::Config for Runtime { type Timestamp = Timestamp; type OnCreate = (); type FindAuthor = FindAuthorTruncated; + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type WeightInfo = pallet_evm::weights::SubstrateWeight; } @@ -769,9 +777,8 @@ impl pallet_vesting::Config for Runtime { parameter_types! { pub const DepositPerItem: Balance = deposit(1, 0); pub const DepositPerByte: Balance = deposit(0, 1); - // The lazy deletion runs inside on_initialize. - pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * - RuntimeBlockWeights::get().max_block; + // Fallback value if storage deposit limit not set by the user + pub const DefaultDepositLimit: Balance = contracts_deposit(1024, 1024 * 1024); pub Schedule: pallet_contracts::Schedule = Default::default(); } @@ -790,6 +797,7 @@ impl pallet_contracts::Config for Runtime { type CallFilter = Nothing; type DepositPerItem = DepositPerItem; type DepositPerByte = DepositPerByte; + type DefaultDepositLimit = DefaultDepositLimit; type CallStack = [pallet_contracts::Frame; 5]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; @@ -798,8 +806,6 @@ impl pallet_contracts::Config for Runtime { XvmExtension, AssetsExtension>, ); - type DeletionQueueDepth = ConstU32<128>; - type DeletionWeightLimit = DeletionWeightLimit; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type MaxCodeLen = ConstU32<{ 123 * 1024 }>; @@ -811,6 +817,7 @@ impl pallet_contracts::Config for Runtime { impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; + type WeightInfo = pallet_sudo::weights::SubstrateWeight; } /// The type used to represent the kinds of proxying allowed. @@ -1027,6 +1034,11 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; +type EventRecord = frame_system::EventRecord< + ::RuntimeEvent, + ::Hash, +>; + impl fp_self_contained::SelfContainedCall for RuntimeCall { type SignedInfo = H160; @@ -1309,7 +1321,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1321,6 +1333,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + ::Runner::call( from, to, @@ -1333,6 +1381,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or_else(|| ::config()), @@ -1349,7 +1399,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1361,6 +1411,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + #[allow(clippy::or_fun_call)] // suggestion not helpful here ::Runner::create( from, @@ -1373,6 +1459,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or(::config()), @@ -1445,11 +1533,7 @@ impl_runtime_apis! { } } - impl pallet_contracts::ContractsApi< - Block, AccountId, Balance, BlockNumber, Hash, - > - for Runtime - { + impl pallet_contracts::ContractsApi for Runtime { fn call( origin: AccountId, dest: AccountId, @@ -1457,9 +1541,19 @@ impl_runtime_apis! { gas_limit: Option, storage_deposit_limit: Option, input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { + ) -> pallet_contracts_primitives::ContractExecResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, true, pallet_contracts::Determinism::Enforced) + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + pallet_contracts::Determinism::Enforced, + ) } fn instantiate( @@ -1470,10 +1564,19 @@ impl_runtime_apis! { code: pallet_contracts_primitives::Code, data: Vec, salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult - { + ) -> pallet_contracts_primitives::ContractInstantiateResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, true) + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + ) } fn upload_code( diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index e5c709e9ff..cb122a3cad 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -45,7 +45,7 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_ethereum::PostLogContent; -use pallet_evm::{FeeCalculator, Runner}; +use pallet_evm::{FeeCalculator, GasWeightMapping, Runner}; use pallet_transaction_payment::{ FeeDetails, Multiplier, RuntimeDispatchInfo, TargetedFeeAdjustment, }; @@ -655,9 +655,8 @@ impl pallet_vesting::Config for Runtime { parameter_types! { pub const DepositPerItem: Balance = MILLISBY / 1_000_000; pub const DepositPerByte: Balance = MILLISBY / 1_000_000; - // The lazy deletion runs inside on_initialize. - pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * - RuntimeBlockWeights::get().max_block; + // Fallback value if storage deposit limit not set by the user + pub const DefaultDepositLimit: Balance = contracts_deposit(1024, 1024 * 1024); pub Schedule: pallet_contracts::Schedule = Default::default(); } @@ -676,6 +675,7 @@ impl pallet_contracts::Config for Runtime { type CallFilter = Nothing; type DepositPerItem = DepositPerItem; type DepositPerByte = DepositPerByte; + type DefaultDepositLimit = DefaultDepositLimit; type CallStack = [pallet_contracts::Frame; 5]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; @@ -684,8 +684,6 @@ impl pallet_contracts::Config for Runtime { XvmExtension, AssetsExtension>, ); - type DeletionQueueDepth = ConstU32<128>; - type DeletionWeightLimit = DeletionWeightLimit; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type MaxCodeLen = ConstU32<{ 123 * 1024 }>; @@ -833,6 +831,13 @@ parameter_types! { ); pub PrecompilesValue: Precompiles = ShibuyaNetworkPrecompiles::<_, _>::new(); pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per PoV size. Value is calculated as: + /// + /// max_gas_limit = max_tx_ref_time / WEIGHT_PER_GAS = max_pov_size * gas_limit_pov_size_ratio + /// gas_limit_pov_size_ratio = ceil((max_tx_ref_time / WEIGHT_PER_GAS) / max_pov_size) + /// + /// Equals 4 for values used by Shibuya runtime. + pub const GasLimitPovSizeRatio: u64 = 4; } impl pallet_evm::Config for Runtime { @@ -856,6 +861,7 @@ impl pallet_evm::Config for Runtime { type Timestamp = Timestamp; type OnCreate = (); type FindAuthor = FindAuthorTruncated; + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type WeightInfo = pallet_evm::weights::SubstrateWeight; } @@ -1017,6 +1023,7 @@ impl pallet_democracy::Config for Runtime { impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; + type WeightInfo = pallet_sudo::weights::SubstrateWeight; } parameter_types! { @@ -1316,6 +1323,11 @@ parameter_types! { pub type Migrations = (frame_support::migrations::RemovePallet,); +type EventRecord = frame_system::EventRecord< + ::RuntimeEvent, + ::Hash, +>; + impl fp_self_contained::SelfContainedCall for RuntimeCall { type SignedInfo = H160; @@ -1571,7 +1583,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1583,6 +1595,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + ::Runner::call( from, to, @@ -1595,6 +1643,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or_else(|| ::config()), @@ -1611,7 +1661,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1623,6 +1673,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + #[allow(clippy::or_fun_call)] // suggestion not helpful here ::Runner::create( from, @@ -1635,6 +1721,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or(::config()), @@ -1707,11 +1795,7 @@ impl_runtime_apis! { } } - impl pallet_contracts::ContractsApi< - Block, AccountId, Balance, BlockNumber, Hash, - > - for Runtime - { + impl pallet_contracts::ContractsApi for Runtime { fn call( origin: AccountId, dest: AccountId, @@ -1719,9 +1803,19 @@ impl_runtime_apis! { gas_limit: Option, storage_deposit_limit: Option, input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { + ) -> pallet_contracts_primitives::ContractExecResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, true, pallet_contracts::Determinism::Enforced) + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + pallet_contracts::Determinism::Enforced, + ) } fn instantiate( @@ -1732,10 +1826,19 @@ impl_runtime_apis! { code: pallet_contracts_primitives::Code, data: Vec, salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult - { + ) -> pallet_contracts_primitives::ContractInstantiateResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, true) + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + ) } fn upload_code( diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index f36fe14106..5e210564b7 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -45,7 +45,7 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_ethereum::PostLogContent; -use pallet_evm::{FeeCalculator, Runner}; +use pallet_evm::{FeeCalculator, GasWeightMapping, Runner}; use pallet_transaction_payment::{ FeeDetails, Multiplier, RuntimeDispatchInfo, TargetedFeeAdjustment, }; @@ -611,9 +611,8 @@ impl pallet_vesting::Config for Runtime { parameter_types! { pub const DepositPerItem: Balance = MILLISDN / 1_000_000; pub const DepositPerByte: Balance = MILLISDN / 1_000_000; - // The lazy deletion runs inside on_initialize. - pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * - RuntimeBlockWeights::get().max_block; + // Fallback value if storage deposit limit not set by the user + pub const DefaultDepositLimit: Balance = contracts_deposit(1024, 1024 * 1024); pub Schedule: pallet_contracts::Schedule = Default::default(); } @@ -632,12 +631,11 @@ impl pallet_contracts::Config for Runtime { type CallFilter = Nothing; type DepositPerItem = DepositPerItem; type DepositPerByte = DepositPerByte; + type DefaultDepositLimit = DefaultDepositLimit; type CallStack = [pallet_contracts::Frame; 5]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; type ChainExtension = (); - type DeletionQueueDepth = ConstU32<128>; - type DeletionWeightLimit = DeletionWeightLimit; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type MaxCodeLen = ConstU32<{ 123 * 1024 }>; @@ -774,6 +772,13 @@ parameter_types! { ); pub PrecompilesValue: Precompiles = ShidenNetworkPrecompiles::<_, _>::new(); pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per PoV size. Value is calculated as: + /// + /// max_gas_limit = max_tx_ref_time / WEIGHT_PER_GAS = max_pov_size * gas_limit_pov_size_ratio + /// gas_limit_pov_size_ratio = ceil((max_tx_ref_time / WEIGHT_PER_GAS) / max_pov_size) + /// + /// Equals 4 for values used by Shiden runtime. + pub const GasLimitPovSizeRatio: u64 = 4; } impl pallet_evm::Config for Runtime { @@ -795,6 +800,7 @@ impl pallet_evm::Config for Runtime { type Timestamp = Timestamp; type OnCreate = (); type FindAuthor = FindAuthorTruncated; + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type WeightInfo = pallet_evm::weights::SubstrateWeight; } @@ -813,6 +819,7 @@ impl pallet_ethereum::Config for Runtime { impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; + type WeightInfo = pallet_sudo::weights::SubstrateWeight; } pub struct EvmRevertCodeHandler; @@ -1072,6 +1079,11 @@ parameter_types! { pub type Migrations = (frame_support::migrations::RemovePallet,); +type EventRecord = frame_system::EventRecord< + ::RuntimeEvent, + ::Hash, +>; + impl fp_self_contained::SelfContainedCall for RuntimeCall { type SignedInfo = H160; @@ -1327,7 +1339,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1339,6 +1351,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + ::Runner::call( from, to, @@ -1351,6 +1399,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or_else(|| ::config()), @@ -1367,7 +1417,7 @@ impl_runtime_apis! { max_priority_fee_per_gas: Option, nonce: Option, estimate: bool, - _access_list: Option)>>, + access_list: Option)>>, ) -> Result { let config = if estimate { let mut config = ::config().clone(); @@ -1379,6 +1429,42 @@ impl_runtime_apis! { let is_transactional = false; let validate = true; + + // Reused approach from Moonbeam since Frontier implementation doesn't support this + let mut estimated_transaction_len = data.len() + + // to: 20 + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 210; + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + #[allow(clippy::or_fun_call)] // suggestion not helpful here ::Runner::create( from, @@ -1391,6 +1477,8 @@ impl_runtime_apis! { Vec::new(), is_transactional, validate, + weight_limit, + proof_size_base_cost, config .as_ref() .unwrap_or(::config()), @@ -1463,11 +1551,7 @@ impl_runtime_apis! { } } - impl pallet_contracts::ContractsApi< - Block, AccountId, Balance, BlockNumber, Hash, - > - for Runtime - { + impl pallet_contracts::ContractsApi for Runtime { fn call( origin: AccountId, dest: AccountId, @@ -1475,9 +1559,19 @@ impl_runtime_apis! { gas_limit: Option, storage_deposit_limit: Option, input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { + ) -> pallet_contracts_primitives::ContractExecResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, true, pallet_contracts::Determinism::Enforced) + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + pallet_contracts::Determinism::Enforced, + ) } fn instantiate( @@ -1488,20 +1582,19 @@ impl_runtime_apis! { code: pallet_contracts_primitives::Code, data: Vec, salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult - { + ) -> pallet_contracts_primitives::ContractInstantiateResult { let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, true) - } - - fn upload_code( - origin: AccountId, - code: Vec, - storage_deposit_limit: Option, - determinism: pallet_contracts::Determinism, - ) -> pallet_contracts_primitives::CodeUploadResult - { - Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism) + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::UnsafeCollect, + ) } fn get_storage(