From 140bc7166ee5f89da5631451634f8c2b4423a703 Mon Sep 17 00:00:00 2001 From: Michal Handzlik Date: Tue, 6 Dec 2022 11:12:59 +0100 Subject: [PATCH] Bring back pallet contracts API to runtime --- bin/runtime/src/lib.rs | 78 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/bin/runtime/src/lib.rs b/bin/runtime/src/lib.rs index 7cb73330f2..679c9fa354 100644 --- a/bin/runtime/src/lib.rs +++ b/bin/runtime/src/lib.rs @@ -26,7 +26,6 @@ use frame_support::{ }; use frame_system::{EnsureRoot, EnsureSignedBy}; pub use pallet_balances::Call as BalancesCall; -use pallet_contracts::weights::WeightInfo; pub use pallet_timestamp::Call as TimestampCall; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; pub use primitives::Balance; @@ -105,10 +104,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("aleph-node"), impl_name: create_runtime_str!("aleph-node"), authoring_version: 1, - spec_version: 44, + spec_version: 45, impl_version: 1, apis: RUNTIME_API_VERSIONS, - transaction_version: 13, + transaction_version: 14, state_version: 0, }; @@ -642,6 +641,9 @@ impl pallet_utility::Config for Runtime { type PalletsOrigin = OriginCaller; } +// Prints debug output of the `contracts` pallet to stdout if the node is started with `-lruntime::contracts=debug`. +const CONTRACTS_DEBUG_OUTPUT: bool = true; + parameter_types! { // Refundable deposit per storage item pub const DepositPerItem: Balance = 32 * DEPOSIT_PER_BYTE; @@ -650,12 +652,7 @@ parameter_types! { // How much weight of each block can be spent on the lazy deletion queue of terminated contracts pub DeletionWeightLimit: Weight = Perbill::from_percent(10) * BlockWeights::get().max_block; // 40ms // Maximum size of the lazy deletion queue of terminated contracts. - // The weight needed for decoding the queue should be less or equal than a tenth - // of the overall weight dedicated to the lazy deletion. - pub DeletionQueueDepth: u32 = DeletionWeightLimit::get().saturating_div(( - ::WeightInfo::on_initialize_per_queue_item(1) - - ::WeightInfo::on_initialize_per_queue_item(0) - ).ref_time() * 10).ref_time() as u32; // 2228 + pub const DeletionQueueDepth: u32 = 128; pub Schedule: pallet_contracts::Schedule = Default::default(); } @@ -921,6 +918,69 @@ impl_runtime_apis! { } } + impl pallet_contracts::ContractsApi + for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + input_data: Vec, + ) -> pallet_contracts_primitives::ContractExecResult { + let gas_limit = gas_limit.unwrap_or(BlockWeights::get().max_block); + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + CONTRACTS_DEBUG_OUTPUT + ) + } + + fn instantiate( + origin: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + code: pallet_contracts_primitives::Code, + data: Vec, + salt: Vec, + ) -> pallet_contracts_primitives::ContractInstantiateResult + { + let gas_limit = gas_limit.unwrap_or(BlockWeights::get().max_block); + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + CONTRACTS_DEBUG_OUTPUT + ) + } + + fn upload_code( + origin: AccountId, + code: Vec, + storage_deposit_limit: Option, + ) -> pallet_contracts_primitives::CodeUploadResult + { + Contracts::bare_upload_code(origin, code, storage_deposit_limit) + } + + fn get_storage( + address: AccountId, + key: Vec, + ) -> pallet_contracts_primitives::GetStorageResult { + Contracts::get_storage(address, key) + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade() -> (Weight, Weight) {