Skip to content

Commit

Permalink
Remove contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann committed Dec 3, 2024
1 parent 29f16e4 commit 0de1a58
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 210 deletions.
64 changes: 1 addition & 63 deletions runtime/battery-station/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -104,60 +96,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

#[derive(scale_info::TypeInfo)]
pub struct ContractsCallfilter;

impl Contains<RuntimeCall> 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;

Expand Down
9 changes: 0 additions & 9 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime> = Default::default();

// Court
/// (Slashable) Bond that is provided for overriding the last appeal.
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>(w: Weight, mut assertions: F)
where
Expand Down Expand Up @@ -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(),
)),
Expand Down
177 changes: 66 additions & 111 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,79 @@ 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};

pub type Block = generic::Block<Header, UncheckedExtrinsic>;

type Address = sp_runtime::MultiAddress<AccountId, ()>;

type Migrations = ();
type TrieId = BoundedVec<u8, ConstU32<128>>;
type CodeHash = <Runtime as frame_system::Config>::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<CodeHash, Balance, ContractsMaxDelegateDependencies>,
}

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::<AccountId, ContractInfo, Twox64Concat>(
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!");
<Runtime as frame_system::Config>::DbWeight::get()
.reads_writes(total_reads, total_writes)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), DispatchError> {
Ok(())
}
}

parameter_types! {
pub const ContractsPalletStr: &'static str = "Contracts";
}
type DeleteContracts = RemovePallet<ContractsPalletStr, RocksDbWeight>;

type Migrations = (ClearContractsChildTries, DeleteContracts);

pub type Executive = frame_executive::Executive<
Runtime,
Expand Down Expand Up @@ -317,7 +381,6 @@ macro_rules! create_runtime {
Identity: pallet_identity::{Call, Event<T>, Pallet, Storage} = 30,
Utility: pallet_utility::{Call, Event, Pallet, Storage} = 31,
Proxy: pallet_proxy::{Call, Event<T>, Pallet, Storage} = 32,
Contracts: pallet_contracts = 33,

// Third-party
AssetManager: orml_currencies::{Call, Pallet, Storage} = 40,
Expand Down Expand Up @@ -734,37 +797,6 @@ macro_rules! impl_config_traits {
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
}

impl pallet_contracts::Config for Runtime {
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type CallFilter = ContractsCallfilter;
type CallStack = [pallet_contracts::Frame<Runtime>; 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<Runtime>;
type WeightInfo = weights::pallet_contracts::WeightInfo<Runtime>;
}

impl pallet_democracy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand Down Expand Up @@ -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<Block> for Runtime {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult<Balance, EventRecord> {
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<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_contracts_primitives::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance, EventRecord> {
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<u8>,
storage_deposit_limit: Option<Balance>,
determinism: pallet_contracts::Determinism,
) -> pallet_contracts_primitives::CodeUploadResult<Hash, Balance>
{
Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism)
}

fn get_storage(
address: AccountId,
key: Vec<u8>,
) -> pallet_contracts_primitives::GetStorageResult {
Contracts::get_storage(address, key)
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
fn query_fee_details(
uxt: <Block as BlockT>::Extrinsic,
Expand Down
16 changes: 0 additions & 16 deletions runtime/zeitgeist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

pub type ContractsCallfilter = Nothing;

#[derive(scale_info::TypeInfo)]
pub struct IsCallable;

Expand All @@ -109,10 +107,6 @@ impl Contains<RuntimeCall> 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,
Expand All @@ -139,16 +133,6 @@ impl Contains<RuntimeCall> 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")]
Expand Down
Loading

0 comments on commit 0de1a58

Please sign in to comment.