diff --git a/runtime/battery-station/src/lib.rs b/runtime/battery-station/src/lib.rs index 4939109db..dc8ec3d5d 100644 --- a/runtime/battery-station/src/lib.rs +++ b/runtime/battery-station/src/lib.rs @@ -46,20 +46,12 @@ use frame_support::{ weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee, Weight}, }; use frame_system::{EnsureRoot, EnsureWithSuccess}; -use orml_currencies::Call::transfer; use pallet_collective::{EnsureProportionAtLeast, PrimeDefaultVote}; use sp_runtime::traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256}; #[cfg(feature = "std")] use sp_version::NativeVersion; use zeitgeist_primitives::types::*; -use zrml_prediction_markets::Call::{ - buy_complete_set, create_market, dispute, edit_market, redeem_shares, report, sell_complete_set, -}; -use zrml_swaps::Call::{ - force_pool_exit, pool_exit, pool_exit_with_exact_asset_amount, - pool_exit_with_exact_pool_amount, pool_join, pool_join_with_exact_asset_amount, - pool_join_with_exact_pool_amount, swap_exact_amount_in, swap_exact_amount_out, -}; +use zrml_swaps::Call::force_pool_exit; #[cfg(feature = "parachain")] use { frame_support::traits::{AsEnsureOriginWithArg, Everything, Nothing}, @@ -104,60 +96,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { state_version: 1, }; -#[derive(scale_info::TypeInfo)] -pub struct ContractsCallfilter; - -impl Contains for ContractsCallfilter { - fn contains(runtime_call: &RuntimeCall) -> bool { - #[allow(clippy::match_like_matches_macro)] - match runtime_call { - RuntimeCall::System(inner_call) => match inner_call { - SystemCall::remark { .. } => true, - SystemCall::remark_with_event { .. } => true, - _ => false, - }, - RuntimeCall::AssetManager(transfer { .. }) => true, - RuntimeCall::PredictionMarkets(inner_call) => { - match inner_call { - buy_complete_set { .. } => true, - dispute { .. } => true, - // Only allow markets using Authorized or Court dispute mechanism - create_market { - dispute_mechanism: - Some(MarketDisputeMechanism::Authorized) - | Some(MarketDisputeMechanism::Court), - .. - } => true, - edit_market { - dispute_mechanism: - Some(MarketDisputeMechanism::Authorized) - | Some(MarketDisputeMechanism::Court), - .. - } => true, - redeem_shares { .. } => true, - report { .. } => true, - sell_complete_set { .. } => true, - _ => false, - } - } - RuntimeCall::Swaps(inner_call) => match inner_call { - pool_exit { .. } => true, - pool_exit_with_exact_asset_amount { .. } => true, - pool_exit_with_exact_pool_amount { .. } => true, - pool_join { .. } => true, - pool_join_with_exact_asset_amount { .. } => true, - pool_join_with_exact_pool_amount { .. } => true, - swap_exact_amount_in { .. } => true, - swap_exact_amount_out { .. } => true, - _ => false, - }, - RuntimeCall::Orderbook(_) => true, - RuntimeCall::Parimutuel(_) => true, - _ => false, - } - } -} - #[derive(scale_info::TypeInfo)] pub struct IsCallable; diff --git a/runtime/battery-station/src/parameters.rs b/runtime/battery-station/src/parameters.rs index cf967016d..7515f102c 100644 --- a/runtime/battery-station/src/parameters.rs +++ b/runtime/battery-station/src/parameters.rs @@ -90,16 +90,7 @@ parameter_types! { pub const TechnicalCommitteeMotionDuration: BlockNumber = 7 * BLOCKS_PER_DAY; // Contracts - pub const ContractsCodeHashLockupDepositPercent: Perbill = Perbill::from_percent(10); - pub const ContractsDefaultDepositLimit: Balance = deposit(16, 16 * 1024 * 1024); - pub const ContractsDepositPerByte: Balance = deposit(0,1); - pub const ContractsDepositPerItem: Balance = deposit(1,0); - pub const ContractsMaxCodeLen: u32 = 123 * 1024; - pub const ContractsMaxDebugBufferLen: u32 = 2 * 1024 * 1024; pub const ContractsMaxDelegateDependencies: u32 = 32; - pub const ContractsMaxStorageKeyLen: u32 = 128; - pub const ContractsUnsafeUnstableInterface: bool = true; - pub ContractsSchedule: pallet_contracts::Schedule = Default::default(); // Court /// (Slashable) Bond that is provided for overriding the last appeal. diff --git a/runtime/common/src/fees.rs b/runtime/common/src/fees.rs index 3c02b7949..31c285378 100644 --- a/runtime/common/src/fees.rs +++ b/runtime/common/src/fees.rs @@ -318,7 +318,7 @@ macro_rules! fee_tests { use pallet_asset_tx_payment::OnChargeAssetTransaction; use sp_core::H256; use sp_runtime::BuildStorage; - use zeitgeist_primitives::constants::BASE; + use zeitgeist_primitives::constants::{BASE, MILLI}; fn run_with_system_weight(w: Weight, mut assertions: F) where @@ -603,7 +603,7 @@ macro_rules! fee_tests { decimals: 10, name: "Polkadot".as_bytes().to_vec().try_into().unwrap(), symbol: "DOT".as_bytes().to_vec().try_into().unwrap(), - existential_deposit: 5 * MILLIS, + existential_deposit: 5 * MILLI, location: Some(xcm::VersionedMultiLocation::V3( xcm::latest::MultiLocation::parent(), )), diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 0a139daaa..b0dd803ab 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -83,7 +83,8 @@ macro_rules! decl_common_types { use scale_info::TypeInfo; use sp_core::storage::ChildInfo; use sp_runtime::{ - generic, DispatchError, DispatchResult, RuntimeDebug, SaturatedConversion, + generic, BoundedBTreeMap, DispatchError, DispatchResult, RuntimeDebug, + SaturatedConversion, }; use zeitgeist_primitives::traits::{DeployPoolApi, DistributeFees, MarketCommonsPalletApi}; @@ -91,7 +92,70 @@ macro_rules! decl_common_types { type Address = sp_runtime::MultiAddress; - type Migrations = (); + type TrieId = BoundedVec>; + type CodeHash = ::Hash; + + // `ContractInfo` struct that we need for `ClearContractsChildTries` but pallet-contracts + // doesn't expose publicly. + #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] + pub struct ContractInfo { + pub trie_id: TrieId, + pub code_hash: CodeHash, + pub storage_bytes: u32, + pub storage_items: u32, + pub storage_byte_deposit: Balance, + pub storage_item_deposit: Balance, + pub storage_base_deposit: Balance, + pub delegate_dependencies: + BoundedBTreeMap, + } + + struct ClearContractsChildTries; + + impl OnRuntimeUpgrade for ClearContractsChildTries { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + log::info!("ClearContractsChildTries: Starting..."); + let mut total_reads = 0u64; + let mut total_writes = 0u64; + for (_, contract_info) in storage_key_iter::( + b"Contracts", + b"ContractInfoOf", + ) { + let trie_id = contract_info.trie_id; + let inner_trie_id = trie_id.into_inner(); + let child_info = ChildInfo::new_default(&inner_trie_id); + let multi_removal_result = child::clear_storage(&child_info, None, None); + let writes = multi_removal_result.loops as u64; + log::info!( + "ClearContractsChildTries: Cleared trie {:?} in {:?} loops", + inner_trie_id, + writes + ); + total_reads = total_reads.saturating_add(1); + total_writes = total_writes.saturating_add(writes); + } + log::info!("ClearContractsChildTries: Done!"); + ::DbWeight::get() + .reads_writes(total_reads, total_writes) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, DispatchError> { + Ok(vec![]) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), DispatchError> { + Ok(()) + } + } + + parameter_types! { + pub const ContractsPalletStr: &'static str = "Contracts"; + } + type DeleteContracts = RemovePallet; + + type Migrations = (ClearContractsChildTries, DeleteContracts); pub type Executive = frame_executive::Executive< Runtime, @@ -317,7 +381,6 @@ macro_rules! create_runtime { Identity: pallet_identity::{Call, Event, Pallet, Storage} = 30, Utility: pallet_utility::{Call, Event, Pallet, Storage} = 31, Proxy: pallet_proxy::{Call, Event, Pallet, Storage} = 32, - Contracts: pallet_contracts = 33, // Third-party AssetManager: orml_currencies::{Call, Pallet, Storage} = 40, @@ -734,37 +797,6 @@ macro_rules! impl_config_traits { type WeightInfo = weights::pallet_collective::WeightInfo; } - impl pallet_contracts::Config for Runtime { - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; - type CallFilter = ContractsCallfilter; - type CallStack = [pallet_contracts::Frame; 5]; - type ChainExtension = (); - type Debug = (); - type DefaultDepositLimit = ContractsDefaultDepositLimit; - type CodeHashLockupDepositPercent = ContractsCodeHashLockupDepositPercent; - type Currency = Balances; - type DepositPerItem = ContractsDepositPerItem; - type DepositPerByte = ContractsDepositPerByte; - type Environment = (); - type MaxCodeLen = ContractsMaxCodeLen; - type MaxDebugBufferLen = ContractsMaxDebugBufferLen; - type MaxDelegateDependencies = ContractsMaxDelegateDependencies; - type MaxStorageKeyLen = ContractsMaxStorageKeyLen; - #[cfg(not(feature = "runtime-benchmarks"))] - type Migrations = (); - #[cfg(feature = "runtime-benchmarks")] - type Migrations = pallet_contracts::migration::codegen::BenchMigrations; - type Randomness = RandomnessCollectiveFlip; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type RuntimeHoldReason = RuntimeHoldReason; - type Schedule = ContractsSchedule; - type Time = Timestamp; - type UnsafeUnstableInterface = ContractsUnsafeUnstableInterface; - type WeightPrice = pallet_transaction_payment::Pallet; - type WeightInfo = weights::pallet_contracts::WeightInfo; - } - impl pallet_democracy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -1316,10 +1348,6 @@ macro_rules! impl_config_traits { #[macro_export] macro_rules! create_runtime_api { ($($additional_apis:tt)*) => { - // Prints debug output of the `contracts` pallet to stdout if the node is - // started with `-lruntime::contracts=debug`. - const CONTRACTS_DEBUG_OUTPUT: bool = true; - impl_runtime_apis! { #[cfg(feature = "parachain")] impl cumulus_primitives_core::CollectCollationInfo for Runtime { @@ -1410,7 +1438,6 @@ macro_rules! create_runtime_api { list_benchmark!(list, extra, pallet_balances, Balances); list_benchmark!(list, extra, pallet_bounties, Bounties); list_benchmark!(list, extra, pallet_collective, AdvisoryCommittee); - list_benchmark!(list, extra, pallet_contracts, Contracts); list_benchmark!(list, extra, pallet_democracy, Democracy); list_benchmark!(list, extra, pallet_identity, Identity); list_benchmark!(list, extra, pallet_membership, AdvisoryCommitteeMembership); @@ -1499,7 +1526,6 @@ macro_rules! create_runtime_api { add_benchmark!(params, batches, pallet_balances, Balances); add_benchmark!(params, batches, pallet_bounties, Bounties); add_benchmark!(params, batches, pallet_collective, AdvisoryCommittee); - add_benchmark!(params, batches, pallet_contracts, Contracts); add_benchmark!(params, batches, pallet_democracy, Democracy); add_benchmark!(params, batches, pallet_identity, Identity); add_benchmark!(params, batches, pallet_membership, AdvisoryCommitteeMembership); @@ -1550,77 +1576,6 @@ macro_rules! create_runtime_api { } } - impl pallet_contracts::ContractsApi< - Block, - AccountId, - Balance, - BlockNumber, - Hash, - EventRecord - > 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(RuntimeBlockWeights::get().max_block); - 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( - 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(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate( - origin, - value, - gas_limit, - storage_deposit_limit, - code, - data, - salt, - pallet_contracts::DebugInfo::UnsafeDebug, - pallet_contracts::CollectEvents::UnsafeCollect, - ) - } - - 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) - } - - fn get_storage( - address: AccountId, - key: Vec, - ) -> pallet_contracts_primitives::GetStorageResult { - Contracts::get_storage(address, key) - } - } - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { fn query_fee_details( uxt: ::Extrinsic, diff --git a/runtime/zeitgeist/src/lib.rs b/runtime/zeitgeist/src/lib.rs index 129f55058..09a5d9663 100644 --- a/runtime/zeitgeist/src/lib.rs +++ b/runtime/zeitgeist/src/lib.rs @@ -94,8 +94,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { state_version: 1, }; -pub type ContractsCallfilter = Nothing; - #[derive(scale_info::TypeInfo)] pub struct IsCallable; @@ -109,10 +107,6 @@ impl Contains for IsCallable { use orml_currencies::Call::update_balance; use pallet_balances::Call::{force_set_balance, force_transfer}; use pallet_collective::Call::set_members; - use pallet_contracts::Call::{ - call, call_old_weight, instantiate, instantiate_old_weight, remove_code, - set_code as set_code_contracts, - }; use pallet_vesting::Call::force_vested_transfer; use zrml_prediction_markets::Call::{ admin_move_market_to_closed, admin_move_market_to_resolved, @@ -139,16 +133,6 @@ impl Contains for IsCallable { _ => true, } } - // Permissioned contracts: Only deployable via utility.dispatch_as(...) - RuntimeCall::Contracts(inner_call) => match inner_call { - call { .. } => true, - call_old_weight { .. } => true, - instantiate { .. } => true, - instantiate_old_weight { .. } => true, - remove_code { .. } => true, - set_code_contracts { .. } => true, - _ => false, - }, // Membership is managed by the respective Membership instance RuntimeCall::Council(set_members { .. }) => false, #[cfg(feature = "parachain")] diff --git a/runtime/zeitgeist/src/parameters.rs b/runtime/zeitgeist/src/parameters.rs index 7c167e58b..dfdc0f972 100644 --- a/runtime/zeitgeist/src/parameters.rs +++ b/runtime/zeitgeist/src/parameters.rs @@ -90,16 +90,7 @@ parameter_types! { pub const TechnicalCommitteeMotionDuration: BlockNumber = 7 * BLOCKS_PER_DAY; // Contracts - pub const ContractsCodeHashLockupDepositPercent: Perbill = Perbill::from_percent(10); - pub const ContractsDefaultDepositLimit: Balance = deposit(16, 16 * 1024 * 1024); - pub const ContractsDepositPerByte: Balance = deposit(0,1); - pub const ContractsDepositPerItem: Balance = deposit(1,0); - pub const ContractsMaxCodeLen: u32 = 123 * 1024; - pub const ContractsMaxStorageKeyLen: u32 = 128; - pub const ContractsMaxDebugBufferLen: u32 = 2 * 1024 * 1024; pub const ContractsMaxDelegateDependencies: u32 = 32; - pub const ContractsUnsafeUnstableInterface: bool = false; - pub ContractsSchedule: pallet_contracts::Schedule = Default::default(); // Court /// (Slashable) Bond that is provided for overriding the last appeal.